void ForceSchemaUpdate(SqlId table, Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor) { String tbl; VectorMap<Id, Value> nmap = GetValueMap(nf, &tbl); VectorMap<Id, Value> omap = GetValueMap(of); SqlUpdate update(SqlId(SchemaTableName(Nvl(~table, tbl)))); for(int i = 0; i < nmap.GetCount(); i++) if(nmap[i] != omap.Get(nmap.GetKey(i), Value())) update(SqlId(nmap.GetKey(i)), nmap[i]); if(update) update.Where(key == keyval).Force(cursor); }
SqlUpdate::SqlUpdate(Fields f) { UpdateFieldOperator ufo; ufo.update = this; f(ufo); table = ufo.table; sel.Set(SqlSet(SqlId("X"))); }
SqlSelect SelectTable(Fields nf) { SqlUtil::SelectColumns helper; nf(helper); ASSERT(*helper.table != '$'); // cannot select from TYPE tables return Select(helper.columns).From(SqlId(helper.table)); }
SqlSet S_info::GetSet(const String& prefix) const { SqlSet set; for(int i = 0; i < column.GetCount(); i++) set << SqlId(prefix + column.GetKey(i)); return set; }
SqlSet S_info::GetOf(const SqlId& table) const { SqlSet set; for(int i = 0; i < ids.GetCount(); i++) set << SqlId(ids[i].Of(table)); return set; }
SqlVal Alias(const SqlId& value, const SqlId& alias) { if(~value == ~alias) return value; StringBuffer out; out << ~value << (char)SQLC_AS << ~alias; return SqlId((String)out); }
SqlVal GetCsAscii(const char* col) { return GetCsAsciiVal(SqlId(col)); }
SqlVal GetCs(const char* col) { return GetCsVal(SqlId(col)); }
SqlId SchemaId(const SqlId& table_id, const SqlId& alias_id) { return SqlId(SchemaTableName(~table_id) + SqlCode(MSSQL, " as ")(" ") + ~alias_id); }
virtual void Field(const char *name, Ref) { set->Cat(SqlId(name)); }
String ForceSchemaInsertRowid(Fields nf, Sql& cursor) { return ForceSchemaInsertRowid(SqlId(), nf, cursor); }
SqlId SchemaTable(const SqlId& table) { return SqlId(SchemaTableName(~table)); }
SqlBool RightJoin(SqlId tab1, SqlId tab2, SqlId key) { return key.Of(tab1).Quoted() == SqlId(key.Of(tab2).Quoted() + "(+)"); }
SqlBool LeftJoin(SqlId tab1, SqlId tab2, SqlId key) { return SqlId(key.Of(tab1).Quoted() + "(+)") == key.Of(tab2).Quoted(); }
SqlBool RightJoin(SqlVal v1, SqlVal v2) { return v1 == SqlId(~v2 + "(+)"); }
SqlBool LeftJoin(SqlVal v1, SqlVal v2) { return SqlId(~v1 + "(+)") == v2; }
void ForceSchemaInsert(Fields nf, Sql& cursor) { ForceSchemaInsert(SqlId(), nf, cursor); }
void ForceSchemaUpdate(Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor) { ForceSchemaUpdate(SqlId(), nf, of, key, keyval, cursor); }
SqlUpdate::SqlUpdate(const SqlId& table) : table(table) { sel.Set(SqlSet(SqlId("X"))); }
void Field(const char *name, Ref f) { sql->GetColumn(SqlId(name), f); }