////////////////////////////////////////////////////////////////////// // sql/template: SQL templates. NAMESPACE_UPP void __sqltempl__instantiation__(Gate2); // a weird compiler bug template C& FetchContainer(C& container, Sql& cursor, Gate2 progress = false) { int done = 0; typedef typename C::ValueType VT; VT T; while(cursor.Fetch(T)) { container.Add(T); if(progress(++done, 0)) throw AbortExc(); } return container; } template C& FetchContainerExc(C& container, const SqlSelect& set, SqlSession& session APPSQLSESSION, Gate2 progress = false) { Sql cursor(session); set.Force(cursor); return FetchContainer(container, cursor, progress); } template C& FetchContainer(C& container, const SqlSelect& set, SqlSession& session, Gate2 progress = false) { try { FetchContainerExc(container, set, session, progress); } catch(Exc e) { // ShowExc(e); } return container; } #ifndef NOAPPSQL template C& FetchContainer(C& container, const SqlSelect& set, Gate2 progress = false) { return FetchContainer(container, set, SQL.GetSession(), progress); } #endif//NOAPPSQL template SqlSet SetOf(I begin, I end) { SqlSet set; while(begin != end) { set |= SqlVal(*begin); ++begin; } return set; } template SqlSet ColumnSetOf(I begin, I end) { SqlSet set; while(begin != end) { set |= SqlCol(*begin); ++begin; } return set; } template inline SqlSet SetOf(const C& container) { return SetOf(container.Begin(), container.End()); } template inline SqlSet ColumnSetOf(const C& container) { return ColumnSetOf(container.Begin(), container.End()); } extern const char *txtFnTSqlTemplateFetchSeqKeyNull(); extern const char *txtFnTSqlTemplateFetchSeqNotFound(); template T& FetchSeq(T& data, SqlId key, Value value, SqlId table, Sql& cursor APPSQLCURSOR) { if(IsNull(value)) throw SqlExc(NFormat(s_(FnTSqlTemplateFetchSeqKeyNull()), ~table, ~key)); Select(data).From(table).Where(key == value).Force(cursor); if(!cursor.Fetch(data)) throw SqlExc(NFormat(s_(FnTSqlTemplateFetchSeqNotFound()), StdFormat(value), ~table, ~key)); return data; } template inline T& FetchSeq(T& data, SqlId key, Value value, Sql& cursor APPSQLCURSOR) { return FetchSeq(data, key, value, SqlId(T::TableName), cursor); } template inline T FetchSeq(SqlId key, Value value, SqlId table, Sql& cursor APPSQLCURSOR, T * = 0) { T temp; return FetchSeq(temp, key, value, table, cursor); } template inline T FetchSeq(SqlId key, Value value, Sql& cursor APPSQLCURSOR, T * = 0) { return FetchSeq(key, value, SqlId(T::TableName), cursor); } template T& FetchSchemaSeq(T& data, SqlId key, Value value, SqlId table, Sql& cursor APPSQLCURSOR) { if(IsNull(value)) throw SqlExc(NFormat(s_(FnTSqlTemplateFetchSeqKeyNull()), ~table, ~key)); Select(data).FromSchema(table).Where(key == value).Force(cursor); if(!cursor.Fetch(data)) throw SqlExc(NFormat(s_(FnTSqlTemplateFetchSeqNotFound()), StdFormat(value), ~table)); return data; } template inline T& FetchSchemaSeq(T& data, SqlId key, Value value, Sql& cursor APPSQLCURSOR) { return FetchSchemaSeq(data, key, value, SqlId(T::TableName), cursor); } template inline T FetchSchemaSeq(SqlId key, Value value, SqlId table, Sql& cursor APPSQLCURSOR, T * = 0) { T temp; return FetchSchemaSeq(temp, key, value, table, cursor); } template inline T FetchSchemaSeq(SqlId key, Value value, Sql& cursor APPSQLCURSOR, T * = 0) { return FetchSeq(key, value, SqlId(T::TableName), cursor); } template SqlSelect SelectWhere(SqlBool cond = true, T * = 0) { return Select(T::ColumnSet()).From(SqlCol(T::TableName)).Where(cond); } template SqlSelect SelectSchemaWhere(SqlBool cond = true, T * = 0) { return Select(T::ColumnSet()).FromSchema(SqlCol(T::TableName)).Where(cond); } END_UPP_NAMESPACE