From c722e8329beb8cd0faa4e7186a8af5fe47f5041c Mon Sep 17 00:00:00 2001 From: rylek Date: Sat, 18 Feb 2012 23:38:08 +0000 Subject: [PATCH] .TSql/util.h,cpp: fixed schema-related functions to match changes in SqlId git-svn-id: svn://ultimatepp.org/upp/trunk@4604 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/TSql/util.cpp | 34 ++++++++++++++++++---------------- uppsrc/TSql/util.h | 24 ++++++++++++------------ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/uppsrc/TSql/util.cpp b/uppsrc/TSql/util.cpp index c48fd14a4..ac5b169e3 100644 --- a/uppsrc/TSql/util.cpp +++ b/uppsrc/TSql/util.cpp @@ -67,7 +67,7 @@ public: } SqlInsert Get(const SqlVal& from_table) const { return GetRaw(Nvl(~from_table, table)); } - SqlInsert GetSchema(const SqlVal& from_table) const { return GetRaw(SchemaTableName(Nvl(~from_table, table))); } + SqlInsert GetSchema(const SqlId& from_table) const { return GetRaw(SchemaTableName(Nvl(~from_table, table))); } private: SqlInsert GetRaw(const String& dest) const @@ -97,7 +97,7 @@ public: operator bool () const { return columns.GetCount(); } SqlUpdate Get(const SqlVal& from_table) const { return GetRaw(Nvl(~from_table, table)); } - SqlUpdate GetSchema(const SqlVal& from_table) const { return GetRaw(SchemaTableName(Nvl(~from_table, table))); } + SqlUpdate GetSchema(const SqlId& from_table) const { return GetRaw(SchemaTableName(Nvl(~from_table, table))); } private: SqlUpdate GetRaw(const String& dest) const @@ -197,7 +197,7 @@ String SchemaTableName(const String& table) return s + '.' + table; } -SqlVal SchemaTable(const SqlVal& table) +SqlId SchemaTable(const SqlId& table) { return SqlId(SchemaTableName(~table)); } @@ -470,7 +470,7 @@ Vector& SyncStrColumn(Vector& dest, SqlId col, const SqlVal& tab return dest; } -Vector LoadSchemaStrColumn(SqlId column, const SqlVal& table, SqlSession& session, bool order) +Vector LoadSchemaStrColumn(SqlId column, const SqlId& table, SqlSession& session, bool order) { Vector result; FetchContainer(result, Select(column).FromSchema(table), session); @@ -479,7 +479,7 @@ Vector LoadSchemaStrColumn(SqlId column, const SqlVal& table, SqlSession return result; } -Vector& SyncSchemaStrColumn(Vector& dest, SqlId col, const SqlVal& table, SqlSession& session) +Vector& SyncSchemaStrColumn(Vector& dest, SqlId col, const SqlId& table, SqlSession& session) { if(dest.IsEmpty()) dest = LoadSchemaStrColumn(col, table, session); @@ -501,12 +501,12 @@ bool IsNotEmpty(const SqlVal& table, SqlId column, const Value& value, Sql& curs return IsNotEmpty(table, column == value, cursor); } -bool IsNotSchemaEmpty(const SqlVal& table, const SqlBool& cond, Sql& cursor) +bool IsNotSchemaEmpty(const SqlId& table, const SqlBool& cond, Sql& cursor) { return IsNotEmpty(Select(ROWNUM).FromSchema(table).Where(cond), cursor); } -bool IsNotSchemaEmpty(const SqlVal& table, SqlId column, const Value& value, Sql& cursor) +bool IsNotSchemaEmpty(const SqlId& table, SqlId column, const Value& value, Sql& cursor) { return IsNotSchemaEmpty(table, column == value, cursor); } @@ -593,34 +593,36 @@ SqlSet DeleteHint(const char *hint, const SqlVal& table) return SqlSet(String().Cat() << "delete /*+ " << hint << " */ from " << ~table, SqlSet::SETOP); } -SqlSet DeleteSchemaHint(const char *hint, const SqlVal& table) +SqlSet DeleteSchemaHint(const char *hint, const SqlId& table) { return DeleteHint(hint, SchemaTable(table)); } -SqlVal Alias(const SqlVal& value, const SqlVal& alias) +SqlVal Alias(const SqlId& value, const SqlId& alias) { if(~value == ~alias) return value; - return SqlId(~value + SqlCase(MSSQL, " as ")(" ") + ~alias); + StringBuffer out; + out << ~value << (char)SQLC_AS << ~alias; + return SqlId((String)out); } -SqlVal SchemaAlias(const SqlVal& table, const SqlVal& alias) +SqlVal SchemaAlias(const SqlId& table, const SqlId& alias) { return Alias(SchemaTable(table), alias); } -SqlVal SchemaAlias(const SqlVal& table) +SqlVal SchemaAlias(const SqlId& table) { return SchemaAlias(table, table); } -SqlId SchemaId(SqlId table_id, SqlId alias_id) +SqlId SchemaId(const SqlId& table_id, const SqlId& alias_id) { return SqlId(SchemaTableName(~table_id) + SqlCase(MSSQL, " as ")(" ") + ~alias_id); } -SqlId SchemaId(SqlId table_id) +SqlId SchemaId(const SqlId& table_id) { return SchemaId(table_id, table_id); } @@ -637,7 +639,7 @@ VectorMap Describe(const SqlVal& table, Sql& cursor) return map; } -VectorMap DescribeSchema(const SqlVal& table, Sql& cursor) +VectorMap DescribeSchema(const SqlId& table, Sql& cursor) { return Describe(SchemaTable(table), cursor); } @@ -647,7 +649,7 @@ int64 SelectCount(const SqlVal& table, const SqlBool& cond, Sql& cursor) return Select(SqlCountRows()).From(table).Where(cond).Fetch(cursor); } -int64 SelectSchemaCount(const SqlVal& table, const SqlBool& cond, Sql& cursor) +int64 SelectSchemaCount(const SqlId& table, const SqlBool& cond, Sql& cursor) { return Select(SqlCountRows()).FromSchema(table).Where(cond).Fetch(cursor); } diff --git a/uppsrc/TSql/util.h b/uppsrc/TSql/util.h index 79fb1af62..b2d075d9b 100644 --- a/uppsrc/TSql/util.h +++ b/uppsrc/TSql/util.h @@ -33,7 +33,7 @@ private: void SetSchema(const String& schema); String GetSchema(); String SchemaTableName(const String& table); -SqlVal SchemaTable(const SqlVal& table); +SqlId SchemaTable(const SqlId& table); String GetInsertString(Fields nf, bool optimize = true); String GetSchemaInsertString(Fields nf, bool optimize = true); @@ -90,11 +90,11 @@ bool IsNotSchemaEmpty(const SqlVal& table, SqlId column, const #endif -SqlVal Alias(const SqlVal& value, const SqlVal& alias); -SqlVal SchemaAlias(const SqlVal& table, const SqlVal& alias); -SqlVal SchemaAlias(const SqlVal& table); -SqlId SchemaId(SqlId table, SqlId alias); -SqlId SchemaId(SqlId table); +SqlVal Alias(const SqlId& value, const SqlId& alias); +SqlVal SchemaAlias(const SqlId& table, const SqlId& alias); +SqlVal SchemaAlias(const SqlId& table); +SqlId SchemaId(const SqlId& table, const SqlId& alias); +SqlId SchemaId(const SqlId& table); inline SqlInsert InsertSchema(SqlId table) { return SqlInsert(SqlId(SchemaTableName(~table))); } inline SqlUpdate UpdateSchema(SqlId table) { return SqlUpdate(SqlId(SchemaTableName(~table))); } @@ -107,23 +107,23 @@ SqlSelect SelectHint(const char *hint, __List##I(E__SqlVal)); __Expand(E__SelectHint); */ SqlSet DeleteHint(const char *hint, const SqlVal& table); -SqlSet DeleteSchemaHint(const char *hint, const SqlVal& table); +SqlSet DeleteSchemaHint(const char *hint, const SqlId& table); VectorMap Describe(const SqlVal& table, Sql& cursor APPSQLCURSOR); -VectorMap DescribeSchema(const SqlVal& table, Sql& cursor APPSQLCURSOR); +VectorMap DescribeSchema(const SqlId& table, Sql& cursor APPSQLCURSOR); int64 SelectCount(const SqlVal& table, const SqlBool& cond, Sql& cursor); -int64 SelectSchemaCount(const SqlVal& table, const SqlBool& cond, Sql& cursor); +int64 SelectSchemaCount(const SqlId& table, const SqlBool& cond, Sql& cursor); #ifndef NOAPPSQL inline int64 SelectCount(const SqlVal& table, const SqlBool& cond = SqlBool::True()) { return SelectCount(table, cond, SQL); } -inline int64 SelectSchemaCount(const SqlVal& table, const SqlBool& cond = SqlBool::True()) { return SelectSchemaCount(table, cond, SQL); } +inline int64 SelectSchemaCount(const SqlId& table, const SqlBool& cond = SqlBool::True()) { return SelectSchemaCount(table, cond, SQL); } #endif Vector LoadStrColumn(SqlId column, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false); Vector& SyncStrColumn(Vector& dest, SqlId col, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false); -Vector LoadSchemaStrColumn(SqlId column, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false); -Vector& SyncSchemaStrColumn(Vector& dest, SqlId col, const SqlVal& table, SqlSession& session APPSQLSESSION); +Vector LoadSchemaStrColumn(SqlId column, const SqlId& table, SqlSession& session APPSQLSESSION, bool order = false); +Vector& SyncSchemaStrColumn(Vector& dest, SqlId col, const SqlId& table, SqlSession& session APPSQLSESSION); SqlVal GetCsVal(const SqlVal& val); // replaces CH for sorts SqlVal GetCs(const char *col);