summaryrefslogtreecommitdiff
authorerik <erik>2007-01-31 21:57:44 (UTC)
committer erik <erik>2007-01-31 21:57:44 (UTC)
commit958e042c5a4d4e38fd1baae50b78a2febfd306ab (patch) (unidiff)
tree7d86d03549cea01b03ce08926624a50fb086890c
parent6b321230cf24e50b11783b3511a457f22ae79a58 (diff)
downloadopie-958e042c5a4d4e38fd1baae50b78a2febfd306ab.zip
opie-958e042c5a4d4e38fd1baae50b78a2febfd306ab.tar.gz
opie-958e042c5a4d4e38fd1baae50b78a2febfd306ab.tar.bz2
The queryByExample member function was not properly overridden by the child
class. This means that the last child in the chain would be called instead. Seeing as how the function is not really implemented in this class I am sure that they do want the override so a user is A. not fooled into thinking it is and B. running into a parent function doing the wrong thing.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp2
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.h2
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index 629e4da..78c3bf7 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -1,449 +1,449 @@
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/* OPIE */ 34/* OPIE */
35#include <opie2/osqldriver.h> 35#include <opie2/osqldriver.h>
36#include <opie2/osqlmanager.h> 36#include <opie2/osqlmanager.h>
37#include <opie2/osqlquery.h> 37#include <opie2/osqlquery.h>
38 38
39#include <opie2/opimrecurrence.h> 39#include <opie2/opimrecurrence.h>
40#include <opie2/odatebookaccessbackend_sql.h> 40#include <opie2/odatebookaccessbackend_sql.h>
41#include <opie2/odebug.h> 41#include <opie2/odebug.h>
42 42
43#include <qpe/global.h> 43#include <qpe/global.h>
44 44
45/* QT */ 45/* QT */
46#include <qarray.h> 46#include <qarray.h>
47#include <qstringlist.h> 47#include <qstringlist.h>
48 48
49/* STD */ 49/* STD */
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52 52
53 53
54using namespace Opie::DB; 54using namespace Opie::DB;
55 55
56namespace { 56namespace {
57 /** 57 /**
58 * a find query for custom elements 58 * a find query for custom elements
59 */ 59 */
60 class FindCustomQuery : public OSQLQuery { 60 class FindCustomQuery : public OSQLQuery {
61 public: 61 public:
62 FindCustomQuery(int uid); 62 FindCustomQuery(int uid);
63 FindCustomQuery(const QArray<int>& ); 63 FindCustomQuery(const QArray<int>& );
64 ~FindCustomQuery(); 64 ~FindCustomQuery();
65 QString query()const; 65 QString query()const;
66 private: 66 private:
67 QString single()const; 67 QString single()const;
68 QString multi()const; 68 QString multi()const;
69 QArray<int> m_uids; 69 QArray<int> m_uids;
70 int m_uid; 70 int m_uid;
71 }; 71 };
72 72
73 FindCustomQuery::FindCustomQuery(int uid) 73 FindCustomQuery::FindCustomQuery(int uid)
74 : OSQLQuery(), m_uid( uid ) { 74 : OSQLQuery(), m_uid( uid ) {
75 } 75 }
76 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 76 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
77 : OSQLQuery(), m_uids( ints ){ 77 : OSQLQuery(), m_uids( ints ){
78 } 78 }
79 FindCustomQuery::~FindCustomQuery() { 79 FindCustomQuery::~FindCustomQuery() {
80 } 80 }
81 QString FindCustomQuery::query()const{ 81 QString FindCustomQuery::query()const{
82// if ( m_uids.count() == 0 ) 82// if ( m_uids.count() == 0 )
83 return single(); 83 return single();
84 } 84 }
85 QString FindCustomQuery::single()const{ 85 QString FindCustomQuery::single()const{
86 QString qu = "select uid, type, value from custom_data where uid = "; 86 QString qu = "select uid, type, value from custom_data where uid = ";
87 qu += QString::number(m_uid); 87 qu += QString::number(m_uid);
88 return qu; 88 return qu;
89 } 89 }
90} 90}
91 91
92 92
93namespace Opie { 93namespace Opie {
94 94
95 95
96ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 96ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
97 const QString& fileName ) 97 const QString& fileName )
98 : ODateBookAccessBackend(), m_driver( NULL ) 98 : ODateBookAccessBackend(), m_driver( NULL )
99{ 99{
100 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; 100 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName;
101 101
102 // Get the standart sql-driver from the OSQLManager.. 102 // Get the standart sql-driver from the OSQLManager..
103 OSQLManager man; 103 OSQLManager man;
104 m_driver = man.standard(); 104 m_driver = man.standard();
105 m_driver->setUrl( m_fileName ); 105 m_driver->setUrl( m_fileName );
106 106
107 initFields(); 107 initFields();
108 108
109 load(); 109 load();
110} 110}
111 111
112ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { 112ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() {
113 if( m_driver ) 113 if( m_driver )
114 delete m_driver; 114 delete m_driver;
115} 115}
116 116
117void ODateBookAccessBackend_SQL::initFields() 117void ODateBookAccessBackend_SQL::initFields()
118{ 118{
119 119
120 // This map contains the translation of the fieldtype id's to 120 // This map contains the translation of the fieldtype id's to
121 // the names of the table columns 121 // the names of the table columns
122 m_fieldMap.insert( OPimEvent::FUid, "uid" ); 122 m_fieldMap.insert( OPimEvent::FUid, "uid" );
123 m_fieldMap.insert( OPimEvent::FCategories, "Categories" ); 123 m_fieldMap.insert( OPimEvent::FCategories, "Categories" );
124 m_fieldMap.insert( OPimEvent::FDescription, "Description" ); 124 m_fieldMap.insert( OPimEvent::FDescription, "Description" );
125 m_fieldMap.insert( OPimEvent::FLocation, "Location" ); 125 m_fieldMap.insert( OPimEvent::FLocation, "Location" );
126 m_fieldMap.insert( OPimEvent::FType, "Type" ); 126 m_fieldMap.insert( OPimEvent::FType, "Type" );
127 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" ); 127 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" );
128 m_fieldMap.insert( OPimEvent::FSound, "Sound" ); 128 m_fieldMap.insert( OPimEvent::FSound, "Sound" );
129 m_fieldMap.insert( OPimEvent::FRType, "RType" ); 129 m_fieldMap.insert( OPimEvent::FRType, "RType" );
130 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" ); 130 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" );
131 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" ); 131 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" );
132 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" ); 132 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" );
133 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" ); 133 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" );
134 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" ); 134 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" );
135 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" ); 135 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" );
136 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" ); 136 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" );
137 m_fieldMap.insert( OPimEvent::FStart, "Start" ); 137 m_fieldMap.insert( OPimEvent::FStart, "Start" );
138 m_fieldMap.insert( OPimEvent::FEnd, "End" ); 138 m_fieldMap.insert( OPimEvent::FEnd, "End" );
139 m_fieldMap.insert( OPimEvent::FNote, "Note" ); 139 m_fieldMap.insert( OPimEvent::FNote, "Note" );
140 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" ); 140 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" );
141 m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" ); 141 m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" );
142 m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" ); 142 m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" );
143 143
144 // Create a map that maps the column name to the id 144 // Create a map that maps the column name to the id
145 QMapConstIterator<int, QString> it; 145 QMapConstIterator<int, QString> it;
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
152bool ODateBookAccessBackend_SQL::load() 152bool 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 OSQLRawQuery raw( qu ); 170 OSQLRawQuery raw( qu );
171 OSQLResult res = m_driver->query( &raw ); 171 OSQLResult res = m_driver->query( &raw );
172 if ( res.state() != OSQLResult::Success ) 172 if ( res.state() != OSQLResult::Success )
173 return false; 173 return false;
174 174
175 update(); 175 update();
176 176
177 return true; 177 return true;
178} 178}
179 179
180void ODateBookAccessBackend_SQL::update() 180void ODateBookAccessBackend_SQL::update()
181{ 181{
182 182
183 QString qu = "select uid from datebook"; 183 QString qu = "select uid from datebook";
184 OSQLRawQuery raw( qu ); 184 OSQLRawQuery raw( qu );
185 OSQLResult res = m_driver->query( &raw ); 185 OSQLResult res = m_driver->query( &raw );
186 if ( res.state() != OSQLResult::Success ){ 186 if ( res.state() != OSQLResult::Success ){
187 // m_uids.clear(); 187 // m_uids.clear();
188 return; 188 return;
189 } 189 }
190 190
191 m_uids = extractUids( res ); 191 m_uids = extractUids( res );
192 192
193} 193}
194 194
195bool ODateBookAccessBackend_SQL::reload() 195bool ODateBookAccessBackend_SQL::reload()
196{ 196{
197 return load(); 197 return load();
198} 198}
199 199
200bool ODateBookAccessBackend_SQL::save() 200bool ODateBookAccessBackend_SQL::save()
201{ 201{
202 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 202 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
203} 203}
204 204
205QArray<int> ODateBookAccessBackend_SQL::allRecords()const 205QArray<int> ODateBookAccessBackend_SQL::allRecords()const
206{ 206{
207 return m_uids; 207 return m_uids;
208} 208}
209 209
210QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) { 210QArray<int> ODateBookAccessBackend_SQL::queryByExample(const int& unUsed, int settings, const QDateTime& ) {
211 qDebug( "Accessing ODateBookAccessBackend_SQL::queryByExample() which is not implemented!" ); 211 qDebug( "Accessing ODateBookAccessBackend_SQL::queryByExample() which is not implemented!" );
212 return QArray<int>(); 212 return QArray<int>();
213} 213}
214 214
215void ODateBookAccessBackend_SQL::clear() 215void ODateBookAccessBackend_SQL::clear()
216{ 216{
217 QString qu = "drop table datebook;"; 217 QString qu = "drop table datebook;";
218 qu += "drop table custom_data;"; 218 qu += "drop table custom_data;";
219 219
220 OSQLRawQuery raw( qu ); 220 OSQLRawQuery raw( qu );
221 OSQLResult res = m_driver->query( &raw ); 221 OSQLResult res = m_driver->query( &raw );
222 222
223 reload(); 223 reload();
224} 224}
225 225
226 226
227OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ 227OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
228 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " )" << oendl; 228 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " )" << oendl;
229 229
230 QString qu = "select *"; 230 QString qu = "select *";
231 qu += "from datebook where uid = " + QString::number(uid); 231 qu += "from datebook where uid = " + QString::number(uid);
232 232
233 odebug << "Query: " << qu << "" << oendl; 233 odebug << "Query: " << qu << "" << oendl;
234 234
235 OSQLRawQuery raw( qu ); 235 OSQLRawQuery raw( qu );
236 OSQLResult res = m_driver->query( &raw ); 236 OSQLResult res = m_driver->query( &raw );
237 237
238 OSQLResultItem resItem = res.first(); 238 OSQLResultItem resItem = res.first();
239 239
240 // Create Map for date event and insert UID 240 // Create Map for date event and insert UID
241 QMap<int,QString> dateEventMap; 241 QMap<int,QString> dateEventMap;
242 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); 242 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) );
243 243
244 // Now insert the data out of the columns into the map. 244 // Now insert the data out of the columns into the map.
245 QMapConstIterator<int, QString> it; 245 QMapConstIterator<int, QString> it;
246 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 246 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
247 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); 247 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
248 } 248 }
249 249
250 // Last step: Put map into date event, add custom map and return it 250 // Last step: Put map into date event, add custom map and return it
251 OPimEvent retDate( dateEventMap ); 251 OPimEvent retDate( dateEventMap );
252 retDate.setExtraMap( requestCustom( uid ) ); 252 retDate.setExtraMap( requestCustom( uid ) );
253 253
254 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " ) end" << oendl; 254 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " ) end" << oendl;
255 return retDate; 255 return retDate;
256} 256}
257 257
258// FIXME: Speed up update of uid's.. 258// FIXME: Speed up update of uid's..
259bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) 259bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
260{ 260{
261 QMap<int,QString> eventMap = ev.toMap(); 261 QMap<int,QString> eventMap = ev.toMap();
262 262
263 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); 263 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
264 QMap<int, QString>::Iterator it; 264 QMap<int, QString>::Iterator it;
265 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 265 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
266 if ( !eventMap[it.key()].isEmpty() ) 266 if ( !eventMap[it.key()].isEmpty() )
267 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); 267 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
268 else 268 else
269 qu += QString( ",\"\"" ); 269 qu += QString( ",\"\"" );
270 } 270 }
271 qu += " );"; 271 qu += " );";
272 272
273 // Add custom entries 273 // Add custom entries
274 int id = 0; 274 int id = 0;
275 QMap<QString, QString> customMap = ev.toExtraMap(); 275 QMap<QString, QString> customMap = ev.toExtraMap();
276 for( QMap<QString, QString>::Iterator it = customMap.begin(); 276 for( QMap<QString, QString>::Iterator it = customMap.begin();
277 it != customMap.end(); ++it ){ 277 it != customMap.end(); ++it ){
278 qu += "insert into custom_data VALUES(" 278 qu += "insert into custom_data VALUES("
279 + QString::number( ev.uid() ) 279 + QString::number( ev.uid() )
280 + "," 280 + ","
281 + QString::number( id++ ) 281 + QString::number( id++ )
282 + ",'" 282 + ",'"
283 + it.key() //.latin1() 283 + it.key() //.latin1()
284 + "'," 284 + "',"
285 + "0" // Priority for future enhancements 285 + "0" // Priority for future enhancements
286 + ",'" 286 + ",'"
287 + it.data() //.latin1() 287 + it.data() //.latin1()
288 + "');"; 288 + "');";
289 } 289 }
290 290
291 OSQLRawQuery raw( qu ); 291 OSQLRawQuery raw( qu );
292 OSQLResult res = m_driver->query( &raw ); 292 OSQLResult res = m_driver->query( &raw );
293 if ( res.state() != OSQLResult::Success ){ 293 if ( res.state() != OSQLResult::Success ){
294 return false; 294 return false;
295 } 295 }
296 296
297 // Update list of uid's 297 // Update list of uid's
298 update(); 298 update();
299 299
300 return true; 300 return true;
301} 301}
302 302
303// FIXME: Speed up update of uid's.. 303// FIXME: Speed up update of uid's..
304bool ODateBookAccessBackend_SQL::remove( int uid ) 304bool ODateBookAccessBackend_SQL::remove( int uid )
305{ 305{
306 QString qu = "DELETE from datebook where uid = " 306 QString qu = "DELETE from datebook where uid = "
307 + QString::number( uid ) + ";"; 307 + QString::number( uid ) + ";";
308 qu += "DELETE from custom_data where uid = " 308 qu += "DELETE from custom_data where uid = "
309 + QString::number( uid ) + ";"; 309 + QString::number( uid ) + ";";
310 310
311 OSQLRawQuery raw( qu ); 311 OSQLRawQuery raw( qu );
312 OSQLResult res = m_driver->query( &raw ); 312 OSQLResult res = m_driver->query( &raw );
313 if ( res.state() != OSQLResult::Success ){ 313 if ( res.state() != OSQLResult::Success ){
314 return false; 314 return false;
315 } 315 }
316 316
317 // Update list of uid's 317 // Update list of uid's
318 update(); 318 update();
319 319
320 return true; 320 return true;
321} 321}
322 322
323bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) 323bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
324{ 324{
325 remove( ev.uid() ); 325 remove( ev.uid() );
326 return add( ev ); 326 return add( ev );
327} 327}
328 328
329 329
330QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 330QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
331{ 331{
332 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; 332 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
333 OSQLRawQuery raw( qu ); 333 OSQLRawQuery raw( qu );
334 OSQLResult res = m_driver->query( &raw ); 334 OSQLResult res = m_driver->query( &raw );
335 if ( res.state() != OSQLResult::Success ){ 335 if ( res.state() != OSQLResult::Success ){
336 QArray<int> nix; 336 QArray<int> nix;
337 return nix; 337 return nix;
338 } 338 }
339 339
340 return extractUids( res ); 340 return extractUids( res );
341} 341}
342 342
343QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const 343QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
344{ 344{
345 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; 345 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\"";
346 OSQLRawQuery raw( qu ); 346 OSQLRawQuery raw( qu );
347 OSQLResult res = m_driver->query( &raw ); 347 OSQLResult res = m_driver->query( &raw );
348 if ( res.state() != OSQLResult::Success ){ 348 if ( res.state() != OSQLResult::Success ){
349 QArray<int> nix; 349 QArray<int> nix;
350 return nix; 350 return nix;
351 } 351 }
352 352
353 return extractUids( res ); 353 return extractUids( res );
354} 354}
355 355
356OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const 356OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()const
357{ 357{
358 QArray<int> nonRepUids = nonRepeats(); 358 QArray<int> nonRepUids = nonRepeats();
359 OPimEvent::ValueList list; 359 OPimEvent::ValueList list;
360 360
361 for (uint i = 0; i < nonRepUids.count(); ++i ){ 361 for (uint i = 0; i < nonRepUids.count(); ++i ){
362 list.append( find( nonRepUids[i] ) ); 362 list.append( find( nonRepUids[i] ) );
363 } 363 }
364 364
365 return list; 365 return list;
366 366
367} 367}
368OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const 368OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()const
369{ 369{
370 QArray<int> rawRepUids = rawRepeats(); 370 QArray<int> rawRepUids = rawRepeats();
371 OPimEvent::ValueList list; 371 OPimEvent::ValueList list;
372 372
373 for (uint i = 0; i < rawRepUids.count(); ++i ){ 373 for (uint i = 0; i < rawRepUids.count(); ++i ){
374 list.append( find( rawRepUids[i] ) ); 374 list.append( find( rawRepUids[i] ) );
375 } 375 }
376 376
377 return list; 377 return list;
378} 378}
379 379
380 380
381QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 381QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
382{ 382{
383 383
384 QString qu = "SELECT uid FROM datebook WHERE ("; 384 QString qu = "SELECT uid FROM datebook WHERE (";
385 385
386 // Do it make sense to search other fields, too ? 386 // Do it make sense to search other fields, too ?
387 qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; 387 qu += " rlike(\""+ r.pattern() + "\", Location ) OR";
388 qu += " rlike(\""+ r.pattern() + "\", Note )"; 388 qu += " rlike(\""+ r.pattern() + "\", Note )";
389 389
390 qu += " )"; 390 qu += " )";
391 391
392 odebug << "query: " << qu << "" << oendl; 392 odebug << "query: " << qu << "" << oendl;
393 393
394 OSQLRawQuery raw( qu ); 394 OSQLRawQuery raw( qu );
395 OSQLResult res = m_driver->query( &raw ); 395 OSQLResult res = m_driver->query( &raw );
396 396
397 return extractUids( res ); 397 return extractUids( res );
398 398
399 399
400 400
401} 401}
402 402
403/* ===== Private Functions ========================================== */ 403/* ===== Private Functions ========================================== */
404 404
405QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const 405QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
406{ 406{
407 QTime t; 407 QTime t;
408 t.start(); 408 t.start();
409 OSQLResultItem::ValueList list = res.results(); 409 OSQLResultItem::ValueList list = res.results();
410 OSQLResultItem::ValueList::Iterator it; 410 OSQLResultItem::ValueList::Iterator it;
411 QArray<int> ints(list.count() ); 411 QArray<int> ints(list.count() );
412 412
413 int i = 0; 413 int i = 0;
414 for (it = list.begin(); it != list.end(); ++it ) { 414 for (it = list.begin(); it != list.end(); ++it ) {
415 ints[i] = (*it).data("uid").toInt(); 415 ints[i] = (*it).data("uid").toInt();
416 i++; 416 i++;
417 } 417 }
418 418
419 return ints; 419 return ints;
420 420
421} 421}
422 422
423QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const 423QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
424{ 424{
425 QTime t; 425 QTime t;
426 t.start(); 426 t.start();
427 427
428 QMap<QString, QString> customMap; 428 QMap<QString, QString> customMap;
429 429
430 FindCustomQuery query( uid ); 430 FindCustomQuery query( uid );
431 OSQLResult res_custom = m_driver->query( &query ); 431 OSQLResult res_custom = m_driver->query( &query );
432 432
433 if ( res_custom.state() == OSQLResult::Failure ) { 433 if ( res_custom.state() == OSQLResult::Failure ) {
434 QMap<QString, QString> empty; 434 QMap<QString, QString> empty;
435 return empty; 435 return empty;
436 } 436 }
437 437
438 OSQLResultItem::ValueList list = res_custom.results(); 438 OSQLResultItem::ValueList list = res_custom.results();
439 OSQLResultItem::ValueList::Iterator it = list.begin(); 439 OSQLResultItem::ValueList::Iterator it = list.begin();
440 for ( ; it != list.end(); ++it ) { 440 for ( ; it != list.end(); ++it ) {
441 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 441 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
442 } 442 }
443 443
444 odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; 444 odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl;
445 return customMap; 445 return customMap;
446} 446}
447 447
448 448
449} 449}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
index a649d25..2de2dca 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
@@ -1,98 +1,98 @@
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#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H 29#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H
30#define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H 30#define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H
31 31
32#include <qmap.h> 32#include <qmap.h>
33#include <opie2/osqlresult.h> 33#include <opie2/osqlresult.h>
34 34
35#include <opie2/odatebookaccessbackend.h> 35#include <opie2/odatebookaccessbackend.h>
36 36
37namespace Opie { 37namespace Opie {
38namespace DB { 38namespace DB {
39class OSQLDriver; 39class OSQLDriver;
40} 40}
41} 41}
42 42
43namespace Opie { 43namespace Opie {
44/** 44/**
45 * This is the default SQL implementation for DateBoook SQL storage 45 * This is the default SQL implementation for DateBoook SQL storage
46 * It fully implements the interface 46 * It fully implements the interface
47 * @see ODateBookAccessBackend 47 * @see ODateBookAccessBackend
48 * @see OPimAccessBackend 48 * @see OPimAccessBackend
49 */ 49 */
50class ODateBookAccessBackend_SQL : public ODateBookAccessBackend { 50class ODateBookAccessBackend_SQL : public ODateBookAccessBackend {
51public: 51public:
52 ODateBookAccessBackend_SQL( const QString& appName, 52 ODateBookAccessBackend_SQL( const QString& appName,
53 const QString& fileName = QString::null); 53 const QString& fileName = QString::null);
54 ~ODateBookAccessBackend_SQL(); 54 ~ODateBookAccessBackend_SQL();
55 55
56 bool load(); 56 bool load();
57 bool reload(); 57 bool reload();
58 bool save(); 58 bool save();
59 59
60 QArray<int> allRecords()const; 60 QArray<int> allRecords()const;
61 QArray<int> matchRegexp(const QRegExp &r) const; 61 QArray<int> matchRegexp(const QRegExp &r) const;
62 QArray<int> queryByExample( const OPimEvent&, int, const QDateTime& d = QDateTime() ); 62 QArray<int> queryByExample( const int& unUsed, int settings, const QDateTime& d = QDateTime() );
63 OPimEvent find( int uid )const; 63 OPimEvent find( int uid )const;
64 void clear(); 64 void clear();
65 bool add( const OPimEvent& ev ); 65 bool add( const OPimEvent& ev );
66 bool remove( int uid ); 66 bool remove( int uid );
67 bool replace( const OPimEvent& ev ); 67 bool replace( const OPimEvent& ev );
68 68
69 QArray<UID> rawRepeats()const; 69 QArray<UID> rawRepeats()const;
70 QArray<UID> nonRepeats()const; 70 QArray<UID> nonRepeats()const;
71 71
72 OPimEvent::ValueList directNonRepeats()const; 72 OPimEvent::ValueList directNonRepeats()const;
73 OPimEvent::ValueList directRawRepeats()const; 73 OPimEvent::ValueList directRawRepeats()const;
74 74
75private: 75private:
76 bool loadFile(); 76 bool loadFile();
77 QString m_fileName; 77 QString m_fileName;
78 QArray<int> m_uids; 78 QArray<int> m_uids;
79 79
80 QMap<int, QString> m_fieldMap; 80 QMap<int, QString> m_fieldMap;
81 QMap<QString, int> m_reverseFieldMap; 81 QMap<QString, int> m_reverseFieldMap;
82 82
83 Opie::DB::OSQLDriver* m_driver; 83 Opie::DB::OSQLDriver* m_driver;
84 84
85 class Private; 85 class Private;
86 Private *d; 86 Private *d;
87 87
88 void initFields(); 88 void initFields();
89 void update(); 89 void update();
90 90
91 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const; 91 QArray<int> extractUids( Opie::DB::OSQLResult& res ) const;
92 QMap<QString, QString> requestCustom( int uid ) const; 92 QMap<QString, QString> requestCustom( int uid ) const;
93 93
94}; 94};
95 95
96} 96}
97 97
98#endif 98#endif