summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccesssql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 3764c7e..944f82a 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -1,63 +1,92 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
1 29
2#include <qdatetime.h> 30#include <qdatetime.h>
3 31
4#include <qpe/global.h> 32#include <qpe/global.h>
5 33
6#include <opie2/osqldriver.h> 34#include <opie2/osqldriver.h>
7#include <opie2/osqlresult.h> 35#include <opie2/osqlresult.h>
8#include <opie2/osqlmanager.h> 36#include <opie2/osqlmanager.h>
9#include <opie2/osqlquery.h> 37#include <opie2/osqlquery.h>
10 38
11#include "otodoaccesssql.h" 39#include <opie2/otodoaccesssql.h>
12#include "opimstate.h" 40#include <opie2/opimstate.h>
13#include "opimnotifymanager.h" 41#include <opie2/opimnotifymanager.h>
14#include "orecur.h" 42#include <opie2/orecur.h>
15 43
44using namespace Opie;
16/* 45/*
17 * first some query 46 * first some query
18 * CREATE query 47 * CREATE query
19 * LOAD query 48 * LOAD query
20 * INSERT 49 * INSERT
21 * REMOVE 50 * REMOVE
22 * CLEAR 51 * CLEAR
23 */ 52 */
24namespace { 53namespace {
25 /** 54 /**
26 * CreateQuery for the Todolist Table 55 * CreateQuery for the Todolist Table
27 */ 56 */
28 class CreateQuery : public OSQLQuery { 57 class CreateQuery : public OSQLQuery {
29 public: 58 public:
30 CreateQuery(); 59 CreateQuery();
31 ~CreateQuery(); 60 ~CreateQuery();
32 QString query()const; 61 QString query()const;
33 }; 62 };
34 63
35 /** 64 /**
36 * LoadQuery 65 * LoadQuery
37 * this one queries for all uids 66 * this one queries for all uids
38 */ 67 */
39 class LoadQuery : public OSQLQuery { 68 class LoadQuery : public OSQLQuery {
40 public: 69 public:
41 LoadQuery(); 70 LoadQuery();
42 ~LoadQuery(); 71 ~LoadQuery();
43 QString query()const; 72 QString query()const;
44 }; 73 };
45 74
46 /** 75 /**
47 * inserts/adds a OTodo to the table 76 * inserts/adds a OTodo to the table
48 */ 77 */
49 class InsertQuery : public OSQLQuery { 78 class InsertQuery : public OSQLQuery {
50 public: 79 public:
51 InsertQuery(const OTodo& ); 80 InsertQuery(const OTodo& );
52 ~InsertQuery(); 81 ~InsertQuery();
53 QString query()const; 82 QString query()const;
54 private: 83 private:
55 OTodo m_todo; 84 OTodo m_todo;
56 }; 85 };
57 86
58 /** 87 /**
59 * removes one from the table 88 * removes one from the table
60 */ 89 */
61 class RemoveQuery : public OSQLQuery { 90 class RemoveQuery : public OSQLQuery {
62 public: 91 public:
63 RemoveQuery(int uid ); 92 RemoveQuery(int uid );
@@ -253,96 +282,98 @@ namespace {
253 } 282 }
254 QString FindQuery::single()const{ 283 QString FindQuery::single()const{
255 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 284 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
256 return qu; 285 return qu;
257 } 286 }
258 QString FindQuery::multi()const { 287 QString FindQuery::multi()const {
259 QString qu = "select * from todolist where "; 288 QString qu = "select * from todolist where ";
260 for (uint i = 0; i < m_uids.count(); i++ ) { 289 for (uint i = 0; i < m_uids.count(); i++ ) {
261 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 290 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
262 } 291 }
263 qu.remove( qu.length()-2, 2 ); 292 qu.remove( qu.length()-2, 2 );
264 return qu; 293 return qu;
265 } 294 }
266 295
267 OverDueQuery::OverDueQuery(): OSQLQuery() {} 296 OverDueQuery::OverDueQuery(): OSQLQuery() {}
268 OverDueQuery::~OverDueQuery() {} 297 OverDueQuery::~OverDueQuery() {}
269 QString OverDueQuery::query()const { 298 QString OverDueQuery::query()const {
270 QDate date = QDate::currentDate(); 299 QDate date = QDate::currentDate();
271 QString str; 300 QString str;
272 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 301 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
273 302
274 return str; 303 return str;
275 } 304 }
276 305
277 306
278 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 307 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
279 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 308 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
280 EffQuery::~EffQuery() {} 309 EffQuery::~EffQuery() {}
281 QString EffQuery::query()const { 310 QString EffQuery::query()const {
282 return m_inc ? with() : out(); 311 return m_inc ? with() : out();
283 } 312 }
284 QString EffQuery::with()const { 313 QString EffQuery::with()const {
285 QString str; 314 QString str;
286 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 315 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
287 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) 316 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() )
288 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); 317 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() );
289 return str; 318 return str;
290 } 319 }
291 QString EffQuery::out()const { 320 QString EffQuery::out()const {
292 QString str; 321 QString str;
293 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 322 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
294 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) 323 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
295 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); 324 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
296 325
297 return str; 326 return str;
298 } 327 }
299}; 328};
300 329
330
331namespace Opie {
301OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) 332OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
302 : OTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) 333 : OTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true)
303{ 334{
304 QString fi = file; 335 QString fi = file;
305 if ( fi.isEmpty() ) 336 if ( fi.isEmpty() )
306 fi = Global::applicationFileName( "todolist", "todolist.db" ); 337 fi = Global::applicationFileName( "todolist", "todolist.db" );
307 OSQLManager man; 338 OSQLManager man;
308 m_driver = man.standard(); 339 m_driver = man.standard();
309 m_driver->setUrl(fi); 340 m_driver->setUrl(fi);
310 // fillDict(); 341 // fillDict();
311} 342}
312 343
313OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ 344OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
314 if( m_driver ) 345 if( m_driver )
315 delete m_driver; 346 delete m_driver;
316} 347}
317 348
318bool OTodoAccessBackendSQL::load(){ 349bool OTodoAccessBackendSQL::load(){
319 if (!m_driver->open() ) 350 if (!m_driver->open() )
320 return false; 351 return false;
321 352
322 CreateQuery creat; 353 CreateQuery creat;
323 OSQLResult res = m_driver->query(&creat ); 354 OSQLResult res = m_driver->query(&creat );
324 355
325 m_dirty = true; 356 m_dirty = true;
326 return true; 357 return true;
327} 358}
328bool OTodoAccessBackendSQL::reload(){ 359bool OTodoAccessBackendSQL::reload(){
329 return load(); 360 return load();
330} 361}
331 362
332bool OTodoAccessBackendSQL::save(){ 363bool OTodoAccessBackendSQL::save(){
333 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 364 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
334} 365}
335QArray<int> OTodoAccessBackendSQL::allRecords()const { 366QArray<int> OTodoAccessBackendSQL::allRecords()const {
336 if (m_dirty ) 367 if (m_dirty )
337 update(); 368 update();
338 369
339 return m_uids; 370 return m_uids;
340} 371}
341QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ 372QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){
342 QArray<int> ints(0); 373 QArray<int> ints(0);
343 return ints; 374 return ints;
344} 375}
345OTodo OTodoAccessBackendSQL::find(int uid ) const{ 376OTodo OTodoAccessBackendSQL::find(int uid ) const{
346 FindQuery query( uid ); 377 FindQuery query( uid );
347 return todo( m_driver->query(&query) ); 378 return todo( m_driver->query(&query) );
348 379
@@ -646,48 +677,50 @@ QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
646 677
647#warning OTodoAccessBackendSQL::matchRegexp() not implemented !! 678#warning OTodoAccessBackendSQL::matchRegexp() not implemented !!
648 679
649#if 0 680#if 0
650 681
651 Copied from xml-backend by not adapted to sql (eilers) 682 Copied from xml-backend by not adapted to sql (eilers)
652 683
653 QArray<int> m_currentQuery( m_events.count() ); 684 QArray<int> m_currentQuery( m_events.count() );
654 uint arraycounter = 0; 685 uint arraycounter = 0;
655 686
656 687
657 688
658 QMap<int, OTodo>::ConstIterator it; 689 QMap<int, OTodo>::ConstIterator it;
659 for (it = m_events.begin(); it != m_events.end(); ++it ) { 690 for (it = m_events.begin(); it != m_events.end(); ++it ) {
660 if ( it.data().match( r ) ) 691 if ( it.data().match( r ) )
661 m_currentQuery[arraycounter++] = it.data().uid(); 692 m_currentQuery[arraycounter++] = it.data().uid();
662 693
663 } 694 }
664 // Shrink to fit.. 695 // Shrink to fit..
665 m_currentQuery.resize(arraycounter); 696 m_currentQuery.resize(arraycounter);
666 697
667 return m_currentQuery; 698 return m_currentQuery;
668#endif 699#endif
669 QArray<int> empty; 700 QArray<int> empty;
670 return empty; 701 return empty;
671} 702}
672QBitArray OTodoAccessBackendSQL::supports()const { 703QBitArray OTodoAccessBackendSQL::supports()const {
673 704
674 return sup(); 705 return sup();
675} 706}
676 707
677QBitArray OTodoAccessBackendSQL::sup() const{ 708QBitArray OTodoAccessBackendSQL::sup() const{
678 709
679 QBitArray ar( OTodo::CompletedDate + 1 ); 710 QBitArray ar( OTodo::CompletedDate + 1 );
680 ar.fill( true ); 711 ar.fill( true );
681 ar[OTodo::CrossReference] = false; 712 ar[OTodo::CrossReference] = false;
682 ar[OTodo::State ] = false; 713 ar[OTodo::State ] = false;
683 ar[OTodo::Reminders] = false; 714 ar[OTodo::Reminders] = false;
684 ar[OTodo::Notifiers] = false; 715 ar[OTodo::Notifiers] = false;
685 ar[OTodo::Maintainer] = false; 716 ar[OTodo::Maintainer] = false;
686 717
687 return ar; 718 return ar;
688} 719}
689 720
690void OTodoAccessBackendSQL::removeAllCompleted(){ 721void OTodoAccessBackendSQL::removeAllCompleted(){
691#warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! 722#warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !!
692 723
693} 724}
725
726}