Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 105c106..41b714e 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -146,50 +146,48 @@ void ODateBookAccessBackend_SQL::initFields() | |||
146 | for ( it = m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 146 | for ( it = m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
147 | m_reverseFieldMap.insert( it.data(), it.key() ); | 147 | m_reverseFieldMap.insert( it.data(), it.key() ); |
148 | } | 148 | } |
149 | 149 | ||
150 | } | 150 | } |
151 | 151 | ||
152 | bool ODateBookAccessBackend_SQL::load() | 152 | bool ODateBookAccessBackend_SQL::load() |
153 | { | 153 | { |
154 | if (!m_driver->open() ) | 154 | if (!m_driver->open() ) |
155 | return false; | 155 | return false; |
156 | 156 | ||
157 | // Don't expect that the database exists. | 157 | // Don't expect that the database exists. |
158 | // It is save here to create the table, even if it | 158 | // It is save here to create the table, even if it |
159 | // do exist. ( Is that correct for all databases ?? ) | 159 | // do exist. ( Is that correct for all databases ?? ) |
160 | QString qu = "create table datebook( uid INTEGER PRIMARY KEY "; | 160 | QString qu = "create table datebook( uid INTEGER PRIMARY KEY "; |
161 | 161 | ||
162 | QMap<int, QString>::Iterator it; | 162 | QMap<int, QString>::Iterator it; |
163 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 163 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
164 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); | 164 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); |
165 | } | 165 | } |
166 | qu += " );"; | 166 | qu += " );"; |
167 | 167 | ||
168 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 168 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
169 | 169 | ||
170 | owarn << "command: " << qu << "" << oendl; | ||
171 | |||
172 | OSQLRawQuery raw( qu ); | 170 | OSQLRawQuery raw( qu ); |
173 | OSQLResult res = m_driver->query( &raw ); | 171 | OSQLResult res = m_driver->query( &raw ); |
174 | if ( res.state() != OSQLResult::Success ) | 172 | if ( res.state() != OSQLResult::Success ) |
175 | return false; | 173 | return false; |
176 | 174 | ||
177 | update(); | 175 | update(); |
178 | 176 | ||
179 | return true; | 177 | return true; |
180 | } | 178 | } |
181 | 179 | ||
182 | void ODateBookAccessBackend_SQL::update() | 180 | void ODateBookAccessBackend_SQL::update() |
183 | { | 181 | { |
184 | 182 | ||
185 | QString qu = "select uid from datebook"; | 183 | QString qu = "select uid from datebook"; |
186 | OSQLRawQuery raw( qu ); | 184 | OSQLRawQuery raw( qu ); |
187 | OSQLResult res = m_driver->query( &raw ); | 185 | OSQLResult res = m_driver->query( &raw ); |
188 | if ( res.state() != OSQLResult::Success ){ | 186 | if ( res.state() != OSQLResult::Success ){ |
189 | // m_uids.clear(); | 187 | // m_uids.clear(); |
190 | return; | 188 | return; |
191 | } | 189 | } |
192 | 190 | ||
193 | m_uids = extractUids( res ); | 191 | m_uids = extractUids( res ); |
194 | 192 | ||
195 | } | 193 | } |
@@ -267,193 +265,184 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) | |||
267 | if ( !eventMap[it.key()].isEmpty() ) | 265 | if ( !eventMap[it.key()].isEmpty() ) |
268 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); | 266 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); |
269 | else | 267 | else |
270 | qu += QString( ",\"\"" ); | 268 | qu += QString( ",\"\"" ); |
271 | } | 269 | } |
272 | qu += " );"; | 270 | qu += " );"; |
273 | 271 | ||
274 | // Add custom entries | 272 | // Add custom entries |
275 | int id = 0; | 273 | int id = 0; |
276 | QMap<QString, QString> customMap = ev.toExtraMap(); | 274 | QMap<QString, QString> customMap = ev.toExtraMap(); |
277 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 275 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
278 | it != customMap.end(); ++it ){ | 276 | it != customMap.end(); ++it ){ |
279 | qu += "insert into custom_data VALUES(" | 277 | qu += "insert into custom_data VALUES(" |
280 | + QString::number( ev.uid() ) | 278 | + QString::number( ev.uid() ) |
281 | + "," | 279 | + "," |
282 | + QString::number( id++ ) | 280 | + QString::number( id++ ) |
283 | + ",'" | 281 | + ",'" |
284 | + it.key() //.latin1() | 282 | + it.key() //.latin1() |
285 | + "'," | 283 | + "'," |
286 | + "0" // Priority for future enhancements | 284 | + "0" // Priority for future enhancements |
287 | + ",'" | 285 | + ",'" |
288 | + it.data() //.latin1() | 286 | + it.data() //.latin1() |
289 | + "');"; | 287 | + "');"; |
290 | } | 288 | } |
291 | owarn << "add " << qu << "" << oendl; | ||
292 | 289 | ||
293 | OSQLRawQuery raw( qu ); | 290 | OSQLRawQuery raw( qu ); |
294 | OSQLResult res = m_driver->query( &raw ); | 291 | OSQLResult res = m_driver->query( &raw ); |
295 | if ( res.state() != OSQLResult::Success ){ | 292 | if ( res.state() != OSQLResult::Success ){ |
296 | return false; | 293 | return false; |
297 | } | 294 | } |
298 | 295 | ||
299 | // Update list of uid's | 296 | // Update list of uid's |
300 | update(); | 297 | update(); |
301 | 298 | ||
302 | return true; | 299 | return true; |
303 | } | 300 | } |
304 | 301 | ||
305 | // FIXME: Speed up update of uid's.. | 302 | // FIXME: Speed up update of uid's.. |
306 | bool ODateBookAccessBackend_SQL::remove( int uid ) | 303 | bool ODateBookAccessBackend_SQL::remove( int uid ) |
307 | { | 304 | { |
308 | QString qu = "DELETE from datebook where uid = " | 305 | QString qu = "DELETE from datebook where uid = " |
309 | + QString::number( uid ) + ";"; | 306 | + QString::number( uid ) + ";"; |
310 | qu += "DELETE from custom_data where uid = " | 307 | qu += "DELETE from custom_data where uid = " |
311 | + QString::number( uid ) + ";"; | 308 | + QString::number( uid ) + ";"; |
312 | 309 | ||
313 | OSQLRawQuery raw( qu ); | 310 | OSQLRawQuery raw( qu ); |
314 | OSQLResult res = m_driver->query( &raw ); | 311 | OSQLResult res = m_driver->query( &raw ); |
315 | if ( res.state() != OSQLResult::Success ){ | 312 | if ( res.state() != OSQLResult::Success ){ |
316 | return false; | 313 | return false; |
317 | } | 314 | } |
318 | 315 | ||
319 | // Update list of uid's | 316 | // Update list of uid's |
320 | update(); | 317 | update(); |
321 | 318 | ||
322 | return true; | 319 | return true; |
323 | } | 320 | } |
324 | 321 | ||
325 | bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) | 322 | bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) |
326 | { | 323 | { |
327 | remove( ev.uid() ); | 324 | remove( ev.uid() ); |
328 | return add( ev ); | 325 | return add( ev ); |
329 | } | 326 | } |
330 | 327 | ||
331 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const | ||
332 | { | ||
333 | return allRecords(); | ||
334 | } | ||
335 | 328 | ||
336 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const | 329 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const |
337 | { | 330 | { |
338 | QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; | 331 | QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; |
339 | OSQLRawQuery raw( qu ); | 332 | OSQLRawQuery raw( qu ); |
340 | OSQLResult res = m_driver->query( &raw ); | 333 | OSQLResult res = m_driver->query( &raw ); |
341 | if ( res.state() != OSQLResult::Success ){ | 334 | if ( res.state() != OSQLResult::Success ){ |
342 | QArray<int> nix; | 335 | QArray<int> nix; |
343 | return nix; | 336 | return nix; |
344 | } | 337 | } |
345 | 338 | ||
346 | return extractUids( res ); | 339 | return extractUids( res ); |
347 | } | 340 | } |
348 | 341 | ||
349 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const | 342 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const |
350 | { | 343 | { |
351 | QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; | 344 | QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; |
352 | OSQLRawQuery raw( qu ); | 345 | OSQLRawQuery raw( qu ); |
353 | OSQLResult res = m_driver->query( &raw ); | 346 | OSQLResult res = m_driver->query( &raw ); |
354 | if ( res.state() != OSQLResult::Success ){ | 347 | if ( res.state() != OSQLResult::Success ){ |
355 | QArray<int> nix; | 348 | QArray<int> nix; |
356 | return nix; | 349 | return nix; |
357 | } | 350 | } |
358 | 351 | ||
359 | return extractUids( res ); | 352 | return extractUids( res ); |
360 | } | 353 | } |
361 | 354 | ||
362 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() | 355 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const |
363 | { | 356 | { |
364 | QArray<int> nonRepUids = nonRepeats(); | 357 | QArray<int> nonRepUids = nonRepeats(); |
365 | OPimEvent::ValueList list; | 358 | OPimEvent::ValueList list; |
366 | 359 | ||
367 | for (uint i = 0; i < nonRepUids.count(); ++i ){ | 360 | for (uint i = 0; i < nonRepUids.count(); ++i ){ |
368 | list.append( find( nonRepUids[i] ) ); | 361 | list.append( find( nonRepUids[i] ) ); |
369 | } | 362 | } |
370 | 363 | ||
371 | return list; | 364 | return list; |
372 | 365 | ||
373 | } | 366 | } |
374 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() | 367 | OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const |
375 | { | 368 | { |
376 | QArray<int> rawRepUids = rawRepeats(); | 369 | QArray<int> rawRepUids = rawRepeats(); |
377 | OPimEvent::ValueList list; | 370 | OPimEvent::ValueList list; |
378 | 371 | ||
379 | for (uint i = 0; i < rawRepUids.count(); ++i ){ | 372 | for (uint i = 0; i < rawRepUids.count(); ++i ){ |
380 | list.append( find( rawRepUids[i] ) ); | 373 | list.append( find( rawRepUids[i] ) ); |
381 | } | 374 | } |
382 | 375 | ||
383 | return list; | 376 | return list; |
384 | } | 377 | } |
385 | 378 | ||
386 | 379 | ||
387 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 380 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
388 | { | 381 | { |
389 | 382 | ||
390 | QString qu = "SELECT uid FROM datebook WHERE ("; | 383 | QString qu = "SELECT uid FROM datebook WHERE ("; |
391 | 384 | ||
392 | // Do it make sense to search other fields, too ? | 385 | // Do it make sense to search other fields, too ? |
393 | qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; | 386 | qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; |
394 | qu += " rlike(\""+ r.pattern() + "\", Note )"; | 387 | qu += " rlike(\""+ r.pattern() + "\", Note )"; |
395 | 388 | ||
396 | qu += " )"; | 389 | qu += " )"; |
397 | 390 | ||
398 | odebug << "query: " << qu << "" << oendl; | 391 | odebug << "query: " << qu << "" << oendl; |
399 | 392 | ||
400 | OSQLRawQuery raw( qu ); | 393 | OSQLRawQuery raw( qu ); |
401 | OSQLResult res = m_driver->query( &raw ); | 394 | OSQLResult res = m_driver->query( &raw ); |
402 | 395 | ||
403 | return extractUids( res ); | 396 | return extractUids( res ); |
404 | 397 | ||
405 | 398 | ||
406 | 399 | ||
407 | } | 400 | } |
408 | 401 | ||
409 | /* ===== Private Functions ========================================== */ | 402 | /* ===== Private Functions ========================================== */ |
410 | 403 | ||
411 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const | 404 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const |
412 | { | 405 | { |
413 | owarn << "extractUids" << oendl; | ||
414 | QTime t; | 406 | QTime t; |
415 | t.start(); | 407 | t.start(); |
416 | OSQLResultItem::ValueList list = res.results(); | 408 | OSQLResultItem::ValueList list = res.results(); |
417 | OSQLResultItem::ValueList::Iterator it; | 409 | OSQLResultItem::ValueList::Iterator it; |
418 | QArray<int> ints(list.count() ); | 410 | QArray<int> ints(list.count() ); |
419 | owarn << " count = " << list.count() << "" << oendl; | ||
420 | 411 | ||
421 | int i = 0; | 412 | int i = 0; |
422 | for (it = list.begin(); it != list.end(); ++it ) { | 413 | for (it = list.begin(); it != list.end(); ++it ) { |
423 | ints[i] = (*it).data("uid").toInt(); | 414 | ints[i] = (*it).data("uid").toInt(); |
424 | i++; | 415 | i++; |
425 | } | 416 | } |
426 | owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; | ||
427 | 417 | ||
428 | return ints; | 418 | return ints; |
429 | 419 | ||
430 | } | 420 | } |
431 | 421 | ||
432 | QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const | 422 | QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const |
433 | { | 423 | { |
434 | QTime t; | 424 | QTime t; |
435 | t.start(); | 425 | t.start(); |
436 | 426 | ||
437 | QMap<QString, QString> customMap; | 427 | QMap<QString, QString> customMap; |
438 | 428 | ||
439 | FindCustomQuery query( uid ); | 429 | FindCustomQuery query( uid ); |
440 | OSQLResult res_custom = m_driver->query( &query ); | 430 | OSQLResult res_custom = m_driver->query( &query ); |
441 | 431 | ||
442 | if ( res_custom.state() == OSQLResult::Failure ) { | 432 | if ( res_custom.state() == OSQLResult::Failure ) { |
443 | owarn << "OSQLResult::Failure in find query !!" << oendl; | ||
444 | QMap<QString, QString> empty; | 433 | QMap<QString, QString> empty; |
445 | return empty; | 434 | return empty; |
446 | } | 435 | } |
447 | 436 | ||
448 | OSQLResultItem::ValueList list = res_custom.results(); | 437 | OSQLResultItem::ValueList list = res_custom.results(); |
449 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 438 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
450 | for ( ; it != list.end(); ++it ) { | 439 | for ( ; it != list.end(); ++it ) { |
451 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 440 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
452 | } | 441 | } |
453 | 442 | ||
454 | odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; | 443 | odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; |
455 | return customMap; | 444 | return customMap; |
456 | } | 445 | } |
457 | 446 | ||
458 | 447 | ||
459 | } | 448 | } |