summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp77
1 files changed, 35 insertions, 42 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index a5be4c8..d0c8052 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -1,108 +1,97 @@
1/* 1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29/*
2 * SQL Backend for the OPIE-Contact Database. 30 * SQL Backend for the OPIE-Contact Database.
3 *
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 *
6 * =====================================================================
7 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 * =====================================================================
12 * =====================================================================
13 * Version: $Id$
14 * =====================================================================
15 * History:
16 * $Log$
17 * Revision 1.4 2003/12/22 10:19:26 eilers
18 * Finishing implementation of sql-backend for datebook. But I have to
19 * port the PIM datebook application to use it, before I could debug the
20 * whole stuff.
21 * Thus, PIM-Database backend is finished, but highly experimental. And some
22 * parts are still generic. For instance, the "queryByExample()" methods are
23 * not (or not fully) implemented. Todo: custom-entries not stored.
24 * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
25 * expression search in the database, which is not supported by sqlite !
26 * Therefore we need either an extended sqlite or a workaround which would
27 * be very slow and memory consuming..
28 *
29 * Revision 1.3 2003/12/08 15:18:10 eilers
30 * Committing unfinished sql implementation before merging to libopie2 starts..
31 *
32 * Revision 1.2 2003/09/29 07:44:26 eilers
33 * Improvement of PIM-SQL Databases, but search queries are still limited.
34 * Addressbook: Changed table layout. Now, we just need 1/3 of disk-space.
35 * Todo: Started to add new attributes. Some type conversions missing.
36 *
37 * Revision 1.1 2003/09/22 14:31:16 eilers
38 * Added first experimental incarnation of sql-backend for addressbook.
39 * Some modifications to be able to compile the todo sql-backend.
40 * A lot of changes fill follow...
41 *
42 */ 31 */
43 32
44#include "ocontactaccessbackend_sql.h" 33#include "ocontactaccessbackend_sql.h"
45 34
46#include <qarray.h> 35#include <qarray.h>
47#include <qdatetime.h> 36#include <qdatetime.h>
48#include <qstringlist.h> 37#include <qstringlist.h>
49 38
50#include <qpe/global.h> 39#include <qpe/global.h>
51#include <qpe/recordfields.h> 40#include <qpe/recordfields.h>
52 41
53#include <opie/ocontactfields.h> 42#include <opie2/ocontactfields.h>
54#include <opie/oconversion.h> 43#include <opie2/oconversion.h>
55#include <opie2/osqldriver.h> 44#include <opie2/osqldriver.h>
56#include <opie2/osqlresult.h> 45#include <opie2/osqlresult.h>
57#include <opie2/osqlmanager.h> 46#include <opie2/osqlmanager.h>
58#include <opie2/osqlquery.h> 47#include <opie2/osqlquery.h>
59 48
60 49
61 50
62 51
63// If defined, we use a horizontal table ( uid, attr1, attr2, attr3, ..., attrn ) instead 52// If defined, we use a horizontal table ( uid, attr1, attr2, attr3, ..., attrn ) instead
64// vertical like "uid, type, value". 53// vertical like "uid, type, value".
65// DON'T DEACTIVATE THIS DEFINE IN PRODUCTIVE ENVIRONMENTS !! 54// DON'T DEACTIVATE THIS DEFINE IN PRODUCTIVE ENVIRONMENTS !!
66#define __STORE_HORIZONTAL_ 55#define __STORE_HORIZONTAL_
67 56
68// Distinct loading is not very fast. If I expect that every person has just 57// Distinct loading is not very fast. If I expect that every person has just
69// one (and always one) 'Last Name', I can request all uid's for existing lastnames, 58// one (and always one) 'Last Name', I can request all uid's for existing lastnames,
70// which is faster.. 59// which is faster..
71// But this may not be true for all entries, like company contacts.. 60// But this may not be true for all entries, like company contacts..
72// The current AddressBook application handles this problem, but other may not.. (eilers) 61// The current AddressBook application handles this problem, but other may not.. (eilers)
73#define __USE_SUPERFAST_LOADQUERY 62#define __USE_SUPERFAST_LOADQUERY
74 63
75 64
76/* 65/*
77 * Implementation of used query types 66 * Implementation of used query types
78 * CREATE query 67 * CREATE query
79 * LOAD query 68 * LOAD query
80 * INSERT 69 * INSERT
81 * REMOVE 70 * REMOVE
82 * CLEAR 71 * CLEAR
83 */ 72 */
84namespace { 73namespace Opie {
85 /** 74 /**
86 * CreateQuery for the Todolist Table 75 * CreateQuery for the Todolist Table
87 */ 76 */
88 class CreateQuery : public OSQLQuery { 77 class CreateQuery : public OSQLQuery {
89 public: 78 public:
90 CreateQuery(); 79 CreateQuery();
91 ~CreateQuery(); 80 ~CreateQuery();
92 QString query()const; 81 QString query()const;
93 }; 82 };
94 83
95 /** 84 /**
96 * Clears (delete) a Table 85 * Clears (delete) a Table
97 */ 86 */
98 class ClearQuery : public OSQLQuery { 87 class ClearQuery : public OSQLQuery {
99 public: 88 public:
100 ClearQuery(); 89 ClearQuery();
101 ~ClearQuery(); 90 ~ClearQuery();
102 QString query()const; 91 QString query()const;
103 92
104 }; 93 };
105 94
106 95
107 /** 96 /**
108 * LoadQuery 97 * LoadQuery
@@ -447,48 +436,50 @@ namespace {
447 436
448 FindCustomQuery::FindCustomQuery(int uid) 437 FindCustomQuery::FindCustomQuery(int uid)
449 : OSQLQuery(), m_uid( uid ) { 438 : OSQLQuery(), m_uid( uid ) {
450 } 439 }
451 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 440 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
452 : OSQLQuery(), m_uids( ints ){ 441 : OSQLQuery(), m_uids( ints ){
453 } 442 }
454 FindCustomQuery::~FindCustomQuery() { 443 FindCustomQuery::~FindCustomQuery() {
455 } 444 }
456 QString FindCustomQuery::query()const{ 445 QString FindCustomQuery::query()const{
457 // if ( m_uids.count() == 0 ) 446 // if ( m_uids.count() == 0 )
458 return single(); 447 return single();
459 } 448 }
460 QString FindCustomQuery::single()const{ 449 QString FindCustomQuery::single()const{
461 QString qu = "select uid, type, value from custom_data where uid = "; 450 QString qu = "select uid, type, value from custom_data where uid = ";
462 qu += QString::number(m_uid); 451 qu += QString::number(m_uid);
463 return qu; 452 return qu;
464 } 453 }
465 454
466}; 455};
467 456
468 457
469/* --------------------------------------------------------------------------- */ 458/* --------------------------------------------------------------------------- */
470 459
460namespace Opie {
461
471OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, 462OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */,
472 const QString& filename ): 463 const QString& filename ):
473 OContactAccessBackend(), m_changed(false), m_driver( NULL ) 464 OContactAccessBackend(), m_changed(false), m_driver( NULL )
474{ 465{
475 qWarning("C'tor OContactAccessBackend_SQL starts"); 466 qWarning("C'tor OContactAccessBackend_SQL starts");
476 QTime t; 467 QTime t;
477 t.start(); 468 t.start();
478 469
479 /* Expecting to access the default filename if nothing else is set */ 470 /* Expecting to access the default filename if nothing else is set */
480 if ( filename.isEmpty() ){ 471 if ( filename.isEmpty() ){
481 m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); 472 m_fileName = Global::applicationFileName( "addressbook","addressbook.db" );
482 } else 473 } else
483 m_fileName = filename; 474 m_fileName = filename;
484 475
485 // Get the standart sql-driver from the OSQLManager.. 476 // Get the standart sql-driver from the OSQLManager..
486 OSQLManager man; 477 OSQLManager man;
487 m_driver = man.standard(); 478 m_driver = man.standard();
488 m_driver->setUrl( m_fileName ); 479 m_driver->setUrl( m_fileName );
489 480
490 load(); 481 load();
491 482
492 qWarning("C'tor OContactAccessBackend_SQL ends: %d ms", t.elapsed() ); 483 qWarning("C'tor OContactAccessBackend_SQL ends: %d ms", t.elapsed() );
493} 484}
494 485
@@ -919,24 +910,26 @@ QMap<QString, QString> OContactAccessBackend_SQL::requestCustom( int uid ) cons
919{ 910{
920 QTime t; 911 QTime t;
921 t.start(); 912 t.start();
922 913
923 QMap<QString, QString> customMap; 914 QMap<QString, QString> customMap;
924 915
925 FindCustomQuery query( uid ); 916 FindCustomQuery query( uid );
926 OSQLResult res_custom = m_driver->query( &query ); 917 OSQLResult res_custom = m_driver->query( &query );
927 918
928 if ( res_custom.state() == OSQLResult::Failure ) { 919 if ( res_custom.state() == OSQLResult::Failure ) {
929 qWarning("OSQLResult::Failure in find query !!"); 920 qWarning("OSQLResult::Failure in find query !!");
930 QMap<QString, QString> empty; 921 QMap<QString, QString> empty;
931 return empty; 922 return empty;
932 } 923 }
933 924
934 OSQLResultItem::ValueList list = res_custom.results(); 925 OSQLResultItem::ValueList list = res_custom.results();
935 OSQLResultItem::ValueList::Iterator it = list.begin(); 926 OSQLResultItem::ValueList::Iterator it = list.begin();
936 for ( ; it != list.end(); ++it ) { 927 for ( ; it != list.end(); ++it ) {
937 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 928 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
938 } 929 }
939 930
940 qWarning("RequestCustom needed: %d ms", t.elapsed() ); 931 qWarning("RequestCustom needed: %d ms", t.elapsed() );
941 return customMap; 932 return customMap;
942} 933}
934
935}