summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp70
1 files changed, 67 insertions, 3 deletions
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
@@ -45,12 +45,49 @@
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 )
@@ -120,13 +157,13 @@ bool ODateBookAccessBackend_SQL::load()
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 )
@@ -199,15 +236,15 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
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{
@@ -362,7 +399,34 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
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}