summaryrefslogtreecommitdiff
path: root/libopie2
authoreilers <eilers>2004-05-04 18:49:04 (UTC)
committer eilers <eilers>2004-05-04 18:49:04 (UTC)
commitf1a3fc696787ae946464469b3f252aa425dbe51b (patch) (unidiff)
treef06602aae8935b3a0d186c921cbdde61c045bcf1 /libopie2
parent04a7f91591987c01d312fbcaf6554ec6d728554d (diff)
downloadopie-f1a3fc696787ae946464469b3f252aa425dbe51b.zip
opie-f1a3fc696787ae946464469b3f252aa425dbe51b.tar.gz
opie-f1a3fc696787ae946464469b3f252aa425dbe51b.tar.bz2
Minor modification in debug output
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index 495a8dd..6c32b40 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -1,452 +1,454 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 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-Calender Database. 30 * SQL Backend for the OPIE-Calender Database.
31 * 31 *
32 */ 32 */
33 33
34#include <stdio.h> 34#include <stdio.h>
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37#include <qarray.h> 37#include <qarray.h>
38#include <qstringlist.h> 38#include <qstringlist.h>
39 39
40#include <qpe/global.h> 40#include <qpe/global.h>
41 41
42#include <opie2/osqldriver.h> 42#include <opie2/osqldriver.h>
43#include <opie2/osqlmanager.h> 43#include <opie2/osqlmanager.h>
44#include <opie2/osqlquery.h> 44#include <opie2/osqlquery.h>
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 { 51namespace {
52 /** 52 /**
53 * a find query for custom elements 53 * a find query for custom elements
54 */ 54 */
55 class FindCustomQuery : public OSQLQuery { 55 class FindCustomQuery : public OSQLQuery {
56 public: 56 public:
57 FindCustomQuery(int uid); 57 FindCustomQuery(int uid);
58 FindCustomQuery(const QArray<int>& ); 58 FindCustomQuery(const QArray<int>& );
59 ~FindCustomQuery(); 59 ~FindCustomQuery();
60 QString query()const; 60 QString query()const;
61 private: 61 private:
62 QString single()const; 62 QString single()const;
63 QString multi()const; 63 QString multi()const;
64 QArray<int> m_uids; 64 QArray<int> m_uids;
65 int m_uid; 65 int m_uid;
66 }; 66 };
67 67
68 FindCustomQuery::FindCustomQuery(int uid) 68 FindCustomQuery::FindCustomQuery(int uid)
69 : OSQLQuery(), m_uid( uid ) { 69 : OSQLQuery(), m_uid( uid ) {
70 } 70 }
71 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 71 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
72 : OSQLQuery(), m_uids( ints ){ 72 : OSQLQuery(), m_uids( ints ){
73 } 73 }
74 FindCustomQuery::~FindCustomQuery() { 74 FindCustomQuery::~FindCustomQuery() {
75 } 75 }
76 QString FindCustomQuery::query()const{ 76 QString FindCustomQuery::query()const{
77 // if ( m_uids.count() == 0 ) 77 // if ( m_uids.count() == 0 )
78 return single(); 78 return single();
79 } 79 }
80 QString FindCustomQuery::single()const{ 80 QString FindCustomQuery::single()const{
81 QString qu = "select uid, type, value from custom_data where uid = "; 81 QString qu = "select uid, type, value from custom_data where uid = ";
82 qu += QString::number(m_uid); 82 qu += QString::number(m_uid);
83 return qu; 83 return qu;
84 } 84 }
85} 85}
86 86
87 87
88namespace Opie { 88namespace Opie {
89 89
90 90
91ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 91ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
92 const QString& fileName ) 92 const QString& fileName )
93 : ODateBookAccessBackend(), m_driver( NULL ) 93 : ODateBookAccessBackend(), m_driver( NULL )
94{ 94{
95 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; 95 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName;
96 96
97 // Get the standart sql-driver from the OSQLManager.. 97 // Get the standart sql-driver from the OSQLManager..
98 OSQLManager man; 98 OSQLManager man;
99 m_driver = man.standard(); 99 m_driver = man.standard();
100 m_driver->setUrl( m_fileName ); 100 m_driver->setUrl( m_fileName );
101 101
102 initFields(); 102 initFields();
103 103
104 load(); 104 load();
105} 105}
106 106
107ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { 107ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() {
108 if( m_driver ) 108 if( m_driver )
109 delete m_driver; 109 delete m_driver;
110} 110}
111 111
112void ODateBookAccessBackend_SQL::initFields() 112void ODateBookAccessBackend_SQL::initFields()
113{ 113{
114 114
115 // This map contains the translation of the fieldtype id's to 115 // This map contains the translation of the fieldtype id's to
116 // the names of the table columns 116 // the names of the table columns
117 m_fieldMap.insert( OPimEvent::FUid, "uid" ); 117 m_fieldMap.insert( OPimEvent::FUid, "uid" );
118 m_fieldMap.insert( OPimEvent::FCategories, "Categories" ); 118 m_fieldMap.insert( OPimEvent::FCategories, "Categories" );
119 m_fieldMap.insert( OPimEvent::FDescription, "Description" ); 119 m_fieldMap.insert( OPimEvent::FDescription, "Description" );
120 m_fieldMap.insert( OPimEvent::FLocation, "Location" ); 120 m_fieldMap.insert( OPimEvent::FLocation, "Location" );
121 m_fieldMap.insert( OPimEvent::FType, "Type" ); 121 m_fieldMap.insert( OPimEvent::FType, "Type" );
122 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" ); 122 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" );
123 m_fieldMap.insert( OPimEvent::FSound, "Sound" ); 123 m_fieldMap.insert( OPimEvent::FSound, "Sound" );
124 m_fieldMap.insert( OPimEvent::FRType, "RType" ); 124 m_fieldMap.insert( OPimEvent::FRType, "RType" );
125 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" ); 125 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" );
126 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" ); 126 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" );
127 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" ); 127 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" );
128 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" ); 128 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" );
129 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" ); 129 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" );
130 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" ); 130 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" );
131 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" ); 131 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" );
132 m_fieldMap.insert( OPimEvent::FStart, "Start" ); 132 m_fieldMap.insert( OPimEvent::FStart, "Start" );
133 m_fieldMap.insert( OPimEvent::FEnd, "End" ); 133 m_fieldMap.insert( OPimEvent::FEnd, "End" );
134 m_fieldMap.insert( OPimEvent::FNote, "Note" ); 134 m_fieldMap.insert( OPimEvent::FNote, "Note" );
135 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" ); 135 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" );
136 m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" ); 136 m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" );
137 m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" ); 137 m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" );
138 138
139 // Create a map that maps the column name to the id 139 // Create a map that maps the column name to the id
140 QMapConstIterator<int, QString> it; 140 QMapConstIterator<int, QString> it;
141 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 141 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
142 m_reverseFieldMap.insert( it.data(), it.key() ); 142 m_reverseFieldMap.insert( it.data(), it.key() );
143 } 143 }
144 144
145} 145}
146 146
147bool ODateBookAccessBackend_SQL::load() 147bool ODateBookAccessBackend_SQL::load()
148{ 148{
149 if (!m_driver->open() ) 149 if (!m_driver->open() )
150 return false; 150 return false;
151 151
152 // Don't expect that the database exists. 152 // Don't expect that the database exists.
153 // It is save here to create the table, even if it 153 // It is save here to create the table, even if it
154 // do exist. ( Is that correct for all databases ?? ) 154 // do exist. ( Is that correct for all databases ?? )
155 QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; 155 QStringqu = "create table datebook( uid INTEGER PRIMARY KEY ";
156 156
157 QMap<int, QString>::Iterator it; 157 QMap<int, QString>::Iterator it;
158 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 158 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
159 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); 159 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() );
160 } 160 }
161 qu += " );"; 161 qu += " );";
162 162
163 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), 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) );";
164 164
165 qWarning( "command: %s", qu.latin1() ); 165 qWarning( "command: %s", qu.latin1() );
166 166
167 OSQLRawQuery raw( qu ); 167 OSQLRawQuery raw( qu );
168 OSQLResult res = m_driver->query( &raw ); 168 OSQLResult res = m_driver->query( &raw );
169 if ( res.state() != OSQLResult::Success ) 169 if ( res.state() != OSQLResult::Success )
170 return false; 170 return false;
171 171
172 update(); 172 update();
173 173
174 return true; 174 return true;
175} 175}
176 176
177void ODateBookAccessBackend_SQL::update() 177void ODateBookAccessBackend_SQL::update()
178{ 178{
179 179
180 QString qu = "select uid from datebook"; 180 QString qu = "select uid from datebook";
181 OSQLRawQuery raw( qu ); 181 OSQLRawQuery raw( qu );
182 OSQLResult res = m_driver->query( &raw ); 182 OSQLResult res = m_driver->query( &raw );
183 if ( res.state() != OSQLResult::Success ){ 183 if ( res.state() != OSQLResult::Success ){
184 // m_uids.clear(); 184 // m_uids.clear();
185 return; 185 return;
186 } 186 }
187 187
188 m_uids = extractUids( res ); 188 m_uids = extractUids( res );
189 189
190} 190}
191 191
192bool ODateBookAccessBackend_SQL::reload() 192bool ODateBookAccessBackend_SQL::reload()
193{ 193{
194 return load(); 194 return load();
195} 195}
196 196
197bool ODateBookAccessBackend_SQL::save() 197bool ODateBookAccessBackend_SQL::save()
198{ 198{
199 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 199 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
200} 200}
201 201
202QArray<int> ODateBookAccessBackend_SQL::allRecords()const 202QArray<int> ODateBookAccessBackend_SQL::allRecords()const
203{ 203{
204 return m_uids; 204 return m_uids;
205} 205}
206 206
207QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) { 207QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) {
208 return QArray<int>(); 208 return QArray<int>();
209} 209}
210 210
211void ODateBookAccessBackend_SQL::clear() 211void ODateBookAccessBackend_SQL::clear()
212{ 212{
213 QString qu = "drop table datebook;"; 213 QString qu = "drop table datebook;";
214 qu += "drop table custom_data;"; 214 qu += "drop table custom_data;";
215 215
216 OSQLRawQuery raw( qu ); 216 OSQLRawQuery raw( qu );
217 OSQLResult res = m_driver->query( &raw ); 217 OSQLResult res = m_driver->query( &raw );
218 218
219 reload(); 219 reload();
220} 220}
221 221
222 222
223OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ 223OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
224 qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid ); 224 qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid );
225 225
226 QString qu = "select *"; 226 QString qu = "select *";
227 qu += "from datebook where uid = " + QString::number(uid); 227 qu += "from datebook where uid = " + QString::number(uid);
228 228
229 qDebug( "Query: %s", qu.latin1() );
230
229 OSQLRawQuery raw( qu ); 231 OSQLRawQuery raw( qu );
230 OSQLResult res = m_driver->query( &raw ); 232 OSQLResult res = m_driver->query( &raw );
231 233
232 OSQLResultItem resItem = res.first(); 234 OSQLResultItem resItem = res.first();
233 235
234 // Create Map for date event and insert UID 236 // Create Map for date event and insert UID
235 QMap<int,QString> dateEventMap; 237 QMap<int,QString> dateEventMap;
236 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); 238 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) );
237 239
238 // Now insert the data out of the columns into the map. 240 // Now insert the data out of the columns into the map.
239 QMapConstIterator<int, QString> it; 241 QMapConstIterator<int, QString> it;
240 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 242 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
241 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); 243 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
242 } 244 }
243 245
244 // Last step: Put map into date event, add custom map and return it 246 // Last step: Put map into date event, add custom map and return it
245 OPimEvent retDate( dateEventMap ); 247 OPimEvent retDate( dateEventMap );
246 retDate.setExtraMap( requestCustom( uid ) ); 248 retDate.setExtraMap( requestCustom( uid ) );
247 249
248 qDebug( "ODateBookAccessBackend_SQL::find() end", uid ); 250 qDebug( "ODateBookAccessBackend_SQL::find( %d ) end", uid );
249 return retDate; 251 return retDate;
250} 252}
251 253
252// FIXME: Speed up update of uid's.. 254// FIXME: Speed up update of uid's..
253bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) 255bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
254{ 256{
255 QMap<int,QString> eventMap = ev.toMap(); 257 QMap<int,QString> eventMap = ev.toMap();
256 258
257 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); 259 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
258 QMap<int, QString>::Iterator it; 260 QMap<int, QString>::Iterator it;
259 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 261 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
260 if ( !eventMap[it.key()].isEmpty() ) 262 if ( !eventMap[it.key()].isEmpty() )
261 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); 263 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
262 else 264 else
263 qu += QString( ",\"\"" ); 265 qu += QString( ",\"\"" );
264 } 266 }
265 qu += " );"; 267 qu += " );";
266 268
267 // Add custom entries 269 // Add custom entries
268 int id = 0; 270 int id = 0;
269 QMap<QString, QString> customMap = ev.toExtraMap(); 271 QMap<QString, QString> customMap = ev.toExtraMap();
270 for( QMap<QString, QString>::Iterator it = customMap.begin(); 272 for( QMap<QString, QString>::Iterator it = customMap.begin();
271 it != customMap.end(); ++it ){ 273 it != customMap.end(); ++it ){
272 qu += "insert into custom_data VALUES(" 274 qu += "insert into custom_data VALUES("
273 + QString::number( ev.uid() ) 275 + QString::number( ev.uid() )
274 + "," 276 + ","
275 + QString::number( id++ ) 277 + QString::number( id++ )
276 + ",'" 278 + ",'"
277 + it.key() //.latin1() 279 + it.key() //.latin1()
278 + "'," 280 + "',"
279 + "0" // Priority for future enhancements 281 + "0" // Priority for future enhancements
280 + ",'" 282 + ",'"
281 + it.data() //.latin1() 283 + it.data() //.latin1()
282 + "');"; 284 + "');";
283 } 285 }
284 qWarning("add %s", qu.latin1() ); 286 qWarning("add %s", qu.latin1() );
285 287
286 OSQLRawQuery raw( qu ); 288 OSQLRawQuery raw( qu );
287 OSQLResult res = m_driver->query( &raw ); 289 OSQLResult res = m_driver->query( &raw );
288 if ( res.state() != OSQLResult::Success ){ 290 if ( res.state() != OSQLResult::Success ){
289 return false; 291 return false;
290 } 292 }
291 293
292 // Update list of uid's 294 // Update list of uid's
293 update(); 295 update();
294 296
295 return true; 297 return true;
296} 298}
297 299
298// FIXME: Speed up update of uid's.. 300// FIXME: Speed up update of uid's..
299bool ODateBookAccessBackend_SQL::remove( int uid ) 301bool ODateBookAccessBackend_SQL::remove( int uid )
300{ 302{
301 QString qu = "DELETE from datebook where uid = " 303 QString qu = "DELETE from datebook where uid = "
302 + QString::number( uid ) + ";"; 304 + QString::number( uid ) + ";";
303 qu += "DELETE from custom_data where uid = " 305 qu += "DELETE from custom_data where uid = "
304 + QString::number( uid ) + ";"; 306 + QString::number( uid ) + ";";
305 307
306 OSQLRawQuery raw( qu ); 308 OSQLRawQuery raw( qu );
307 OSQLResult res = m_driver->query( &raw ); 309 OSQLResult res = m_driver->query( &raw );
308 if ( res.state() != OSQLResult::Success ){ 310 if ( res.state() != OSQLResult::Success ){
309 return false; 311 return false;
310 } 312 }
311 313
312 // Update list of uid's 314 // Update list of uid's
313 update(); 315 update();
314 316
315 return true; 317 return true;
316} 318}
317 319
318bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) 320bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
319{ 321{
320 remove( ev.uid() ); 322 remove( ev.uid() );
321 return add( ev ); 323 return add( ev );
322} 324}
323 325
324QArray<int> ODateBookAccessBackend_SQL::rawEvents()const 326QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
325{ 327{
326 return allRecords(); 328 return allRecords();
327} 329}
328 330
329QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 331QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
330{ 332{
331 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; 333 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
332 OSQLRawQuery raw( qu ); 334 OSQLRawQuery raw( qu );
333 OSQLResult res = m_driver->query( &raw ); 335 OSQLResult res = m_driver->query( &raw );
334 if ( res.state() != OSQLResult::Success ){ 336 if ( res.state() != OSQLResult::Success ){
335 QArray<int> nix; 337 QArray<int> nix;
336 return nix; 338 return nix;
337 } 339 }
338 340
339 return extractUids( res ); 341 return extractUids( res );
340} 342}
341 343
342QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const 344QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
343{ 345{
344 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; 346 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\"";
345 OSQLRawQuery raw( qu ); 347 OSQLRawQuery raw( qu );
346 OSQLResult res = m_driver->query( &raw ); 348 OSQLResult res = m_driver->query( &raw );
347 if ( res.state() != OSQLResult::Success ){ 349 if ( res.state() != OSQLResult::Success ){
348 QArray<int> nix; 350 QArray<int> nix;
349 return nix; 351 return nix;
350 } 352 }
351 353
352 return extractUids( res ); 354 return extractUids( res );
353} 355}
354 356
355OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() 357OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
356{ 358{
357 QArray<int> nonRepUids = nonRepeats(); 359 QArray<int> nonRepUids = nonRepeats();
358 OPimEvent::ValueList list; 360 OPimEvent::ValueList list;
359 361
360 for (uint i = 0; i < nonRepUids.count(); ++i ){ 362 for (uint i = 0; i < nonRepUids.count(); ++i ){
361 list.append( find( nonRepUids[i] ) ); 363 list.append( find( nonRepUids[i] ) );
362 } 364 }
363 365
364 return list; 366 return list;
365 367
366} 368}
367OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() 369OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
368{ 370{
369 QArray<int> rawRepUids = rawRepeats(); 371 QArray<int> rawRepUids = rawRepeats();
370 OPimEvent::ValueList list; 372 OPimEvent::ValueList list;
371 373
372 for (uint i = 0; i < rawRepUids.count(); ++i ){ 374 for (uint i = 0; i < rawRepUids.count(); ++i ){
373 list.append( find( rawRepUids[i] ) ); 375 list.append( find( rawRepUids[i] ) );
374 } 376 }
375 377
376 return list; 378 return list;
377} 379}
378 380
379 381
380QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 382QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
381{ 383{
382 384
383 QString qu = "SELECT uid FROM datebook WHERE ("; 385 QString qu = "SELECT uid FROM datebook WHERE (";
384 386
385 // Do it make sense to search other fields, too ? 387 // Do it make sense to search other fields, too ?
386 qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; 388 qu += " rlike(\""+ r.pattern() + "\", Location ) OR";
387 qu += " rlike(\""+ r.pattern() + "\", Note )"; 389 qu += " rlike(\""+ r.pattern() + "\", Note )";
388 390
389 qu += " )"; 391 qu += " )";
390 392
391 qDebug( "query: %s", qu.latin1() ); 393 qDebug( "query: %s", qu.latin1() );
392 394
393 OSQLRawQuery raw( qu ); 395 OSQLRawQuery raw( qu );
394 OSQLResult res = m_driver->query( &raw ); 396 OSQLResult res = m_driver->query( &raw );
395 397
396 return extractUids( res ); 398 return extractUids( res );
397 399
398 400
399 401
400} 402}
401 403
402/* ===== Private Functions ========================================== */ 404/* ===== Private Functions ========================================== */
403 405
404QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const 406QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
405{ 407{
406 qWarning("extractUids"); 408 qWarning("extractUids");
407 QTime t; 409 QTime t;
408 t.start(); 410 t.start();
409 OSQLResultItem::ValueList list = res.results(); 411 OSQLResultItem::ValueList list = res.results();
410 OSQLResultItem::ValueList::Iterator it; 412 OSQLResultItem::ValueList::Iterator it;
411 QArray<int> ints(list.count() ); 413 QArray<int> ints(list.count() );
412 qWarning(" count = %d", list.count() ); 414 qWarning(" count = %d", list.count() );
413 415
414 int i = 0; 416 int i = 0;
415 for (it = list.begin(); it != list.end(); ++it ) { 417 for (it = list.begin(); it != list.end(); ++it ) {
416 ints[i] = (*it).data("uid").toInt(); 418 ints[i] = (*it).data("uid").toInt();
417 i++; 419 i++;
418 } 420 }
419 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 421 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
420 422
421 return ints; 423 return ints;
422 424
423} 425}
424 426
425QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const 427QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
426{ 428{
427 QTime t; 429 QTime t;
428 t.start(); 430 t.start();
429 431
430 QMap<QString, QString> customMap; 432 QMap<QString, QString> customMap;
431 433
432 FindCustomQuery query( uid ); 434 FindCustomQuery query( uid );
433 OSQLResult res_custom = m_driver->query( &query ); 435 OSQLResult res_custom = m_driver->query( &query );
434 436
435 if ( res_custom.state() == OSQLResult::Failure ) { 437 if ( res_custom.state() == OSQLResult::Failure ) {
436 qWarning("OSQLResult::Failure in find query !!"); 438 qWarning("OSQLResult::Failure in find query !!");
437 QMap<QString, QString> empty; 439 QMap<QString, QString> empty;
438 return empty; 440 return empty;
439 } 441 }
440 442
441 OSQLResultItem::ValueList list = res_custom.results(); 443 OSQLResultItem::ValueList list = res_custom.results();
442 OSQLResultItem::ValueList::Iterator it = list.begin(); 444 OSQLResultItem::ValueList::Iterator it = list.begin();
443 for ( ; it != list.end(); ++it ) { 445 for ( ; it != list.end(); ++it ) {
444 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 446 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
445 } 447 }
446 448
447 qDebug("RequestCustom needed: %d ms", t.elapsed() ); 449 qDebug("RequestCustom needed: %d ms", t.elapsed() );
448 return customMap; 450 return customMap;
449} 451}
450 452
451 453
452} 454}