Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 756f405..e79696c 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -1,100 +1,97 @@ | |||
1 | /* | 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 | */ | ||
29 | /* | ||
2 | * SQL Backend for the OPIE-Calender Database. | 30 | * SQL Backend for the OPIE-Calender Database. |
3 | * | 31 | * |
4 | * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * ===================================================================== | ||
13 | * Version: $Id$ | ||
14 | * ===================================================================== | ||
15 | * History: | ||
16 | * $Log$ | ||
17 | * Revision 1.3 2003/12/22 11:41:39 eilers | ||
18 | * Fixing stupid bug, found by sourcode review.. | ||
19 | * | ||
20 | * Revision 1.2 2003/12/22 10:19:26 eilers | ||
21 | * Finishing implementation of sql-backend for datebook. But I have to | ||
22 | * port the PIM datebook application to use it, before I could debug the | ||
23 | * whole stuff. | ||
24 | * Thus, PIM-Database backend is finished, but highly experimental. And some | ||
25 | * parts are still generic. For instance, the "queryByExample()" methods are | ||
26 | * not (or not fully) implemented. Todo: custom-entries not stored. | ||
27 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | ||
28 | * expression search in the database, which is not supported by sqlite ! | ||
29 | * Therefore we need either an extended sqlite or a workaround which would | ||
30 | * be very slow and memory consuming.. | ||
31 | * | ||
32 | * Revision 1.1 2003/12/08 15:18:12 eilers | ||
33 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
34 | * | ||
35 | * | ||
36 | */ | 32 | */ |
37 | 33 | ||
38 | #include <stdio.h> | 34 | #include <stdio.h> |
39 | #include <stdlib.h> | 35 | #include <stdlib.h> |
40 | 36 | ||
41 | #include <qarray.h> | 37 | #include <qarray.h> |
42 | #include <qstringlist.h> | 38 | #include <qstringlist.h> |
43 | 39 | ||
44 | #include <qpe/global.h> | 40 | #include <qpe/global.h> |
45 | 41 | ||
46 | #include <opie2/osqldriver.h> | 42 | #include <opie2/osqldriver.h> |
47 | #include <opie2/osqlmanager.h> | 43 | #include <opie2/osqlmanager.h> |
48 | #include <opie2/osqlquery.h> | 44 | #include <opie2/osqlquery.h> |
49 | 45 | ||
50 | #include "orecur.h" | 46 | #include <opie2/orecur.h> |
51 | #include "odatebookaccessbackend_sql.h" | 47 | #include <opie2/odatebookaccessbackend_sql.h> |
52 | 48 | ||
49 | namespace Opie { | ||
53 | 50 | ||
54 | 51 | ||
55 | ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | 52 | ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , |
56 | const QString& fileName ) | 53 | const QString& fileName ) |
57 | : ODateBookAccessBackend(), m_driver( NULL ) | 54 | : ODateBookAccessBackend(), m_driver( NULL ) |
58 | { | 55 | { |
59 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; | 56 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; |
60 | 57 | ||
61 | // Get the standart sql-driver from the OSQLManager.. | 58 | // Get the standart sql-driver from the OSQLManager.. |
62 | OSQLManager man; | 59 | OSQLManager man; |
63 | m_driver = man.standard(); | 60 | m_driver = man.standard(); |
64 | m_driver->setUrl( m_fileName ); | 61 | m_driver->setUrl( m_fileName ); |
65 | 62 | ||
66 | initFields(); | 63 | initFields(); |
67 | 64 | ||
68 | load(); | 65 | load(); |
69 | } | 66 | } |
70 | 67 | ||
71 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { | 68 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { |
72 | if( m_driver ) | 69 | if( m_driver ) |
73 | delete m_driver; | 70 | delete m_driver; |
74 | } | 71 | } |
75 | 72 | ||
76 | void ODateBookAccessBackend_SQL::initFields() | 73 | void ODateBookAccessBackend_SQL::initFields() |
77 | { | 74 | { |
78 | 75 | ||
79 | // This map contains the translation of the fieldtype id's to | 76 | // This map contains the translation of the fieldtype id's to |
80 | // the names of the table columns | 77 | // the names of the table columns |
81 | m_fieldMap.insert( OEvent::FUid, "uid" ); | 78 | m_fieldMap.insert( OEvent::FUid, "uid" ); |
82 | m_fieldMap.insert( OEvent::FCategories, "Categories" ); | 79 | m_fieldMap.insert( OEvent::FCategories, "Categories" ); |
83 | m_fieldMap.insert( OEvent::FDescription, "Description" ); | 80 | m_fieldMap.insert( OEvent::FDescription, "Description" ); |
84 | m_fieldMap.insert( OEvent::FLocation, "Location" ); | 81 | m_fieldMap.insert( OEvent::FLocation, "Location" ); |
85 | m_fieldMap.insert( OEvent::FType, "Type" ); | 82 | m_fieldMap.insert( OEvent::FType, "Type" ); |
86 | m_fieldMap.insert( OEvent::FAlarm, "Alarm" ); | 83 | m_fieldMap.insert( OEvent::FAlarm, "Alarm" ); |
87 | m_fieldMap.insert( OEvent::FSound, "Sound" ); | 84 | m_fieldMap.insert( OEvent::FSound, "Sound" ); |
88 | m_fieldMap.insert( OEvent::FRType, "RType" ); | 85 | m_fieldMap.insert( OEvent::FRType, "RType" ); |
89 | m_fieldMap.insert( OEvent::FRWeekdays, "RWeekdays" ); | 86 | m_fieldMap.insert( OEvent::FRWeekdays, "RWeekdays" ); |
90 | m_fieldMap.insert( OEvent::FRPosition, "RPosition" ); | 87 | m_fieldMap.insert( OEvent::FRPosition, "RPosition" ); |
91 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); | 88 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); |
92 | m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); | 89 | m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); |
93 | m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); | 90 | m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); |
94 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); | 91 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); |
95 | m_fieldMap.insert( OEvent::FRExceptions, "RExceptions" ); | 92 | m_fieldMap.insert( OEvent::FRExceptions, "RExceptions" ); |
96 | m_fieldMap.insert( OEvent::FStart, "Start" ); | 93 | m_fieldMap.insert( OEvent::FStart, "Start" ); |
97 | m_fieldMap.insert( OEvent::FEnd, "End" ); | 94 | m_fieldMap.insert( OEvent::FEnd, "End" ); |
98 | m_fieldMap.insert( OEvent::FNote, "Note" ); | 95 | m_fieldMap.insert( OEvent::FNote, "Note" ); |
99 | m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); | 96 | m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); |
100 | m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); | 97 | m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); |
@@ -320,48 +317,50 @@ OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() | |||
320 | for (uint i = 0; i < nonRepUids.count(); ++i ){ | 317 | for (uint i = 0; i < nonRepUids.count(); ++i ){ |
321 | list.append( find( nonRepUids[i] ) ); | 318 | list.append( find( nonRepUids[i] ) ); |
322 | } | 319 | } |
323 | 320 | ||
324 | return list; | 321 | return list; |
325 | 322 | ||
326 | } | 323 | } |
327 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() | 324 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() |
328 | { | 325 | { |
329 | QArray<int> rawRepUids = rawRepeats(); | 326 | QArray<int> rawRepUids = rawRepeats(); |
330 | OEvent::ValueList list; | 327 | OEvent::ValueList list; |
331 | 328 | ||
332 | for (uint i = 0; i < rawRepUids.count(); ++i ){ | 329 | for (uint i = 0; i < rawRepUids.count(); ++i ){ |
333 | list.append( find( rawRepUids[i] ) ); | 330 | list.append( find( rawRepUids[i] ) ); |
334 | } | 331 | } |
335 | 332 | ||
336 | return list; | 333 | return list; |
337 | } | 334 | } |
338 | 335 | ||
339 | 336 | ||
340 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 337 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
341 | { | 338 | { |
342 | QArray<int> null; | 339 | QArray<int> null; |
343 | return null; | 340 | return null; |
344 | } | 341 | } |
345 | 342 | ||
346 | /* ===== Private Functions ========================================== */ | 343 | /* ===== Private Functions ========================================== */ |
347 | 344 | ||
348 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const | 345 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const |
349 | { | 346 | { |
350 | qWarning("extractUids"); | 347 | qWarning("extractUids"); |
351 | QTime t; | 348 | QTime t; |
352 | t.start(); | 349 | t.start(); |
353 | OSQLResultItem::ValueList list = res.results(); | 350 | OSQLResultItem::ValueList list = res.results(); |
354 | OSQLResultItem::ValueList::Iterator it; | 351 | OSQLResultItem::ValueList::Iterator it; |
355 | QArray<int> ints(list.count() ); | 352 | QArray<int> ints(list.count() ); |
356 | qWarning(" count = %d", list.count() ); | 353 | qWarning(" count = %d", list.count() ); |
357 | 354 | ||
358 | int i = 0; | 355 | int i = 0; |
359 | for (it = list.begin(); it != list.end(); ++it ) { | 356 | for (it = list.begin(); it != list.end(); ++it ) { |
360 | ints[i] = (*it).data("uid").toInt(); | 357 | ints[i] = (*it).data("uid").toInt(); |
361 | i++; | 358 | i++; |
362 | } | 359 | } |
363 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); | 360 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); |
364 | 361 | ||
365 | return ints; | 362 | return ints; |
366 | 363 | ||
367 | } | 364 | } |
365 | |||
366 | } | ||