summaryrefslogtreecommitdiff
authoreilers <eilers>2004-04-05 07:03:09 (UTC)
committer eilers <eilers>2004-04-05 07:03:09 (UTC)
commite6e31e93aa55bb967a044fe3660201000a6e59b0 (patch) (unidiff)
tree1071fa4b22698fd56dde283bbb7375478b7e1ddf
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 (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
@@ -41,2 +41,3 @@
41 41
42#include <opie2/opimcontact.h>
42#include <opie2/opimcontactfields.h> 43#include <opie2/opimcontactfields.h>
@@ -48,2 +49,3 @@
48 49
50using namespace Opie;
49using namespace Opie::DB; 51using namespace Opie::DB;
@@ -52,4 +54,3 @@ using namespace Opie::DB;
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
@@ -59,3 +60,3 @@ using namespace Opie::DB;
59 */ 60 */
60namespace Opie { 61namespace {
61 /** 62 /**
@@ -152,3 +153,3 @@ namespace Opie {
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)
@@ -170,3 +171,3 @@ namespace Opie {
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
@@ -223,25 +224,17 @@ namespace Opie {
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 {
@@ -251,3 +244,2 @@ namespace Opie {
251 break; 244 break;
252
253 default: 245 default:
@@ -270,3 +262,3 @@ namespace Opie {
270 + ",'" 262 + ",'"
271 + it.key() //.latin1() 263 + it.key()
272 + "'," 264 + "',"
@@ -274,3 +266,3 @@ namespace Opie {
274 + ",'" 266 + ",'"
275 + it.data() //.latin1() 267 + it.data()
276 + "');"; 268 + "');";
@@ -278,3 +270,3 @@ namespace Opie {
278 // qu += "commit;"; 270 // qu += "commit;";
279 qWarning("add %s", qu.latin1() ); 271 qDebug("add %s", qu.latin1() );
280 return qu; 272 return qu;
@@ -360,3 +352,3 @@ OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* a
360{ 352{
361 qWarning("C'tor OPimContactAccessBackend_SQL starts"); 353 qDebug("C'tor OPimContactAccessBackend_SQL starts");
362 QTime t; 354 QTime t;
@@ -377,3 +369,3 @@ OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* a
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}
@@ -478,3 +470,3 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
478{ 470{
479 qWarning("OPimContactAccessBackend_SQL::find()"); 471 qDebug("OPimContactAccessBackend_SQL::find()");
480 QTime t; 472 QTime t;
@@ -485,3 +477,3 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
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;
@@ -491,5 +483,14 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
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
@@ -500,9 +501,67 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
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:
@@ -512,7 +571,7 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
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
@@ -522,6 +581,8 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
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
@@ -549,3 +610,8 @@ const uint OPimContactAccessBackend_SQL::querySettings()
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}
@@ -563,6 +629,6 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
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
@@ -611,3 +677,3 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
611 677
612 // qWarning("sorted query is: %s", query.latin1() ); 678 // qDebug("sorted query is: %s", query.latin1() );
613 679
@@ -622,3 +688,3 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
622 688
623 qWarning("sorted needed %d ms!", t.elapsed() ); 689 qDebug("sorted needed %d ms!", t.elapsed() );
624 return list; 690 return list;
@@ -629,3 +695,3 @@ void OPimContactAccessBackend_SQL::update()
629{ 695{
630 qWarning("Update starts"); 696 qDebug("Update starts");
631 QTime t; 697 QTime t;
@@ -645,3 +711,3 @@ void OPimContactAccessBackend_SQL::update()
645 711
646 qWarning("Update ends %d ms", t.elapsed() ); 712 qDebug("Update ends %d ms", t.elapsed() );
647} 713}
@@ -650,3 +716,3 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
650{ 716{
651 qWarning("extractUids"); 717 qDebug("extractUids");
652 QTime t; 718 QTime t;
@@ -656,3 +722,3 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
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
@@ -663,3 +729,3 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
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
@@ -698,3 +764,3 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
698 764
699 // qWarning("Reading %s... found: %s", (*it).latin1(), value.latin1() ); 765 // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() );
700 766
@@ -716,3 +782,3 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
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:
@@ -726,4 +792,4 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
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 );
@@ -755,3 +821,3 @@ QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) c
755 821
756 qWarning("RequestCustom needed: %d ms", t.elapsed() ); 822 qDebug("RequestCustom needed: %d ms", t.elapsed() );
757 return customMap; 823 return customMap;
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
@@ -232,2 +232,3 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
232 checkDate = new QDate( (*it)->birthday() ); 232 checkDate = new QDate( (*it)->birthday() );
233 // fall through
233 case Qtopia::Anniversary: 234 case Qtopia::Anniversary:
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
@@ -50,2 +50,39 @@ using 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 {
@@ -125,3 +162,3 @@ bool ODateBookAccessBackend_SQL::load()
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
@@ -204,5 +241,5 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
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;
@@ -367,2 +404,29 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
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
@@ -90,3 +90,5 @@ private:
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
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
@@ -3,2 +3,3 @@
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>
@@ -30,2 +31,4 @@
30#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qmap.h>
33#include <qstring.h>
31 34
@@ -150,2 +153,20 @@ namespace {
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() {}
@@ -159,3 +180,3 @@ namespace {
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;
@@ -181,3 +202,5 @@ namespace {
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 */
@@ -217,5 +240,5 @@ namespace {
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() ) + ","
@@ -242,11 +265,31 @@ namespace {
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;
@@ -302,3 +345,6 @@ namespace {
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
@@ -317,4 +363,8 @@ namespace {
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;
@@ -324,4 +374,8 @@ namespace {
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
@@ -329,2 +383,20 @@ namespace {
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};
@@ -334,3 +406,3 @@ namespace 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{
@@ -385,3 +457,3 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
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 );
@@ -395,3 +467,3 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
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];
@@ -470,3 +542,3 @@ QArray<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;
@@ -491,3 +563,6 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
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";
@@ -500,3 +575,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
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 );
@@ -526,3 +601,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
526 if ( !asc ) { 601 if ( !asc ) {
527 qWarning("not ascending!"); 602 qDebug("not ascending!");
528 query += " DESC"; 603 query += " DESC";
@@ -530,3 +605,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
530 605
531 qWarning( query ); 606 qDebug( query );
532 OSQLRawQuery raw(query ); 607 OSQLRawQuery raw(query );
@@ -547,3 +622,3 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
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 ) {
@@ -555,3 +630,3 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{
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) );
@@ -561,3 +636,3 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{
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) ) );
@@ -567,3 +642,6 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{
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();
@@ -572,3 +650,3 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
572 650
573 qWarning("Item is completed: %d", item.data("completed").toInt() ); 651 qDebug("Item is completed: %d", item.data("completed").toInt() );
574 652
@@ -616,2 +694,5 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
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;
@@ -626,2 +707,4 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
626void OPimTodoAccessBackendSQL::fillDict() { 707void OPimTodoAccessBackendSQL::fillDict() {
708
709#if 0
627 /* initialize dict */ 710 /* initialize dict */
@@ -647,2 +730,4 @@ void OPimTodoAccessBackendSQL::fillDict() {
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}
@@ -666,3 +751,3 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
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
@@ -727,2 +812,28 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
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
@@ -31,3 +31,3 @@
31 31
32#include <qasciidict.h> 32/* #include <qasciidict.h> */
33 33
@@ -82,4 +82,5 @@ private:
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;
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
@@ -2,3 +2,3 @@
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>