-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 495a8dd..6c32b40 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -181,116 +181,118 @@ void ODateBookAccessBackend_SQL::update() | |||
181 | OSQLRawQuery raw( qu ); | 181 | OSQLRawQuery raw( qu ); |
182 | OSQLResult res = m_driver->query( &raw ); | 182 | OSQLResult res = m_driver->query( &raw ); |
183 | if ( res.state() != OSQLResult::Success ){ | 183 | if ( res.state() != OSQLResult::Success ){ |
184 | // m_uids.clear(); | 184 | // m_uids.clear(); |
185 | return; | 185 | return; |
186 | } | 186 | } |
187 | 187 | ||
188 | m_uids = extractUids( res ); | 188 | m_uids = extractUids( res ); |
189 | 189 | ||
190 | } | 190 | } |
191 | 191 | ||
192 | bool ODateBookAccessBackend_SQL::reload() | 192 | bool ODateBookAccessBackend_SQL::reload() |
193 | { | 193 | { |
194 | return load(); | 194 | return load(); |
195 | } | 195 | } |
196 | 196 | ||
197 | bool ODateBookAccessBackend_SQL::save() | 197 | bool ODateBookAccessBackend_SQL::save() |
198 | { | 198 | { |
199 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 199 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
200 | } | 200 | } |
201 | 201 | ||
202 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const | 202 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const |
203 | { | 203 | { |
204 | return m_uids; | 204 | return m_uids; |
205 | } | 205 | } |
206 | 206 | ||
207 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) { | 207 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) { |
208 | return QArray<int>(); | 208 | return QArray<int>(); |
209 | } | 209 | } |
210 | 210 | ||
211 | void ODateBookAccessBackend_SQL::clear() | 211 | void ODateBookAccessBackend_SQL::clear() |
212 | { | 212 | { |
213 | QString qu = "drop table datebook;"; | 213 | QString qu = "drop table datebook;"; |
214 | qu += "drop table custom_data;"; | 214 | qu += "drop table custom_data;"; |
215 | 215 | ||
216 | OSQLRawQuery raw( qu ); | 216 | OSQLRawQuery raw( qu ); |
217 | OSQLResult res = m_driver->query( &raw ); | 217 | OSQLResult res = m_driver->query( &raw ); |
218 | 218 | ||
219 | reload(); | 219 | reload(); |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | 223 | OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ |
224 | qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid ); | 224 | qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid ); |
225 | 225 | ||
226 | QString qu = "select *"; | 226 | QString qu = "select *"; |
227 | qu += "from datebook where uid = " + QString::number(uid); | 227 | qu += "from datebook where uid = " + QString::number(uid); |
228 | 228 | ||
229 | qDebug( "Query: %s", qu.latin1() ); | ||
230 | |||
229 | OSQLRawQuery raw( qu ); | 231 | OSQLRawQuery raw( qu ); |
230 | OSQLResult res = m_driver->query( &raw ); | 232 | OSQLResult res = m_driver->query( &raw ); |
231 | 233 | ||
232 | OSQLResultItem resItem = res.first(); | 234 | OSQLResultItem resItem = res.first(); |
233 | 235 | ||
234 | // Create Map for date event and insert UID | 236 | // Create Map for date event and insert UID |
235 | QMap<int,QString> dateEventMap; | 237 | QMap<int,QString> dateEventMap; |
236 | dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); | 238 | dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); |
237 | 239 | ||
238 | // Now insert the data out of the columns into the map. | 240 | // Now insert the data out of the columns into the map. |
239 | QMapConstIterator<int, QString> it; | 241 | QMapConstIterator<int, QString> it; |
240 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 242 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
241 | dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); | 243 | dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); |
242 | } | 244 | } |
243 | 245 | ||
244 | // Last step: Put map into date event, add custom map and return it | 246 | // Last step: Put map into date event, add custom map and return it |
245 | OPimEvent retDate( dateEventMap ); | 247 | OPimEvent retDate( dateEventMap ); |
246 | retDate.setExtraMap( requestCustom( uid ) ); | 248 | retDate.setExtraMap( requestCustom( uid ) ); |
247 | 249 | ||
248 | qDebug( "ODateBookAccessBackend_SQL::find() end", uid ); | 250 | qDebug( "ODateBookAccessBackend_SQL::find( %d ) end", uid ); |
249 | return retDate; | 251 | return retDate; |
250 | } | 252 | } |
251 | 253 | ||
252 | // FIXME: Speed up update of uid's.. | 254 | // FIXME: Speed up update of uid's.. |
253 | bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) | 255 | bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) |
254 | { | 256 | { |
255 | QMap<int,QString> eventMap = ev.toMap(); | 257 | QMap<int,QString> eventMap = ev.toMap(); |
256 | 258 | ||
257 | QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); | 259 | QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); |
258 | QMap<int, QString>::Iterator it; | 260 | QMap<int, QString>::Iterator it; |
259 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 261 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
260 | if ( !eventMap[it.key()].isEmpty() ) | 262 | if ( !eventMap[it.key()].isEmpty() ) |
261 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); | 263 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); |
262 | else | 264 | else |
263 | qu += QString( ",\"\"" ); | 265 | qu += QString( ",\"\"" ); |
264 | } | 266 | } |
265 | qu += " );"; | 267 | qu += " );"; |
266 | 268 | ||
267 | // Add custom entries | 269 | // Add custom entries |
268 | int id = 0; | 270 | int id = 0; |
269 | QMap<QString, QString> customMap = ev.toExtraMap(); | 271 | QMap<QString, QString> customMap = ev.toExtraMap(); |
270 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 272 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
271 | it != customMap.end(); ++it ){ | 273 | it != customMap.end(); ++it ){ |
272 | qu += "insert into custom_data VALUES(" | 274 | qu += "insert into custom_data VALUES(" |
273 | + QString::number( ev.uid() ) | 275 | + QString::number( ev.uid() ) |
274 | + "," | 276 | + "," |
275 | + QString::number( id++ ) | 277 | + QString::number( id++ ) |
276 | + ",'" | 278 | + ",'" |
277 | + it.key() //.latin1() | 279 | + it.key() //.latin1() |
278 | + "'," | 280 | + "'," |
279 | + "0" // Priority for future enhancements | 281 | + "0" // Priority for future enhancements |
280 | + ",'" | 282 | + ",'" |
281 | + it.data() //.latin1() | 283 | + it.data() //.latin1() |
282 | + "');"; | 284 | + "');"; |
283 | } | 285 | } |
284 | qWarning("add %s", qu.latin1() ); | 286 | qWarning("add %s", qu.latin1() ); |
285 | 287 | ||
286 | OSQLRawQuery raw( qu ); | 288 | OSQLRawQuery raw( qu ); |
287 | OSQLResult res = m_driver->query( &raw ); | 289 | OSQLResult res = m_driver->query( &raw ); |
288 | if ( res.state() != OSQLResult::Success ){ | 290 | if ( res.state() != OSQLResult::Success ){ |
289 | return false; | 291 | return false; |
290 | } | 292 | } |
291 | 293 | ||
292 | // Update list of uid's | 294 | // Update list of uid's |
293 | update(); | 295 | update(); |
294 | 296 | ||
295 | return true; | 297 | return true; |
296 | } | 298 | } |