Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index e893b38..756f405 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -5,24 +5,27 @@ | |||
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * Version: $Id$ | 13 | * Version: $Id$ |
14 | * ===================================================================== | 14 | * ===================================================================== |
15 | * History: | 15 | * History: |
16 | * $Log$ | 16 | * $Log$ |
17 | * Revision 1.3 2003/12/22 11:41:39 eilers | ||
18 | * Fixing stupid bug, found by sourcode review.. | ||
19 | * | ||
17 | * Revision 1.2 2003/12/22 10:19:26 eilers | 20 | * Revision 1.2 2003/12/22 10:19:26 eilers |
18 | * Finishing implementation of sql-backend for datebook. But I have to | 21 | * Finishing implementation of sql-backend for datebook. But I have to |
19 | * port the PIM datebook application to use it, before I could debug the | 22 | * port the PIM datebook application to use it, before I could debug the |
20 | * whole stuff. | 23 | * whole stuff. |
21 | * Thus, PIM-Database backend is finished, but highly experimental. And some | 24 | * Thus, PIM-Database backend is finished, but highly experimental. And some |
22 | * parts are still generic. For instance, the "queryByExample()" methods are | 25 | * parts are still generic. For instance, the "queryByExample()" methods are |
23 | * not (or not fully) implemented. Todo: custom-entries not stored. | 26 | * not (or not fully) implemented. Todo: custom-entries not stored. |
24 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | 27 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular |
25 | * expression search in the database, which is not supported by sqlite ! | 28 | * expression search in the database, which is not supported by sqlite ! |
26 | * Therefore we need either an extended sqlite or a workaround which would | 29 | * Therefore we need either an extended sqlite or a workaround which would |
27 | * be very slow and memory consuming.. | 30 | * be very slow and memory consuming.. |
28 | * | 31 | * |
@@ -197,24 +200,25 @@ OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | |||
197 | // Now insert the data out of the columns into the map. | 200 | // Now insert the data out of the columns into the map. |
198 | QMapConstIterator<int, QString> it; | 201 | QMapConstIterator<int, QString> it; |
199 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 202 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
200 | dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); | 203 | dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); |
201 | } | 204 | } |
202 | 205 | ||
203 | // Last step: Put map into date event and return it | 206 | // Last step: Put map into date event and return it |
204 | OEvent retDate( dateEventMap ); | 207 | OEvent retDate( dateEventMap ); |
205 | 208 | ||
206 | return retDate; | 209 | return retDate; |
207 | } | 210 | } |
208 | 211 | ||
212 | // FIXME: Speed up update of uid's.. | ||
209 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) | 213 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) |
210 | { | 214 | { |
211 | QMap<int,QString> eventMap = ev.toMap(); | 215 | QMap<int,QString> eventMap = ev.toMap(); |
212 | 216 | ||
213 | QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); | 217 | QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); |
214 | QMap<int, QString>::Iterator it; | 218 | QMap<int, QString>::Iterator it; |
215 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 219 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
216 | if ( !eventMap[it.key()].isEmpty() ) | 220 | if ( !eventMap[it.key()].isEmpty() ) |
217 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); | 221 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); |
218 | else | 222 | else |
219 | qu += QString( ",\"\"" ); | 223 | qu += QString( ",\"\"" ); |
220 | } | 224 | } |
@@ -236,40 +240,47 @@ bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) | |||
236 | + ",'" | 240 | + ",'" |
237 | + it.data() //.latin1() | 241 | + it.data() //.latin1() |
238 | + "');"; | 242 | + "');"; |
239 | } | 243 | } |
240 | qWarning("add %s", qu.latin1() ); | 244 | qWarning("add %s", qu.latin1() ); |
241 | 245 | ||
242 | OSQLRawQuery raw( qu ); | 246 | OSQLRawQuery raw( qu ); |
243 | OSQLResult res = m_driver->query( &raw ); | 247 | OSQLResult res = m_driver->query( &raw ); |
244 | if ( res.state() != OSQLResult::Success ){ | 248 | if ( res.state() != OSQLResult::Success ){ |
245 | return false; | 249 | return false; |
246 | } | 250 | } |
247 | 251 | ||
252 | // Update list of uid's | ||
253 | update(); | ||
254 | |||
248 | return true; | 255 | return true; |
249 | } | 256 | } |
250 | 257 | ||
258 | // FIXME: Speed up update of uid's.. | ||
251 | bool ODateBookAccessBackend_SQL::remove( int uid ) | 259 | bool ODateBookAccessBackend_SQL::remove( int uid ) |
252 | { | 260 | { |
253 | QString qu = "DELETE from datebook where uid = " | 261 | QString qu = "DELETE from datebook where uid = " |
254 | + QString::number( uid ) + ";"; | 262 | + QString::number( uid ) + ";"; |
255 | qu += "DELETE from custom_data where uid = " | 263 | qu += "DELETE from custom_data where uid = " |
256 | + QString::number( uid ) + ";"; | 264 | + QString::number( uid ) + ";"; |
257 | 265 | ||
258 | OSQLRawQuery raw( qu ); | 266 | OSQLRawQuery raw( qu ); |
259 | OSQLResult res = m_driver->query( &raw ); | 267 | OSQLResult res = m_driver->query( &raw ); |
260 | if ( res.state() != OSQLResult::Success ){ | 268 | if ( res.state() != OSQLResult::Success ){ |
261 | return false; | 269 | return false; |
262 | } | 270 | } |
263 | 271 | ||
272 | // Update list of uid's | ||
273 | update(); | ||
274 | |||
264 | return true; | 275 | return true; |
265 | } | 276 | } |
266 | 277 | ||
267 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) | 278 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) |
268 | { | 279 | { |
269 | remove( ev.uid() ); | 280 | remove( ev.uid() ); |
270 | return add( ev ); | 281 | return add( ev ); |
271 | } | 282 | } |
272 | 283 | ||
273 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const | 284 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const |
274 | { | 285 | { |
275 | return allRecords(); | 286 | return allRecords(); |