summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
authoreilers <eilers>2004-04-02 12:21:19 (UTC)
committer eilers <eilers>2004-04-02 12:21:19 (UTC)
commitbf7ec4adff3226b085421e0ea0b0699b748d3328 (patch) (unidiff)
tree4db1eefa301438b43c20140a6625d5b04c5916de /libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
parent7b3b820494376699ec431deea3ecd41309037997 (diff)
downloadopie-bf7ec4adff3226b085421e0ea0b0699b748d3328.zip
opie-bf7ec4adff3226b085421e0ea0b0699b748d3328.tar.gz
opie-bf7ec4adff3226b085421e0ea0b0699b748d3328.tar.bz2
Removed the avaluation code. Horizontal layout won the competition, therfore the rest is removed..
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp177
1 files changed, 1 insertions, 176 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index d16d692..1ea35a8 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -1,6 +1,6 @@
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@epost.de>
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 .>+-=
@@ -49,19 +49,6 @@
49using namespace Opie::DB; 49using namespace Opie::DB;
50 50
51 51
52// If defined, we use a horizontal table ( uid, attr1, attr2, attr3, ..., attrn ) instead
53// vertical like "uid, type, value".
54// DON'T DEACTIVATE THIS DEFINE IN PRODUCTIVE ENVIRONMENTS !!
55#define __STORE_HORIZONTAL_
56
57// Distinct loading is not very fast. If I expect that every person has just
58// one (and always one) 'Last Name', I can request all uid's for existing lastnames,
59// which is faster..
60// But this may not be true for all entries, like company contacts..
61// The current AddressBook application handles this problem, but other may not.. (eilers)
62#define __USE_SUPERFAST_LOADQUERY
63
64
65/* 52/*
66 * Implementation of used query types 53 * Implementation of used query types
67 * CREATE query 54 * CREATE query
@@ -172,7 +159,6 @@ namespace Opie {
172 CreateQuery::~CreateQuery() {} 159 CreateQuery::~CreateQuery() {}
173 QString CreateQuery::query()const { 160 QString CreateQuery::query()const {
174 QString qu; 161 QString qu;
175#ifdef __STORE_HORIZONTAL_
176 162
177 qu += "create table addressbook( uid PRIMARY KEY "; 163 qu += "create table addressbook( uid PRIMARY KEY ";
178 164
@@ -184,13 +170,6 @@ namespace Opie {
184 170
185 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; 171 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );";
186 172
187#else
188
189 qu += "create table addressbook( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id));";
190 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );";
191 // qu += "create table dates( uid PRIMARY KEY, type, day, month, year, hour, minute, second );";
192
193#endif // __STORE_HORIZONTAL_
194 return qu; 173 return qu;
195 } 174 }
196 175
@@ -209,15 +188,7 @@ namespace Opie {
209 LoadQuery::~LoadQuery() {} 188 LoadQuery::~LoadQuery() {}
210 QString LoadQuery::query()const { 189 QString LoadQuery::query()const {
211 QString qu; 190 QString qu;
212#ifdef __STORE_HORIZONTAL_
213 qu += "select uid from addressbook"; 191 qu += "select uid from addressbook";
214#else
215# ifndef __USE_SUPERFAST_LOADQUERY
216 qu += "select distinct uid from addressbook";
217# else
218 qu += "select uid from addressbook where type = 'Last Name'";
219# endif // __USE_SUPERFAST_LOADQUERY
220#endif // __STORE_HORIZONTAL_
221 192
222 return qu; 193 return qu;
223 } 194 }
@@ -235,7 +206,6 @@ namespace Opie {
235 */ 206 */
236 QString InsertQuery::query()const{ 207 QString InsertQuery::query()const{
237 208
238#ifdef __STORE_HORIZONTAL_
239 QString qu; 209 QString qu;
240 qu += "insert into addressbook VALUES( " + 210 qu += "insert into addressbook VALUES( " +
241 QString::number( m_contact.uid() ); 211 QString::number( m_contact.uid() );
@@ -287,75 +257,8 @@ namespace Opie {
287 qu += " );"; 257 qu += " );";
288 258
289 259
290#else
291 // Get all information out of the contact-class
292 // Remember: The category is stored in contactMap, too !
293 QMap<int, QString> contactMap = m_contact.toMap();
294
295 QMap<QString, QString> addressbook_db;
296
297 // Get the translation from the ID to the String
298 QMap<int, QString> transMap = OPimContactFields::idToUntrFields();
299
300 for( QMap<int, QString>::Iterator it = contactMap.begin();
301 it != contactMap.end(); ++it ){
302 switch ( it.key() ){
303 case Qtopia::Birthday:{
304 // These entries should stored in a special format
305 // year-month-day
306 QDate day = m_contact.birthday();
307 addressbook_db.insert( transMap[it.key()],
308 QString("%1-%2-%3")
309 .arg( day.year() )
310 .arg( day.month() )
311 .arg( day.day() ) );
312 }
313 break;
314 case Qtopia::Anniversary:{
315 // These entries should stored in a special format
316 // year-month-day
317 QDate day = m_contact.anniversary();
318 addressbook_db.insert( transMap[it.key()],
319 QString("%1-%2-%3")
320 .arg( day.year() )
321 .arg( day.month() )
322 .arg( day.day() ) );
323 }
324 break;
325 case Qtopia::AddressUid: // Ignore UID
326 break;
327 default: // Translate id to String
328 addressbook_db.insert( transMap[it.key()], it.data() );
329 break;
330 }
331
332 }
333
334 // Now convert this whole stuff into a SQL String, beginning with
335 // the addressbook table..
336 QString qu;
337 // qu += "begin transaction;";
338 int id = 0;
339 for( QMap<QString, QString>::Iterator it = addressbook_db.begin();
340 it != addressbook_db.end(); ++it ){
341 qu += "insert into addressbook VALUES("
342 + QString::number( m_contact.uid() )
343 + ","
344 + QString::number( id++ )
345 + ",'"
346 + it.key() //.latin1()
347 + "',"
348 + "0" // Priority for future enhancements
349 + ",'"
350 + it.data() //.latin1()
351 + "');";
352 }
353
354 #endif //__STORE_HORIZONTAL_
355 // Now add custom data.. 260 // Now add custom data..
356#ifdef __STORE_HORIZONTAL_
357 int id = 0; 261 int id = 0;
358#endif
359 id = 0; 262 id = 0;
360 QMap<QString, QString> customMap = m_contact.toExtraMap(); 263 QMap<QString, QString> customMap = m_contact.toExtraMap();
361 for( QMap<QString, QString>::Iterator it = customMap.begin(); 264 for( QMap<QString, QString>::Iterator it = customMap.begin();
@@ -417,7 +320,6 @@ namespace Opie {
417 return qu; 320 return qu;
418 } 321 }
419 */ 322 */
420#ifdef __STORE_HORIZONTAL_
421 QString FindQuery::single()const{ 323 QString FindQuery::single()const{
422 QString qu = "select *"; 324 QString qu = "select *";
423 qu += " from addressbook where uid = " + QString::number(m_uid); 325 qu += " from addressbook where uid = " + QString::number(m_uid);
@@ -425,13 +327,6 @@ namespace Opie {
425 // qWarning("find query: %s", qu.latin1() ); 327 // qWarning("find query: %s", qu.latin1() );
426 return qu; 328 return qu;
427 } 329 }
428#else
429 QString FindQuery::single()const{
430 QString qu = "select uid, type, value from addressbook where uid = ";
431 qu += QString::number(m_uid);
432 return qu;
433 }
434#endif
435 330
436 331
437 FindCustomQuery::FindCustomQuery(int uid) 332 FindCustomQuery::FindCustomQuery(int uid)
@@ -708,13 +603,8 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
708 QTime t; 603 QTime t;
709 t.start(); 604 t.start();
710 605
711#ifdef __STORE_HORIZONTAL_
712 QString query = "SELECT uid FROM addressbook "; 606 QString query = "SELECT uid FROM addressbook ";
713 query += "ORDER BY \"Last Name\" "; 607 query += "ORDER BY \"Last Name\" ";
714#else
715 QString query = "SELECT uid FROM addressbook WHERE type = 'Last Name' ";
716 query += "ORDER BY upper( value )";
717#endif
718 608
719 if ( !asc ) 609 if ( !asc )
720 query += "DESC"; 610 query += "DESC";
@@ -777,7 +667,6 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
777 667
778} 668}
779 669
780#ifdef __STORE_HORIZONTAL_
781QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const 670QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
782{ 671{
783 QTime t; 672 QTime t;
@@ -841,70 +730,6 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
841 730
842 return nonCustomMap; 731 return nonCustomMap;
843} 732}
844#else
845
846QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
847{
848 QTime t;
849 t.start();
850
851 QMap<int, QString> nonCustomMap;
852
853 int t2needed = 0;
854 QTime t2;
855 t2.start();
856 FindQuery query( uid );
857 OSQLResult res_noncustom = m_driver->query( &query );
858 t2needed = t2.elapsed();
859
860 if ( res_noncustom.state() == OSQLResult::Failure ) {
861 qWarning("OSQLResult::Failure in find query !!");
862 QMap<int, QString> empty;
863 return empty;
864 }
865
866 int t3needed = 0;
867 QTime t3;
868 t3.start();
869 QMap<QString, int> translateMap = OPimContactFields::untrFieldsToId();
870
871 OSQLResultItem::ValueList list = res_noncustom.results();
872 OSQLResultItem::ValueList::Iterator it = list.begin();
873 for ( ; it != list.end(); ++it ) {
874 if ( (*it).data("type") != "" ){
875 int typeId = translateMap[(*it).data( "type" )];
876 switch( typeId ){
877 case Qtopia::Birthday:
878 case Qtopia::Anniversary:{
879 // Birthday and Anniversary are encoded special ( yyyy-mm-dd )
880 QStringList list = QStringList::split( '-', (*it).data( "value" ) );
881 QStringList::Iterator lit = list.begin();
882 int year = (*lit).toInt();
883 qWarning("1. %s", (*lit).latin1());
884 int month = (*(++lit)).toInt();
885 qWarning("2. %s", (*lit).latin1());
886 int day = (*(++lit)).toInt();
887 qWarning("3. %s", (*lit).latin1());
888 qWarning( "RequestNonCustom->Converting:%s to Year: %d, Month: %d, Day: %d ", (*it).data( "value" ).latin1(), year, month, day );
889 QDate date( year, month, day );
890 nonCustomMap.insert( typeId, OPimDateConversion::dateToString( date ) );
891 }
892 break;
893 default:
894 nonCustomMap.insert( typeId,
895 (*it).data( "value" ) );
896 }
897 }
898 }
899 // Add UID to Map..
900 nonCustomMap.insert( Qtopia::AddressUid, QString::number( uid ) );
901 t3needed = t3.elapsed();
902
903 qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", t.elapsed(), t2needed, t3needed );
904 return nonCustomMap;
905}
906
907#endif // __STORE_HORIZONTAL_
908 733
909QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const 734QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const
910{ 735{