.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
This commit is contained in:
rylek 2012-02-18 23:38:08 +00:00
parent 99097aaeb8
commit 679c08db9f
2 changed files with 30 additions and 28 deletions

View file

@ -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<String>& SyncStrColumn(Vector<String>& dest, SqlId col, const SqlVal& tab
return dest;
}
Vector<String> LoadSchemaStrColumn(SqlId column, const SqlVal& table, SqlSession& session, bool order)
Vector<String> LoadSchemaStrColumn(SqlId column, const SqlId& table, SqlSession& session, bool order)
{
Vector<String> result;
FetchContainer(result, Select(column).FromSchema(table), session);
@ -479,7 +479,7 @@ Vector<String> LoadSchemaStrColumn(SqlId column, const SqlVal& table, SqlSession
return result;
}
Vector<String>& SyncSchemaStrColumn(Vector<String>& dest, SqlId col, const SqlVal& table, SqlSession& session)
Vector<String>& SyncSchemaStrColumn(Vector<String>& 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<String, SqlColumnInfo> Describe(const SqlVal& table, Sql& cursor)
return map;
}
VectorMap<String, SqlColumnInfo> DescribeSchema(const SqlVal& table, Sql& cursor)
VectorMap<String, SqlColumnInfo> 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);
}

View file

@ -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<String, SqlColumnInfo> Describe(const SqlVal& table, Sql& cursor APPSQLCURSOR);
VectorMap<String, SqlColumnInfo> DescribeSchema(const SqlVal& table, Sql& cursor APPSQLCURSOR);
VectorMap<String, SqlColumnInfo> 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<String> LoadStrColumn(SqlId column, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false);
Vector<String>& SyncStrColumn(Vector<String>& dest, SqlId col, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false);
Vector<String> LoadSchemaStrColumn(SqlId column, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false);
Vector<String>& SyncSchemaStrColumn(Vector<String>& dest, SqlId col, const SqlVal& table, SqlSession& session APPSQLSESSION);
Vector<String> LoadSchemaStrColumn(SqlId column, const SqlId& table, SqlSession& session APPSQLSESSION, bool order = false);
Vector<String>& SyncSchemaStrColumn(Vector<String>& dest, SqlId col, const SqlId& table, SqlSession& session APPSQLSESSION);
SqlVal GetCsVal(const SqlVal& val); // replaces CH for sorts
SqlVal GetCs(const char *col);