mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 22:02:58 -06:00
+Sql: new method SqlUpdate::Column(const SqlSet& cols, const SqlSet& vals) supports Oracle-style multicolumn SET in UPDATE (UPDATE xxx set (A, B, C) = select A, B, C from yyy)
+TSql: new variants Force[Schema]Update support incremental updates according to comparison of 'old' and 'new' row data git-svn-id: svn://ultimatepp.org/upp/trunk@2570 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
83d052093d
commit
6388462fa4
6 changed files with 60 additions and 1 deletions
|
|
@ -236,7 +236,7 @@ struct sReadFields : public FieldOperator {
|
|||
Sql *sql;
|
||||
|
||||
void Field(const char *name, Ref f) {
|
||||
f = (*sql)[SqlId(name)];
|
||||
sql->GetColumn(SqlId(name), f);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -262,6 +262,17 @@ void Sql::GetColumn(int i, Ref r) const {
|
|||
cn->GetColumn(i, r);
|
||||
}
|
||||
|
||||
void Sql::GetColumn(SqlId colid, Ref r) const
|
||||
{
|
||||
String s = ~colid;
|
||||
for(int i = 0; i < cn->info.GetCount(); i++)
|
||||
if(cn->info[i].name == s) {
|
||||
GetColumn(i, r);
|
||||
return;
|
||||
}
|
||||
r.SetNull();
|
||||
}
|
||||
|
||||
Value Sql::operator[](int i) const {
|
||||
Value v;
|
||||
cn->GetColumn(i, v);
|
||||
|
|
|
|||
|
|
@ -295,6 +295,11 @@ void SqlUpdate::Column(SqlId column, SqlVal val) {
|
|||
set.Cat(SqlVal(SqlVal(column), " = ", val, SqlS::COMP));
|
||||
}
|
||||
|
||||
void SqlUpdate::Column(const SqlSet& cols, const SqlSet& val)
|
||||
{
|
||||
set.Cat(SqlVal(SqlS(cols(), SqlS::HIGH), " = ", SqlS(val(), SqlS::HIGH), SqlS::COMP));
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// deprecated
|
||||
|
||||
|
|
|
|||
|
|
@ -613,7 +613,9 @@ class SqlUpdate {
|
|||
|
||||
public:
|
||||
void Column(SqlId column, SqlVal val);
|
||||
void Column(const SqlSet& cols, const SqlSet& val);
|
||||
SqlUpdate& operator()(SqlId column, SqlVal val) { Column(column, val); return *this; }
|
||||
SqlUpdate& operator()(const SqlSet& cols, const SqlSet& val) { Column(cols, val); return *this; }
|
||||
SqlUpdate& operator()(Fields f);
|
||||
SqlUpdate& Where(SqlBool w) { where = w; return *this; }
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ public:
|
|||
int GetColumns() const;
|
||||
|
||||
void GetColumn(int i, Ref r) const;
|
||||
void GetColumn(SqlId colid, Ref r) const;
|
||||
Value operator[](int i) const;
|
||||
Value operator[](SqlId colid) const;
|
||||
const SqlColumnInfo& GetColumnInfo(int i) const { return cn->info[i]; }
|
||||
|
|
|
|||
|
|
@ -377,6 +377,24 @@ void ForceUpdate(SqlId table, Fields nf, SqlId key, const Value& keyval, Sql& cu
|
|||
cursor & helper.Get(table).Where(key == keyval);
|
||||
}
|
||||
|
||||
void ForceUpdate(Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor)
|
||||
{
|
||||
ForceUpdate(SqlId(), nf, of, key, keyval, cursor);
|
||||
}
|
||||
|
||||
void ForceUpdate(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(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);
|
||||
}
|
||||
|
||||
void ForceDelete(SqlId table, SqlId key, const Value& keyval, Sql& cursor)
|
||||
{
|
||||
if(!cursor.Delete(table, key, keyval))
|
||||
|
|
@ -413,6 +431,24 @@ void ForceSchemaUpdate(SqlId table, Fields nf, SqlId key, const Value& keyval, S
|
|||
helper.GetSchema(table).Where(key == keyval).Force(cursor);
|
||||
}
|
||||
|
||||
void ForceSchemaUpdate(Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor)
|
||||
{
|
||||
ForceSchemaUpdate(SqlId(), nf, of, key, keyval, cursor);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void ForceSchemaDelete(SqlId table, SqlId key, const Value& keyval, Sql& cursor)
|
||||
{
|
||||
Delete(SchemaTable(table)).Where(key == keyval).Force(cursor);
|
||||
|
|
|
|||
|
|
@ -61,12 +61,16 @@ void ForceInsert(Fields nf, Sql& cursor APPSQLCURSOR);
|
|||
void ForceInsert(SqlId table, Fields nf, Sql& cursor APPSQLCURSOR);
|
||||
void ForceUpdate(Fields nf, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceUpdate(SqlId table, Fields nf, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceUpdate(Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceUpdate(SqlId table, Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceDelete(SqlId table, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceExecute(const String& s, Sql& cursor APPSQLCURSOR);
|
||||
void ForceSchemaInsert(Fields nf, Sql& cursor APPSQLCURSOR);
|
||||
void ForceSchemaInsert(SqlId table, Fields nf, Sql& cursor APPSQLCURSOR);
|
||||
void ForceSchemaUpdate(Fields nf, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceSchemaUpdate(SqlId table, Fields nf, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceSchemaUpdate(Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceSchemaUpdate(SqlId table, Fields nf, Fields of, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
void ForceSchemaDelete(SqlId table, SqlId key, const Value& keyval, Sql& cursor APPSQLCURSOR);
|
||||
|
||||
bool IsNotEmpty(const SqlSelect& select, Sql& cursor APPSQLCURSOR);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue