summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccesssql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp444
1 files changed, 224 insertions, 220 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 132b5a6..6f65c48 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -7,63 +7,67 @@
7 .>+-= 7 .>+-=
8 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
9.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
11.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
12 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
13 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
14 .%`+i> _;_. 14 .%`+i> _;_.
15 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
17 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
21++= -. .` .: details. 21++= -. .` .: details.
22 : = ...= . :.=- 22 : = ...= . :.=-
23 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
24 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
25 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <qdatetime.h> 31/* OPIE */
32#include <qmap.h>
33#include <qstring.h>
34
35#include <qpe/global.h>
36
37#include <opie2/osqldriver.h> 32#include <opie2/osqldriver.h>
38#include <opie2/osqlresult.h> 33#include <opie2/osqlresult.h>
39#include <opie2/osqlmanager.h> 34#include <opie2/osqlmanager.h>
40#include <opie2/osqlquery.h> 35#include <opie2/osqlquery.h>
41 36
42#include <opie2/otodoaccesssql.h> 37#include <opie2/otodoaccesssql.h>
43#include <opie2/opimstate.h> 38#include <opie2/opimstate.h>
44#include <opie2/opimnotifymanager.h> 39#include <opie2/opimnotifymanager.h>
45#include <opie2/opimrecurrence.h> 40#include <opie2/opimrecurrence.h>
41#include <opie2/odebug.h>
42
43#include <qpe/global.h>
44
45/* QT */
46#include <qdatetime.h>
47#include <qmap.h>
48#include <qstring.h>
49
46 50
47using namespace Opie::DB; 51using namespace Opie::DB;
48 52
49using namespace Opie; 53using namespace Opie;
50/* 54/*
51 * first some query 55 * first some query
52 * CREATE query 56 * CREATE query
53 * LOAD query 57 * LOAD query
54 * INSERT 58 * INSERT
55 * REMOVE 59 * REMOVE
56 * CLEAR 60 * CLEAR
57 */ 61 */
58namespace { 62namespace {
59 /** 63 /**
60 * CreateQuery for the Todolist Table 64 * CreateQuery for the Todolist Table
61 */ 65 */
62 class CreateQuery : public OSQLQuery { 66 class CreateQuery : public OSQLQuery {
63 public: 67 public:
64 CreateQuery(); 68 CreateQuery();
65 ~CreateQuery(); 69 ~CreateQuery();
66 QString query()const; 70 QString query()const;
67 }; 71 };
68 72
69 /** 73 /**
@@ -130,364 +134,364 @@ namespace {
130 134
131 /** 135 /**
132 * overdue query 136 * overdue query
133 */ 137 */
134 class OverDueQuery : public OSQLQuery { 138 class OverDueQuery : public OSQLQuery {
135 public: 139 public:
136 OverDueQuery(); 140 OverDueQuery();
137 ~OverDueQuery(); 141 ~OverDueQuery();
138 QString query()const; 142 QString query()const;
139 }; 143 };
140 class EffQuery : public OSQLQuery { 144 class EffQuery : public OSQLQuery {
141 public: 145 public:
142 EffQuery( const QDate&, const QDate&, bool inc ); 146 EffQuery( const QDate&, const QDate&, bool inc );
143 ~EffQuery(); 147 ~EffQuery();
144 QString query()const; 148 QString query()const;
145 private: 149 private:
146 QString with()const; 150 QString with()const;
147 QString out()const; 151 QString out()const;
148 QDate m_start; 152 QDate m_start;
149 QDate m_end; 153 QDate m_end;
150 bool m_inc :1; 154 bool m_inc :1;
151 }; 155 };
152 156
153 157
154 /** 158 /**
155 * a find query for custom elements 159 * a find query for custom elements
156 */ 160 */
157 class FindCustomQuery : public OSQLQuery { 161 class FindCustomQuery : public OSQLQuery {
158 public: 162 public:
159 FindCustomQuery(int uid); 163 FindCustomQuery(int uid);
160 FindCustomQuery(const QArray<int>& ); 164 FindCustomQuery(const QArray<int>& );
161 ~FindCustomQuery(); 165 ~FindCustomQuery();
162 QString query()const; 166 QString query()const;
163 private: 167 private:
164 QString single()const; 168 QString single()const;
165 QString multi()const; 169 QString multi()const;
166 QArray<int> m_uids; 170 QArray<int> m_uids;
167 int m_uid; 171 int m_uid;
168 }; 172 };
169 173
170 174
171 175
172 CreateQuery::CreateQuery() : OSQLQuery() {} 176 CreateQuery::CreateQuery() : OSQLQuery() {}
173 CreateQuery::~CreateQuery() {} 177 CreateQuery::~CreateQuery() {}
174 QString CreateQuery::query()const { 178 QString CreateQuery::query()const {
175 QString qu; 179 QString qu;
176 qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; 180 qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
177 qu += "description, summary, priority, DueDate, progress , state, "; 181 qu += "description, summary, priority, DueDate, progress , state, ";
178 // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) 182 // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers)
179 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; 183 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
180 qu += "reminders, alarms, maintainer, startdate, completeddate);"; 184 qu += "reminders, alarms, maintainer, startdate, completeddate);";
181 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 185 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
182 return qu; 186 return qu;
183 } 187 }
184 188
185 LoadQuery::LoadQuery() : OSQLQuery() {} 189 LoadQuery::LoadQuery() : OSQLQuery() {}
186 LoadQuery::~LoadQuery() {} 190 LoadQuery::~LoadQuery() {}
187 QString LoadQuery::query()const { 191 QString LoadQuery::query()const {
188 QString qu; 192 QString qu;
189 // We do not need "distinct" here. The primary key is always unique.. 193 // We do not need "distinct" here. The primary key is always unique..
190 //qu += "select distinct uid from todolist"; 194 //qu += "select distinct uid from todolist";
191 qu += "select uid from todolist"; 195 qu += "select uid from todolist";
192 196
193 return qu; 197 return qu;
194 } 198 }
195 199
196 InsertQuery::InsertQuery( const OPimTodo& todo ) 200 InsertQuery::InsertQuery( const OPimTodo& todo )
197 : OSQLQuery(), m_todo( todo ) { 201 : OSQLQuery(), m_todo( todo ) {
198 } 202 }
199 InsertQuery::~InsertQuery() { 203 InsertQuery::~InsertQuery() {
200 } 204 }
201 /* 205 /*
202 * converts from a OPimTodo to a query 206 * converts from a OPimTodo to a query
203 * we leave out X-Ref + Maintainer 207 * we leave out X-Ref + Maintainer
204 * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding 208 * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding
205 * decoding stuff there.. (eilers) 209 * decoding stuff there.. (eilers)
206 */ 210 */
207 QString InsertQuery::query()const{ 211 QString InsertQuery::query()const{
208 212
209 int year, month, day; 213 int year, month, day;
210 year = month = day = 0; 214 year = month = day = 0;
211 if (m_todo.hasDueDate() ) { 215 if (m_todo.hasDueDate() ) {
212 QDate date = m_todo.dueDate(); 216 QDate date = m_todo.dueDate();
213 year = date.year(); 217 year = date.year();
214 month = date.month(); 218 month = date.month();
215 day = date.day(); 219 day = date.day();
216 } 220 }
217 int sYear = 0, sMonth = 0, sDay = 0; 221 int sYear = 0, sMonth = 0, sDay = 0;
218 if( m_todo.hasStartDate() ){ 222 if( m_todo.hasStartDate() ){
219 QDate sDate = m_todo.startDate(); 223 QDate sDate = m_todo.startDate();
220 sYear = sDate.year(); 224 sYear = sDate.year();
221 sMonth= sDate.month(); 225 sMonth= sDate.month();
222 sDay = sDate.day(); 226 sDay = sDate.day();
223 } 227 }
224 228
225 int eYear = 0, eMonth = 0, eDay = 0; 229 int eYear = 0, eMonth = 0, eDay = 0;
226 if( m_todo.hasCompletedDate() ){ 230 if( m_todo.hasCompletedDate() ){
227 QDate eDate = m_todo.completedDate(); 231 QDate eDate = m_todo.completedDate();
228 eYear = eDate.year(); 232 eYear = eDate.year();
229 eMonth= eDate.month(); 233 eMonth= eDate.month();
230 eDay = eDate.day(); 234 eDay = eDate.day();
231 } 235 }
232 QString qu; 236 QString qu;
233 QMap<int, QString> recMap = m_todo.recurrence().toMap(); 237 QMap<int, QString> recMap = m_todo.recurrence().toMap();
234 qu = "insert into todolist VALUES(" 238 qu = "insert into todolist VALUES("
235 + QString::number( m_todo.uid() ) + "," 239 + QString::number( m_todo.uid() ) + ","
236 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," 240 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
237 + QString::number( m_todo.isCompleted() ) + "," 241 + QString::number( m_todo.isCompleted() ) + ","
238 + "'" + m_todo.description() + "'" + "," 242 + "'" + m_todo.description() + "'" + ","
239 + "'" + m_todo.summary() + "'" + "," 243 + "'" + m_todo.summary() + "'" + ","
240 + QString::number(m_todo.priority() ) + "," 244 + QString::number(m_todo.priority() ) + ","
241 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" 245 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-"
242 + QString::number(month).rightJustify( 2, '0' ) 246 + QString::number(month).rightJustify( 2, '0' )
243 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," 247 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + ","
244 + QString::number( m_todo.progress() ) + "," 248 + QString::number( m_todo.progress() ) + ","
245 + QString::number( m_todo.state().state() ) + "," 249 + QString::number( m_todo.state().state() ) + ","
246 + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," 250 + "'" + recMap[ OPimRecurrence::RType ] + "'" + ","
247 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," 251 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + ","
248 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," 252 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + ","
249 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," 253 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + ","
250 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," 254 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + ","
251 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," 255 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + ","
252 + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," 256 + "'" + recMap[ OPimRecurrence::Created ] + "'" + ","
253 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; 257 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ",";
254 258
255 if ( m_todo.hasNotifiers() ) { 259 if ( m_todo.hasNotifiers() ) {
256 OPimNotifyManager manager = m_todo.notifiers(); 260 OPimNotifyManager manager = m_todo.notifiers();
257 qu += "'" + manager.remindersToString() + "'" + "," 261 qu += "'" + manager.remindersToString() + "'" + ","
258 + "'" + manager.alarmsToString() + "'" + ","; 262 + "'" + manager.alarmsToString() + "'" + ",";
259 } 263 }
260 else{ 264 else{
261 qu += QString( "''" ) + "," 265 qu += QString( "''" ) + ","
262 + "''" + ","; 266 + "''" + ",";
263 } 267 }
264 268
265 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 269 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
266 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" 270 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
267 + QString::number(sMonth).rightJustify( 2, '0' ) 271 + QString::number(sMonth).rightJustify( 2, '0' )
268 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," 272 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + ","
269 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" 273 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-"
270 + QString::number(eMonth).rightJustify( 2, '0' ) 274 + QString::number(eMonth).rightJustify( 2, '0' )
271 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" 275 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'"
272 + "); "; 276 + "); ";
273 277
274 // Save custom Entries: 278 // Save custom Entries:
275 int id = 0; 279 int id = 0;
276 id = 0; 280 id = 0;
277 QMap<QString, QString> customMap = m_todo.toExtraMap(); 281 QMap<QString, QString> customMap = m_todo.toExtraMap();
278 for( QMap<QString, QString>::Iterator it = customMap.begin(); 282 for( QMap<QString, QString>::Iterator it = customMap.begin();
279 it != customMap.end(); ++it ){ 283 it != customMap.end(); ++it ){
280 qu += "insert into custom_data VALUES(" 284 qu += "insert into custom_data VALUES("
281 + QString::number( m_todo.uid() ) 285 + QString::number( m_todo.uid() )
282 + "," 286 + ","
283 + QString::number( id++ ) 287 + QString::number( id++ )
284 + ",'" 288 + ",'"
285 + it.key() 289 + it.key()
286 + "'," 290 + "',"
287 + "0" // Priority for future enhancements 291 + "0" // Priority for future enhancements
288 + ",'" 292 + ",'"
289 + it.data() 293 + it.data()
290 + "');"; 294 + "');";
291 } 295 }
292 296
293 297
294 qDebug("add %s", qu.latin1() ); 298 odebug << "add " << qu << "" << oendl;
295 return qu; 299 return qu;
296 } 300 }
297 301
298 RemoveQuery::RemoveQuery(int uid ) 302 RemoveQuery::RemoveQuery(int uid )
299 : OSQLQuery(), m_uid( uid ) {} 303 : OSQLQuery(), m_uid( uid ) {}
300 RemoveQuery::~RemoveQuery() {} 304 RemoveQuery::~RemoveQuery() {}
301 QString RemoveQuery::query()const { 305 QString RemoveQuery::query()const {
302 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; 306 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
303 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); 307 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
304 return qu; 308 return qu;
305 } 309 }
306 310
307 311
308 ClearQuery::ClearQuery() 312 ClearQuery::ClearQuery()
309 : OSQLQuery() {} 313 : OSQLQuery() {}
310 ClearQuery::~ClearQuery() {} 314 ClearQuery::~ClearQuery() {}
311 QString ClearQuery::query()const { 315 QString ClearQuery::query()const {
312 QString qu = "drop table todolist"; 316 QString qu = "drop table todolist";
313 return qu; 317 return qu;
314 } 318 }
315 FindQuery::FindQuery(int uid) 319 FindQuery::FindQuery(int uid)
316 : OSQLQuery(), m_uid(uid ) { 320 : OSQLQuery(), m_uid(uid ) {
317 } 321 }
318 FindQuery::FindQuery(const QArray<int>& ints) 322 FindQuery::FindQuery(const QArray<int>& ints)
319 : OSQLQuery(), m_uids(ints){ 323 : OSQLQuery(), m_uids(ints){
320 } 324 }
321 FindQuery::~FindQuery() { 325 FindQuery::~FindQuery() {
322 } 326 }
323 QString FindQuery::query()const{ 327 QString FindQuery::query()const{
324 if (m_uids.count() == 0 ) 328 if (m_uids.count() == 0 )
325 return single(); 329 return single();
326 else 330 else
327 return multi(); 331 return multi();
328 } 332 }
329 QString FindQuery::single()const{ 333 QString FindQuery::single()const{
330 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 334 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
331 return qu; 335 return qu;
332 } 336 }
333 QString FindQuery::multi()const { 337 QString FindQuery::multi()const {
334 QString qu = "select * from todolist where "; 338 QString qu = "select * from todolist where ";
335 for (uint i = 0; i < m_uids.count(); i++ ) { 339 for (uint i = 0; i < m_uids.count(); i++ ) {
336 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 340 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
337 } 341 }
338 qu.remove( qu.length()-2, 2 ); 342 qu.remove( qu.length()-2, 2 );
339 return qu; 343 return qu;
340 } 344 }
341 345
342 OverDueQuery::OverDueQuery(): OSQLQuery() {} 346 OverDueQuery::OverDueQuery(): OSQLQuery() {}
343 OverDueQuery::~OverDueQuery() {} 347 OverDueQuery::~OverDueQuery() {}
344 QString OverDueQuery::query()const { 348 QString OverDueQuery::query()const {
345 QDate date = QDate::currentDate(); 349 QDate date = QDate::currentDate();
346 QString str; 350 QString str;
347 str = QString("select uid from todolist where DueDate ='%1-%2-%3'") 351 str = QString("select uid from todolist where DueDate ='%1-%2-%3'")
348 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 352 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
349 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 353 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
350 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); 354 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) );
351 355
352 return str; 356 return str;
353 } 357 }
354 358
355 359
356 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 360 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
357 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 361 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
358 EffQuery::~EffQuery() {} 362 EffQuery::~EffQuery() {}
359 QString EffQuery::query()const { 363 QString EffQuery::query()const {
360 return m_inc ? with() : out(); 364 return m_inc ? with() : out();
361 } 365 }
362 QString EffQuery::with()const { 366 QString EffQuery::with()const {
363 QString str; 367 QString str;
364 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 368 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
365 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 369 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
366 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 370 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
367 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 371 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
368 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) 372 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
369 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) 373 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
370 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); 374 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
371 return str; 375 return str;
372 } 376 }
373 QString EffQuery::out()const { 377 QString EffQuery::out()const {
374 QString str; 378 QString str;
375 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 379 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
376 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 380 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
377 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 381 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
378 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 382 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
379 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) 383 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
380 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) 384 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
381 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); 385 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
382 386
383 return str; 387 return str;
384 } 388 }
385 389
386 FindCustomQuery::FindCustomQuery(int uid) 390 FindCustomQuery::FindCustomQuery(int uid)
387 : OSQLQuery(), m_uid( uid ) { 391 : OSQLQuery(), m_uid( uid ) {
388 } 392 }
389 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 393 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
390 : OSQLQuery(), m_uids( ints ){ 394 : OSQLQuery(), m_uids( ints ){
391 } 395 }
392 FindCustomQuery::~FindCustomQuery() { 396 FindCustomQuery::~FindCustomQuery() {
393 } 397 }
394 QString FindCustomQuery::query()const{ 398 QString FindCustomQuery::query()const{
395 return single(); // Multiple requests not supported ! 399 return single(); // Multiple requests not supported !
396 } 400 }
397 QString FindCustomQuery::single()const{ 401 QString FindCustomQuery::single()const{
398 QString qu = "select uid, type, value from custom_data where uid = "; 402 QString qu = "select uid, type, value from custom_data where uid = ";
399 qu += QString::number(m_uid); 403 qu += QString::number(m_uid);
400 return qu; 404 return qu;
401 } 405 }
402 406
403}; 407};
404 408
405 409
406namespace Opie { 410namespace Opie {
407OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) 411OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file )
408 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) 412 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true)
409{ 413{
410 QString fi = file; 414 QString fi = file;
411 if ( fi.isEmpty() ) 415 if ( fi.isEmpty() )
412 fi = Global::applicationFileName( "todolist", "todolist.db" ); 416 fi = Global::applicationFileName( "todolist", "todolist.db" );
413 OSQLManager man; 417 OSQLManager man;
414 m_driver = man.standard(); 418 m_driver = man.standard();
415 m_driver->setUrl(fi); 419 m_driver->setUrl(fi);
416 // fillDict(); 420 // fillDict();
417} 421}
418 422
419OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ 423OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){
420 if( m_driver ) 424 if( m_driver )
421 delete m_driver; 425 delete m_driver;
422} 426}
423 427
424bool OPimTodoAccessBackendSQL::load(){ 428bool OPimTodoAccessBackendSQL::load(){
425 if (!m_driver->open() ) 429 if (!m_driver->open() )
426 return false; 430 return false;
427 431
428 CreateQuery creat; 432 CreateQuery creat;
429 OSQLResult res = m_driver->query(&creat ); 433 OSQLResult res = m_driver->query(&creat );
430 434
431 m_dirty = true; 435 m_dirty = true;
432 return true; 436 return true;
433} 437}
434bool OPimTodoAccessBackendSQL::reload(){ 438bool OPimTodoAccessBackendSQL::reload(){
435 return load(); 439 return load();
436} 440}
437 441
438bool OPimTodoAccessBackendSQL::save(){ 442bool OPimTodoAccessBackendSQL::save(){
439 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 443 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
440} 444}
441QArray<int> OPimTodoAccessBackendSQL::allRecords()const { 445QArray<int> OPimTodoAccessBackendSQL::allRecords()const {
442 if (m_dirty ) 446 if (m_dirty )
443 update(); 447 update();
444 448
445 return m_uids; 449 return m_uids;
446} 450}
447QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ 451QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){
448 QArray<int> ints(0); 452 QArray<int> ints(0);
449 return ints; 453 return ints;
450} 454}
451OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ 455OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
452 FindQuery query( uid ); 456 FindQuery query( uid );
453 return todo( m_driver->query(&query) ); 457 return todo( m_driver->query(&query) );
454 458
455} 459}
456OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 460OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
457 uint cur, Frontend::CacheDirection dir ) const{ 461 uint cur, Frontend::CacheDirection dir ) const{
458 uint CACHE = readAhead(); 462 uint CACHE = readAhead();
459 qDebug("searching for %d", uid ); 463 odebug << "searching for " << uid << "" << oendl;
460 QArray<int> search( CACHE ); 464 QArray<int> search( CACHE );
461 uint size =0; 465 uint size =0;
462 OPimTodo to; 466 OPimTodo to;
463 467
464 // we try to cache CACHE items 468 // we try to cache CACHE items
465 switch( dir ) { 469 switch( dir ) {
466 /* forward */ 470 /* forward */
467 case 0: // FIXME: Not a good style to use magic numbers here (eilers) 471 case 0: // FIXME: Not a good style to use magic numbers here (eilers)
468 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 472 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
469 qDebug("size %d %d", size, ints[i] ); 473 odebug << "size " << size << " " << ints[i] << "" << oendl;
470 search[size] = ints[i]; 474 search[size] = ints[i];
471 size++; 475 size++;
472 } 476 }
473 break; 477 break;
474 /* reverse */ 478 /* reverse */
475 case 1: // FIXME: Not a good style to use magic numbers here (eilers) 479 case 1: // FIXME: Not a good style to use magic numbers here (eilers)
476 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 480 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
477 search[size] = ints[i]; 481 search[size] = ints[i];
478 size++; 482 size++;
479 } 483 }
480 break; 484 break;
481 } 485 }
482 search.resize( size ); 486 search.resize( size );
483 FindQuery query( search ); 487 FindQuery query( search );
484 OSQLResult res = m_driver->query( &query ); 488 OSQLResult res = m_driver->query( &query );
485 if ( res.state() != OSQLResult::Success ) 489 if ( res.state() != OSQLResult::Success )
486 return to; 490 return to;
487 491
488 return todo( res ); 492 return todo( res );
489} 493}
490void OPimTodoAccessBackendSQL::clear() { 494void OPimTodoAccessBackendSQL::clear() {
491 ClearQuery cle; 495 ClearQuery cle;
492 OSQLResult res = m_driver->query( &cle ); 496 OSQLResult res = m_driver->query( &cle );
493 CreateQuery qu; 497 CreateQuery qu;
@@ -520,177 +524,177 @@ bool OPimTodoAccessBackendSQL::remove( int uid ) {
520 * but we need the cache for that 524 * but we need the cache for that
521 * now we remove 525 * now we remove
522 */ 526 */
523bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { 527bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
524 remove( t.uid() ); 528 remove( t.uid() );
525 bool b= add(t); 529 bool b= add(t);
526 m_dirty = false; // we changed some stuff but the UID stayed the same 530 m_dirty = false; // we changed some stuff but the UID stayed the same
527 return b; 531 return b;
528} 532}
529QArray<int> OPimTodoAccessBackendSQL::overDue() { 533QArray<int> OPimTodoAccessBackendSQL::overDue() {
530 OverDueQuery qu; 534 OverDueQuery qu;
531 return uids( m_driver->query(&qu ) ); 535 return uids( m_driver->query(&qu ) );
532} 536}
533QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, 537QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
534 const QDate& t, 538 const QDate& t,
535 bool u) { 539 bool u) {
536 EffQuery ef(s, t, u ); 540 EffQuery ef(s, t, u );
537 return uids (m_driver->query(&ef) ); 541 return uids (m_driver->query(&ef) );
538} 542}
539/* 543/*
540 * 544 *
541 */ 545 */
542QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 546QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
543 int sortFilter, int cat ) { 547 int sortFilter, int cat ) {
544 qDebug("sorted %d, %d", asc, sortOrder ); 548 odebug << "sorted " << asc << ", " << sortOrder << "" << oendl;
545 QString query; 549 QString query;
546 query = "select uid from todolist WHERE "; 550 query = "select uid from todolist WHERE ";
547 551
548 /* 552 /*
549 * Sort Filter stuff 553 * Sort Filter stuff
550 * not that straight forward 554 * not that straight forward
551 * FIXME: Replace magic numbers 555 * FIXME: Replace magic numbers
552 * 556 *
553 */ 557 */
554 /* Category */ 558 /* Category */
555 if ( sortFilter & 1 ) { 559 if ( sortFilter & 1 ) {
556 QString str; 560 QString str;
557 if (cat != 0 ) str = QString::number( cat ); 561 if (cat != 0 ) str = QString::number( cat );
558 query += " categories like '%" +str+"%' AND"; 562 query += " categories like '%" +str+"%' AND";
559 } 563 }
560 /* Show only overdue */ 564 /* Show only overdue */
561 if ( sortFilter & 2 ) { 565 if ( sortFilter & 2 ) {
562 QDate date = QDate::currentDate(); 566 QDate date = QDate::currentDate();
563 QString due; 567 QString due;
564 QString base; 568 QString base;
565 base = QString("DueDate <= '%1-%2-%3' AND completed = 0") 569 base = QString("DueDate <= '%1-%2-%3' AND completed = 0")
566 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 570 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
567 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 571 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
568 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); 572 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
569 query += " " + base + " AND"; 573 query += " " + base + " AND";
570 } 574 }
571 /* not show completed */ 575 /* not show completed */
572 if ( sortFilter & 4 ) { 576 if ( sortFilter & 4 ) {
573 query += " completed = 0 AND"; 577 query += " completed = 0 AND";
574 }else{ 578 }else{
575 query += " ( completed = 1 OR completed = 0) AND"; 579 query += " ( completed = 1 OR completed = 0) AND";
576 } 580 }
577 /* strip the end */ 581 /* strip the end */
578 query = query.remove( query.length()-3, 3 ); 582 query = query.remove( query.length()-3, 3 );
579 583
580 584
581 /* 585 /*
582 * sort order stuff 586 * sort order stuff
583 * quite straight forward 587 * quite straight forward
584 */ 588 */
585 query += "ORDER BY "; 589 query += "ORDER BY ";
586 switch( sortOrder ) { 590 switch( sortOrder ) {
587 /* completed */ 591 /* completed */
588 case 0: 592 case 0:
589 query += "completed"; 593 query += "completed";
590 break; 594 break;
591 case 1: 595 case 1:
592 query += "priority"; 596 query += "priority";
593 break; 597 break;
594 case 2: 598 case 2:
595 query += "summary"; 599 query += "summary";
596 break; 600 break;
597 case 3: 601 case 3:
598 query += "DueDate"; 602 query += "DueDate";
599 break; 603 break;
600 } 604 }
601 605
602 if ( !asc ) { 606 if ( !asc ) {
603 qDebug("not ascending!"); 607 odebug << "not ascending!" << oendl;
604 query += " DESC"; 608 query += " DESC";
605 } 609 }
606 610
607 qDebug( query ); 611 odebug << query << oendl;
608 OSQLRawQuery raw(query ); 612 OSQLRawQuery raw(query );
609 return uids( m_driver->query(&raw) ); 613 return uids( m_driver->query(&raw) );
610} 614}
611bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 615bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
612 if ( str == "0-0-0" ) 616 if ( str == "0-0-0" )
613 return false; 617 return false;
614 else{ 618 else{
615 int day, year, month; 619 int day, year, month;
616 QStringList list = QStringList::split("-", str ); 620 QStringList list = QStringList::split("-", str );
617 year = list[0].toInt(); 621 year = list[0].toInt();
618 month = list[1].toInt(); 622 month = list[1].toInt();
619 day = list[2].toInt(); 623 day = list[2].toInt();
620 da.setYMD( year, month, day ); 624 da.setYMD( year, month, day );
621 return true; 625 return true;
622 } 626 }
623} 627}
624OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ 628OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{
625 if ( res.state() == OSQLResult::Failure ) { 629 if ( res.state() == OSQLResult::Failure ) {
626 OPimTodo to; 630 OPimTodo to;
627 return to; 631 return to;
628 } 632 }
629 633
630 OSQLResultItem::ValueList list = res.results(); 634 OSQLResultItem::ValueList list = res.results();
631 OSQLResultItem::ValueList::Iterator it = list.begin(); 635 OSQLResultItem::ValueList::Iterator it = list.begin();
632 qDebug("todo1"); 636 odebug << "todo1" << oendl;
633 OPimTodo to = todo( (*it) ); 637 OPimTodo to = todo( (*it) );
634 cache( to ); 638 cache( to );
635 ++it; 639 ++it;
636 640
637 for ( ; it != list.end(); ++it ) { 641 for ( ; it != list.end(); ++it ) {
638 qDebug("caching"); 642 odebug << "caching" << oendl;
639 cache( todo( (*it) ) ); 643 cache( todo( (*it) ) );
640 } 644 }
641 return to; 645 return to;
642} 646}
643OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 647OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
644 qDebug("todo(ResultItem)"); 648 odebug << "todo(ResultItem)" << oendl;
645 649
646 // Request information from addressbook table and create the OPimTodo-object. 650 // Request information from addressbook table and create the OPimTodo-object.
647 651
648 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 652 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
649 hasDueDate = date( dueDate, item.data("DueDate") ); 653 hasDueDate = date( dueDate, item.data("DueDate") );
650 QStringList cats = QStringList::split(";", item.data("categories") ); 654 QStringList cats = QStringList::split(";", item.data("categories") );
651 655
652 qDebug("Item is completed: %d", item.data("completed").toInt() ); 656 odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
653 657
654 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 658 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
655 cats, item.data("summary"), item.data("description"), 659 cats, item.data("summary"), item.data("description"),
656 item.data("progress").toUShort(), hasDueDate, dueDate, 660 item.data("progress").toUShort(), hasDueDate, dueDate,
657 item.data("uid").toInt() ); 661 item.data("uid").toInt() );
658 662
659 bool isOk; 663 bool isOk;
660 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 664 int prioInt = QString( item.data("priority") ).toInt( &isOk );
661 if ( isOk ) 665 if ( isOk )
662 to.setPriority( prioInt ); 666 to.setPriority( prioInt );
663 667
664 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 668 bool hasStartDate = false; QDate startDate = QDate::currentDate();
665 hasStartDate = date( startDate, item.data("startdate") ); 669 hasStartDate = date( startDate, item.data("startdate") );
666 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); 670 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
667 hasCompletedDate = date( completedDate, item.data("completeddate") ); 671 hasCompletedDate = date( completedDate, item.data("completeddate") );
668 672
669 if ( hasStartDate ) 673 if ( hasStartDate )
670 to.setStartDate( startDate ); 674 to.setStartDate( startDate );
671 if ( hasCompletedDate ) 675 if ( hasCompletedDate )
672 to.setCompletedDate( completedDate ); 676 to.setCompletedDate( completedDate );
673 677
674 OPimNotifyManager& manager = to.notifiers(); 678 OPimNotifyManager& manager = to.notifiers();
675 manager.alarmsFromString( item.data("alarms") ); 679 manager.alarmsFromString( item.data("alarms") );
676 manager.remindersFromString( item.data("reminders") ); 680 manager.remindersFromString( item.data("reminders") );
677 681
678 OPimState pimState; 682 OPimState pimState;
679 pimState.setState( QString( item.data("state") ).toInt() ); 683 pimState.setState( QString( item.data("state") ).toInt() );
680 to.setState( pimState ); 684 to.setState( pimState );
681 685
682 QMap<int, QString> recMap; 686 QMap<int, QString> recMap;
683 recMap.insert( OPimRecurrence::RType , item.data("RType") ); 687 recMap.insert( OPimRecurrence::RType , item.data("RType") );
684 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); 688 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") );
685 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); 689 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") );
686 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); 690 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") );
687 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); 691 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") );
688 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); 692 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") );
689 recMap.insert( OPimRecurrence::Created , item.data("Created") ); 693 recMap.insert( OPimRecurrence::Created , item.data("Created") );
690 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); 694 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") );
691 695
692 OPimRecurrence recur; 696 OPimRecurrence recur;
693 recur.fromMap( recMap ); 697 recur.fromMap( recMap );
694 to.setRecurrence( recur ); 698 to.setRecurrence( recur );
695 699
696 // Finally load the custom-entries for this UID and put it into the created object 700 // Finally load the custom-entries for this UID and put it into the created object
@@ -729,152 +733,152 @@ void OPimTodoAccessBackendSQL::fillDict() {
729 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); 733 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
730// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) 734// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
731// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) 735// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
732 736
733#endif 737#endif
734} 738}
735/* 739/*
736 * need to be const so let's fool the 740 * need to be const so let's fool the
737 * compiler :( 741 * compiler :(
738 */ 742 */
739void OPimTodoAccessBackendSQL::update()const { 743void OPimTodoAccessBackendSQL::update()const {
740 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; 744 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false;
741 LoadQuery lo; 745 LoadQuery lo;
742 OSQLResult res = m_driver->query(&lo); 746 OSQLResult res = m_driver->query(&lo);
743 if ( res.state() != OSQLResult::Success ) 747 if ( res.state() != OSQLResult::Success )
744 return; 748 return;
745 749
746 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); 750 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res );
747} 751}
748QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 752QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
749 753
750 OSQLResultItem::ValueList list = res.results(); 754 OSQLResultItem::ValueList list = res.results();
751 OSQLResultItem::ValueList::Iterator it; 755 OSQLResultItem::ValueList::Iterator it;
752 QArray<int> ints(list.count() ); 756 QArray<int> ints(list.count() );
753 qDebug(" count = %d", list.count() ); 757 odebug << " count = " << list.count() << "" << oendl;
754 758
755 int i = 0; 759 int i = 0;
756 for (it = list.begin(); it != list.end(); ++it ) { 760 for (it = list.begin(); it != list.end(); ++it ) {
757 ints[i] = (*it).data("uid").toInt(); 761 ints[i] = (*it).data("uid").toInt();
758 i++; 762 i++;
759 } 763 }
760 return ints; 764 return ints;
761} 765}
762 766
763QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 767QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
764{ 768{
765 769
766#if 0 770#if 0
767 QArray<int> empty; 771 QArray<int> empty;
768 return empty; 772 return empty;
769 773
770#else 774#else
771 QString qu = "SELECT uid FROM todolist WHERE ("; 775 QString qu = "SELECT uid FROM todolist WHERE (";
772 776
773 // Do it make sense to search other fields, too ? 777 // Do it make sense to search other fields, too ?
774 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; 778 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
775 qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; 779 qu += " rlike(\""+ r.pattern() + "\",\"summary\")";
776 780
777 qu += ")"; 781 qu += ")";
778 782
779 qDebug( "query: %s", qu.latin1() ); 783 odebug << "query: " << qu << "" << oendl;
780 784
781 OSQLRawQuery raw( qu ); 785 OSQLRawQuery raw( qu );
782 OSQLResult res = m_driver->query( &raw ); 786 OSQLResult res = m_driver->query( &raw );
783 787
784 return uids( res ); 788 return uids( res );
785 789
786 790
787#endif 791#endif
788 792
789} 793}
790QBitArray OPimTodoAccessBackendSQL::supports()const { 794QBitArray OPimTodoAccessBackendSQL::supports()const {
791 795
792 return sup(); 796 return sup();
793} 797}
794 798
795QBitArray OPimTodoAccessBackendSQL::sup() const{ 799QBitArray OPimTodoAccessBackendSQL::sup() const{
796 800
797 QBitArray ar( OPimTodo::CompletedDate + 1 ); 801 QBitArray ar( OPimTodo::CompletedDate + 1 );
798 ar.fill( true ); 802 ar.fill( true );
799 ar[OPimTodo::CrossReference] = false; 803 ar[OPimTodo::CrossReference] = false;
800 ar[OPimTodo::State ] = false; 804 ar[OPimTodo::State ] = false;
801 ar[OPimTodo::Reminders] = false; 805 ar[OPimTodo::Reminders] = false;
802 ar[OPimTodo::Notifiers] = false; 806 ar[OPimTodo::Notifiers] = false;
803 ar[OPimTodo::Maintainer] = false; 807 ar[OPimTodo::Maintainer] = false;
804 808
805 return ar; 809 return ar;
806} 810}
807 811
808void OPimTodoAccessBackendSQL::removeAllCompleted(){ 812void OPimTodoAccessBackendSQL::removeAllCompleted(){
809 // First we need the uids from all entries which are 813 // First we need the uids from all entries which are
810 // completed. Then, we just have to remove them... 814 // completed. Then, we just have to remove them...
811 815
812 QString qu = "SELECT uid FROM todolist WHERE completed = 1"; 816 QString qu = "SELECT uid FROM todolist WHERE completed = 1";
813 817
814 OSQLRawQuery raw( qu ); 818 OSQLRawQuery raw( qu );
815 OSQLResult res = m_driver->query( &raw ); 819 OSQLResult res = m_driver->query( &raw );
816 820
817 QArray<int> completed_uids = uids( res ); 821 QArray<int> completed_uids = uids( res );
818 822
819 qDebug( "Number of completed: %d", completed_uids.size() ); 823 odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
820 824
821 if ( completed_uids.size() == 0 ) 825 if ( completed_uids.size() == 0 )
822 return; 826 return;
823 827
824 qu = "DELETE FROM todolist WHERE ("; 828 qu = "DELETE FROM todolist WHERE (";
825 QString query; 829 QString query;
826 830
827 for ( int i = 0; i < completed_uids.size(); i++ ){ 831 for ( int i = 0; i < completed_uids.size(); i++ ){
828 if ( !query.isEmpty() ) 832 if ( !query.isEmpty() )
829 query += " OR "; 833 query += " OR ";
830 query += QString( "uid = %1" ).arg( completed_uids[i] ); 834 query += QString( "uid = %1" ).arg( completed_uids[i] );
831 } 835 }
832 qu += query + " );"; 836 qu += query + " );";
833 837
834 // Put remove of custom entries in this query to speed up.. 838 // Put remove of custom entries in this query to speed up..
835 qu += "DELETE FORM custom_data WHERE ("; 839 qu += "DELETE FORM custom_data WHERE (";
836 query = ""; 840 query = "";
837 841
838 for ( int i = 0; i < completed_uids.size(); i++ ){ 842 for ( int i = 0; i < completed_uids.size(); i++ ){
839 if ( !query.isEmpty() ) 843 if ( !query.isEmpty() )
840 query += " OR "; 844 query += " OR ";
841 query += QString( "uid = %1" ).arg( completed_uids[i] ); 845 query += QString( "uid = %1" ).arg( completed_uids[i] );
842 } 846 }
843 qu += query + " );"; 847 qu += query + " );";
844 848
845 qDebug( "query: %s", qu.latin1() ); 849 odebug << "query: " << qu << "" << oendl;
846 850
847 OSQLRawQuery raw2( qu ); 851 OSQLRawQuery raw2( qu );
848 res = m_driver->query( &raw2 ); 852 res = m_driver->query( &raw2 );
849 if ( res.state() == OSQLResult::Failure ) { 853 if ( res.state() == OSQLResult::Failure ) {
850 qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() ); 854 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl;
851 } 855 }
852} 856}
853 857
854 858
855QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const 859QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
856{ 860{
857 QMap<QString, QString> customMap; 861 QMap<QString, QString> customMap;
858 862
859 FindCustomQuery query( uid ); 863 FindCustomQuery query( uid );
860 OSQLResult res_custom = m_driver->query( &query ); 864 OSQLResult res_custom = m_driver->query( &query );
861 865
862 if ( res_custom.state() == OSQLResult::Failure ) { 866 if ( res_custom.state() == OSQLResult::Failure ) {
863 qWarning("OSQLResult::Failure in find query !!"); 867 owarn << "OSQLResult::Failure in find query !!" << oendl;
864 QMap<QString, QString> empty; 868 QMap<QString, QString> empty;
865 return empty; 869 return empty;
866 } 870 }
867 871
868 OSQLResultItem::ValueList list = res_custom.results(); 872 OSQLResultItem::ValueList list = res_custom.results();
869 OSQLResultItem::ValueList::Iterator it = list.begin(); 873 OSQLResultItem::ValueList::Iterator it = list.begin();
870 for ( ; it != list.end(); ++it ) { 874 for ( ; it != list.end(); ++it ) {
871 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 875 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
872 } 876 }
873 877
874 return customMap; 878 return customMap;
875} 879}
876 880
877 881
878 882
879 883
880} 884}