summaryrefslogtreecommitdiff
authoreilers <eilers>2003-12-22 11:41:39 (UTC)
committer eilers <eilers>2003-12-22 11:41:39 (UTC)
commit5be4ab495ca232d64305b2634e3bca074f542539 (patch) (unidiff)
tree6255155e18ed63b52505aaa794ed45332bac8cec
parent8d91c030bd4cb8ef296eb25fee9394ca4a8319f8 (diff)
downloadopie-5be4ab495ca232d64305b2634e3bca074f542539.zip
opie-5be4ab495ca232d64305b2634e3bca074f542539.tar.gz
opie-5be4ab495ca232d64305b2634e3bca074f542539.tar.bz2
Fixing stupid bug, found by sourcode review..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/odatebookaccessbackend_sql.cpp11
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp11
2 files changed, 22 insertions, 0 deletions
diff --git a/libopie/pim/odatebookaccessbackend_sql.cpp b/libopie/pim/odatebookaccessbackend_sql.cpp
index e893b38..756f405 100644
--- a/libopie/pim/odatebookaccessbackend_sql.cpp
+++ b/libopie/pim/odatebookaccessbackend_sql.cpp
@@ -1,40 +1,43 @@
1/* 1/*
2 * SQL Backend for the OPIE-Calender Database. 2 * SQL Backend for the OPIE-Calender Database.
3 * 3 *
4 * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de) 4 * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de)
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 *
29 * Revision 1.1 2003/12/08 15:18:12 eilers 32 * Revision 1.1 2003/12/08 15:18:12 eilers
30 * Committing unfinished sql implementation before merging to libopie2 starts.. 33 * Committing unfinished sql implementation before merging to libopie2 starts..
31 * 34 *
32 * 35 *
33 */ 36 */
34 37
35#include <stdio.h> 38#include <stdio.h>
36#include <stdlib.h> 39#include <stdlib.h>
37 40
38#include <qarray.h> 41#include <qarray.h>
39#include <qstringlist.h> 42#include <qstringlist.h>
40 43
@@ -185,103 +188,111 @@ OEvent ODateBookAccessBackend_SQL::find( int uid ) const{
185 QString qu = "select *"; 188 QString qu = "select *";
186 qu += "from datebook where uid = " + QString::number(uid); 189 qu += "from datebook where uid = " + QString::number(uid);
187 190
188 OSQLRawQuery raw( qu ); 191 OSQLRawQuery raw( qu );
189 OSQLResult res = m_driver->query( &raw ); 192 OSQLResult res = m_driver->query( &raw );
190 193
191 OSQLResultItem resItem = res.first(); 194 OSQLResultItem resItem = res.first();
192 195
193 // Create Map for date event and insert UID 196 // Create Map for date event and insert UID
194 QMap<int,QString> dateEventMap; 197 QMap<int,QString> dateEventMap;
195 dateEventMap.insert( OEvent::FUid, QString::number( uid ) ); 198 dateEventMap.insert( OEvent::FUid, QString::number( uid ) );
196 199
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..
209bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) 213bool 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 }
221 qu += " );"; 225 qu += " );";
222 226
223 // Add custom entries 227 // Add custom entries
224 int id = 0; 228 int id = 0;
225 QMap<QString, QString> customMap = ev.toExtraMap(); 229 QMap<QString, QString> customMap = ev.toExtraMap();
226 for( QMap<QString, QString>::Iterator it = customMap.begin(); 230 for( QMap<QString, QString>::Iterator it = customMap.begin();
227 it != customMap.end(); ++it ){ 231 it != customMap.end(); ++it ){
228 qu += "insert into custom_data VALUES(" 232 qu += "insert into custom_data VALUES("
229 + QString::number( ev.uid() ) 233 + QString::number( ev.uid() )
230 + "," 234 + ","
231 + QString::number( id++ ) 235 + QString::number( id++ )
232 + ",'" 236 + ",'"
233 + it.key() //.latin1() 237 + it.key() //.latin1()
234 + "'," 238 + "',"
235 + "0" // Priority for future enhancements 239 + "0" // Priority for future enhancements
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 }
251
252 // Update list of uid's
253 update();
247 254
248 return true; 255 return true;
249} 256}
250 257
258// FIXME: Speed up update of uid's..
251bool ODateBookAccessBackend_SQL::remove( int uid ) 259bool 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
267bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) 278bool 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
273QArray<int> ODateBookAccessBackend_SQL::rawEvents()const 284QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
274{ 285{
275 return allRecords(); 286 return allRecords();
276} 287}
277 288
278QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 289QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
279{ 290{
280 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; 291 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
281 OSQLRawQuery raw( qu ); 292 OSQLRawQuery raw( qu );
282 OSQLResult res = m_driver->query( &raw ); 293 OSQLResult res = m_driver->query( &raw );
283 if ( res.state() != OSQLResult::Success ){ 294 if ( res.state() != OSQLResult::Success ){
284 QArray<int> nix; 295 QArray<int> nix;
285 return nix; 296 return nix;
286 } 297 }
287 298
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
@@ -1,40 +1,43 @@
1/* 1/*
2 * SQL Backend for the OPIE-Calender Database. 2 * SQL Backend for the OPIE-Calender Database.
3 * 3 *
4 * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de) 4 * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de)
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 *
29 * Revision 1.1 2003/12/08 15:18:12 eilers 32 * Revision 1.1 2003/12/08 15:18:12 eilers
30 * Committing unfinished sql implementation before merging to libopie2 starts.. 33 * Committing unfinished sql implementation before merging to libopie2 starts..
31 * 34 *
32 * 35 *
33 */ 36 */
34 37
35#include <stdio.h> 38#include <stdio.h>
36#include <stdlib.h> 39#include <stdlib.h>
37 40
38#include <qarray.h> 41#include <qarray.h>
39#include <qstringlist.h> 42#include <qstringlist.h>
40 43
@@ -185,103 +188,111 @@ OEvent ODateBookAccessBackend_SQL::find( int uid ) const{
185 QString qu = "select *"; 188 QString qu = "select *";
186 qu += "from datebook where uid = " + QString::number(uid); 189 qu += "from datebook where uid = " + QString::number(uid);
187 190
188 OSQLRawQuery raw( qu ); 191 OSQLRawQuery raw( qu );
189 OSQLResult res = m_driver->query( &raw ); 192 OSQLResult res = m_driver->query( &raw );
190 193
191 OSQLResultItem resItem = res.first(); 194 OSQLResultItem resItem = res.first();
192 195
193 // Create Map for date event and insert UID 196 // Create Map for date event and insert UID
194 QMap<int,QString> dateEventMap; 197 QMap<int,QString> dateEventMap;
195 dateEventMap.insert( OEvent::FUid, QString::number( uid ) ); 198 dateEventMap.insert( OEvent::FUid, QString::number( uid ) );
196 199
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..
209bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) 213bool 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 }
221 qu += " );"; 225 qu += " );";
222 226
223 // Add custom entries 227 // Add custom entries
224 int id = 0; 228 int id = 0;
225 QMap<QString, QString> customMap = ev.toExtraMap(); 229 QMap<QString, QString> customMap = ev.toExtraMap();
226 for( QMap<QString, QString>::Iterator it = customMap.begin(); 230 for( QMap<QString, QString>::Iterator it = customMap.begin();
227 it != customMap.end(); ++it ){ 231 it != customMap.end(); ++it ){
228 qu += "insert into custom_data VALUES(" 232 qu += "insert into custom_data VALUES("
229 + QString::number( ev.uid() ) 233 + QString::number( ev.uid() )
230 + "," 234 + ","
231 + QString::number( id++ ) 235 + QString::number( id++ )
232 + ",'" 236 + ",'"
233 + it.key() //.latin1() 237 + it.key() //.latin1()
234 + "'," 238 + "',"
235 + "0" // Priority for future enhancements 239 + "0" // Priority for future enhancements
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 }
251
252 // Update list of uid's
253 update();
247 254
248 return true; 255 return true;
249} 256}
250 257
258// FIXME: Speed up update of uid's..
251bool ODateBookAccessBackend_SQL::remove( int uid ) 259bool 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
267bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) 278bool 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
273QArray<int> ODateBookAccessBackend_SQL::rawEvents()const 284QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
274{ 285{
275 return allRecords(); 286 return allRecords();
276} 287}
277 288
278QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 289QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
279{ 290{
280 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; 291 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
281 OSQLRawQuery raw( qu ); 292 OSQLRawQuery raw( qu );
282 OSQLResult res = m_driver->query( &raw ); 293 OSQLResult res = m_driver->query( &raw );
283 if ( res.state() != OSQLResult::Success ){ 294 if ( res.state() != OSQLResult::Success ){
284 QArray<int> nix; 295 QArray<int> nix;
285 return nix; 296 return nix;
286 } 297 }
287 298