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
#include "SqlCtrl.h"

NAMESPACE_UPP

void SqlLoad(MapConvert& cv, Sql& sql) {
cv.Clear();
while(sql.Fetch())
cv.Add(sql[0], sql[1]);
}

void SqlLoad(MapConvert& cv, const SqlSelect& set, SqlSession& ss) {
Sql sql(ss);
ss.ClearError();
sql * set;
if(ShowError(sql)) return;
SqlLoad(cv, sql);
}

#ifndef NOAPPSQL
void operator*=(MapConvert& cv, const SqlSelect& set) {
SqlLoad(cv, set);
}
#endif

void SqlLoad(DropList& dl, Sql& sql) {
dl.ClearList();
while(sql.Fetch())
if(sql.GetColumns() == 1)
dl.Add(sql[0]);
else
dl.Add(sql[0], sql[1]);
}

void SqlLoad(DropList& dl, const SqlSelect& set, SqlSession& ss) {
Sql sql(ss);
ss.ClearError();
sql * set;
if(ShowError(sql)) return;
SqlLoad(dl, sql);
}

#ifndef NOAPPSQL
void operator*=(DropList& dl, const SqlSelect& set) {
SqlLoad(dl, set);
}
#endif

void SqlOption::SetData(const Value& data) {
String s = data;
if(IsThreeState() && IsNull(data))
Set(Null);
else
Set(!(IsNull(s) || s == "0"));
}

Value SqlOption::GetData() const {
if(IsThreeState() && IsNull(Get()))
return String();
return Get() ? "1" : "0";
}

Value SqlNOption::GetData() const
{
if(Get()) return "1";
return Null;
}

void SqlCtrls::Add(SqlId id, Ctrl& ctrl) {
Item& m = item.Add();
m.id = id;
m.ctrl = &ctrl;
}

void SqlCtrls::Table(Ctrl& dlg, SqlId table)
{
Vector<String> col = GetSchColumns(~table);
for(Ctrl *q = dlg.GetFirstChild(); q; q = q->GetNext()) {
String id = ToUpper(q->GetLayoutId());
if(!dynamic_cast<Button *>(q) && !dynamic_cast<Label *>(q) && FindIndex(col, id) >= 0)
Add(id, *q);
}
}

SqlSet SqlCtrls::Set() const {
SqlSet set;
for(int i = 0; i < item.GetCount(); i++)
set.Cat(item[i].id);
return set;
}

void SqlCtrls::Read(Sql& sql)
{
for(int i = 0; i < item.GetCount(); i++) {
Item& m = item[i];
m.ctrl->SetData(sql[m.id]);
}
}

bool SqlCtrls::Fetch(Sql& sql) {
if(!sql.Fetch()) return false;
Read(sql);
return true;
}

void SqlCtrls::Insert(SqlInsert& insert) const {
for(int i = 0; i < item.GetCount(); i++)
insert(item[i].id, item[i].ctrl->GetData());
}

void SqlCtrls::Update(SqlUpdate& update) const {
for(int i = 0; i < item.GetCount(); i++)
update(item[i].id, item[i].ctrl->GetData());
}

void SqlCtrls::UpdateModified(SqlUpdate& update) const {
for(int i = 0; i < item.GetCount(); i++)
if(item[i].ctrl->IsModified())
update(item[i].id, item[i].ctrl->GetData());
}

SqlInsert SqlCtrls::Insert(SqlId table) const {
SqlInsert insert(table);
Insert(insert);
return insert;
}

SqlUpdate SqlCtrls::Update(SqlId table) const {
SqlUpdate update(table);
Update(update);
return update;
}

SqlUpdate SqlCtrls::UpdateModified(SqlId table) const {
SqlUpdate update(table);
UpdateModified(update);
return update;
}

bool SqlCtrls::Accept()
{
for(int i = 0; i < item.GetCount(); i++)
if(!item[i].ctrl->Accept()) return false;
return true;
}

void SqlCtrls::ClearModify() {
for(int i = 0; i < item.GetCount(); i++)
item[i].ctrl->ClearModify();
}

bool SqlCtrls::IsModified() {
for(int i = 0; i < item.GetCount(); i++)
if(item[i].ctrl->IsModified()) return true;
return false;
}

void SqlCtrls::Enable(bool b)
{
for(int i = 0; i < item.GetCount(); i++)
item[i].ctrl->Enable(b);
}

void SqlCtrls::SetNull()
{
for(int i = 0; i < item.GetCount(); i++)
item[i].ctrl->SetData(Null);
}

Callback SqlCtrls::operator<<=(Callback cb)
{
for(int i = 0; i < item.GetCount(); i++)
item[i].ctrl->WhenAction = cb;
return cb;
}

bool SqlCtrls::Load(Sql& sql, SqlId table, SqlBool where)
{
sql * Select(*this).From(table).Where(where);
return Fetch(sql);
}

#ifndef NOAPPSQL
bool SqlCtrls::Load(SqlId table, SqlBool set)
{
return Load(SQL, table, set);
}
#endif

END_UPP_NAMESPACE

Change log

r4713 by cxl on Mar 22, 2012   Diff
SqlCtrl: Now supports ThreeState mode
Go to: 
Project members, sign in to write a code review

Older revisions

r4345 by cxl on Dec 26, 2011   Diff
Sql: GetSchColumn now guaranteed to be
uppercase
r4312 by cxl on Dec 16, 2011   Diff
SqlCtrl: SqlCtrls now support
automatic creation based on schema
introspection
r3458 by cxl on May 26, 2011   Diff
SqlCtrl: new SqlNOption similar to
SqlOption, but returns Null on flase
(instead of ''0'')
All revisions of this file

File info

Size: 3711 bytes, 189 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting