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
NAMESPACE_UPP

void __sqltempl__instantiation__(Gate2<int, int>); // a weird compiler bug

#define DEFID(x) const Id x(#x);
#define _DEFID(x) const Id _##x(#x);
#define _SQLID(x) const SqlId _##x(#x);

const SqlId& ALL(); // <*>
const SqlId& QUE(); // <?>

class SqlBlock
{
public:
#ifndef NOAPPSQL
SqlBlock(SqlSession& session = SQL.GetSession())
: session(session), done(false) { session.ClearError(); session.Begin(); }
#else
SqlBlock(SqlSession& session)
: session(session), done(false) { session.ClearError(); session.Begin(); }
#endif
~SqlBlock() { if(!done) session.Rollback(); }

void Commit() { ASSERT(!done); done = true; session.Commit(); }
void Rollback() { ASSERT(!done); done = true; session.Rollback(); }
void Flush() { ASSERT(!done); session.Commit(); session.Begin(); }

private:
SqlSession& session;
bool done;
};

void SetSchema(const String& schema);
String GetSchema();
String SchemaTableName(const String& table);
SqlId SchemaTable(const SqlId& table);

String GetInsertString(Fields nf, bool optimize = true);
String GetSchemaInsertString(Fields nf, bool optimize = true);
void InsertScript(SqlSchema& schema, Fields nf, bool optimize = true);
void InsertSchemaScript(SqlSchema& schema, Fields nf, bool optimize = true);

SqlSelect SelectTable(Fields nf);
SqlSelect SelectSchemaTable(Fields nf);
SqlSelect SelectColumns(Fields nf);

Value GetValue(Fields nf, SqlId field);
Ref GetRef(Fields nf, SqlId field);
String GetTableName(Fields nf);

VectorMap<Id, Ref> GetRefMap(Fields nf, String *tablename = NULL);
VectorMap<Id, Value> GetValueMap(Fields nf, String *tablename = NULL);

String ForceInsertRowid(const SqlInsert& insert, Sql& cursor APPSQLCURSOR);
String ForceInsertRowid(Fields nf, Sql& cursor APPSQLCURSOR);
String ForceInsertRowid(SqlId table, Fields nf, Sql& cursor APPSQLCURSOR);
String ForceSchemaInsertRowid(Fields nf, Sql& cursor APPSQLCURSOR);
String ForceSchemaInsertRowid(SqlId table, Fields nf, Sql& cursor APPSQLCURSOR);

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);
bool IsNotEmpty(const SqlVal& table, const SqlBool& cond, Sql& cursor APPSQLCURSOR);
bool IsNotEmpty(const SqlVal& table, SqlId column, const Value& value, Sql& cursor APPSQLCURSOR);
bool IsNotSchemaEmpty(const SqlVal& table, const SqlBool& cond, Sql& cursor APPSQLCURSOR);
bool IsNotSchemaEmpty(const SqlVal& table, SqlId column, const Value& value, Sql& cursor APPSQLCURSOR);

#ifdef PLATFORM_WIN32 // bw, move to tsql/ctrl
//bool LockSql(Sql& cursor APPSQLCURSOR);
//bool LockSql(const SqlVal& table, SqlBool where, Sql& cursor APPSQLCURSOR);
//bool LockSql(const SqlVal& table, SqlId column, const Value& value, Sql& cursor APPSQLCURSOR);
//bool LockSchemaSql(const SqlVal& table, SqlBool where, Sql& cursor APPSQLCURSOR);
//bool LockSchemaSql(const SqlVal& table, SqlId column, const Value& value, Sql& cursor APPSQLCURSOR);

//Mirek 06/12/22 - not defined anywhere in uppsrc, clashes with idis

#endif

SqlVal Alias(const SqlId& value, const SqlId& alias);
SqlVal SchemaAlias(const SqlId& table, const SqlId& alias);
SqlVal SchemaAlias(const SqlId& table);
SqlId SchemaId(const SqlId& table, const SqlId& alias);
SqlId SchemaId(const SqlId& table);

inline SqlInsert InsertSchema(SqlId table) { return SqlInsert(SqlId(SchemaTableName(~table))); }
inline SqlUpdate UpdateSchema(SqlId table) { return SqlUpdate(SqlId(SchemaTableName(~table))); }
inline SqlDelete DeleteSchema(SqlId table) { return Delete(SqlId(SchemaTableName(~table))); }
/* use .Hint instead...
SqlSelect SelectHint(const char *hint, SqlSet set);

#define E__SelectHint(I)\
SqlSelect SelectHint(const char *hint, __List##I(E__SqlVal));
__Expand(E__SelectHint);
*/
SqlSet DeleteHint(const char *hint, const SqlVal& table);
SqlSet DeleteSchemaHint(const char *hint, const SqlId& table);

VectorMap<String, SqlColumnInfo> Describe(const SqlVal& table, Sql& cursor APPSQLCURSOR);
VectorMap<String, SqlColumnInfo> DescribeSchema(const SqlId& table, Sql& cursor APPSQLCURSOR);

int64 SelectCount(const SqlVal& table, const SqlBool& cond, Sql& cursor);
int64 SelectSchemaCount(const SqlId& table, const SqlBool& cond, Sql& cursor);

#ifndef NOAPPSQL
inline int64 SelectCount(const SqlVal& table, const SqlBool& cond = SqlBool::True()) { return SelectCount(table, cond, SQL); }
inline int64 SelectSchemaCount(const SqlId& table, const SqlBool& cond = SqlBool::True()) { return SelectSchemaCount(table, cond, SQL); }
#endif

Vector<String> LoadStrColumn(SqlId column, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false);
Vector<String>& SyncStrColumn(Vector<String>& dest, SqlId col, const SqlVal& table, SqlSession& session APPSQLSESSION, bool order = false);
Vector<String> LoadSchemaStrColumn(SqlId column, const SqlId& table, SqlSession& session APPSQLSESSION, bool order = false);
Vector<String>& SyncSchemaStrColumn(Vector<String>& dest, SqlId col, const SqlId& table, SqlSession& session APPSQLSESSION);

SqlVal GetCsVal(const SqlVal& val); // replaces CH for sorts
SqlVal GetCs(const char *col);
SqlVal GetCsAsciiVal(const SqlVal& val); // replaces CH and removes accents
SqlVal GetCsAscii(const char *col);
SqlBool LikeSmartWild(const SqlVal& exp, const String& s);

SqlBool GetTextRange(const String& s1, const String& s2, const SqlVal& exp);
SqlBool GetNumRange(double min, double max, const SqlVal& exp);
SqlBool GetDateRange(Date d1, Date d2, const SqlVal& exp, bool force_range = false);
SqlBool GetTimeRange(Time d1, Time d2, const SqlVal& exp, bool force_range = false);

String GetYearDayIndex(Date date);
SqlVal GetYearDayIndex(const SqlVal& date);
SqlBool GetYearDayRange(const SqlVal& date, Date min, Date max);

END_UPP_NAMESPACE

Change log

r4604 by rylek on Feb 18, 2012   Diff
.TSql/util.h,cpp: fixed schema-related
functions to match changes in SqlId
Go to: 
Project members, sign in to write a code review

Older revisions

r3777 by rylek on Aug 21, 2011   Diff
.plugin/sqlite: fixed conversion of
statement to UTF8
.Core/XML.cpp: ReadTextE updated to
reflect modified IsText / ReadText
logic
...
r3466 by rylek on May 27, 2011   Diff
.Sql: modified SqlSession::SetError
logic to overwrite last error out of
transactions
.TSql: adjusted SqlBlock to do a
ClearError when starting a transaction
...
r2570 by rylek on Jul 27, 2010   Diff
+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,
...
All revisions of this file

File info

Size: 8258 bytes, 143 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting