My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
enum {
ORACLE = 1,
SQLITE3 = 2,
MY_SQL = 4,
MSSQL = 8,
PGSQL = 16,
FIREBIRD = 32, // not implemented yet
DB2 = 64, // not implemented yet
};

class SqlBool;
class SqlVal;
class SqlSet;
class SqlSelect;
class Case;

// ----------

struct FieldOperator {
String table;

void Table(const char *name) { table = name; }

virtual void Field(Ref f);
virtual void Field(const char *name, Ref f);

FieldOperator& operator()(const char *name, Ref f) { Field(name, f); return *this; }
FieldOperator& operator()(const String& name, Ref f) { Field(name, f); return *this; }
FieldOperator& operator()(Id id, Ref f) { Field(~id, f); return *this; }
FieldOperator& operator()(const char *name, bool& b);
FieldOperator& operator()(const String& name, bool& b) { return (*this)(~name, b); }
FieldOperator& operator()(Id id, bool& b) { return (*this)(~id, b); }

FieldOperator();
virtual ~FieldOperator();
};

typedef Callback1<FieldOperator&> Fields;

struct FieldDumper : public FieldOperator {
String s;
virtual void Field(const char *name, Ref f);
};

template <class T>
String DumpFields(T& s) {
FieldDumper dump;
s.FieldLayout(dump);
return dump.s;
}

void td_scalar(SqlSet& set, const String& prefix, const char *x);
void td_array(SqlSet& set, const String& prefix, const char *x, int cnt);
void td_var(SqlSet& set, const String& prefix, const char *x, SqlSet (*f)(const String&));
void td_shrink(String *array, int cnt);

bool EqualFields(Fields a, Fields b);
String AsString(Fields a);

// ----------

enum {
SQLC_IF = 1,
SQLC_ELSEIF = 2,
SQLC_ELSE = 3,
SQLC_ENDIF = 4,
SQLC_DATE = 5,
SQLC_TIME = 6,
SQLC_STRING = 7,
SQLC_BINARY = 8,
SQLC_ID = 9, // '\t'
SQLC_OF = 10,
SQLC_AS = 11,
SQLC_COMMA = 12,
};

class SqlCase {
String s;

public:
SqlCase(byte cond, const String& text);
SqlCase operator()(byte cond, const String& text);

String operator()(const String& text);
String operator()();
};

String SqlCompile(byte dialect, const String& s);

String SqlFormat(int x);
String SqlFormat(double x);
String SqlFormat(int64 x);
String SqlFormat(const char *s, int len);
String SqlFormat(const char *s);
String SqlFormat(const String& x);
String SqlFormat(Date x);
String SqlFormat(Time x);
String SqlFormat(const Value& x);
String SqlFormatBinary(const char *s, int l);
String SqlFormatBinary(const String& x);

class SqlId : Moveable<SqlId> {
protected:
Id id;

private:
void PutOf0(String& s, const SqlId& b) const;
void PutOf(String& s, const SqlId& b) const;

public:
static void UseQuotes(bool b = true);

bool IsEqual(const SqlId& b) const { return id == b.id; }
bool IsEqual(const Id& b) const { return id == b; }
bool IsNull() const { return id.IsNull(); }

operator const Id&() const { return id; }
const String& ToString() const { return id.ToString(); }
const String& operator~() const { return ToString(); }
String Quoted() const;

SqlId Of(SqlId id) const;
SqlId Of(const char *of) const;
SqlId As(const char *as) const;
SqlId As(SqlId id) const { return As(~id.ToString()); }
SqlId operator[](int i) const; // deprecated
SqlId operator&(const SqlId& s) const; // depreceted
SqlId operator[](const SqlId& id) const; // deprecated

SqlId operator()(SqlId p) const;

//$ SqlId operator()(SqlId p, SqlId p1, ...);
#define E__PutSqlId(I) PutOf(x, p##I)
#define E__SqlId(I) const SqlId& p##I
#define E__Of(I) \
SqlId operator()(const SqlId& p, __List##I(E__SqlId)) const { \
String x; \
PutOf0(x, p); \
__List##I(E__PutSqlId); \
return x; \
}
__Expand(E__Of)
#undef E__Of
#undef E__PutSqlId
#undef E__SqlId

SqlId() {}
SqlId(const char *s) : id(s) {}
SqlId(const String& s) : id(s) {}
SqlId(const Id& id) : id(id) {}
};

typedef SqlId SqlCol; // Deprecated

#define SQLID(x) const UPP::SqlId x(#x);
#define SQL_ID(n, x) const UPP::SqlId n(#x);

class SqlS : Moveable<SqlS> {
protected:
String text;
byte priority;

void Init(const SqlS& a, const char *o, int olen, const SqlS& b, int pr, int prb);

public:
enum PRIORITY {
EMPTY = 0,
LOW = 20,
SETOP = 50,
SET = 100,
LOR = 120,
LAND = 130,
TRUEVAL = 135,
FALSEVAL = 136,
COMP = 140,
ADD = 150,
MUL = 160,
UNARY = 170,
FN = 180,
HIGH = 200,
NULLVAL = 250,
};

String operator()() const;
String operator()(int at) const;
String operator()(int at, byte cond) const;
const String& operator~() const { return text; }
bool IsEmpty() const { return priority == EMPTY; }

SqlS() : priority(EMPTY) {}
SqlS(const char *s, int pr) : text(s), priority(pr) {}
SqlS(const String& s, int pr) : text(s), priority(pr) {}

force_inline SqlS(const SqlS& a, const char *op, const SqlS& b, int pr, int prb) { Init(a, op, strlen(op), b, pr, prb); }
force_inline SqlS(const SqlS& a, const char *op, const SqlS& b, int pr) { Init(a, op, strlen(op), b, pr, pr); }
};

class SqlVal : public SqlS, Moveable<SqlVal> {
public:
void SetNull() { text = "NULL"; priority = NULLVAL; }
void SetHigh(const String& s) { text = s; priority = HIGH; }
bool IsNull() const { return priority == NULLVAL; }

SqlVal As(const char *as) const;
SqlVal As(const SqlId& id) const;

SqlVal() {}
SqlVal(const String& s, int pr) : SqlS(s, pr) {}
SqlVal(const SqlS& a, const char *o, const SqlS& b, int pa, int pb)
: SqlS(a, o, b, pa, pb) {}
SqlVal(const SqlS& a, const char *o, const SqlS& b, int p)
: SqlS(a, o, b, p) {}

SqlVal(int x);
SqlVal(int64 x);
SqlVal(double x);
SqlVal(const String& x);
SqlVal(const char *x);
SqlVal(Date x);
SqlVal(Time x);
SqlVal(const Value& x);
SqlVal(const Nuller&);
SqlVal(const SqlId& id);
SqlVal(const SqlId& (*id)());
SqlVal(const Case& x);
};

SqlVal operator-(const SqlVal& a);
SqlVal operator+(const SqlVal& a, const SqlVal& b);
SqlVal operator-(const SqlVal& a, const SqlVal& b);
SqlVal operator*(const SqlVal& a, const SqlVal& b);
SqlVal operator/(const SqlVal& a, const SqlVal& b);
SqlVal operator%(const SqlVal& a, const SqlVal& b);
SqlVal operator|(const SqlVal& a, const SqlVal& b); // String concatenation

SqlVal& operator+=(SqlVal& a, const SqlVal& b);
SqlVal& operator-=(SqlVal& a, const SqlVal& b);
SqlVal& operator*=(SqlVal& a, const SqlVal& b);
SqlVal& operator/=(SqlVal& a, const SqlVal& b);
SqlVal& operator%=(SqlVal& a, const SqlVal& b);
SqlVal& operator|=(SqlVal& a, const SqlVal& b);

SqlVal SqlFunc(const char* name, const SqlVal& a);
SqlVal SqlFunc(const char* name, const SqlVal& a, const SqlVal& b);
SqlVal SqlFunc(const char* name, const SqlVal& a, const SqlVal& b, const SqlVal& c);
SqlVal SqlFunc(const char* nm, const SqlVal& a, const SqlVal& b, const SqlVal& c, const SqlVal& d);
SqlVal SqlFunc(const char* name, const SqlSet& set);

SqlVal Decode(const SqlVal& exp, const SqlSet& variants);
SqlVal Distinct(const SqlVal& exp);
SqlSet Distinct(const SqlSet& columns);
SqlVal All(const SqlVal& exp);
SqlSet All(const SqlSet& columns);
SqlId SqlAll();
SqlVal Count(const SqlVal& exp);
SqlVal Count(const SqlSet& exp);
SqlVal SqlCountRows();
SqlVal Descending(const SqlVal& exp);

SqlVal SqlMax(const SqlVal& a);
SqlVal SqlMin(const SqlVal& a);
SqlVal SqlSum(const SqlVal& a);

SqlVal Avg(const SqlVal& a);
SqlVal Stddev(const SqlVal& a);
SqlVal Variance(const SqlVal& a);

SqlVal Greatest(const SqlVal& a, const SqlVal& b);
SqlVal Least(const SqlVal& a, const SqlVal& b);

SqlVal ConvertCharset(const SqlVal& exp, const SqlVal& charset);
SqlVal ConvertAscii(const SqlVal& exp);
SqlVal Upper(const SqlVal& exp);
SqlVal Lower(const SqlVal& exp);
SqlVal Length(const SqlVal& exp);
SqlVal UpperAscii(const SqlVal& exp);
SqlVal Substr(const SqlVal& a, const SqlVal& b);
SqlVal Substr(const SqlVal& a, const SqlVal& b, const SqlVal& c);
SqlVal Instr(const SqlVal& a, const SqlVal& b);
SqlVal Wild(const char* s);

SqlVal SqlDate(const SqlVal& year, const SqlVal& month, const SqlVal& day);
SqlVal AddMonths(const SqlVal& date, const SqlVal& months);
SqlVal LastDay(const SqlVal& date);
SqlVal MonthsBetween(const SqlVal& date1, const SqlVal& date2);
SqlVal NextDay(const SqlVal& date);

SqlVal Cast(const char* type, const SqlId& a);

SqlVal SqlNvl(const SqlVal& a);
inline SqlVal Nvl(const SqlVal& a) { return SqlNvl(SqlVal(a)); }
inline SqlVal Nvl(const SqlId& a) { return SqlNvl(SqlVal(a)); }

SqlVal SqlNvl(const SqlVal& a, const SqlVal& b);
inline SqlVal Nvl(const SqlVal& a, const SqlVal& b) { return SqlNvl(SqlVal(a), SqlVal(b)); }
inline SqlVal Nvl(const SqlVal& a, const SqlId& b) { return SqlNvl(SqlVal(a), SqlVal(b)); }
inline SqlVal Nvl(const SqlId& a, const SqlVal& b) { return SqlNvl(SqlVal(a), SqlVal(b)); }
inline SqlVal Nvl(const SqlId& a, const SqlId& b) { return SqlNvl(SqlVal(a), SqlVal(b)); }

SqlVal Coalesce(const SqlVal& exp1, const SqlVal& exp2);
SqlVal Coalesce(const SqlVal& exp1, const SqlVal& exp2, const SqlVal& exp3);
SqlVal Coalesce(const SqlVal& exp1, const SqlVal& exp2, const SqlVal& exp3, const SqlVal& exp4);

SqlVal Prior(const SqlId& a);

SqlVal NextVal(const SqlId& a);
SqlVal CurrVal(const SqlId& a);
SqlVal OuterJoin(const SqlId& col); //Oracle only, deprecated

