mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Sql: SqlExp support for Insert...From...GroupBy...Having, S_* now has Get and GetColumnIds
git-svn-id: svn://ultimatepp.org/upp/trunk@6365 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
abf2649909
commit
b219ba0db1
4 changed files with 42 additions and 10 deletions
|
|
@ -302,12 +302,19 @@ SqlInsert::operator SqlStatement() const {
|
|||
String s = "insert into " + table.Quoted();
|
||||
if(!set1.IsEmpty()) {
|
||||
s << set1();
|
||||
if(from.IsEmpty() && where.IsEmpty()) {
|
||||
if(from.IsEmpty() && where.IsEmpty() && groupby.IsEmpty()) {
|
||||
if(!set2.IsEmpty())
|
||||
s << " values " << set2();
|
||||
}
|
||||
else
|
||||
s << ' ' + SqlStatement(Select(set2).From(from).Where(where)).GetText();
|
||||
else {
|
||||
SqlSelect sel;
|
||||
sel = Select(set2).From(from).Where(where);
|
||||
if(!groupby.IsEmpty())
|
||||
sel.GroupBy(groupby);
|
||||
if(!having.IsEmpty())
|
||||
sel.Having(having);
|
||||
s << ' ' + SqlStatement(sel).GetText();
|
||||
}
|
||||
}
|
||||
return SqlStatement(s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -628,6 +628,8 @@ class SqlInsert {
|
|||
SqlSet set2;
|
||||
SqlSet from;
|
||||
SqlBool where;
|
||||
SqlSet groupby;
|
||||
SqlBool having;
|
||||
|
||||
public:
|
||||
void Column(const SqlId& column, SqlVal val);
|
||||
|
|
@ -640,6 +642,11 @@ public:
|
|||
SqlInsert& From(SqlSet _from) { from = _from; return *this; }
|
||||
SqlInsert& From(SqlVal from) { return From(SqlSet(from)); }
|
||||
SqlInsert& Where(SqlBool w) { where = w; return *this; }
|
||||
SqlInsert& GroupBy(const SqlSet& columnset) { groupby = columnset; return *this; }
|
||||
SqlInsert& GroupBy(SqlVal a) { return GroupBy(SqlSet(a)); }
|
||||
SqlInsert& GroupBy(SqlVal a, SqlVal b) { return GroupBy(SqlSet(a, b)); }
|
||||
SqlInsert& GroupBy(SqlVal a, SqlVal b, SqlVal c) { return GroupBy(SqlSet(a, b, c)); }
|
||||
SqlInsert& Having(const SqlBool& exp) { having = exp; return *this; }
|
||||
|
||||
SqlId GetTable() const { return table; }
|
||||
SqlId GetKeyColumn() const { return keycolumn; }
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ struct S_##Table b { \
|
|||
public:\
|
||||
void Shrink(); \
|
||||
void Clear(); \
|
||||
static const char TableName[]; \
|
||||
static const SqlSet& ColumnSet(); \
|
||||
static SqlSet ColumnSet(const String& prefix); \
|
||||
static SqlSet Of(SqlId table); \
|
||||
static const char TableName[]; \
|
||||
static const SqlSet& ColumnSet(); \
|
||||
static SqlSet ColumnSet(const String& prefix); \
|
||||
static SqlSet Of(SqlId table); \
|
||||
static const Vector<SqlId>& GetColumnIds(); \
|
||||
void FieldLayoutRaw(FieldOperator& f, const String& prefix = String()); \
|
||||
void FieldLayout(FieldOperator& f); \
|
||||
operator Fields() { return callback(this, &S_##Table::FieldLayout); } \
|
||||
|
|
@ -16,6 +17,7 @@ public:\
|
|||
bool operator!=(const S_##Table& x) const { return !EqualFields(const_cast<S_##Table&>(*this), const_cast<S_##Table&>(x)); } \
|
||||
String ToString() const { return AsString((Fields)const_cast<S_##Table&>(*this)); } \
|
||||
Value Get(SqlId column_id) const; \
|
||||
ValueMap Get() const; \
|
||||
S_##Table();
|
||||
|
||||
#define TYPE(Table) CODETYPE(Table, __NIL)
|
||||
|
|
|
|||
|
|
@ -126,15 +126,31 @@ void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\
|
|||
|
||||
#include SCHEMADIALECT
|
||||
|
||||
// S_*::Get(SqlId column_id)
|
||||
// S_*::Get(SqlId column_id) const
|
||||
|
||||
#define TYPE(x) Value S_##x::Get(SqlId column_id) const { String col = ~column_id;
|
||||
#define COLUMN(type, ctype, name, width, prec) static String _x0_x_##name(#name); if(_x0_x_##name == col) return name;
|
||||
#define END_TYPE return Value(); }
|
||||
#define COLUMN(type, ctype, name, width, prec) static String _x0_x_##name(#name); if(_x0_x_##name == col) return name;
|
||||
#define END_TYPE return Value(); }
|
||||
|
||||
#include SCHEMADIALECT
|
||||
|
||||
|
||||
// ValueMap S_*::Get() const
|
||||
|
||||
#define TYPE(x) ValueMap S_##x::Get() const { ValueMap vm;
|
||||
#define COLUMN(type, ctype, name, width, prec) static String _x0_x_##name(#name); vm.Add(_x0_x_##name, name);
|
||||
#define END_TYPE return vm; }
|
||||
|
||||
#include SCHEMADIALECT
|
||||
|
||||
// static const Vector<SqlId>& GetColumnIds();
|
||||
|
||||
#define TYPE(x) const Vector<SqlId>& S_##x::GetColumnIds() { static Vector<SqlId> cols; ONCELOCK {
|
||||
#define COLUMN(type, ctype, name, width, prec) cols.Add(#name);
|
||||
#define END_TYPE } return cols; }
|
||||
|
||||
#include SCHEMADIALECT
|
||||
|
||||
// Introspection
|
||||
|
||||
#define TYPE(x) void SchDbInfo##x() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue