author | eilers <eilers> | 2004-04-05 07:03:09 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-04-05 07:03:09 (UTC) |
commit | e6e31e93aa55bb967a044fe3660201000a6e59b0 (patch) (unidiff) | |
tree | 1071fa4b22698fd56dde283bbb7375478b7e1ddf /libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |
parent | 6be3d148fc1d610ebfa193012657b3b77d9368e3 (diff) | |
download | opie-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 (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 70 |
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 | |||
@@ -48,6 +48,43 @@ | |||
48 | 48 | ||
49 | using namespace Opie::DB; | 49 | using namespace Opie::DB; |
50 | 50 | ||
51 | namespace { | ||
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 | |||
51 | namespace Opie { | 88 | namespace Opie { |
52 | 89 | ||
53 | 90 | ||
@@ -123,7 +160,7 @@ bool ODateBookAccessBackend_SQL::load() | |||
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 | ||
@@ -202,9 +239,9 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | |||
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 | ||
@@ -365,4 +402,31 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const | |||
365 | 402 | ||
366 | } | 403 | } |
367 | 404 | ||
405 | QMap<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 | } |