summaryrefslogtreecommitdiff
authoreilers <eilers>2004-04-02 12:21:19 (UTC)
committer eilers <eilers>2004-04-02 12:21:19 (UTC)
commitbf7ec4adff3226b085421e0ea0b0699b748d3328 (patch) (unidiff)
tree4db1eefa301438b43c20140a6625d5b04c5916de
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 (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,88 +1,75 @@
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 .>+-=
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;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
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/* 29/*
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/opimcontactfields.h> 42#include <opie2/opimcontactfields.h>
43#include <opie2/opimdateconversion.h> 43#include <opie2/opimdateconversion.h>
44#include <opie2/osqldriver.h> 44#include <opie2/osqldriver.h>
45#include <opie2/osqlresult.h> 45#include <opie2/osqlresult.h>
46#include <opie2/osqlmanager.h> 46#include <opie2/osqlmanager.h>
47#include <opie2/osqlquery.h> 47#include <opie2/osqlquery.h>
48 48
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
68 * LOAD query 55 * LOAD query
69 * INSERT 56 * INSERT
70 * REMOVE 57 * REMOVE
71 * CLEAR 58 * CLEAR
72 */ 59 */
73namespace Opie { 60namespace Opie {
74 /** 61 /**
75 * CreateQuery for the Todolist Table 62 * CreateQuery for the Todolist Table
76 */ 63 */
77 class CreateQuery : public OSQLQuery { 64 class CreateQuery : public OSQLQuery {
78 public: 65 public:
79 CreateQuery(); 66 CreateQuery();
80 ~CreateQuery(); 67 ~CreateQuery();
81 QString query()const; 68 QString query()const;
82 }; 69 };
83 70
84 /** 71 /**
85 * Clears (delete) a Table 72 * Clears (delete) a Table
86 */ 73 */
87 class ClearQuery : public OSQLQuery { 74 class ClearQuery : public OSQLQuery {
88 public: 75 public:
@@ -151,112 +138,95 @@ namespace Opie {
151 class FindCustomQuery : public OSQLQuery { 138 class FindCustomQuery : public OSQLQuery {
152 public: 139 public:
153 FindCustomQuery(int uid); 140 FindCustomQuery(int uid);
154 FindCustomQuery(const QArray<int>& ); 141 FindCustomQuery(const QArray<int>& );
155 ~FindCustomQuery(); 142 ~FindCustomQuery();
156 QString query()const; 143 QString query()const;
157 private: 144 private:
158 QString single()const; 145 QString single()const;
159 QString multi()const; 146 QString multi()const;
160 QArray<int> m_uids; 147 QArray<int> m_uids;
161 int m_uid; 148 int m_uid;
162 }; 149 };
163 150
164 151
165 152
166 // We using three tables to store the information: 153 // We using three tables to store the information:
167 // 1. addressbook : It contains General information about the contact (non custom) 154 // 1. addressbook : It contains General information about the contact (non custom)
168 // 2. custom_data : Not official supported entries 155 // 2. custom_data : Not official supported entries
169 // All tables are connected by the uid of the contact. 156 // All tables are connected by the uid of the contact.
170 // Maybe I should add a table for meta-information ? 157 // Maybe I should add a table for meta-information ?
171 CreateQuery::CreateQuery() : OSQLQuery() {} 158 CreateQuery::CreateQuery() : OSQLQuery() {}
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
179 QStringList fieldList = OPimContactFields::untrfields( false ); 165 QStringList fieldList = OPimContactFields::untrfields( false );
180 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 166 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
181 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); 167 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it );
182 } 168 }
183 qu += " );"; 169 qu += " );";
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
197 ClearQuery::ClearQuery() 176 ClearQuery::ClearQuery()
198 : OSQLQuery() {} 177 : OSQLQuery() {}
199 ClearQuery::~ClearQuery() {} 178 ClearQuery::~ClearQuery() {}
200 QString ClearQuery::query()const { 179 QString ClearQuery::query()const {
201 QString qu = "drop table addressbook;"; 180 QString qu = "drop table addressbook;";
202 qu += "drop table custom_data;"; 181 qu += "drop table custom_data;";
203 // qu += "drop table dates;"; 182 // qu += "drop table dates;";
204 return qu; 183 return qu;
205 } 184 }
206 185
207 186
208 LoadQuery::LoadQuery() : OSQLQuery() {} 187 LoadQuery::LoadQuery() : OSQLQuery() {}
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 }
224 195
225 196
226 InsertQuery::InsertQuery( const OPimContact& contact ) 197 InsertQuery::InsertQuery( const OPimContact& contact )
227 : OSQLQuery(), m_contact( contact ) { 198 : OSQLQuery(), m_contact( contact ) {
228 } 199 }
229 200
230 InsertQuery::~InsertQuery() { 201 InsertQuery::~InsertQuery() {
231 } 202 }
232 203
233 /* 204 /*
234 * converts from a OPimContact to a query 205 * converts from a OPimContact to a query
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() );
242 212
243 // Get all information out of the contact-class 213 // Get all information out of the contact-class
244 // Remember: The category is stored in contactMap, too ! 214 // Remember: The category is stored in contactMap, too !
245 QMap<int, QString> contactMap = m_contact.toMap(); 215 QMap<int, QString> contactMap = m_contact.toMap();
246 216
247 QStringList fieldList = OPimContactFields::untrfields( false ); 217 QStringList fieldList = OPimContactFields::untrfields( false );
248 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 218 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
249 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 219 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
250 // Convert Column-String to Id and get value for this id.. 220 // Convert Column-String to Id and get value for this id..
251 // Hmmm.. Maybe not very cute solution.. 221 // Hmmm.. Maybe not very cute solution..
252 int id = translate[*it]; 222 int id = translate[*it];
253 switch ( id ){ 223 switch ( id ){
254 case Qtopia::Birthday:{ 224 case Qtopia::Birthday:{
255 // These entries should stored in a special format 225 // These entries should stored in a special format
256 // year-month-day 226 // year-month-day
257 QDate day = m_contact.birthday(); 227 QDate day = m_contact.birthday();
258 if ( day.isValid() ){ 228 if ( day.isValid() ){
259 qu += QString(",\"%1-%2-%3\"") 229 qu += QString(",\"%1-%2-%3\"")
260 .arg( day.year() ) 230 .arg( day.year() )
261 .arg( day.month() ) 231 .arg( day.month() )
262 .arg( day.day() ); 232 .arg( day.day() );
@@ -266,117 +236,50 @@ namespace Opie {
266 } 236 }
267 break; 237 break;
268 case Qtopia::Anniversary:{ 238 case Qtopia::Anniversary:{
269 // These entries should stored in a special format 239 // These entries should stored in a special format
270 // year-month-day 240 // year-month-day
271 QDate day = m_contact.anniversary(); 241 QDate day = m_contact.anniversary();
272 if ( day.isValid() ){ 242 if ( day.isValid() ){
273 qu += QString(",\"%1-%2-%3\"") 243 qu += QString(",\"%1-%2-%3\"")
274 .arg( day.year() ) 244 .arg( day.year() )
275 .arg( day.month() ) 245 .arg( day.month() )
276 .arg( day.day() ); 246 .arg( day.day() );
277 } else { 247 } else {
278 qu += ",\"\""; 248 qu += ",\"\"";
279 } 249 }
280 } 250 }
281 break; 251 break;
282 252
283 default: 253 default:
284 qu += QString( ",\"%1\"" ).arg( contactMap[id] ); 254 qu += QString( ",\"%1\"" ).arg( contactMap[id] );
285 } 255 }
286 } 256 }
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();
362 it != customMap.end(); ++it ){ 265 it != customMap.end(); ++it ){
363 qu += "insert into custom_data VALUES(" 266 qu += "insert into custom_data VALUES("
364 + QString::number( m_contact.uid() ) 267 + QString::number( m_contact.uid() )
365 + "," 268 + ","
366 + QString::number( id++ ) 269 + QString::number( id++ )
367 + ",'" 270 + ",'"
368 + it.key() //.latin1() 271 + it.key() //.latin1()
369 + "'," 272 + "',"
370 + "0" // Priority for future enhancements 273 + "0" // Priority for future enhancements
371 + ",'" 274 + ",'"
372 + it.data() //.latin1() 275 + it.data() //.latin1()
373 + "');"; 276 + "');";
374 } 277 }
375 // qu += "commit;"; 278 // qu += "commit;";
376 qWarning("add %s", qu.latin1() ); 279 qWarning("add %s", qu.latin1() );
377 return qu; 280 return qu;
378 } 281 }
379 282
380 283
381 RemoveQuery::RemoveQuery(int uid ) 284 RemoveQuery::RemoveQuery(int uid )
382 : OSQLQuery(), m_uid( uid ) {} 285 : OSQLQuery(), m_uid( uid ) {}
@@ -396,63 +299,55 @@ namespace Opie {
396 : OSQLQuery(), m_uid( uid ) { 299 : OSQLQuery(), m_uid( uid ) {
397 } 300 }
398 FindQuery::FindQuery(const QArray<int>& ints) 301 FindQuery::FindQuery(const QArray<int>& ints)
399 : OSQLQuery(), m_uids( ints ){ 302 : OSQLQuery(), m_uids( ints ){
400 } 303 }
401 FindQuery::~FindQuery() { 304 FindQuery::~FindQuery() {
402 } 305 }
403 QString FindQuery::query()const{ 306 QString FindQuery::query()const{
404 // if ( m_uids.count() == 0 ) 307 // if ( m_uids.count() == 0 )
405 return single(); 308 return single();
406 } 309 }
407 /* 310 /*
408 else 311 else
409 return multi(); 312 return multi();
410 } 313 }
411 QString FindQuery::multi()const { 314 QString FindQuery::multi()const {
412 QString qu = "select uid, type, value from addressbook where"; 315 QString qu = "select uid, type, value from addressbook where";
413 for (uint i = 0; i < m_uids.count(); i++ ) { 316 for (uint i = 0; i < m_uids.count(); i++ ) {
414 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 317 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
415 } 318 }
416 qu.remove( qu.length()-2, 2 ); // Hmmmm.. 319 qu.remove( qu.length()-2, 2 ); // Hmmmm..
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);
424 326
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)
438 : OSQLQuery(), m_uid( uid ) { 333 : OSQLQuery(), m_uid( uid ) {
439 } 334 }
440 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 335 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
441 : OSQLQuery(), m_uids( ints ){ 336 : OSQLQuery(), m_uids( ints ){
442 } 337 }
443 FindCustomQuery::~FindCustomQuery() { 338 FindCustomQuery::~FindCustomQuery() {
444 } 339 }
445 QString FindCustomQuery::query()const{ 340 QString FindCustomQuery::query()const{
446 // if ( m_uids.count() == 0 ) 341 // if ( m_uids.count() == 0 )
447 return single(); 342 return single();
448 } 343 }
449 QString FindCustomQuery::single()const{ 344 QString FindCustomQuery::single()const{
450 QString qu = "select uid, type, value from custom_data where uid = "; 345 QString qu = "select uid, type, value from custom_data where uid = ";
451 qu += QString::number(m_uid); 346 qu += QString::number(m_uid);
452 return qu; 347 return qu;
453 } 348 }
454 349
455}; 350};
456 351
457 352
458/* --------------------------------------------------------------------------- */ 353/* --------------------------------------------------------------------------- */
@@ -687,55 +582,50 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
687 | OPimContactAccess::DateYear 582 | OPimContactAccess::DateYear
688 | OPimContactAccess::DateMonth 583 | OPimContactAccess::DateMonth
689 | OPimContactAccess::DateDay 584 | OPimContactAccess::DateDay
690 ) 585 )
691 ){ 586 ){
692 case OPimContactAccess::RegExp: 587 case OPimContactAccess::RegExp:
693 return ( true ); 588 return ( true );
694 case OPimContactAccess::WildCards: 589 case OPimContactAccess::WildCards:
695 return ( true ); 590 return ( true );
696 case OPimContactAccess::ExactMatch: 591 case OPimContactAccess::ExactMatch:
697 return ( true ); 592 return ( true );
698 case 0: // one of the upper removed bits were set.. 593 case 0: // one of the upper removed bits were set..
699 return ( true ); 594 return ( true );
700 default: 595 default:
701 return ( false ); 596 return ( false );
702 } 597 }
703 598
704} 599}
705 600
706QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) 601QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
707{ 602{
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";
721 611
722 // qWarning("sorted query is: %s", query.latin1() ); 612 // qWarning("sorted query is: %s", query.latin1() );
723 613
724 OSQLRawQuery raw( query ); 614 OSQLRawQuery raw( query );
725 OSQLResult res = m_driver->query( &raw ); 615 OSQLResult res = m_driver->query( &raw );
726 if ( res.state() != OSQLResult::Success ){ 616 if ( res.state() != OSQLResult::Success ){
727 QArray<int> empty; 617 QArray<int> empty;
728 return empty; 618 return empty;
729 } 619 }
730 620
731 QArray<int> list = extractUids( res ); 621 QArray<int> list = extractUids( res );
732 622
733 qWarning("sorted needed %d ms!", t.elapsed() ); 623 qWarning("sorted needed %d ms!", t.elapsed() );
734 return list; 624 return list;
735} 625}
736 626
737 627
738void OPimContactAccessBackend_SQL::update() 628void OPimContactAccessBackend_SQL::update()
739{ 629{
740 qWarning("Update starts"); 630 qWarning("Update starts");
741 QTime t; 631 QTime t;
@@ -756,49 +646,48 @@ void OPimContactAccessBackend_SQL::update()
756 qWarning("Update ends %d ms", t.elapsed() ); 646 qWarning("Update ends %d ms", t.elapsed() );
757} 647}
758 648
759QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 649QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
760{ 650{
761 qWarning("extractUids"); 651 qWarning("extractUids");
762 QTime t; 652 QTime t;
763 t.start(); 653 t.start();
764 OSQLResultItem::ValueList list = res.results(); 654 OSQLResultItem::ValueList list = res.results();
765 OSQLResultItem::ValueList::Iterator it; 655 OSQLResultItem::ValueList::Iterator it;
766 QArray<int> ints(list.count() ); 656 QArray<int> ints(list.count() );
767 qWarning(" count = %d", list.count() ); 657 qWarning(" count = %d", list.count() );
768 658
769 int i = 0; 659 int i = 0;
770 for (it = list.begin(); it != list.end(); ++it ) { 660 for (it = list.begin(); it != list.end(); ++it ) {
771 ints[i] = (*it).data("uid").toInt(); 661 ints[i] = (*it).data("uid").toInt();
772 i++; 662 i++;
773 } 663 }
774 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 664 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
775 665
776 return ints; 666 return ints;
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;
784 t.start(); 673 t.start();
785 674
786 QMap<int, QString> nonCustomMap; 675 QMap<int, QString> nonCustomMap;
787 676
788 int t2needed = 0; 677 int t2needed = 0;
789 int t3needed = 0; 678 int t3needed = 0;
790 QTime t2; 679 QTime t2;
791 t2.start(); 680 t2.start();
792 FindQuery query( uid ); 681 FindQuery query( uid );
793 OSQLResult res_noncustom = m_driver->query( &query ); 682 OSQLResult res_noncustom = m_driver->query( &query );
794 t2needed = t2.elapsed(); 683 t2needed = t2.elapsed();
795 684
796 OSQLResultItem resItem = res_noncustom.first(); 685 OSQLResultItem resItem = res_noncustom.first();
797 686
798 QTime t3; 687 QTime t3;
799 t3.start(); 688 t3.start();
800 // Now loop through all columns 689 // Now loop through all columns
801 QStringList fieldList = OPimContactFields::untrfields( false ); 690 QStringList fieldList = OPimContactFields::untrfields( false );
802 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 691 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
803 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 692 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
804 // Get data for the selected column and store it with the 693 // Get data for the selected column and store it with the
@@ -820,112 +709,48 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
820 int day = (*(++lit)).toInt(); 709 int day = (*(++lit)).toInt();
821 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ 710 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){
822 QDate date( year, month, day ); 711 QDate date( year, month, day );
823 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); 712 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) );
824 } 713 }
825 } 714 }
826 break; 715 break;
827 case Qtopia::AddressCategory: 716 case Qtopia::AddressCategory:
828 qWarning("Category is: %s", value.latin1() ); 717 qWarning("Category is: %s", value.latin1() );
829 default: 718 default:
830 nonCustomMap.insert( id, value ); 719 nonCustomMap.insert( id, value );
831 } 720 }
832 } 721 }
833 722
834 // First insert uid 723 // First insert uid
835 nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); 724 nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) );
836 t3needed = t3.elapsed(); 725 t3needed = t3.elapsed();
837 726
838 // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() ); 727 // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() );
839 qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", 728 qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms",
840 t.elapsed(), t2needed, t3needed ); 729 t.elapsed(), t2needed, t3needed );
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{
911 QTime t; 736 QTime t;
912 t.start(); 737 t.start();
913 738
914 QMap<QString, QString> customMap; 739 QMap<QString, QString> customMap;
915 740
916 FindCustomQuery query( uid ); 741 FindCustomQuery query( uid );
917 OSQLResult res_custom = m_driver->query( &query ); 742 OSQLResult res_custom = m_driver->query( &query );
918 743
919 if ( res_custom.state() == OSQLResult::Failure ) { 744 if ( res_custom.state() == OSQLResult::Failure ) {
920 qWarning("OSQLResult::Failure in find query !!"); 745 qWarning("OSQLResult::Failure in find query !!");
921 QMap<QString, QString> empty; 746 QMap<QString, QString> empty;
922 return empty; 747 return empty;
923 } 748 }
924 749
925 OSQLResultItem::ValueList list = res_custom.results(); 750 OSQLResultItem::ValueList list = res_custom.results();
926 OSQLResultItem::ValueList::Iterator it = list.begin(); 751 OSQLResultItem::ValueList::Iterator it = list.begin();
927 for ( ; it != list.end(); ++it ) { 752 for ( ; it != list.end(); ++it ) {
928 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 753 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
929 } 754 }
930 755
931 qWarning("RequestCustom needed: %d ms", t.elapsed() ); 756 qWarning("RequestCustom needed: %d ms", t.elapsed() );