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
@@ -50,2 +50,39 @@ using 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 {
@@ -125,3 +162,3 @@ bool ODateBookAccessBackend_SQL::load()
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
@@ -204,5 +241,5 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
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;
@@ -367,2 +404,29 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
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}