mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-19 22:04:01 -06:00
Sql: SqlExp support for 'union all' (as operator+)
git-svn-id: svn://ultimatepp.org/upp/trunk@7701 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
deac71fc8e
commit
eb87f9b6ef
4 changed files with 49 additions and 30 deletions
|
|
@ -8,6 +8,13 @@ SqlSet operator|(const SqlSet& s1, const SqlSet& s2) {
|
|||
return SqlSet(s1(SqlSet::SET, ~SQLITE3) + " union " + s2(SqlSet::SET, ~SQLITE3), SqlSet::SETOP);
|
||||
}
|
||||
|
||||
SqlSet operator+(const SqlSet& s1, const SqlSet& s2)
|
||||
{
|
||||
if(s1.IsEmpty()) return s2;
|
||||
if(s2.IsEmpty()) return s1;
|
||||
return SqlSet(s1(SqlSet::SET, ~SQLITE3) + " union all " + s2(SqlSet::SET, ~SQLITE3), SqlSet::SETOP);
|
||||
}
|
||||
|
||||
SqlSet operator&(const SqlSet& s1, const SqlSet& s2) {
|
||||
if(s1.IsEmpty()) return s2;
|
||||
if(s2.IsEmpty()) return s1;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@ SqlSelect& SqlSelect::operator|=(const SqlSelect& s2) {
|
|||
return SetOp(s2, " union ");
|
||||
}
|
||||
|
||||
SqlSelect& SqlSelect::operator+=(const SqlSelect& s2)
|
||||
{
|
||||
return SetOp(s2, " union all ");
|
||||
}
|
||||
|
||||
SqlSelect& SqlSelect::operator&=(const SqlSelect& s2) {
|
||||
return SetOp(s2, " intersect ");
|
||||
}
|
||||
|
|
@ -60,6 +65,13 @@ SqlSelect operator-(const SqlSelect& s1, const SqlSelect& s2) {
|
|||
return s;
|
||||
}
|
||||
|
||||
SqlSelect operator+(const SqlSelect& s1, const SqlSelect& s2)
|
||||
{
|
||||
SqlSelect s = s1;
|
||||
s += s2;
|
||||
return s;
|
||||
}
|
||||
|
||||
SqlSelect& SqlSelect::Where(const SqlBool& exp) {
|
||||
if(!exp.IsTrue() && !exp.IsEmpty())
|
||||
text << " where " << ~exp;
|
||||
|
|
|
|||
|
|
@ -433,6 +433,7 @@ class Sql;
|
|||
#define E__SqlVal(I) const SqlVal& p##I
|
||||
|
||||
SqlSet operator|(const SqlSet& s1, const SqlSet& s2); // union
|
||||
SqlSet operator+(const SqlSet& s1, const SqlSet& s2); // union all
|
||||
SqlSet operator&(const SqlSet& s1, const SqlSet& s2); // intersection
|
||||
SqlSet operator-(const SqlSet& s1, const SqlSet& s2); // difference
|
||||
|
||||
|
|
@ -462,6 +463,7 @@ public:
|
|||
SqlSet& operator<<(const SqlVal& val) { return Cat(val); }
|
||||
|
||||
SqlSet& operator|=(const SqlSet& set) { return *this = *this | set; }
|
||||
SqlSet& operator+=(const SqlSet& set) { return *this = *this + set; }
|
||||
SqlSet& operator&=(const SqlSet& set) { return *this = *this & set; }
|
||||
SqlSet& operator-=(const SqlSet& set) { return *this = *this - set; }
|
||||
|
||||
|
|
@ -604,9 +606,10 @@ __Expand(E__QSelect);
|
|||
|
||||
bool IsEmpty() { return text.IsEmpty(); }
|
||||
|
||||
SqlSelect& operator|=(const SqlSelect& s2);
|
||||
SqlSelect& operator&=(const SqlSelect& s2);
|
||||
SqlSelect& operator-=(const SqlSelect& s2);
|
||||
SqlSelect& operator|=(const SqlSelect& s2); // union
|
||||
SqlSelect& operator&=(const SqlSelect& s2); // intersect
|
||||
SqlSelect& operator-=(const SqlSelect& s2); // except
|
||||
SqlSelect& operator+=(const SqlSelect& s2); // union all
|
||||
|
||||
//Deprecated!!!
|
||||
bool Execute(Sql& sql) const { return SqlStatement(*this).Execute(sql); }
|
||||
|
|
@ -617,9 +620,10 @@ __Expand(E__QSelect);
|
|||
Value Fetch() const { return SqlStatement(*this).Fetch(); }
|
||||
};
|
||||
|
||||
SqlSelect operator|(const SqlSelect& s1, const SqlSelect& s2);
|
||||
SqlSelect operator&(const SqlSelect& s1, const SqlSelect& s2);
|
||||
SqlSelect operator-(const SqlSelect& s1, const SqlSelect& s2);
|
||||
SqlSelect operator|(const SqlSelect& s1, const SqlSelect& s2); // union
|
||||
SqlSelect operator&(const SqlSelect& s1, const SqlSelect& s2); // intersect
|
||||
SqlSelect operator-(const SqlSelect& s1, const SqlSelect& s2); // except
|
||||
SqlSelect operator+(const SqlSelect& s1, const SqlSelect& s2); // union all
|
||||
|
||||
inline SqlSelect SelectAll() { return SqlSelect(SqlAll()); }
|
||||
inline SqlSelect Select(const SqlSet& set) { return SqlSelect(set); }
|
||||
|
|
|
|||
|
|
@ -264,30 +264,26 @@ topic "SqlExp in examples";
|
|||
:: [s0;%- [C1 select COLUMN]&]
|
||||
[s0;%- [C1 from TABLE]&]
|
||||
[s0;%- [C1 where ][*C1 not exists (select COLUMN from TABLE1)]]
|
||||
:: [s0;%- [C1 Select(COLUMN)]&]
|
||||
[s0;%- [C1 .From(TABLE)]&]
|
||||
[s0;%- [C1 .Where(COLUMN `=`= (][*C1 Select(COLUMN1).From(TABLE1) `|]&]
|
||||
[s0;%- [*C1 Select(COLUMN2).From(TABLE2)][C1 ))]]
|
||||
:: [s0;%- [C1 select COLUMN]&]
|
||||
[s0;%- [C1 from TABLE]&]
|
||||
[s0;%- [C1 where COLUMN in (][*C1 select COLUMN1 from TABLE1]&]
|
||||
[s0;%- [*C1 union (select COLUMN2 from TABLE2)][C1 )]]
|
||||
:: [s0;%- [C1 Select(COLUMN)]&]
|
||||
[s0;%- [C1 .From(TABLE)]&]
|
||||
[s0;%- [C1 .Where(COLUMN `=`= (][*C1 Select(COLUMN1).From(TABLE1) `&]&]
|
||||
[s0;%- [*C1 Select(COLUMN2).From(TABLE2)][C1 ))]]
|
||||
:: [s0;%- [C1 select COLUMN]&]
|
||||
[s0;%- [C1 from TABLE]&]
|
||||
[s0;%- [C1 where COLUMN in (][*C1 select COLUMN1 from TABLE1]&]
|
||||
[s0;%- [*C1 intersect (select COLUMN2 from TABLE2)][C1 )]]
|
||||
:: [s0;%- [C1 Select(COLUMN)]&]
|
||||
[s0;%- [C1 .From(TABLE)]&]
|
||||
[s0;%- [C1 .Where(COLUMN `=`= (][*C1 Select(COLUMN1).From(TABLE1) `-]&]
|
||||
[s0;%- [*C1 Select(COLUMN2).From(TABLE2)))]]
|
||||
:: [s0;%- [C1 select COLUMN]&]
|
||||
[s0;%- [C1 from TABLE]&]
|
||||
[s0;%- [C1 where COLUMN in (][*C1 select COLUMN1 from TABLE1]&]
|
||||
[s0;%- [*C1 minus (select COLUMN2 from TABLE2)][C1 )]]
|
||||
:: [s0;%- [C1 Select(COLUMN1)]&]
|
||||
[s0;%- [C1 .From(TABLE1)]&]
|
||||
[s0;%- [*C1 `|][C1 Select(COLUMN2).From(TABLE2)]]
|
||||
:: [s0;%- [C1 ((select COLUMN1 from TABLE1)]&]
|
||||
[s0;%- [*C1 union ][C1 (select COLUMN2 from TABLE2))]]
|
||||
:: [s0;%- [C1 Select(COLUMN1)]&]
|
||||
[s0;%- [C1 .From(TABLE1)]&]
|
||||
[s0;%- [*C1 `+][C1 Select(COLUMN2).From(TABLE2)]]
|
||||
:: [s0;%- [C1 ((select COLUMN1 from TABLE1)]&]
|
||||
[s0;%- [*C1 union all][C1 (select COLUMN2 from TABLE2))]]
|
||||
:: [s0;%- [C1 Select(COLUMN1)]&]
|
||||
[s0;%- [C1 .From(TABLE1)]&]
|
||||
[s0;%- [*C1 `&][C1 Select(COLUMN2).From(TABLE2)]]
|
||||
:: [s0;%- [C1 ((select COLUMN1 from TABLE1)]&]
|
||||
[s0;%- [*C1 intersect ][C1 (select COLUMN2 from TABLE2))]]
|
||||
:: [s0;%- [C1 Select(COLUMN1)]&]
|
||||
[s0;%- [C1 .From(TABLE1)]&]
|
||||
[s0;%- [*C1 `-][C1 Select(COLUMN2).From(TABLE2)]]
|
||||
:: [s0;%- [C1 ((select COLUMN1 from TABLE1)]&]
|
||||
[s0;%- [*C1 except ][C1 (select COLUMN2 from TABLE2))]]
|
||||
:: [s0;%- [C1 Select(COLUMN)]&]
|
||||
[s0;%- [C1 .From(TABLE)]&]
|
||||
[s0;%- [C1 .Where(COLUMN `=`= 0)]&]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue