summaryrefslogtreecommitdiff
path: root/libopie2
authorzecke <zecke>2002-10-07 14:59:44 (UTC)
committer zecke <zecke>2002-10-07 14:59:44 (UTC)
commite68537563c9950654b9a771730f0fc3890803a54 (patch) (unidiff)
treefd64fada00405ca8ad65e9334bcdb4c3da3f1a9a /libopie2
parent645b377506fb32f4519e70d43c020084943debae (diff)
downloadopie-e68537563c9950654b9a771730f0fc3890803a54.zip
opie-e68537563c9950654b9a771730f0fc3890803a54.tar.gz
opie-e68537563c9950654b9a771730f0fc3890803a54.tar.bz2
Fix sorted SQL query
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 25536e0..8add9f7 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -1,454 +1,457 @@
1 1
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include <qpe/global.h> 4#include <qpe/global.h>
5 5
6#include <opie/osqldriver.h> 6#include <opie/osqldriver.h>
7#include <opie/osqlresult.h> 7#include <opie/osqlresult.h>
8#include <opie/osqlmanager.h> 8#include <opie/osqlmanager.h>
9#include <opie/osqlquery.h> 9#include <opie/osqlquery.h>
10 10
11#include "otodoaccesssql.h" 11#include "otodoaccesssql.h"
12 12
13/* 13/*
14 * first some query 14 * first some query
15 * CREATE query 15 * CREATE query
16 * LOAD query 16 * LOAD query
17 * INSERT 17 * INSERT
18 * REMOVE 18 * REMOVE
19 * CLEAR 19 * CLEAR
20 */ 20 */
21namespace { 21namespace {
22 /** 22 /**
23 * CreateQuery for the Todolist Table 23 * CreateQuery for the Todolist Table
24 */ 24 */
25 class CreateQuery : public OSQLQuery { 25 class CreateQuery : public OSQLQuery {
26 public: 26 public:
27 CreateQuery(); 27 CreateQuery();
28 ~CreateQuery(); 28 ~CreateQuery();
29 QString query()const; 29 QString query()const;
30 }; 30 };
31 31
32 /** 32 /**
33 * LoadQuery 33 * LoadQuery
34 * this one queries for all uids 34 * this one queries for all uids
35 */ 35 */
36 class LoadQuery : public OSQLQuery { 36 class LoadQuery : public OSQLQuery {
37 public: 37 public:
38 LoadQuery(); 38 LoadQuery();
39 ~LoadQuery(); 39 ~LoadQuery();
40 QString query()const; 40 QString query()const;
41 }; 41 };
42 42
43 /** 43 /**
44 * inserts/adds a OTodo to the table 44 * inserts/adds a OTodo to the table
45 */ 45 */
46 class InsertQuery : public OSQLQuery { 46 class InsertQuery : public OSQLQuery {
47 public: 47 public:
48 InsertQuery(const OTodo& ); 48 InsertQuery(const OTodo& );
49 ~InsertQuery(); 49 ~InsertQuery();
50 QString query()const; 50 QString query()const;
51 private: 51 private:
52 OTodo m_todo; 52 OTodo m_todo;
53 }; 53 };
54 54
55 /** 55 /**
56 * removes one from the table 56 * removes one from the table
57 */ 57 */
58 class RemoveQuery : public OSQLQuery { 58 class RemoveQuery : public OSQLQuery {
59 public: 59 public:
60 RemoveQuery(int uid ); 60 RemoveQuery(int uid );
61 ~RemoveQuery(); 61 ~RemoveQuery();
62 QString query()const; 62 QString query()const;
63 private: 63 private:
64 int m_uid; 64 int m_uid;
65 }; 65 };
66 66
67 /** 67 /**
68 * Clears (delete) a Table 68 * Clears (delete) a Table
69 */ 69 */
70 class ClearQuery : public OSQLQuery { 70 class ClearQuery : public OSQLQuery {
71 public: 71 public:
72 ClearQuery(); 72 ClearQuery();
73 ~ClearQuery(); 73 ~ClearQuery();
74 QString query()const; 74 QString query()const;
75 75
76 }; 76 };
77 77
78 /** 78 /**
79 * a find query 79 * a find query
80 */ 80 */
81 class FindQuery : public OSQLQuery { 81 class FindQuery : public OSQLQuery {
82 public: 82 public:
83 FindQuery(int uid); 83 FindQuery(int uid);
84 ~FindQuery(); 84 ~FindQuery();
85 QString query()const; 85 QString query()const;
86 private: 86 private:
87 int m_uid; 87 int m_uid;
88 }; 88 };
89 89
90 /** 90 /**
91 * overdue query 91 * overdue query
92 */ 92 */
93 class OverDueQuery : public OSQLQuery { 93 class OverDueQuery : public OSQLQuery {
94 public: 94 public:
95 OverDueQuery(); 95 OverDueQuery();
96 ~OverDueQuery(); 96 ~OverDueQuery();
97 QString query()const; 97 QString query()const;
98 }; 98 };
99 class EffQuery : public OSQLQuery { 99 class EffQuery : public OSQLQuery {
100 public: 100 public:
101 EffQuery( const QDate&, const QDate&, bool inc ); 101 EffQuery( const QDate&, const QDate&, bool inc );
102 ~EffQuery(); 102 ~EffQuery();
103 QString query()const; 103 QString query()const;
104 private: 104 private:
105 QString with()const; 105 QString with()const;
106 QString out()const; 106 QString out()const;
107 QDate m_start; 107 QDate m_start;
108 QDate m_end; 108 QDate m_end;
109 bool m_inc :1; 109 bool m_inc :1;
110 }; 110 };
111 111
112 112
113 CreateQuery::CreateQuery() : OSQLQuery() {} 113 CreateQuery::CreateQuery() : OSQLQuery() {}
114 CreateQuery::~CreateQuery() {} 114 CreateQuery::~CreateQuery() {}
115 QString CreateQuery::query()const { 115 QString CreateQuery::query()const {
116 QString qu; 116 QString qu;
117 qu += "create table todolist( uid, categories, completed, progress, "; 117 qu += "create table todolist( uid, categories, completed, progress, ";
118 qu += "summary, DueDate, priority, description )"; 118 qu += "summary, DueDate, priority, description )";
119 return qu; 119 return qu;
120 } 120 }
121 121
122 LoadQuery::LoadQuery() : OSQLQuery() {} 122 LoadQuery::LoadQuery() : OSQLQuery() {}
123 LoadQuery::~LoadQuery() {} 123 LoadQuery::~LoadQuery() {}
124 QString LoadQuery::query()const { 124 QString LoadQuery::query()const {
125 QString qu; 125 QString qu;
126 qu += "select distinct uid from todolist"; 126 qu += "select distinct uid from todolist";
127 127
128 return qu; 128 return qu;
129 } 129 }
130 130
131 InsertQuery::InsertQuery( const OTodo& todo ) 131 InsertQuery::InsertQuery( const OTodo& todo )
132 : OSQLQuery(), m_todo( todo ) { 132 : OSQLQuery(), m_todo( todo ) {
133 } 133 }
134 InsertQuery::~InsertQuery() { 134 InsertQuery::~InsertQuery() {
135 } 135 }
136 /* 136 /*
137 * converts from a OTodo to a query 137 * converts from a OTodo to a query
138 * we leave out X-Ref + Alarms 138 * we leave out X-Ref + Alarms
139 */ 139 */
140 QString InsertQuery::query()const{ 140 QString InsertQuery::query()const{
141 int year, month, day; 141 int year, month, day;
142 year = month = day = 0; 142 year = month = day = 0;
143 if (m_todo.hasDueDate() ) { 143 if (m_todo.hasDueDate() ) {
144 QDate date = m_todo.dueDate(); 144 QDate date = m_todo.dueDate();
145 year = date.year(); 145 year = date.year();
146 month = date.month(); 146 month = date.month();
147 day = date.day(); 147 day = date.day();
148 } 148 }
149 QString qu; 149 QString qu;
150 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; 150 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',";
151 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; 151 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ",";
152 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; 152 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',";
153 qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; 153 qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')";
154 154
155 qWarning("add %s", qu.latin1() ); 155 qWarning("add %s", qu.latin1() );
156 return qu; 156 return qu;
157 } 157 }
158 158
159 RemoveQuery::RemoveQuery(int uid ) 159 RemoveQuery::RemoveQuery(int uid )
160 : OSQLQuery(), m_uid( uid ) {} 160 : OSQLQuery(), m_uid( uid ) {}
161 RemoveQuery::~RemoveQuery() {} 161 RemoveQuery::~RemoveQuery() {}
162 QString RemoveQuery::query()const { 162 QString RemoveQuery::query()const {
163 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); 163 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid);
164 return qu; 164 return qu;
165 } 165 }
166 166
167 167
168 ClearQuery::ClearQuery() 168 ClearQuery::ClearQuery()
169 : OSQLQuery() {} 169 : OSQLQuery() {}
170 ClearQuery::~ClearQuery() {} 170 ClearQuery::~ClearQuery() {}
171 QString ClearQuery::query()const { 171 QString ClearQuery::query()const {
172 QString qu = "drop table todolist"; 172 QString qu = "drop table todolist";
173 return qu; 173 return qu;
174 } 174 }
175 FindQuery::FindQuery(int uid) 175 FindQuery::FindQuery(int uid)
176 : OSQLQuery(), m_uid(uid ) { 176 : OSQLQuery(), m_uid(uid ) {
177 } 177 }
178 FindQuery::~FindQuery() { 178 FindQuery::~FindQuery() {
179 } 179 }
180 QString FindQuery::query()const{ 180 QString FindQuery::query()const{
181 QString qu = "select uid, categories, completed, progress, summary, "; 181 QString qu = "select uid, categories, completed, progress, summary, ";
182 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); 182 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid);
183 return qu; 183 return qu;
184 } 184 }
185 185
186 OverDueQuery::OverDueQuery(): OSQLQuery() {} 186 OverDueQuery::OverDueQuery(): OSQLQuery() {}
187 OverDueQuery::~OverDueQuery() {} 187 OverDueQuery::~OverDueQuery() {}
188 QString OverDueQuery::query()const { 188 QString OverDueQuery::query()const {
189 QDate date = QDate::currentDate(); 189 QDate date = QDate::currentDate();
190 QString str; 190 QString str;
191 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 191 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
192 192
193 return str; 193 return str;
194 } 194 }
195 195
196 196
197 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 197 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
198 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 198 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
199 EffQuery::~EffQuery() {} 199 EffQuery::~EffQuery() {}
200 QString EffQuery::query()const { 200 QString EffQuery::query()const {
201 return m_inc ? with() : out(); 201 return m_inc ? with() : out();
202 } 202 }
203 QString EffQuery::with()const { 203 QString EffQuery::with()const {
204 QString str; 204 QString str;
205 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 205 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
206 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) 206 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() )
207 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); 207 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() );
208 return str; 208 return str;
209 } 209 }
210 QString EffQuery::out()const { 210 QString EffQuery::out()const {
211 QString str; 211 QString str;
212 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 212 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
213 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) 213 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
214 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); 214 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
215 215
216 return str; 216 return str;
217 } 217 }
218}; 218};
219 219
220OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) 220OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
221 : OTodoAccessBackend(), m_dict(15) 221 : OTodoAccessBackend(), m_dict(15)
222{ 222{
223 QString fi = file; 223 QString fi = file;
224 if ( fi.isEmpty() ) 224 if ( fi.isEmpty() )
225 fi = Global::applicationFileName( "todolist", "todolist.db" ); 225 fi = Global::applicationFileName( "todolist", "todolist.db" );
226 OSQLManager man; 226 OSQLManager man;
227 m_driver = man.standard(); 227 m_driver = man.standard();
228 m_driver->setUrl(fi); 228 m_driver->setUrl(fi);
229 fillDict(); 229 fillDict();
230} 230}
231 231
232OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ 232OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
233} 233}
234bool OTodoAccessBackendSQL::load(){ 234bool OTodoAccessBackendSQL::load(){
235 if (!m_driver->open() ) 235 if (!m_driver->open() )
236 return false; 236 return false;
237 237
238 CreateQuery creat; 238 CreateQuery creat;
239 OSQLResult res = m_driver->query(&creat ); 239 OSQLResult res = m_driver->query(&creat );
240 240
241 update(); 241 update();
242 qWarning("loaded %d", m_uids.count() ); 242 qWarning("loaded %d", m_uids.count() );
243 return true; 243 return true;
244} 244}
245bool OTodoAccessBackendSQL::reload(){ 245bool OTodoAccessBackendSQL::reload(){
246 return load(); 246 return load();
247} 247}
248 248
249bool OTodoAccessBackendSQL::save(){ 249bool OTodoAccessBackendSQL::save(){
250 return m_driver->close(); 250 return m_driver->close();
251} 251}
252QArray<int> OTodoAccessBackendSQL::allRecords()const { 252QArray<int> OTodoAccessBackendSQL::allRecords()const {
253 return m_uids; 253 return m_uids;
254} 254}
255QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ 255QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
256 QArray<int> ints(0); 256 QArray<int> ints(0);
257 return ints; 257 return ints;
258} 258}
259OTodo OTodoAccessBackendSQL::find(int uid ) const{ 259OTodo OTodoAccessBackendSQL::find(int uid ) const{
260 FindQuery query( uid ); 260 FindQuery query( uid );
261 return todo( m_driver->query(&query) ); 261 return todo( m_driver->query(&query) );
262 262
263} 263}
264void OTodoAccessBackendSQL::clear() { 264void OTodoAccessBackendSQL::clear() {
265 ClearQuery cle; 265 ClearQuery cle;
266 OSQLResult res = m_driver->query( &cle ); 266 OSQLResult res = m_driver->query( &cle );
267 CreateQuery qu; 267 CreateQuery qu;
268 res = m_driver->query(&qu); 268 res = m_driver->query(&qu);
269} 269}
270bool OTodoAccessBackendSQL::add( const OTodo& t) { 270bool OTodoAccessBackendSQL::add( const OTodo& t) {
271 InsertQuery ins( t ); 271 InsertQuery ins( t );
272 OSQLResult res = m_driver->query( &ins ); 272 OSQLResult res = m_driver->query( &ins );
273 273
274 if ( res.state() == OSQLResult::Failure ) 274 if ( res.state() == OSQLResult::Failure )
275 return false; 275 return false;
276 int c = m_uids.count(); 276 int c = m_uids.count();
277 m_uids.resize( c+1 ); 277 m_uids.resize( c+1 );
278 m_uids[c] = t.uid(); 278 m_uids[c] = t.uid();
279 279
280 return true; 280 return true;
281} 281}
282bool OTodoAccessBackendSQL::remove( int uid ) { 282bool OTodoAccessBackendSQL::remove( int uid ) {
283 RemoveQuery rem( uid ); 283 RemoveQuery rem( uid );
284 OSQLResult res = m_driver->query(&rem ); 284 OSQLResult res = m_driver->query(&rem );
285 285
286 if ( res.state() == OSQLResult::Failure ) 286 if ( res.state() == OSQLResult::Failure )
287 return false; 287 return false;
288 288
289 update(); 289 update();
290 return true; 290 return true;
291} 291}
292/* 292/*
293 * FIXME better set query 293 * FIXME better set query
294 * but we need the cache for that 294 * but we need the cache for that
295 * now we remove 295 * now we remove
296 */ 296 */
297bool OTodoAccessBackendSQL::replace( const OTodo& t) { 297bool OTodoAccessBackendSQL::replace( const OTodo& t) {
298 remove( t.uid() ); 298 remove( t.uid() );
299 return add(t); 299 return add(t);
300} 300}
301QArray<int> OTodoAccessBackendSQL::overDue() { 301QArray<int> OTodoAccessBackendSQL::overDue() {
302 OverDueQuery qu; 302 OverDueQuery qu;
303 return uids( m_driver->query(&qu ) ); 303 return uids( m_driver->query(&qu ) );
304} 304}
305QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, 305QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s,
306 const QDate& t, 306 const QDate& t,
307 bool u) { 307 bool u) {
308 EffQuery ef(s, t, u ); 308 EffQuery ef(s, t, u );
309 return uids (m_driver->query(&ef) ); 309 return uids (m_driver->query(&ef) );
310} 310}
311/* 311/*
312 * 312 *
313 */ 313 */
314QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 314QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
315 int sortFilter, int cat ) { 315 int sortFilter, int cat ) {
316 QString query; 316 QString query;
317 query = "select uid from todolist WHERE "; 317 query = "select uid from todolist WHERE ";
318 318
319 /* 319 /*
320 * Sort Filter stuff 320 * Sort Filter stuff
321 * not that straight forward 321 * not that straight forward
322 * 322 *
323 */ 323 */
324 /* Category */ 324 /* Category */
325 if ( sortFilter & 1 ) { 325 if ( sortFilter & 1 ) {
326 query += " categories like '%" +QString::number(cat)+"%' AND"; 326 QString str;
327 if (cat != 0 ) str = QString::number( cat );
328 query += " categories like '%" +str+"%' AND";
327 } 329 }
328 /* Show only overdue */ 330 /* Show only overdue */
329 if ( sortFilter & 2 ) { 331 if ( sortFilter & 2 ) {
330 QDate date = QDate::currentDate(); 332 QDate date = QDate::currentDate();
331 QString due; 333 QString due;
332 QString base; 334 QString base;
333 base = QString("DueDate <= '%1-%2-%3' AND WHERE completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); 335 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() );
334 query += " " + base + " AND"; 336 query += " " + base + " AND";
335 } 337 }
336 /* not show completed */ 338 /* not show completed */
337 if ( sortFilter & 4 ) { 339 if ( sortFilter & 4 ) {
338 query += " completed = 0 AND"; 340 query += " completed = 0 AND";
339 }else{ 341 }else{
340 query += " ( completed = 1 OR completed = 0) AND"; 342 query += " ( completed = 1 OR completed = 0) AND";
341 } 343 }
342 /* srtip the end */ 344 /* srtip the end */
343 query = query.remove( query.length()-3, 3 ); 345 query = query.remove( query.length()-3, 3 );
344 346
345 347
346 /* 348 /*
347 * sort order stuff 349 * sort order stuff
348 * quite straight forward 350 * quite straight forward
349 */ 351 */
350 query += "ORDER BY "; 352 query += "ORDER BY ";
351 switch( sortOrder ) { 353 switch( sortOrder ) {
352 /* completed */ 354 /* completed */
353 case 0: 355 case 0:
354 query += "completed"; 356 query += "completed";
355 break; 357 break;
356 case 1: 358 case 1:
357 query += "priority"; 359 query += "priority";
358 break; 360 break;
359 case 2: 361 case 2:
360 query += "description"; 362 query += "description";
361 break; 363 break;
362 case 3: 364 case 3:
363 query += "DueDate"; 365 query += "DueDate";
364 break; 366 break;
365 } 367 }
366 if ( !asc ) 368 if ( !asc )
367 query += " DESC"; 369 query += " DESC";
368 370
369 qWarning( query ); 371 qWarning( query );
370 OSQLRawQuery raw(query ); 372 OSQLRawQuery raw(query );
371 return uids( m_driver->query(&raw) ); 373 return uids( m_driver->query(&raw) );
372} 374}
373bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 375bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
374 if ( str == "0-0-0" ) 376 if ( str == "0-0-0" )
375 return false; 377 return false;
376 else{ 378 else{
377 int day, year, month; 379 int day, year, month;
378 QStringList list = QStringList::split("-", str ); 380 QStringList list = QStringList::split("-", str );
379 year = list[0].toInt(); 381 year = list[0].toInt();
380 month = list[1].toInt(); 382 month = list[1].toInt();
381 day = list[2].toInt(); 383 day = list[2].toInt();
382 da.setYMD( year, month, day ); 384 da.setYMD( year, month, day );
383 return true; 385 return true;
384 } 386 }
385} 387}
386OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ 388OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
387 if ( res.state() == OSQLResult::Failure ) { 389 if ( res.state() == OSQLResult::Failure ) {
388 OTodo to; 390 OTodo to;
389 return to; 391 return to;
390 } 392 }
391 393
392 OSQLResultItem::ValueList list = res.results(); 394 OSQLResultItem::ValueList list = res.results();
393 OSQLResultItem::ValueList::Iterator it = list.begin(); 395 OSQLResultItem::ValueList::Iterator it = list.begin();
394 396
395 bool has = false; QDate da = QDate::currentDate(); 397 bool has = false; QDate da = QDate::currentDate();
396 has = date( da, (*it).data("DueDate") ); 398 has = date( da, (*it).data("DueDate") );
397 QStringList cats = QStringList::split(";", (*it).data("categories") ); 399 QStringList cats = QStringList::split(";", (*it).data("categories") );
398 400
399 OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), 401 OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(),
400 cats, (*it).data("summary"), (*it).data("description"), 402 cats, (*it).data("summary"), (*it).data("description"),
401 (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); 403 (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() );
402 return to; 404 return to;
403} 405}
404OTodo OTodoAccessBackendSQL::todo( int uid )const { 406OTodo OTodoAccessBackendSQL::todo( int uid )const {
405 FindQuery find( uid ); 407 FindQuery find( uid );
406 return todo( m_driver->query(&find) ); 408 return todo( m_driver->query(&find) );
407} 409}
408/* 410/*
409 * update the dict 411 * update the dict
410 */ 412 */
411void OTodoAccessBackendSQL::fillDict() { 413void OTodoAccessBackendSQL::fillDict() {
412 /* initialize dict */ 414 /* initialize dict */
413 /* 415 /*
414 * UPDATE dict if you change anything!!! 416 * UPDATE dict if you change anything!!!
415 */ 417 */
416 m_dict.setAutoDelete( TRUE ); 418 m_dict.setAutoDelete( TRUE );
417 m_dict.insert("Categories" , new int(OTodo::Category) ); 419 m_dict.insert("Categories" , new int(OTodo::Category) );
418 m_dict.insert("Uid" , new int(OTodo::Uid) ); 420 m_dict.insert("Uid" , new int(OTodo::Uid) );
419 m_dict.insert("HasDate" , new int(OTodo::HasDate) ); 421 m_dict.insert("HasDate" , new int(OTodo::HasDate) );
420 m_dict.insert("Completed" , new int(OTodo::Completed) ); 422 m_dict.insert("Completed" , new int(OTodo::Completed) );
421 m_dict.insert("Description" , new int(OTodo::Description) ); 423 m_dict.insert("Description" , new int(OTodo::Description) );
422 m_dict.insert("Summary" , new int(OTodo::Summary) ); 424 m_dict.insert("Summary" , new int(OTodo::Summary) );
423 m_dict.insert("Priority" , new int(OTodo::Priority) ); 425 m_dict.insert("Priority" , new int(OTodo::Priority) );
424 m_dict.insert("DateDay" , new int(OTodo::DateDay) ); 426 m_dict.insert("DateDay" , new int(OTodo::DateDay) );
425 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 427 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) );
426 m_dict.insert("DateYear" , new int(OTodo::DateYear) ); 428 m_dict.insert("DateYear" , new int(OTodo::DateYear) );
427 m_dict.insert("Progress" , new int(OTodo::Progress) ); 429 m_dict.insert("Progress" , new int(OTodo::Progress) );
428 m_dict.insert("Completed", new int(OTodo::Completed) ); 430 m_dict.insert("Completed", new int(OTodo::Completed) );
429 m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); 431 m_dict.insert("CrossReference", new int(OTodo::CrossReference) );
430 m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); 432 m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
431 m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); 433 m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
432} 434}
433void OTodoAccessBackendSQL::update() { 435void OTodoAccessBackendSQL::update() {
434 LoadQuery lo; 436 LoadQuery lo;
435 OSQLResult res = m_driver->query(&lo); 437 OSQLResult res = m_driver->query(&lo);
436 if ( res.state() != OSQLResult::Success ) 438 if ( res.state() != OSQLResult::Success )
437 return; 439 return;
438 440
439 m_uids = uids( res ); 441 m_uids = uids( res );
440} 442}
441QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 443QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
442 444
443 OSQLResultItem::ValueList list = res.results(); 445 OSQLResultItem::ValueList list = res.results();
444 OSQLResultItem::ValueList::Iterator it; 446 OSQLResultItem::ValueList::Iterator it;
445 QArray<int> ints(list.count() ); 447 QArray<int> ints(list.count() );
448 qWarning(" count = %d", list.count() );
446 449
447 int i = 0; 450 int i = 0;
448 for (it = list.begin(); it != list.end(); ++it ) { 451 for (it = list.begin(); it != list.end(); ++it ) {
449 ints[i] = (*it).data("uid").toInt(); 452 ints[i] = (*it).data("uid").toInt();
450 i++; 453 i++;
451 } 454 }
452 return ints; 455 return ints;
453} 456}
454 457