inline SqlVal operator++(const SqlId& a) { return NextVal(a); }

SqlVal SqlTxt(const char *s);

SqlVal SqlRowNum();

SqlVal SqlArg();

SqlVal SqlBinary(const String& data);

class SqlBool : public SqlS, Moveable<SqlBool> {
public:
void SetTrue();
void SetFalse();
void SetBool(bool b);

bool IsTrue() const { return priority == TRUEVAL; }
bool IsFalse() const { return priority == FALSEVAL; }
bool IsBool() const { return IsTrue() || IsFalse(); }
bool AsBool() const { ASSERT(IsBool()); return IsTrue(); }

SqlBool(const String& s, int pr) : SqlS(s, pr) {}
SqlBool(const SqlS& a, const char *o, const SqlS& b, int pa, int pb)
: SqlS(a, o, b, pa, pb) {}
SqlBool(const SqlS& a, const char *o, const SqlS& b, int p)
: SqlS(a, o, b, p) {}

static SqlBool True() { return SqlBool(true); }
static SqlBool False() { return SqlBool(false); }

SqlBool() {}
SqlBool(bool b) { SetBool(b); }
};

SqlBool operator!(const SqlBool& a);

SqlBool operator<(const SqlVal& a, const SqlVal& b);
SqlBool operator<=(const SqlVal& a, const SqlVal& b);
SqlBool operator>=(const SqlVal& a, const SqlVal& b);
SqlBool operator>(const SqlVal& a, const SqlVal& b);
SqlBool operator==(const SqlVal& a, const SqlVal& b);
SqlBool operator!=(const SqlVal& a, const SqlVal& b);

SqlBool IsSame(const SqlVal& a, const SqlVal& b);

SqlBool operator||(const SqlBool& a, const SqlBool& b);
SqlBool operator&&(const SqlBool& a, const SqlBool& b);
SqlBool operator- (const SqlBool& a, const SqlBool& b);
SqlBool operator|=(SqlBool& a, const SqlBool& b);
SqlBool operator&=(SqlBool& a, const SqlBool& b);

SqlBool SqlIsNull(const SqlVal& a);
SqlBool NotNull(const SqlVal& a);

inline SqlBool IsNull(const SqlId& a) { return SqlIsNull(a); }
inline SqlBool IsNull(const SqlVal& a) { return SqlIsNull(a); }

SqlBool Like(const SqlVal& a, const SqlVal& b, bool casesensitive = true);
SqlBool NotLike(const SqlVal& a, const SqlVal& b, bool casesensitive = true);

SqlBool Between(const SqlVal& a, const SqlVal& low, const SqlVal& high);
SqlBool NotBetween(const SqlVal&a, const SqlVal& low, const SqlVal& high);

SqlBool In(const SqlVal& a, const SqlSet& b);
SqlBool NotIn(const SqlVal& a, const SqlSet& b);
SqlBool Exists(const SqlSet& set);
SqlBool NotExists(const SqlSet& set);

SqlBool LikeUpperAscii(const SqlVal& a, const SqlVal& b);

SqlBool LeftJoin(SqlVal v1, SqlVal v2); // Deprecated
SqlBool RightJoin(SqlVal v1, SqlVal v2); // Deprecated

SqlBool Join(SqlId tab1, SqlId tab2, SqlId key); // Deprecated
SqlBool LeftJoin(SqlId tab1, SqlId tab2, SqlId key); // Deprecated
SqlBool RightJoin(SqlId tab1, SqlId tab2, SqlId key); // Deprecated

SqlBool SqlFirstRow(); // Oracle specific

inline SqlBool operator==(const SqlVal& a, const SqlSet& b) { return In(a, b); }
inline SqlBool operator!=(const SqlVal& a, const SqlSet& b) { return NotIn(a, b); }

inline const SqlVal& operator+(const SqlVal& a) { return a; }

class Case : public SqlS, Moveable<Case> {
public:
Case(const SqlBool& cond, const SqlVal& val)
{
text = "case when " + ~cond + " then " + ~val + " end";
}
Case& operator()(const SqlBool& cond, const SqlVal& val)
{
text.Insert(text.GetLength() - 4, " when " + ~cond + " then " + ~val);
return *this;
}
Case& operator()(const SqlVal& val)
{
text.Insert(text.GetLength() - 4, " else " + ~val);
return *this;
}
};

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); // intersection
SqlSet operator-(const SqlSet& s1, const SqlSet& s2); // difference

class SqlSet : Moveable<SqlSet> {
protected:
String text;
byte priority;

public:
enum PRIORITY {
SETOP = 50,
SET = 100,
HIGH = 200,
};

String operator~() const;
String operator()() const;
String operator()(int at) const;
String operator()(int at, byte cond) const;
bool IsEmpty() const { return text.IsEmpty(); }

SqlSet& Cat(const SqlVal& val); // adding a member
SqlSet& Cat(const SqlSet& set);
SqlSet& operator|=(const SqlVal& val) { return Cat(val); }
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; }

void Clear() { text.Clear(); }

SqlSet() {}
explicit SqlSet(const SqlVal& p0);

#define E__SqlSet(I) SqlSet(const SqlVal& p0, __List##I(E__SqlVal));
__Expand(E__SqlSet);

explicit SqlSet(Fields nfields);

SqlSet(const String& s, PRIORITY p) { text = s; priority = p; }
};

class SqlSetC : public SqlSet {
public:
SqlSetC(const String& s) { text = s; priority = SET; }
SqlSetC(const char* s) { text = s; priority = SET; }
};

class SqlStatement {
String text;

public:
SqlStatement() {}
explicit SqlStatement(const String& s) : text(s) {}

String Get(int dialect) const;
#ifndef flagNOAPPSQL
String Get() const;
#endif
String GetText() const { return text; }
bool IsEmpty() const { return text.IsEmpty(); }
operator bool() const { return !IsEmpty(); }

//Deprecated!!!
bool Execute(Sql& cursor) const;
void Force(Sql& cursor) const;
Value Fetch(Sql& cursor) const;
bool Execute() const;
void Force() const;
Value Fetch() const;
};

class SqlSelect {
String text;
String tables;
bool on;

SqlSelect& InnerJoin0(const String& table);
SqlSelect& LeftJoin0(const String& table);
SqlSelect& RightJoin0(const String& table);
SqlSelect& FullJoin0(const String& table);
SqlSelect& SetOp(const SqlSelect& s2, const char *op);

public:
SqlSelect& operator()(const SqlVal& val);

operator bool() const { return text.GetCount(); }

SqlSelect& Hint(const char *hint);

SqlSelect& Get();
SqlSelect& From(const SqlSet& set);
SqlSelect& From(const SqlId& table);
SqlSelect& From(const SqlId& table1, const SqlId& table2);
SqlSelect& From(const SqlId& table1, const SqlId& table2, const SqlId& table3);
SqlSelect& From(const SqlVal& a) { return From(SqlSet(a)); }

SqlSelect& InnerJoin(const SqlId& table) { return InnerJoin0(table.Quoted()); }
SqlSelect& LeftJoin(const SqlId& table) { return LeftJoin0(table.Quoted()); }
SqlSelect& RightJoin(const SqlId& table) { return RightJoin0(table.Quoted()); }
SqlSelect& FullJoin(const SqlId& table) { return FullJoin0(table.Quoted()); }

SqlSelect& InnerJoin(const SqlSet& set) { return InnerJoin0(~set(SqlSet::SET)); }
SqlSelect& LeftJoin(const SqlSet& set) { return LeftJoin0(~set(SqlSet::SET)); }
SqlSelect& RightJoin(const SqlSet& set) { return RightJoin0(~set(SqlSet::SET)); }
SqlSelect& FullJoin(const SqlSet& set) { return FullJoin0(~set(SqlSet::SET)); }

SqlSelect& InnerJoinRef(const SqlId& table);
SqlSelect& LeftJoinRef(const SqlId& table);
SqlSelect& RightJoinRef(const SqlId& table);
SqlSelect& FullJoinRef(const SqlId& table);

SqlSelect& Where(const SqlBool& exp);
SqlSelect& On(const SqlBool& exp);
SqlSelect& StartWith(const SqlBool& exp);
SqlSelect& ConnectBy(const SqlBool& exp);
SqlSelect& GroupBy(const SqlSet& columnset);
SqlSelect& Having(const SqlBool& exp);
SqlSelect& OrderBy(const SqlSet& columnset);
SqlSelect& ForUpdate();
SqlSelect& NoWait();

SqlSelect& GroupBy(SqlVal a) { return GroupBy(SqlSet(a)); }
SqlSelect& GroupBy(SqlVal a, SqlVal b) { return GroupBy(SqlSet(a, b)); }
SqlSelect& GroupBy(SqlVal a, SqlVal b, SqlVal c) { return GroupBy(SqlSet(a, b, c)); }
SqlSelect& OrderBy(SqlVal a) { return OrderBy(SqlSet(a)); }
SqlSelect& OrderBy(SqlVal a, SqlVal b) { return OrderBy(SqlSet(a, b)); }
SqlSelect& OrderBy(SqlVal a, SqlVal b, SqlVal c) { return OrderBy(SqlSet(a, b, c)); }
SqlSelect& Limit(int limit);
SqlSelect& Limit(int64 offset, int limit);
SqlSelect& Offset(int64 offset);

operator SqlSet() const { return SqlSet(text, SqlSet::SETOP); }
operator SqlStatement() const { return SqlStatement(text); }
SqlVal AsValue() const;
SqlSet AsTable(const SqlId& tab) const;

SqlSelect(Fields f);
SqlSelect(const SqlSet& s) { text = ~s; on = false; }
SqlSelect() { on = false; }
#define E__QSelect(I) SqlSelect(__List##I(E__SqlVal));
__Expand(E__QSelect);
#undef E__QSelect

bool IsEmpty() { return text.IsEmpty(); }

SqlSelect& operator|=(const SqlSelect& s2);
SqlSelect& operator&=(const SqlSelect& s2);
SqlSelect& operator-=(const SqlSelect& s2);

//Deprecated!!!
bool Execute(Sql& sql) const { return SqlStatement(*this).Execute(sql); }
void Force(Sql& sql) const { return SqlStatement(*this).Force(sql); }
Value Fetch(Sql& sql) const { return SqlStatement(*this).Fetch(sql); }
bool Execute() const { return SqlStatement(*this).Execute(); }
void Force() const { return SqlStatement(*this).Force(); }
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);

inline SqlSelect Select(const SqlSet& set) { return SqlSelect(set); }
inline SqlSelect Select(Fields f) { return SqlSelect(f); }

#define E__QSelect(I) SqlSelect Select(__List##I(E__SqlVal));
__Expand(E__QSelect);
#undef E__QSelect

class SqlDelete {
String text;

public:
SqlDelete& Where(const SqlBool& b);

operator SqlStatement() const { return SqlStatement(text); }

SqlDelete(SqlVal table);

//Deprecated!!!
bool Execute(Sql& sql) const { return SqlStatement(*this).Execute(sql); }
void Force(Sql& sql) const { return SqlStatement(*this).Force(sql); }
Value Fetch(Sql& sql) const { return SqlStatement(*this).Fetch(sql); }
bool Execute() const { return SqlStatement(*this).Execute(); }
void Force() const { return SqlStatement(*this).Force(); }
Value Fetch() const { return SqlStatement(*this).Fetch(); }
};

inline SqlDelete Delete(SqlVal table) { return SqlDelete(table); }

class SqlInsert {
SqlId table;
SqlId keycolumn;
SqlVal keyvalue;
SqlSet set1;
SqlSet set2;
SqlSet from;
SqlBool where;

public:
void Column(const SqlId& column, SqlVal val);
void Column(const SqlId& column) { Column(column, column); }
SqlInsert& operator()(const SqlId& column, SqlVal val) { Column(column, val); return *this; }
SqlInsert& operator()(const SqlId& column) { Column(column, column); return *this; }
SqlInsert& operator()(Fields f, bool nokey = false);
SqlInsert& From(const SqlId& from);
SqlInsert& From(SqlSet _from) { from = _from; return *this; }
SqlInsert& From(SqlVal from) { return From(SqlSet(from)); }
SqlInsert& Where(SqlBool w) { where = w; return *this; }

SqlId GetTable() const { return table; }
SqlId GetKeyColumn() const { return keycolumn; }
SqlVal GetKeyValue() const { return keyvalue; }

operator SqlStatement() const;
operator bool() const { return !set1.IsEmpty(); }

SqlInsert(const SqlId& table) : table(table) {}
SqlInsert(const SqlId& table, const SqlSet& set1, const SqlSet& set2)
: table(table), set1(set1), set2(set2) {}
SqlInsert(Fields f, bool nokey = false);

//Deprecated!!!
bool Execute(Sql& sql) const { return SqlStatement(*this).Execute(sql); }
void Force(Sql& sql) const { return SqlStatement(*this).Force(sql); }
Value Fetch(Sql& sql) const { return SqlStatement(*this).Fetch(sql); }
bool Execute() const { return SqlStatement(*this).Execute(); }
void Force() const { return SqlStatement(*this).Force(); }
Value Fetch() const { return SqlStatement(*this).Fetch(); }
};

inline SqlInsert Insert(const SqlId& table) { return SqlInsert(table); }
inline SqlInsert Insert(Fields f) { return SqlInsert(f); }
inline SqlInsert InsertNoKey(Fields f) { return SqlInsert(f, true); }

class SqlUpdate {
SqlId table;
SqlSet set;
SqlBool where;

public:
void Column(const SqlId& column, SqlVal val);
void Column(const SqlSet& cols, const SqlSet& val);
SqlUpdate& operator()(const 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; }

operator SqlStatement() const;

operator bool() const { return !set.IsEmpty(); }

SqlUpdate(const SqlId& table) : table(table) {}
SqlUpdate(Fields f);

//Deprecated!!!
bool Execute(Sql& sql) const { return SqlStatement(*this).Execute(sql); }
void Force(Sql& sql) const { return SqlStatement(*this).Force(sql); }
Value Fetch(Sql& sql) const { return SqlStatement(*this).Fetch(sql); }
bool Execute() const { return SqlStatement(*this).Execute(); }
void Force() const { return SqlStatement(*this).Force(); }
Value Fetch() const { return SqlStatement(*this).Fetch(); }
};

inline SqlUpdate Update(const SqlId& table) { return SqlUpdate(table); }
inline SqlUpdate Update(Fields f) { return SqlUpdate(f); }

Change log

r4626 by cxl on Feb 27, 2012   Diff
Sql: Fixed issue with quoted Null SqlId,
ide: debugging code for lost config
Go to: 
Project members, sign in to write a code review

Older revisions

r4612 by rylek on Feb 23, 2012   Diff
.Sql/SqlStatement.cpp: bug fix in
SqlSelect::AsTable to suppress extra
parentheses around aliased subselect
r4554 by cxl on Feb 6, 2012   Diff
Sql: Quoting SqlId changed to be
explicit option, SqlTxt added
r4529 by cxl on Feb 3, 2012   Diff
Sql: SqlId escaping now tests whether
escaped Id is indeed valid SQL id, no
escaping otherwise (workaround for use
of SqlId('table.*') and similar)
All revisions of this file

File info

Size: 24590 bytes, 684 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting