summaryrefslogtreecommitdiff
path: root/libopie2
authoreilers <eilers>2004-04-05 07:03:09 (UTC)
committer eilers <eilers>2004-04-05 07:03:09 (UTC)
commite6e31e93aa55bb967a044fe3660201000a6e59b0 (patch) (unidiff)
tree1071fa4b22698fd56dde283bbb7375478b7e1ddf /libopie2
parent6be3d148fc1d610ebfa193012657b3b77d9368e3 (diff)
downloadopie-e6e31e93aa55bb967a044fe3660201000a6e59b0.zip
opie-e6e31e93aa55bb967a044fe3660201000a6e59b0.tar.gz
opie-e6e31e93aa55bb967a044fe3660201000a6e59b0.tar.bz2
SQL-Backends are almost finished !
Works: Loading/Storing data, Most important search queries for Address/todo Unfinished: Search-Queries for Datebook, regexp search
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp180
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp1
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp70
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.h2
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp173
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h5
-rw-r--r--libopie2/opiepim/core/opimcontact.h2
7 files changed, 339 insertions, 94 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index 1ea35a8..3142f75 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -30,43 +30,44 @@
30 * SQL Backend for the OPIE-Contact Database. 30 * SQL Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33#include "ocontactaccessbackend_sql.h" 33#include "ocontactaccessbackend_sql.h"
34 34
35#include <qarray.h> 35#include <qarray.h>
36#include <qdatetime.h> 36#include <qdatetime.h>
37#include <qstringlist.h> 37#include <qstringlist.h>
38 38
39#include <qpe/global.h> 39#include <qpe/global.h>
40#include <qpe/recordfields.h> 40#include <qpe/recordfields.h>
41 41
42#include <opie2/opimcontact.h>
42#include <opie2/opimcontactfields.h> 43#include <opie2/opimcontactfields.h>
43#include <opie2/opimdateconversion.h> 44#include <opie2/opimdateconversion.h>
44#include <opie2/osqldriver.h> 45#include <opie2/osqldriver.h>
45#include <opie2/osqlresult.h> 46#include <opie2/osqlresult.h>
46#include <opie2/osqlmanager.h> 47#include <opie2/osqlmanager.h>
47#include <opie2/osqlquery.h> 48#include <opie2/osqlquery.h>
48 49
50using namespace Opie;
49using namespace Opie::DB; 51using namespace Opie::DB;
50 52
51 53
52/* 54/*
53 * Implementation of used query types 55 * Implementation of used query types * CREATE query
54 * CREATE query
55 * LOAD query 56 * LOAD query
56 * INSERT 57 * INSERT
57 * REMOVE 58 * REMOVE
58 * CLEAR 59 * CLEAR
59 */ 60 */
60namespace Opie { 61namespace {
61 /** 62 /**
62 * CreateQuery for the Todolist Table 63 * CreateQuery for the Todolist Table
63 */ 64 */
64 class CreateQuery : public OSQLQuery { 65 class CreateQuery : public OSQLQuery {
65 public: 66 public:
66 CreateQuery(); 67 CreateQuery();
67 ~CreateQuery(); 68 ~CreateQuery();
68 QString query()const; 69 QString query()const;
69 }; 70 };
70 71
71 /** 72 /**
72 * Clears (delete) a Table 73 * Clears (delete) a Table
@@ -141,43 +142,43 @@ namespace Opie {
141 FindCustomQuery(const QArray<int>& ); 142 FindCustomQuery(const QArray<int>& );
142 ~FindCustomQuery(); 143 ~FindCustomQuery();
143 QString query()const; 144 QString query()const;
144 private: 145 private:
145 QString single()const; 146 QString single()const;
146 QString multi()const; 147 QString multi()const;
147 QArray<int> m_uids; 148 QArray<int> m_uids;
148 int m_uid; 149 int m_uid;
149 }; 150 };
150 151
151 152
152 153
153 // We using three tables to store the information: 154 // We using two tables to store the information:
154 // 1. addressbook : It contains General information about the contact (non custom) 155 // 1. addressbook : It contains General information about the contact (non custom)
155 // 2. custom_data : Not official supported entries 156 // 2. custom_data : Not official supported entries
156 // All tables are connected by the uid of the contact. 157 // All tables are connected by the uid of the contact.
157 // Maybe I should add a table for meta-information ? 158 // Maybe I should add a table for meta-information ?
158 CreateQuery::CreateQuery() : OSQLQuery() {} 159 CreateQuery::CreateQuery() : OSQLQuery() {}
159 CreateQuery::~CreateQuery() {} 160 CreateQuery::~CreateQuery() {}
160 QString CreateQuery::query()const { 161 QString CreateQuery::query()const {
161 QString qu; 162 QString qu;
162 163
163 qu += "create table addressbook( uid PRIMARY KEY "; 164 qu += "create table addressbook( uid PRIMARY KEY ";
164 165
165 QStringList fieldList = OPimContactFields::untrfields( false ); 166 QStringList fieldList = OPimContactFields::untrfields( false );
166 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 167 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
167 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); 168 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it );
168 } 169 }
169 qu += " );"; 170 qu += " );";
170 171
171 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; 172 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
172 173
173 return qu; 174 return qu;
174 } 175 }
175 176
176 ClearQuery::ClearQuery() 177 ClearQuery::ClearQuery()
177 : OSQLQuery() {} 178 : OSQLQuery() {}
178 ClearQuery::~ClearQuery() {} 179 ClearQuery::~ClearQuery() {}
179 QString ClearQuery::query()const { 180 QString ClearQuery::query()const {
180 QString qu = "drop table addressbook;"; 181 QString qu = "drop table addressbook;";
181 qu += "drop table custom_data;"; 182 qu += "drop table custom_data;";
182 // qu += "drop table dates;"; 183 // qu += "drop table dates;";
183 return qu; 184 return qu;
@@ -212,80 +213,71 @@ namespace Opie {
212 213
213 // Get all information out of the contact-class 214 // Get all information out of the contact-class
214 // Remember: The category is stored in contactMap, too ! 215 // Remember: The category is stored in contactMap, too !
215 QMap<int, QString> contactMap = m_contact.toMap(); 216 QMap<int, QString> contactMap = m_contact.toMap();
216 217
217 QStringList fieldList = OPimContactFields::untrfields( false ); 218 QStringList fieldList = OPimContactFields::untrfields( false );
218 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 219 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
219 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 220 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
220 // Convert Column-String to Id and get value for this id.. 221 // Convert Column-String to Id and get value for this id..
221 // Hmmm.. Maybe not very cute solution.. 222 // Hmmm.. Maybe not very cute solution..
222 int id = translate[*it]; 223 int id = translate[*it];
223 switch ( id ){ 224 switch ( id ){
224 case Qtopia::Birthday:{ 225 case Qtopia::Birthday:
225 // These entries should stored in a special format 226 case Qtopia::Anniversary:{
226 // year-month-day 227 QDate day;
227 QDate day = m_contact.birthday(); 228 if ( id == Qtopia::Birthday ){
228 if ( day.isValid() ){ 229 day = m_contact.birthday();
229 qu += QString(",\"%1-%2-%3\"")
230 .arg( day.year() )
231 .arg( day.month() )
232 .arg( day.day() );
233 } else { 230 } else {
234 qu += ",\"\""; 231 day = m_contact.anniversary();
235 } 232 }
236 }
237 break;
238 case Qtopia::Anniversary:{
239 // These entries should stored in a special format 233 // These entries should stored in a special format
240 // year-month-day 234 // year-month-day
241 QDate day = m_contact.anniversary();
242 if ( day.isValid() ){ 235 if ( day.isValid() ){
243 qu += QString(",\"%1-%2-%3\"") 236 qu += QString(",\"%1-%2-%3\"")
244 .arg( day.year() ) 237 .arg( QString::number( day.year() ).rightJustify( 4, '0' ) )
245 .arg( day.month() ) 238 .arg( QString::number( day.month() ).rightJustify( 2, '0' ) )
246 .arg( day.day() ); 239 .arg( QString::number( day.day() ).rightJustify( 2, '0' ) );
247 } else { 240 } else {
248 qu += ",\"\""; 241 qu += ",\"\"";
249 } 242 }
250 } 243 }
251 break; 244 break;
252
253 default: 245 default:
254 qu += QString( ",\"%1\"" ).arg( contactMap[id] ); 246 qu += QString( ",\"%1\"" ).arg( contactMap[id] );
255 } 247 }
256 } 248 }
257 qu += " );"; 249 qu += " );";
258 250
259 251
260 // Now add custom data.. 252 // Now add custom data..
261 int id = 0; 253 int id = 0;
262 id = 0; 254 id = 0;
263 QMap<QString, QString> customMap = m_contact.toExtraMap(); 255 QMap<QString, QString> customMap = m_contact.toExtraMap();
264 for( QMap<QString, QString>::Iterator it = customMap.begin(); 256 for( QMap<QString, QString>::Iterator it = customMap.begin();
265 it != customMap.end(); ++it ){ 257 it != customMap.end(); ++it ){
266 qu += "insert into custom_data VALUES(" 258 qu += "insert into custom_data VALUES("
267 + QString::number( m_contact.uid() ) 259 + QString::number( m_contact.uid() )
268 + "," 260 + ","
269 + QString::number( id++ ) 261 + QString::number( id++ )
270 + ",'" 262 + ",'"
271 + it.key() //.latin1() 263 + it.key()
272 + "'," 264 + "',"
273 + "0" // Priority for future enhancements 265 + "0" // Priority for future enhancements
274 + ",'" 266 + ",'"
275 + it.data() //.latin1() 267 + it.data()
276 + "');"; 268 + "');";
277 } 269 }
278 // qu += "commit;"; 270 // qu += "commit;";
279 qWarning("add %s", qu.latin1() ); 271 qDebug("add %s", qu.latin1() );
280 return qu; 272 return qu;
281 } 273 }
282 274
283 275
284 RemoveQuery::RemoveQuery(int uid ) 276 RemoveQuery::RemoveQuery(int uid )
285 : OSQLQuery(), m_uid( uid ) {} 277 : OSQLQuery(), m_uid( uid ) {}
286 RemoveQuery::~RemoveQuery() {} 278 RemoveQuery::~RemoveQuery() {}
287 QString RemoveQuery::query()const { 279 QString RemoveQuery::query()const {
288 QString qu = "DELETE from addressbook where uid = " 280 QString qu = "DELETE from addressbook where uid = "
289 + QString::number(m_uid) + ";"; 281 + QString::number(m_uid) + ";";
290 qu += "DELETE from custom_data where uid = " 282 qu += "DELETE from custom_data where uid = "
291 + QString::number(m_uid) + ";"; 283 + QString::number(m_uid) + ";";
@@ -349,42 +341,42 @@ namespace Opie {
349 341
350}; 342};
351 343
352 344
353/* --------------------------------------------------------------------------- */ 345/* --------------------------------------------------------------------------- */
354 346
355namespace Opie { 347namespace Opie {
356 348
357OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, 349OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */,
358 const QString& filename ): 350 const QString& filename ):
359 OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) 351 OPimContactAccessBackend(), m_changed(false), m_driver( NULL )
360{ 352{
361 qWarning("C'tor OPimContactAccessBackend_SQL starts"); 353 qDebug("C'tor OPimContactAccessBackend_SQL starts");
362 QTime t; 354 QTime t;
363 t.start(); 355 t.start();
364 356
365 /* Expecting to access the default filename if nothing else is set */ 357 /* Expecting to access the default filename if nothing else is set */
366 if ( filename.isEmpty() ){ 358 if ( filename.isEmpty() ){
367 m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); 359 m_fileName = Global::applicationFileName( "addressbook","addressbook.db" );
368 } else 360 } else
369 m_fileName = filename; 361 m_fileName = filename;
370 362
371 // Get the standart sql-driver from the OSQLManager.. 363 // Get the standart sql-driver from the OSQLManager..
372 OSQLManager man; 364 OSQLManager man;
373 m_driver = man.standard(); 365 m_driver = man.standard();
374 m_driver->setUrl( m_fileName ); 366 m_driver->setUrl( m_fileName );
375 367
376 load(); 368 load();
377 369
378 qWarning("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); 370 qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() );
379} 371}
380 372
381OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () 373OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL ()
382{ 374{
383 if( m_driver ) 375 if( m_driver )
384 delete m_driver; 376 delete m_driver;
385} 377}
386 378
387bool OPimContactAccessBackend_SQL::load () 379bool OPimContactAccessBackend_SQL::load ()
388{ 380{
389 if (!m_driver->open() ) 381 if (!m_driver->open() )
390 return false; 382 return false;
@@ -467,113 +459,187 @@ bool OPimContactAccessBackend_SQL::remove ( int uid )
467 459
468bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) 460bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact )
469{ 461{
470 if ( !remove( contact.uid() ) ) 462 if ( !remove( contact.uid() ) )
471 return false; 463 return false;
472 464
473 return add( contact ); 465 return add( contact );
474} 466}
475 467
476 468
477OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const 469OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
478{ 470{
479 qWarning("OPimContactAccessBackend_SQL::find()"); 471 qDebug("OPimContactAccessBackend_SQL::find()");
480 QTime t; 472 QTime t;
481 t.start(); 473 t.start();
482 474
483 OPimContact retContact( requestNonCustom( uid ) ); 475 OPimContact retContact( requestNonCustom( uid ) );
484 retContact.setExtraMap( requestCustom( uid ) ); 476 retContact.setExtraMap( requestCustom( uid ) );
485 477
486 qWarning("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); 478 qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() );
487 return retContact; 479 return retContact;
488} 480}
489 481
490 482
491 483
492QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() ) 484QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd )
493{ 485{
494 QString qu = "SELECT uid FROM addressbook WHERE"; 486 QString qu = "SELECT uid FROM addressbook WHERE";
487 QString searchQuery ="";
488
489 QDate startDate;
490
491 if ( qd.isValid() )
492 startDate = qd.date();
493 else
494 startDate = QDate::currentDate();
495
495 496
496 QMap<int, QString> queryFields = query.toMap(); 497 QMap<int, QString> queryFields = query.toMap();
497 QStringList fieldList = OPimContactFields::untrfields( false ); 498 QStringList fieldList = OPimContactFields::untrfields( false );
498 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 499 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
499 500
500 // Convert every filled field to a SQL-Query 501 // Convert every filled field to a SQL-Query
501 bool isAnyFieldSelected = false; 502 // bool isAnyFieldSelected = false;
502 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 503 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
504
503 int id = translate[*it]; 505 int id = translate[*it];
504 QString queryStr = queryFields[id]; 506 QString queryStr = queryFields[id];
507 QDate* endDate = 0l;
508
505 if ( !queryStr.isEmpty() ){ 509 if ( !queryStr.isEmpty() ){
506 isAnyFieldSelected = true; 510 // If something is alredy stored in the query, add an "AND"
511 // to the end of the string to prepare for the next ..
512 if ( !searchQuery.isEmpty() )
513 searchQuery += " AND";
514
515 // isAnyFieldSelected = true;
507 switch( id ){ 516 switch( id ){
517 case Qtopia::Birthday:
518 endDate = new QDate( query.birthday() );
519 // Fall through !
520 case Qtopia::Anniversary:
521 if ( endDate == 0l )
522 endDate = new QDate( query.anniversary() );
523
524 if ( settings & OPimContactAccess::DateDiff ) {
525 searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" )
526 .arg( *it )
527 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) )
528 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) )
529 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) )
530 .arg( *it )
531 .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) )
532 .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) )
533 .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ;
534 }
535
536 if ( settings & OPimContactAccess::DateYear ){
537 if ( settings & OPimContactAccess::DateDiff )
538 searchQuery += " AND";
539
540 searchQuery += QString( " (\"%1\" LIKE '%2-%')" )
541 .arg( *it )
542 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) );
543 }
544
545 if ( settings & OPimContactAccess::DateMonth ){
546 if ( ( settings & OPimContactAccess::DateDiff )
547 || ( settings & OPimContactAccess::DateYear ) )
548 searchQuery += " AND";
549
550 searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" )
551 .arg( *it )
552 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) );
553 }
554
555 if ( settings & OPimContactAccess::DateDay ){
556 if ( ( settings & OPimContactAccess::DateDiff )
557 || ( settings & OPimContactAccess::DateYear )
558 || ( settings & OPimContactAccess::DateMonth ) )
559 searchQuery += " AND";
560
561 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" )
562 .arg( *it )
563 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) );
564 }
565
566 break;
508 default: 567 default:
509 // Switching between case sensitive and insensitive... 568 // Switching between case sensitive and insensitive...
510 // LIKE is not case sensitive, GLOB is case sensitive 569 // LIKE is not case sensitive, GLOB is case sensitive
511 // Do exist a better solution to switch this ? 570 // Do exist a better solution to switch this ?
512 if ( settings & OPimContactAccess::IgnoreCase ) 571 if ( settings & OPimContactAccess::IgnoreCase )
513 qu += "(\"" + *it + "\"" + " LIKE " + "'" 572 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'"
514 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND "; 573 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")";
515 else 574 else
516 qu += "(\"" + *it + "\"" + " GLOB " + "'" 575 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'"
517 + queryStr + "'" + ") AND "; 576 + queryStr + "'" + ")";
518 577
519 } 578 }
520 } 579 }
521 } 580 }
522 // Skip trailing "AND" 581 // Skip trailing "AND"
523 if ( isAnyFieldSelected ) 582 // if ( isAnyFieldSelected )
524 qu = qu.left( qu.length() - 4 ); 583 // qu = qu.left( qu.length() - 4 );
584
585 qu += searchQuery;
525 586
526 qWarning( "queryByExample query: %s", qu.latin1() ); 587 qDebug( "queryByExample query: %s", qu.latin1() );
527 588
528 // Execute query and return the received uid's 589 // Execute query and return the received uid's
529 OSQLRawQuery raw( qu ); 590 OSQLRawQuery raw( qu );
530 OSQLResult res = m_driver->query( &raw ); 591 OSQLResult res = m_driver->query( &raw );
531 if ( res.state() != OSQLResult::Success ){ 592 if ( res.state() != OSQLResult::Success ){
532 QArray<int> empty; 593 QArray<int> empty;
533 return empty; 594 return empty;
534 } 595 }
535 596
536 QArray<int> list = extractUids( res ); 597 QArray<int> list = extractUids( res );
537 598
538 return list; 599 return list;
539} 600}
540 601
541QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 602QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
542{ 603{
543 QArray<int> nix(0); 604 QArray<int> nix(0);
544 return nix; 605 return nix;
545} 606}
546 607
547const uint OPimContactAccessBackend_SQL::querySettings() 608const uint OPimContactAccessBackend_SQL::querySettings()
548{ 609{
549 return OPimContactAccess::IgnoreCase 610 return OPimContactAccess::IgnoreCase
550 || OPimContactAccess::WildCards; 611 || OPimContactAccess::WildCards
612 || OPimContactAccess::DateDiff
613 || OPimContactAccess::DateYear
614 || OPimContactAccess::DateMonth
615 || OPimContactAccess::DateDay
616 ;
551} 617}
552 618
553bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const 619bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
554{ 620{
555 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 621 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
556 * may be added with any of the other settings. IgnoreCase should never used alone. 622 * may be added with any of the other settings. IgnoreCase should never used alone.
557 * Wildcards, RegExp, ExactMatch should never used at the same time... 623 * Wildcards, RegExp, ExactMatch should never used at the same time...
558 */ 624 */
559 625
560 // Step 1: Check whether the given settings are supported by this backend 626 // Step 1: Check whether the given settings are supported by this backend
561 if ( ( querySettings & ( 627 if ( ( querySettings & (
562 OPimContactAccess::IgnoreCase 628 OPimContactAccess::IgnoreCase
563 | OPimContactAccess::WildCards 629 | OPimContactAccess::WildCards
564 // | OPimContactAccess::DateDiff 630 | OPimContactAccess::DateDiff
565 // | OPimContactAccess::DateYear 631 | OPimContactAccess::DateYear
566 // | OPimContactAccess::DateMonth 632 | OPimContactAccess::DateMonth
567 // | OPimContactAccess::DateDay 633 | OPimContactAccess::DateDay
568 // | OPimContactAccess::RegExp 634 // | OPimContactAccess::RegExp
569 // | OPimContactAccess::ExactMatch 635 // | OPimContactAccess::ExactMatch
570 ) ) != querySettings ) 636 ) ) != querySettings )
571 return false; 637 return false;
572 638
573 // Step 2: Check whether the given combinations are ok.. 639 // Step 2: Check whether the given combinations are ok..
574 640
575 // IngoreCase alone is invalid 641 // IngoreCase alone is invalid
576 if ( querySettings == OPimContactAccess::IgnoreCase ) 642 if ( querySettings == OPimContactAccess::IgnoreCase )
577 return false; 643 return false;
578 644
579 // WildCards, RegExp and ExactMatch should never used at the same time 645 // WildCards, RegExp and ExactMatch should never used at the same time
@@ -600,77 +666,77 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
600 666
601QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) 667QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
602{ 668{
603 QTime t; 669 QTime t;
604 t.start(); 670 t.start();
605 671
606 QString query = "SELECT uid FROM addressbook "; 672 QString query = "SELECT uid FROM addressbook ";
607 query += "ORDER BY \"Last Name\" "; 673 query += "ORDER BY \"Last Name\" ";
608 674
609 if ( !asc ) 675 if ( !asc )
610 query += "DESC"; 676 query += "DESC";
611 677
612 // qWarning("sorted query is: %s", query.latin1() ); 678 // qDebug("sorted query is: %s", query.latin1() );
613 679
614 OSQLRawQuery raw( query ); 680 OSQLRawQuery raw( query );
615 OSQLResult res = m_driver->query( &raw ); 681 OSQLResult res = m_driver->query( &raw );
616 if ( res.state() != OSQLResult::Success ){ 682 if ( res.state() != OSQLResult::Success ){
617 QArray<int> empty; 683 QArray<int> empty;
618 return empty; 684 return empty;
619 } 685 }
620 686
621 QArray<int> list = extractUids( res ); 687 QArray<int> list = extractUids( res );
622 688
623 qWarning("sorted needed %d ms!", t.elapsed() ); 689 qDebug("sorted needed %d ms!", t.elapsed() );
624 return list; 690 return list;
625} 691}
626 692
627 693
628void OPimContactAccessBackend_SQL::update() 694void OPimContactAccessBackend_SQL::update()
629{ 695{
630 qWarning("Update starts"); 696 qDebug("Update starts");
631 QTime t; 697 QTime t;
632 t.start(); 698 t.start();
633 699
634 // Now load the database set and extract the uid's 700 // Now load the database set and extract the uid's
635 // which will be held locally 701 // which will be held locally
636 702
637 LoadQuery lo; 703 LoadQuery lo;
638 OSQLResult res = m_driver->query(&lo); 704 OSQLResult res = m_driver->query(&lo);
639 if ( res.state() != OSQLResult::Success ) 705 if ( res.state() != OSQLResult::Success )
640 return; 706 return;
641 707
642 m_uids = extractUids( res ); 708 m_uids = extractUids( res );
643 709
644 m_changed = false; 710 m_changed = false;
645 711
646 qWarning("Update ends %d ms", t.elapsed() ); 712 qDebug("Update ends %d ms", t.elapsed() );
647} 713}
648 714
649QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 715QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
650{ 716{
651 qWarning("extractUids"); 717 qDebug("extractUids");
652 QTime t; 718 QTime t;
653 t.start(); 719 t.start();
654 OSQLResultItem::ValueList list = res.results(); 720 OSQLResultItem::ValueList list = res.results();
655 OSQLResultItem::ValueList::Iterator it; 721 OSQLResultItem::ValueList::Iterator it;
656 QArray<int> ints(list.count() ); 722 QArray<int> ints(list.count() );
657 qWarning(" count = %d", list.count() ); 723 qDebug(" count = %d", list.count() );
658 724
659 int i = 0; 725 int i = 0;
660 for (it = list.begin(); it != list.end(); ++it ) { 726 for (it = list.begin(); it != list.end(); ++it ) {
661 ints[i] = (*it).data("uid").toInt(); 727 ints[i] = (*it).data("uid").toInt();
662 i++; 728 i++;
663 } 729 }
664 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 730 qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
665 731
666 return ints; 732 return ints;
667 733
668} 734}
669 735
670QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const 736QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
671{ 737{
672 QTime t; 738 QTime t;
673 t.start(); 739 t.start();
674 740
675 QMap<int, QString> nonCustomMap; 741 QMap<int, QString> nonCustomMap;
676 742
@@ -687,54 +753,54 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
687 QTime t3; 753 QTime t3;
688 t3.start(); 754 t3.start();
689 // Now loop through all columns 755 // Now loop through all columns
690 QStringList fieldList = OPimContactFields::untrfields( false ); 756 QStringList fieldList = OPimContactFields::untrfields( false );
691 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 757 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
692 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 758 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
693 // Get data for the selected column and store it with the 759 // Get data for the selected column and store it with the
694 // corresponding id into the map.. 760 // corresponding id into the map..
695 761
696 int id = translate[*it]; 762 int id = translate[*it];
697 QString value = resItem.data( (*it) ); 763 QString value = resItem.data( (*it) );
698 764
699 // qWarning("Reading %s... found: %s", (*it).latin1(), value.latin1() ); 765 // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() );
700 766
701 switch( id ){ 767 switch( id ){
702 case Qtopia::Birthday: 768 case Qtopia::Birthday:
703 case Qtopia::Anniversary:{ 769 case Qtopia::Anniversary:{
704 // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) 770 // Birthday and Anniversary are encoded special ( yyyy-mm-dd )
705 QStringList list = QStringList::split( '-', value ); 771 QStringList list = QStringList::split( '-', value );
706 QStringList::Iterator lit = list.begin(); 772 QStringList::Iterator lit = list.begin();
707 int year = (*lit).toInt(); 773 int year = (*lit).toInt();
708 int month = (*(++lit)).toInt(); 774 int month = (*(++lit)).toInt();
709 int day = (*(++lit)).toInt(); 775 int day = (*(++lit)).toInt();
710 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ 776 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){
711 QDate date( year, month, day ); 777 QDate date( year, month, day );
712 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); 778 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) );
713 } 779 }
714 } 780 }
715 break; 781 break;
716 case Qtopia::AddressCategory: 782 case Qtopia::AddressCategory:
717 qWarning("Category is: %s", value.latin1() ); 783 qDebug("Category is: %s", value.latin1() );
718 default: 784 default:
719 nonCustomMap.insert( id, value ); 785 nonCustomMap.insert( id, value );
720 } 786 }
721 } 787 }
722 788
723 // First insert uid 789 // First insert uid
724 nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); 790 nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) );
725 t3needed = t3.elapsed(); 791 t3needed = t3.elapsed();
726 792
727 // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() ); 793 // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() );
728 qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", 794 qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms",
729 t.elapsed(), t2needed, t3needed ); 795 t.elapsed(), t2needed, t3needed );
730 796
731 return nonCustomMap; 797 return nonCustomMap;
732} 798}
733 799
734QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const 800QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const
735{ 801{
736 QTime t; 802 QTime t;
737 t.start(); 803 t.start();
738 804
739 QMap<QString, QString> customMap; 805 QMap<QString, QString> customMap;
740 806
@@ -744,17 +810,17 @@ QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) c
744 if ( res_custom.state() == OSQLResult::Failure ) { 810 if ( res_custom.state() == OSQLResult::Failure ) {
745 qWarning("OSQLResult::Failure in find query !!"); 811 qWarning("OSQLResult::Failure in find query !!");
746 QMap<QString, QString> empty; 812 QMap<QString, QString> empty;
747 return empty; 813 return empty;
748 } 814 }
749 815
750 OSQLResultItem::ValueList list = res_custom.results(); 816 OSQLResultItem::ValueList list = res_custom.results();
751 OSQLResultItem::ValueList::Iterator it = list.begin(); 817 OSQLResultItem::ValueList::Iterator it = list.begin();
752 for ( ; it != list.end(); ++it ) { 818 for ( ; it != list.end(); ++it ) {
753 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 819 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
754 } 820 }
755 821
756 qWarning("RequestCustom needed: %d ms", t.elapsed() ); 822 qDebug("RequestCustom needed: %d ms", t.elapsed() );
757 return customMap; 823 return customMap;
758} 824}
759 825
760} 826}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 2b467c3..7b4d81f 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -221,24 +221,25 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
221 * if all fields matches. 221 * if all fields matches.
222 */ 222 */
223 QDate* queryDate = 0l; 223 QDate* queryDate = 0l;
224 QDate* checkDate = 0l; 224 QDate* checkDate = 0l;
225 bool allcorrect = true; 225 bool allcorrect = true;
226 for ( int i = 0; i < Qtopia::Groups; i++ ) { 226 for ( int i = 0; i < Qtopia::Groups; i++ ) {
227 // Birthday and anniversary are special nonstring fields and should 227 // Birthday and anniversary are special nonstring fields and should
228 // be handled specially 228 // be handled specially
229 switch ( i ){ 229 switch ( i ){
230 case Qtopia::Birthday: 230 case Qtopia::Birthday:
231 queryDate = new QDate( query.birthday() ); 231 queryDate = new QDate( query.birthday() );
232 checkDate = new QDate( (*it)->birthday() ); 232 checkDate = new QDate( (*it)->birthday() );
233 // fall through
233 case Qtopia::Anniversary: 234 case Qtopia::Anniversary:
234 if ( queryDate == 0l ){ 235 if ( queryDate == 0l ){
235 queryDate = new QDate( query.anniversary() ); 236 queryDate = new QDate( query.anniversary() );
236 checkDate = new QDate( (*it)->anniversary() ); 237 checkDate = new QDate( (*it)->anniversary() );
237 } 238 }
238 239
239 if ( queryDate->isValid() ){ 240 if ( queryDate->isValid() ){
240 if( checkDate->isValid() ){ 241 if( checkDate->isValid() ){
241 if ( settings & OPimContactAccess::DateYear ){ 242 if ( settings & OPimContactAccess::DateYear ){
242 if ( queryDate->year() != checkDate->year() ) 243 if ( queryDate->year() != checkDate->year() )
243 allcorrect = false; 244 allcorrect = false;
244 } 245 }
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index a779dc1..8a8cb0b 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -39,24 +39,61 @@
39 39
40#include <qpe/global.h> 40#include <qpe/global.h>
41 41
42#include <opie2/osqldriver.h> 42#include <opie2/osqldriver.h>
43#include <opie2/osqlmanager.h> 43#include <opie2/osqlmanager.h>
44#include <opie2/osqlquery.h> 44#include <opie2/osqlquery.h>
45 45
46#include <opie2/opimrecurrence.h> 46#include <opie2/opimrecurrence.h>
47#include <opie2/odatebookaccessbackend_sql.h> 47#include <opie2/odatebookaccessbackend_sql.h>
48 48
49using namespace Opie::DB; 49using namespace Opie::DB;
50 50
51namespace {
52 /**
53 * a find query for custom elements
54 */
55 class FindCustomQuery : public OSQLQuery {
56 public:
57 FindCustomQuery(int uid);
58 FindCustomQuery(const QArray<int>& );
59 ~FindCustomQuery();
60 QString query()const;
61 private:
62 QString single()const;
63 QString multi()const;
64 QArray<int> m_uids;
65 int m_uid;
66 };
67
68 FindCustomQuery::FindCustomQuery(int uid)
69 : OSQLQuery(), m_uid( uid ) {
70 }
71 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
72 : OSQLQuery(), m_uids( ints ){
73 }
74 FindCustomQuery::~FindCustomQuery() {
75 }
76 QString FindCustomQuery::query()const{
77 // if ( m_uids.count() == 0 )
78 return single();
79 }
80 QString FindCustomQuery::single()const{
81 QString qu = "select uid, type, value from custom_data where uid = ";
82 qu += QString::number(m_uid);
83 return qu;
84 }
85}
86
87
51namespace Opie { 88namespace Opie {
52 89
53 90
54ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 91ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
55 const QString& fileName ) 92 const QString& fileName )
56 : ODateBookAccessBackend(), m_driver( NULL ) 93 : ODateBookAccessBackend(), m_driver( NULL )
57{ 94{
58 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; 95 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName;
59 96
60 // Get the standart sql-driver from the OSQLManager.. 97 // Get the standart sql-driver from the OSQLManager..
61 OSQLManager man; 98 OSQLManager man;
62 m_driver = man.standard(); 99 m_driver = man.standard();
@@ -114,25 +151,25 @@ bool ODateBookAccessBackend_SQL::load()
114 151
115 // Don't expect that the database exists. 152 // Don't expect that the database exists.
116 // It is save here to create the table, even if it 153 // It is save here to create the table, even if it
117 // do exist. ( Is that correct for all databases ?? ) 154 // do exist. ( Is that correct for all databases ?? )
118 QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; 155 QStringqu = "create table datebook( uid INTEGER PRIMARY KEY ";
119 156
120 QMap<int, QString>::Iterator it; 157 QMap<int, QString>::Iterator it;
121 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 158 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
122 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); 159 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() );
123 } 160 }
124 qu += " );"; 161 qu += " );";
125 162
126 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; 163 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
127 164
128 qWarning( "command: %s", qu.latin1() ); 165 qWarning( "command: %s", qu.latin1() );
129 166
130 OSQLRawQuery raw( qu ); 167 OSQLRawQuery raw( qu );
131 OSQLResult res = m_driver->query( &raw ); 168 OSQLResult res = m_driver->query( &raw );
132 if ( res.state() != OSQLResult::Success ) 169 if ( res.state() != OSQLResult::Success )
133 return false; 170 return false;
134 171
135 update(); 172 update();
136 173
137 return true; 174 return true;
138} 175}
@@ -193,27 +230,27 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
193 OSQLResultItem resItem = res.first(); 230 OSQLResultItem resItem = res.first();
194 231
195 // Create Map for date event and insert UID 232 // Create Map for date event and insert UID
196 QMap<int,QString> dateEventMap; 233 QMap<int,QString> dateEventMap;
197 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); 234 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) );
198 235
199 // Now insert the data out of the columns into the map. 236 // Now insert the data out of the columns into the map.
200 QMapConstIterator<int, QString> it; 237 QMapConstIterator<int, QString> it;
201 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 238 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
202 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); 239 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
203 } 240 }
204 241
205 // Last step: Put map into date event and return it 242 // Last step: Put map into date event, add custom map and return it
206 OPimEvent retDate( dateEventMap ); 243 OPimEvent retDate( dateEventMap );
207 244 retDate.setExtraMap( requestCustom( uid ) );
208 return retDate; 245 return retDate;
209} 246}
210 247
211// FIXME: Speed up update of uid's.. 248// FIXME: Speed up update of uid's..
212bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) 249bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
213{ 250{
214 QMap<int,QString> eventMap = ev.toMap(); 251 QMap<int,QString> eventMap = ev.toMap();
215 252
216 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); 253 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
217 QMap<int, QString>::Iterator it; 254 QMap<int, QString>::Iterator it;
218 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 255 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
219 if ( !eventMap[it.key()].isEmpty() ) 256 if ( !eventMap[it.key()].isEmpty() )
@@ -356,13 +393,40 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
356 393
357 int i = 0; 394 int i = 0;
358 for (it = list.begin(); it != list.end(); ++it ) { 395 for (it = list.begin(); it != list.end(); ++it ) {
359 ints[i] = (*it).data("uid").toInt(); 396 ints[i] = (*it).data("uid").toInt();
360 i++; 397 i++;
361 } 398 }
362 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 399 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
363 400
364 return ints; 401 return ints;
365 402
366} 403}
367 404
405QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
406{
407 QTime t;
408 t.start();
409
410 QMap<QString, QString> customMap;
411
412 FindCustomQuery query( uid );
413 OSQLResult res_custom = m_driver->query( &query );
414
415 if ( res_custom.state() == OSQLResult::Failure ) {
416 qWarning("OSQLResult::Failure in find query !!");
417 QMap<QString, QString> empty;
418 return empty;
419 }
420
421 OSQLResultItem::ValueList list = res_custom.results();
422 OSQLResultItem::ValueList::Iterator it = list.begin();
423 for ( ; it != list.end(); ++it ) {
424 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
425 }
426
427 qDebug("RequestCustom needed: %d ms", t.elapsed() );
428 return customMap;
429}
430
431
368} 432}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
index 60d7f21..b624159 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
@@ -79,19 +79,21 @@ private:
79 QArray<int> m_uids; 79 QArray<int> m_uids;
80 80
81 QMap<int, QString> m_fieldMap; 81 QMap<int, QString> m_fieldMap;
82 QMap<QString, int> m_reverseFieldMap; 82 QMap<QString, int> m_reverseFieldMap;
83 83
84 Opie::DB::OSQLDriver* m_driver; 84 Opie::DB::OSQLDriver* m_driver;
85 85
86 class Private; 86 class Private;
87 Private *d; 87 Private *d;
88 88
89 void initFields(); 89 void initFields();
90 void update(); 90 void update();
91
91 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const; 92 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const;
93 QMap<QString, QString> requestCustom( int uid ) const;
92 94
93}; 95};
94 96
95} 97}
96 98
97#endif 99#endif
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index d218090..b4170fc 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -1,15 +1,16 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 Copyright (C) Holger Freyther (zecke@handhelds.org)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 6 .=l.
6 .>+-= 7 .>+-=
7 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 14 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
@@ -19,24 +20,26 @@
19..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 21++= -. .` .: details.
21 : = ...= . :.=- 22 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
28*/ 29*/
29 30
30#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qmap.h>
33#include <qstring.h>
31 34
32#include <qpe/global.h> 35#include <qpe/global.h>
33 36
34#include <opie2/osqldriver.h> 37#include <opie2/osqldriver.h>
35#include <opie2/osqlresult.h> 38#include <opie2/osqlresult.h>
36#include <opie2/osqlmanager.h> 39#include <opie2/osqlmanager.h>
37#include <opie2/osqlquery.h> 40#include <opie2/osqlquery.h>
38 41
39#include <opie2/otodoaccesssql.h> 42#include <opie2/otodoaccesssql.h>
40#include <opie2/opimstate.h> 43#include <opie2/opimstate.h>
41#include <opie2/opimnotifymanager.h> 44#include <opie2/opimnotifymanager.h>
42#include <opie2/opimrecurrence.h> 45#include <opie2/opimrecurrence.h>
@@ -139,56 +142,76 @@ namespace {
139 EffQuery( const QDate&, const QDate&, bool inc ); 142 EffQuery( const QDate&, const QDate&, bool inc );
140 ~EffQuery(); 143 ~EffQuery();
141 QString query()const; 144 QString query()const;
142 private: 145 private:
143 QString with()const; 146 QString with()const;
144 QString out()const; 147 QString out()const;
145 QDate m_start; 148 QDate m_start;
146 QDate m_end; 149 QDate m_end;
147 bool m_inc :1; 150 bool m_inc :1;
148 }; 151 };
149 152
150 153
154 /**
155 * a find query for custom elements
156 */
157 class FindCustomQuery : public OSQLQuery {
158 public:
159 FindCustomQuery(int uid);
160 FindCustomQuery(const QArray<int>& );
161 ~FindCustomQuery();
162 QString query()const;
163 private:
164 QString single()const;
165 QString multi()const;
166 QArray<int> m_uids;
167 int m_uid;
168 };
169
170
171
151 CreateQuery::CreateQuery() : OSQLQuery() {} 172 CreateQuery::CreateQuery() : OSQLQuery() {}
152 CreateQuery::~CreateQuery() {} 173 CreateQuery::~CreateQuery() {}
153 QString CreateQuery::query()const { 174 QString CreateQuery::query()const {
154 QString qu; 175 QString qu;
155 qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; 176 qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
156 qu += "description, summary, priority, DueDate, progress , state, "; 177 qu += "description, summary, priority, DueDate, progress , state, ";
157 // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) 178 // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers)
158 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; 179 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
159 qu += "reminders, alarms, maintainer, startdate, completeddate);"; 180 qu += "reminders, alarms, maintainer, startdate, completeddate);";
160 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 181 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
161 return qu; 182 return qu;
162 } 183 }
163 184
164 LoadQuery::LoadQuery() : OSQLQuery() {} 185 LoadQuery::LoadQuery() : OSQLQuery() {}
165 LoadQuery::~LoadQuery() {} 186 LoadQuery::~LoadQuery() {}
166 QString LoadQuery::query()const { 187 QString LoadQuery::query()const {
167 QString qu; 188 QString qu;
168 // We do not need "distinct" here. The primary key is always unique.. 189 // We do not need "distinct" here. The primary key is always unique..
169 //qu += "select distinct uid from todolist"; 190 //qu += "select distinct uid from todolist";
170 qu += "select uid from todolist"; 191 qu += "select uid from todolist";
171 192
172 return qu; 193 return qu;
173 } 194 }
174 195
175 InsertQuery::InsertQuery( const OPimTodo& todo ) 196 InsertQuery::InsertQuery( const OPimTodo& todo )
176 : OSQLQuery(), m_todo( todo ) { 197 : OSQLQuery(), m_todo( todo ) {
177 } 198 }
178 InsertQuery::~InsertQuery() { 199 InsertQuery::~InsertQuery() {
179 } 200 }
180 /* 201 /*
181 * converts from a OPimTodo to a query 202 * converts from a OPimTodo to a query
182 * we leave out X-Ref + Alarms 203 * we leave out X-Ref + Maintainer
204 * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding
205 * decoding stuff there.. (eilers)
183 */ 206 */
184 QString InsertQuery::query()const{ 207 QString InsertQuery::query()const{
185 208
186 int year, month, day; 209 int year, month, day;
187 year = month = day = 0; 210 year = month = day = 0;
188 if (m_todo.hasDueDate() ) { 211 if (m_todo.hasDueDate() ) {
189 QDate date = m_todo.dueDate(); 212 QDate date = m_todo.dueDate();
190 year = date.year(); 213 year = date.year();
191 month = date.month(); 214 month = date.month();
192 day = date.day(); 215 day = date.day();
193 } 216 }
194 int sYear = 0, sMonth = 0, sDay = 0; 217 int sYear = 0, sMonth = 0, sDay = 0;
@@ -206,58 +229,78 @@ namespace {
206 eMonth= eDate.month(); 229 eMonth= eDate.month();
207 eDay = eDate.day(); 230 eDay = eDate.day();
208 } 231 }
209 QString qu; 232 QString qu;
210 QMap<int, QString> recMap = m_todo.recurrence().toMap(); 233 QMap<int, QString> recMap = m_todo.recurrence().toMap();
211 qu = "insert into todolist VALUES(" 234 qu = "insert into todolist VALUES("
212 + QString::number( m_todo.uid() ) + "," 235 + QString::number( m_todo.uid() ) + ","
213 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," 236 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
214 + QString::number( m_todo.isCompleted() ) + "," 237 + QString::number( m_todo.isCompleted() ) + ","
215 + "'" + m_todo.description() + "'" + "," 238 + "'" + m_todo.description() + "'" + ","
216 + "'" + m_todo.summary() + "'" + "," 239 + "'" + m_todo.summary() + "'" + ","
217 + QString::number(m_todo.priority() ) + "," 240 + QString::number(m_todo.priority() ) + ","
218 + "'" + QString::number(year) + "-" 241 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-"
219 + QString::number(month) 242 + QString::number(month).rightJustify( 2, '0' )
220 + "-" + QString::number( day ) + "'" + "," 243 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + ","
221 + QString::number( m_todo.progress() ) + "," 244 + QString::number( m_todo.progress() ) + ","
222 + QString::number( m_todo.state().state() ) + "," 245 + QString::number( m_todo.state().state() ) + ","
223 + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," 246 + "'" + recMap[ OPimRecurrence::RType ] + "'" + ","
224 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," 247 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + ","
225 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," 248 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + ","
226 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," 249 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + ","
227 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," 250 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + ","
228 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," 251 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + ","
229 + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," 252 + "'" + recMap[ OPimRecurrence::Created ] + "'" + ","
230 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; 253 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ",";
231 254
232 if ( m_todo.hasNotifiers() ) { 255 if ( m_todo.hasNotifiers() ) {
233 OPimNotifyManager manager = m_todo.notifiers(); 256 OPimNotifyManager manager = m_todo.notifiers();
234 qu += "'" + manager.remindersToString() + "'" + "," 257 qu += "'" + manager.remindersToString() + "'" + ","
235 + "'" + manager.alarmsToString() + "'" + ","; 258 + "'" + manager.alarmsToString() + "'" + ",";
236 } 259 }
237 else{ 260 else{
238 qu += QString( "''" ) + "," 261 qu += QString( "''" ) + ","
239 + "''" + ","; 262 + "''" + ",";
240 } 263 }
241 264
242 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 265 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
243 + "'" + QString::number(sYear) + "-" 266 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
244 + QString::number(sMonth) 267 + QString::number(sMonth).rightJustify( 2, '0' )
245 + "-" + QString::number(sDay) + "'" + "," 268 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + ","
246 + "'" + QString::number(eYear) + "-" 269 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-"
247 + QString::number(eMonth) 270 + QString::number(eMonth).rightJustify( 2, '0' )
248 + "-"+QString::number(eDay) + "'" 271 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'"
249 + ")"; 272 + ")";
250 273
251 qWarning("add %s", qu.latin1() ); 274 // Save custom Entries:
275 int id = 0;
276 id = 0;
277 QMap<QString, QString> customMap = m_todo.toExtraMap();
278 for( QMap<QString, QString>::Iterator it = customMap.begin();
279 it != customMap.end(); ++it ){
280 qu += "insert into custom_data VALUES("
281 + QString::number( m_todo.uid() )
282 + ","
283 + QString::number( id++ )
284 + ",'"
285 + it.key()
286 + "',"
287 + "0" // Priority for future enhancements
288 + ",'"
289 + it.data()
290 + "');";
291 }
292
293
294 qDebug("add %s", qu.latin1() );
252 return qu; 295 return qu;
253 } 296 }
254 297
255 RemoveQuery::RemoveQuery(int uid ) 298 RemoveQuery::RemoveQuery(int uid )
256 : OSQLQuery(), m_uid( uid ) {} 299 : OSQLQuery(), m_uid( uid ) {}
257 RemoveQuery::~RemoveQuery() {} 300 RemoveQuery::~RemoveQuery() {}
258 QString RemoveQuery::query()const { 301 QString RemoveQuery::query()const {
259 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); 302 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid);
260 return qu; 303 return qu;
261 } 304 }
262 305
263 306
@@ -291,57 +334,86 @@ namespace {
291 for (uint i = 0; i < m_uids.count(); i++ ) { 334 for (uint i = 0; i < m_uids.count(); i++ ) {
292 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 335 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
293 } 336 }
294 qu.remove( qu.length()-2, 2 ); 337 qu.remove( qu.length()-2, 2 );
295 return qu; 338 return qu;
296 } 339 }
297 340
298 OverDueQuery::OverDueQuery(): OSQLQuery() {} 341 OverDueQuery::OverDueQuery(): OSQLQuery() {}
299 OverDueQuery::~OverDueQuery() {} 342 OverDueQuery::~OverDueQuery() {}
300 QString OverDueQuery::query()const { 343 QString OverDueQuery::query()const {
301 QDate date = QDate::currentDate(); 344 QDate date = QDate::currentDate();
302 QString str; 345 QString str;
303 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 346 str = QString("select uid from todolist where DueDate ='%1-%2-%3'")
347 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
348 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
349 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) );
304 350
305 return str; 351 return str;
306 } 352 }
307 353
308 354
309 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 355 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
310 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 356 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
311 EffQuery::~EffQuery() {} 357 EffQuery::~EffQuery() {}
312 QString EffQuery::query()const { 358 QString EffQuery::query()const {
313 return m_inc ? with() : out(); 359 return m_inc ? with() : out();
314 } 360 }
315 QString EffQuery::with()const { 361 QString EffQuery::with()const {
316 QString str; 362 QString str;
317 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 363 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
318 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) 364 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
319 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); 365 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
366 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
367 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
368 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
369 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
320 return str; 370 return str;
321 } 371 }
322 QString EffQuery::out()const { 372 QString EffQuery::out()const {
323 QString str; 373 QString str;
324 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 374 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
325 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) 375 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
326 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); 376 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
377 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
378 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
379 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
380 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
327 381
328 return str; 382 return str;
329 } 383 }
384
385 FindCustomQuery::FindCustomQuery(int uid)
386 : OSQLQuery(), m_uid( uid ) {
387 }
388 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
389 : OSQLQuery(), m_uids( ints ){
390 }
391 FindCustomQuery::~FindCustomQuery() {
392 }
393 QString FindCustomQuery::query()const{
394 return single(); // Multiple requests not supported !
395 }
396 QString FindCustomQuery::single()const{
397 QString qu = "select uid, type, value from custom_data where uid = ";
398 qu += QString::number(m_uid);
399 return qu;
400 }
401
330}; 402};
331 403
332 404
333namespace Opie { 405namespace Opie {
334OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) 406OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file )
335 : OPimTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) 407 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true)
336{ 408{
337 QString fi = file; 409 QString fi = file;
338 if ( fi.isEmpty() ) 410 if ( fi.isEmpty() )
339 fi = Global::applicationFileName( "todolist", "todolist.db" ); 411 fi = Global::applicationFileName( "todolist", "todolist.db" );
340 OSQLManager man; 412 OSQLManager man;
341 m_driver = man.standard(); 413 m_driver = man.standard();
342 m_driver->setUrl(fi); 414 m_driver->setUrl(fi);
343 // fillDict(); 415 // fillDict();
344} 416}
345 417
346OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ 418OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){
347 if( m_driver ) 419 if( m_driver )
@@ -374,35 +446,35 @@ QArray<int> OPimTodoAccessBackendSQL::allRecords()const {
374QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ 446QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){
375 QArray<int> ints(0); 447 QArray<int> ints(0);
376 return ints; 448 return ints;
377} 449}
378OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ 450OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
379 FindQuery query( uid ); 451 FindQuery query( uid );
380 return todo( m_driver->query(&query) ); 452 return todo( m_driver->query(&query) );
381 453
382} 454}
383OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 455OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
384 uint cur, Frontend::CacheDirection dir ) const{ 456 uint cur, Frontend::CacheDirection dir ) const{
385 uint CACHE = readAhead(); 457 uint CACHE = readAhead();
386 qWarning("searching for %d", uid ); 458 qDebug("searching for %d", uid );
387 QArray<int> search( CACHE ); 459 QArray<int> search( CACHE );
388 uint size =0; 460 uint size =0;
389 OPimTodo to; 461 OPimTodo to;
390 462
391 // we try to cache CACHE items 463 // we try to cache CACHE items
392 switch( dir ) { 464 switch( dir ) {
393 /* forward */ 465 /* forward */
394 case 0: // FIXME: Not a good style to use magic numbers here (eilers) 466 case 0: // FIXME: Not a good style to use magic numbers here (eilers)
395 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 467 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
396 qWarning("size %d %d", size, ints[i] ); 468 qDebug("size %d %d", size, ints[i] );
397 search[size] = ints[i]; 469 search[size] = ints[i];
398 size++; 470 size++;
399 } 471 }
400 break; 472 break;
401 /* reverse */ 473 /* reverse */
402 case 1: // FIXME: Not a good style to use magic numbers here (eilers) 474 case 1: // FIXME: Not a good style to use magic numbers here (eilers)
403 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 475 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
404 search[size] = ints[i]; 476 search[size] = ints[i];
405 size++; 477 size++;
406 } 478 }
407 break; 479 break;
408 } 480 }
@@ -459,55 +531,58 @@ QArray<int> OPimTodoAccessBackendSQL::overDue() {
459} 531}
460QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, 532QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
461 const QDate& t, 533 const QDate& t,
462 bool u) { 534 bool u) {
463 EffQuery ef(s, t, u ); 535 EffQuery ef(s, t, u );
464 return uids (m_driver->query(&ef) ); 536 return uids (m_driver->query(&ef) );
465} 537}
466/* 538/*
467 * 539 *
468 */ 540 */
469QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 541QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
470 int sortFilter, int cat ) { 542 int sortFilter, int cat ) {
471 qWarning("sorted %d, %d", asc, sortOrder ); 543 qDebug("sorted %d, %d", asc, sortOrder );
472 QString query; 544 QString query;
473 query = "select uid from todolist WHERE "; 545 query = "select uid from todolist WHERE ";
474 546
475 /* 547 /*
476 * Sort Filter stuff 548 * Sort Filter stuff
477 * not that straight forward 549 * not that straight forward
478 * FIXME: Replace magic numbers 550 * FIXME: Replace magic numbers
479 * 551 *
480 */ 552 */
481 /* Category */ 553 /* Category */
482 if ( sortFilter & 1 ) { 554 if ( sortFilter & 1 ) {
483 QString str; 555 QString str;
484 if (cat != 0 ) str = QString::number( cat ); 556 if (cat != 0 ) str = QString::number( cat );
485 query += " categories like '%" +str+"%' AND"; 557 query += " categories like '%" +str+"%' AND";
486 } 558 }
487 /* Show only overdue */ 559 /* Show only overdue */
488 if ( sortFilter & 2 ) { 560 if ( sortFilter & 2 ) {
489 QDate date = QDate::currentDate(); 561 QDate date = QDate::currentDate();
490 QString due; 562 QString due;
491 QString base; 563 QString base;
492 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); 564 base = QString("DueDate <= '%1-%2-%3' AND completed = 0")
565 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
566 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
567 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
493 query += " " + base + " AND"; 568 query += " " + base + " AND";
494 } 569 }
495 /* not show completed */ 570 /* not show completed */
496 if ( sortFilter & 4 ) { 571 if ( sortFilter & 4 ) {
497 query += " completed = 0 AND"; 572 query += " completed = 0 AND";
498 }else{ 573 }else{
499 query += " ( completed = 1 OR completed = 0) AND"; 574 query += " ( completed = 1 OR completed = 0) AND";
500 } 575 }
501 /* srtip the end */ 576 /* strip the end */
502 query = query.remove( query.length()-3, 3 ); 577 query = query.remove( query.length()-3, 3 );
503 578
504 579
505 /* 580 /*
506 * sort order stuff 581 * sort order stuff
507 * quite straight forward 582 * quite straight forward
508 */ 583 */
509 query += "ORDER BY "; 584 query += "ORDER BY ";
510 switch( sortOrder ) { 585 switch( sortOrder ) {
511 /* completed */ 586 /* completed */
512 case 0: 587 case 0:
513 query += "completed"; 588 query += "completed";
@@ -515,71 +590,74 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
515 case 1: 590 case 1:
516 query += "priority"; 591 query += "priority";
517 break; 592 break;
518 case 2: 593 case 2:
519 query += "summary"; 594 query += "summary";
520 break; 595 break;
521 case 3: 596 case 3:
522 query += "DueDate"; 597 query += "DueDate";
523 break; 598 break;
524 } 599 }
525 600
526 if ( !asc ) { 601 if ( !asc ) {
527 qWarning("not ascending!"); 602 qDebug("not ascending!");
528 query += " DESC"; 603 query += " DESC";
529 } 604 }
530 605
531 qWarning( query ); 606 qDebug( query );
532 OSQLRawQuery raw(query ); 607 OSQLRawQuery raw(query );
533 return uids( m_driver->query(&raw) ); 608 return uids( m_driver->query(&raw) );
534} 609}
535bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 610bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
536 if ( str == "0-0-0" ) 611 if ( str == "0-0-0" )
537 return false; 612 return false;
538 else{ 613 else{
539 int day, year, month; 614 int day, year, month;
540 QStringList list = QStringList::split("-", str ); 615 QStringList list = QStringList::split("-", str );
541 year = list[0].toInt(); 616 year = list[0].toInt();
542 month = list[1].toInt(); 617 month = list[1].toInt();
543 day = list[2].toInt(); 618 day = list[2].toInt();
544 da.setYMD( year, month, day ); 619 da.setYMD( year, month, day );
545 return true; 620 return true;
546 } 621 }
547} 622}
548OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{ 623OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{
549 if ( res.state() == OSQLResult::Failure ) { 624 if ( res.state() == OSQLResult::Failure ) {
550 OPimTodo to; 625 OPimTodo to;
551 return to; 626 return to;
552 } 627 }
553 628
554 OSQLResultItem::ValueList list = res.results(); 629 OSQLResultItem::ValueList list = res.results();
555 OSQLResultItem::ValueList::Iterator it = list.begin(); 630 OSQLResultItem::ValueList::Iterator it = list.begin();
556 qWarning("todo1"); 631 qDebug("todo1");
557 OPimTodo to = todo( (*it) ); 632 OPimTodo to = todo( (*it) );
558 cache( to ); 633 cache( to );
559 ++it; 634 ++it;
560 635
561 for ( ; it != list.end(); ++it ) { 636 for ( ; it != list.end(); ++it ) {
562 qWarning("caching"); 637 qDebug("caching");
563 cache( todo( (*it) ) ); 638 cache( todo( (*it) ) );
564 } 639 }
565 return to; 640 return to;
566} 641}
567OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 642OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
568 qWarning("todo"); 643 qDebug("todo(ResultItem)");
644
645 // Request information from addressbook table and create the OPimTodo-object.
646
569 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 647 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
570 hasDueDate = date( dueDate, item.data("DueDate") ); 648 hasDueDate = date( dueDate, item.data("DueDate") );
571 QStringList cats = QStringList::split(";", item.data("categories") ); 649 QStringList cats = QStringList::split(";", item.data("categories") );
572 650
573 qWarning("Item is completed: %d", item.data("completed").toInt() ); 651 qDebug("Item is completed: %d", item.data("completed").toInt() );
574 652
575 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 653 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
576 cats, item.data("summary"), item.data("description"), 654 cats, item.data("summary"), item.data("description"),
577 item.data("progress").toUShort(), hasDueDate, dueDate, 655 item.data("progress").toUShort(), hasDueDate, dueDate,
578 item.data("uid").toInt() ); 656 item.data("uid").toInt() );
579 657
580 bool isOk; 658 bool isOk;
581 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 659 int prioInt = QString( item.data("priority") ).toInt( &isOk );
582 if ( isOk ) 660 if ( isOk )
583 to.setPriority( prioInt ); 661 to.setPriority( prioInt );
584 662
585 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 663 bool hasStartDate = false; QDate startDate = QDate::currentDate();
@@ -605,75 +683,82 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
605 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); 683 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") );
606 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); 684 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") );
607 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); 685 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") );
608 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); 686 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") );
609 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); 687 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") );
610 recMap.insert( OPimRecurrence::Created , item.data("Created") ); 688 recMap.insert( OPimRecurrence::Created , item.data("Created") );
611 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); 689 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") );
612 690
613 OPimRecurrence recur; 691 OPimRecurrence recur;
614 recur.fromMap( recMap ); 692 recur.fromMap( recMap );
615 to.setRecurrence( recur ); 693 to.setRecurrence( recur );
616 694
695 // Finally load the custom-entries for this UID and put it into the created object
696 to.setExtraMap( requestCustom( to.uid() ) );
697
617 return to; 698 return to;
618} 699}
619OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { 700OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
620 FindQuery find( uid ); 701 FindQuery find( uid );
621 return todo( m_driver->query(&find) ); 702 return todo( m_driver->query(&find) );
622} 703}
623/* 704/*
624 * update the dict 705 * update the dict
625 */ 706 */
626void OPimTodoAccessBackendSQL::fillDict() { 707void OPimTodoAccessBackendSQL::fillDict() {
708
709#if 0
627 /* initialize dict */ 710 /* initialize dict */
628 /* 711 /*
629 * UPDATE dict if you change anything!!! 712 * UPDATE dict if you change anything!!!
630 * FIXME: Isn't this dict obsolete ? (eilers) 713 * FIXME: Isn't this dict obsolete ? (eilers)
631 */ 714 */
632 m_dict.setAutoDelete( TRUE ); 715 m_dict.setAutoDelete( TRUE );
633 m_dict.insert("Categories" , new int(OPimTodo::Category) ); 716 m_dict.insert("Categories" , new int(OPimTodo::Category) );
634 m_dict.insert("Uid" , new int(OPimTodo::Uid) ); 717 m_dict.insert("Uid" , new int(OPimTodo::Uid) );
635 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); 718 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) );
636 m_dict.insert("Completed" , new int(OPimTodo::Completed) ); 719 m_dict.insert("Completed" , new int(OPimTodo::Completed) );
637 m_dict.insert("Description" , new int(OPimTodo::Description) ); 720 m_dict.insert("Description" , new int(OPimTodo::Description) );
638 m_dict.insert("Summary" , new int(OPimTodo::Summary) ); 721 m_dict.insert("Summary" , new int(OPimTodo::Summary) );
639 m_dict.insert("Priority" , new int(OPimTodo::Priority) ); 722 m_dict.insert("Priority" , new int(OPimTodo::Priority) );
640 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); 723 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) );
641 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); 724 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
642 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); 725 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) );
643 m_dict.insert("Progress" , new int(OPimTodo::Progress) ); 726 m_dict.insert("Progress" , new int(OPimTodo::Progress) );
644 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) 727 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers)
645 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); 728 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
646// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) 729// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
647// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) 730// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
731
732#endif
648} 733}
649/* 734/*
650 * need to be const so let's fool the 735 * need to be const so let's fool the
651 * compiler :( 736 * compiler :(
652 */ 737 */
653void OPimTodoAccessBackendSQL::update()const { 738void OPimTodoAccessBackendSQL::update()const {
654 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; 739 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false;
655 LoadQuery lo; 740 LoadQuery lo;
656 OSQLResult res = m_driver->query(&lo); 741 OSQLResult res = m_driver->query(&lo);
657 if ( res.state() != OSQLResult::Success ) 742 if ( res.state() != OSQLResult::Success )
658 return; 743 return;
659 744
660 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); 745 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res );
661} 746}
662QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 747QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
663 748
664 OSQLResultItem::ValueList list = res.results(); 749 OSQLResultItem::ValueList list = res.results();
665 OSQLResultItem::ValueList::Iterator it; 750 OSQLResultItem::ValueList::Iterator it;
666 QArray<int> ints(list.count() ); 751 QArray<int> ints(list.count() );
667 qWarning(" count = %d", list.count() ); 752 qDebug(" count = %d", list.count() );
668 753
669 int i = 0; 754 int i = 0;
670 for (it = list.begin(); it != list.end(); ++it ) { 755 for (it = list.begin(); it != list.end(); ++it ) {
671 ints[i] = (*it).data("uid").toInt(); 756 ints[i] = (*it).data("uid").toInt();
672 i++; 757 i++;
673 } 758 }
674 return ints; 759 return ints;
675} 760}
676 761
677QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 762QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
678{ 763{
679 764
@@ -716,13 +801,39 @@ QBitArray OPimTodoAccessBackendSQL::sup() const{
716 ar[OPimTodo::Reminders] = false; 801 ar[OPimTodo::Reminders] = false;
717 ar[OPimTodo::Notifiers] = false; 802 ar[OPimTodo::Notifiers] = false;
718 ar[OPimTodo::Maintainer] = false; 803 ar[OPimTodo::Maintainer] = false;
719 804
720 return ar; 805 return ar;
721} 806}
722 807
723void OPimTodoAccessBackendSQL::removeAllCompleted(){ 808void OPimTodoAccessBackendSQL::removeAllCompleted(){
724#warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !! 809#warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !!
725 810
726} 811}
727 812
813
814QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
815{
816 QMap<QString, QString> customMap;
817
818 FindCustomQuery query( uid );
819 OSQLResult res_custom = m_driver->query( &query );
820
821 if ( res_custom.state() == OSQLResult::Failure ) {
822 qWarning("OSQLResult::Failure in find query !!");
823 QMap<QString, QString> empty;
824 return empty;
825 }
826
827 OSQLResultItem::ValueList list = res_custom.results();
828 OSQLResultItem::ValueList::Iterator it = list.begin();
829 for ( ; it != list.end(); ++it ) {
830 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
831 }
832
833 return customMap;
834}
835
836
837
838
728} 839}
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 0ae2591..0cc7722 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -20,25 +20,25 @@
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29#ifndef OPIE_PIM_ACCESS_SQL_H 29#ifndef OPIE_PIM_ACCESS_SQL_H
30#define OPIE_PIM_ACCESS_SQL_H 30#define OPIE_PIM_ACCESS_SQL_H
31 31
32#include <qasciidict.h> 32/* #include <qasciidict.h> */
33 33
34#include <opie2/otodoaccessbackend.h> 34#include <opie2/otodoaccessbackend.h>
35 35
36namespace Opie { 36namespace Opie {
37namespace DB { 37namespace DB {
38class OSQLDriver; 38class OSQLDriver;
39class OSQLResult; 39class OSQLResult;
40class OSQLResultItem; 40class OSQLResultItem;
41} 41}
42} 42}
43 43
44namespace Opie { 44namespace Opie {
@@ -71,22 +71,23 @@ public:
71 void removeAllCompleted(); 71 void removeAllCompleted();
72 72
73 73
74private: 74private:
75 void update()const; 75 void update()const;
76 void fillDict(); 76 void fillDict();
77 inline bool date( QDate& date, const QString& )const; 77 inline bool date( QDate& date, const QString& )const;
78 inline OPimTodo todo( const Opie::DB::OSQLResult& )const; 78 inline OPimTodo todo( const Opie::DB::OSQLResult& )const;
79 inline OPimTodo todo( Opie::DB::OSQLResultItem& )const; 79 inline OPimTodo todo( Opie::DB::OSQLResultItem& )const;
80 inline QArray<int> uids( const Opie::DB::OSQLResult& )const; 80 inline QArray<int> uids( const Opie::DB::OSQLResult& )const;
81 OPimTodo todo( int uid )const; 81 OPimTodo todo( int uid )const;
82 QBitArray sup() const; 82 QBitArray sup() const;
83 QMap<QString, QString> requestCustom( int uid ) const;
83 84
84 QAsciiDict<int> m_dict; 85 // QAsciiDict<int> m_dict;
85 Opie::DB::OSQLDriver* m_driver; 86 Opie::DB::OSQLDriver* m_driver;
86 QArray<int> m_uids; 87 QArray<int> m_uids;
87 bool m_dirty : 1; 88 bool m_dirty : 1;
88}; 89};
89 90
90} 91}
91 92
92#endif 93#endif
diff --git a/libopie2/opiepim/core/opimcontact.h b/libopie2/opiepim/core/opimcontact.h
index c08f7ed..9d3cacc 100644
--- a/libopie2/opiepim/core/opimcontact.h
+++ b/libopie2/opiepim/core/opimcontact.h
@@ -1,15 +1,15 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) Stefan Eilers <eilers.stefan@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;