author | eilers <eilers> | 2004-08-29 12:48:43 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-08-29 12:48:43 (UTC) |
commit | 45327ef3c0f093fc227682f79158632afc09e6d1 (patch) (unidiff) | |
tree | bdfe4e602abcef87117528d2c9c4166820488d11 | |
parent | dd159675e6e3c361bc20eaa6994265e73b6599ef (diff) | |
download | opie-45327ef3c0f093fc227682f79158632afc09e6d1.zip opie-45327ef3c0f093fc227682f79158632afc09e6d1.tar.gz opie-45327ef3c0f093fc227682f79158632afc09e6d1.tar.bz2 |
Fixed some quirks..
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 6f65c48..12a8bea 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -76,802 +76,807 @@ namespace { | |||
76 | */ | 76 | */ |
77 | class LoadQuery : public OSQLQuery { | 77 | class LoadQuery : public OSQLQuery { |
78 | public: | 78 | public: |
79 | LoadQuery(); | 79 | LoadQuery(); |
80 | ~LoadQuery(); | 80 | ~LoadQuery(); |
81 | QString query()const; | 81 | QString query()const; |
82 | }; | 82 | }; |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * inserts/adds a OPimTodo to the table | 85 | * inserts/adds a OPimTodo to the table |
86 | */ | 86 | */ |
87 | class InsertQuery : public OSQLQuery { | 87 | class InsertQuery : public OSQLQuery { |
88 | public: | 88 | public: |
89 | InsertQuery(const OPimTodo& ); | 89 | InsertQuery(const OPimTodo& ); |
90 | ~InsertQuery(); | 90 | ~InsertQuery(); |
91 | QString query()const; | 91 | QString query()const; |
92 | private: | 92 | private: |
93 | OPimTodo m_todo; | 93 | OPimTodo m_todo; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * removes one from the table | 97 | * removes one from the table |
98 | */ | 98 | */ |
99 | class RemoveQuery : public OSQLQuery { | 99 | class RemoveQuery : public OSQLQuery { |
100 | public: | 100 | public: |
101 | RemoveQuery(int uid ); | 101 | RemoveQuery(int uid ); |
102 | ~RemoveQuery(); | 102 | ~RemoveQuery(); |
103 | QString query()const; | 103 | QString query()const; |
104 | private: | 104 | private: |
105 | int m_uid; | 105 | int m_uid; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Clears (delete) a Table | 109 | * Clears (delete) a Table |
110 | */ | 110 | */ |
111 | class ClearQuery : public OSQLQuery { | 111 | class ClearQuery : public OSQLQuery { |
112 | public: | 112 | public: |
113 | ClearQuery(); | 113 | ClearQuery(); |
114 | ~ClearQuery(); | 114 | ~ClearQuery(); |
115 | QString query()const; | 115 | QString query()const; |
116 | 116 | ||
117 | }; | 117 | }; |
118 | 118 | ||
119 | /** | 119 | /** |
120 | * a find query | 120 | * a find query |
121 | */ | 121 | */ |
122 | class FindQuery : public OSQLQuery { | 122 | class FindQuery : public OSQLQuery { |
123 | public: | 123 | public: |
124 | FindQuery(int uid); | 124 | FindQuery(int uid); |
125 | FindQuery(const QArray<int>& ); | 125 | FindQuery(const QArray<int>& ); |
126 | ~FindQuery(); | 126 | ~FindQuery(); |
127 | QString query()const; | 127 | QString query()const; |
128 | private: | 128 | private: |
129 | QString single()const; | 129 | QString single()const; |
130 | QString multi()const; | 130 | QString multi()const; |
131 | QArray<int> m_uids; | 131 | QArray<int> m_uids; |
132 | int m_uid; | 132 | int m_uid; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * overdue query | 136 | * overdue query |
137 | */ | 137 | */ |
138 | class OverDueQuery : public OSQLQuery { | 138 | class OverDueQuery : public OSQLQuery { |
139 | public: | 139 | public: |
140 | OverDueQuery(); | 140 | OverDueQuery(); |
141 | ~OverDueQuery(); | 141 | ~OverDueQuery(); |
142 | QString query()const; | 142 | QString query()const; |
143 | }; | 143 | }; |
144 | class EffQuery : public OSQLQuery { | 144 | class EffQuery : public OSQLQuery { |
145 | public: | 145 | public: |
146 | EffQuery( const QDate&, const QDate&, bool inc ); | 146 | EffQuery( const QDate&, const QDate&, bool inc ); |
147 | ~EffQuery(); | 147 | ~EffQuery(); |
148 | QString query()const; | 148 | QString query()const; |
149 | private: | 149 | private: |
150 | QString with()const; | 150 | QString with()const; |
151 | QString out()const; | 151 | QString out()const; |
152 | QDate m_start; | 152 | QDate m_start; |
153 | QDate m_end; | 153 | QDate m_end; |
154 | bool m_inc :1; | 154 | bool m_inc :1; |
155 | }; | 155 | }; |
156 | 156 | ||
157 | 157 | ||
158 | /** | 158 | /** |
159 | * a find query for custom elements | 159 | * a find query for custom elements |
160 | */ | 160 | */ |
161 | class FindCustomQuery : public OSQLQuery { | 161 | class FindCustomQuery : public OSQLQuery { |
162 | public: | 162 | public: |
163 | FindCustomQuery(int uid); | 163 | FindCustomQuery(int uid); |
164 | FindCustomQuery(const QArray<int>& ); | 164 | FindCustomQuery(const QArray<int>& ); |
165 | ~FindCustomQuery(); | 165 | ~FindCustomQuery(); |
166 | QString query()const; | 166 | QString query()const; |
167 | private: | 167 | private: |
168 | QString single()const; | 168 | QString single()const; |
169 | QString multi()const; | 169 | QString multi()const; |
170 | QArray<int> m_uids; | 170 | QArray<int> m_uids; |
171 | int m_uid; | 171 | int m_uid; |
172 | }; | 172 | }; |
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | CreateQuery::CreateQuery() : OSQLQuery() {} | 176 | CreateQuery::CreateQuery() : OSQLQuery() {} |
177 | CreateQuery::~CreateQuery() {} | 177 | CreateQuery::~CreateQuery() {} |
178 | QString CreateQuery::query()const { | 178 | QString CreateQuery::query()const { |
179 | QString qu; | 179 | QString qu; |
180 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; | 180 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
181 | qu += "description, summary, priority, DueDate, progress , state, "; | 181 | qu += "description, summary, priority, DueDate, progress , state, "; |
182 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) | 182 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) |
183 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; | 183 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; |
184 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; | 184 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; |
185 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 185 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
186 | return qu; | 186 | return qu; |
187 | } | 187 | } |
188 | 188 | ||
189 | LoadQuery::LoadQuery() : OSQLQuery() {} | 189 | LoadQuery::LoadQuery() : OSQLQuery() {} |
190 | LoadQuery::~LoadQuery() {} | 190 | LoadQuery::~LoadQuery() {} |
191 | QString LoadQuery::query()const { | 191 | QString LoadQuery::query()const { |
192 | QString qu; | 192 | QString qu; |
193 | // We do not need "distinct" here. The primary key is always unique.. | 193 | // We do not need "distinct" here. The primary key is always unique.. |
194 | //qu += "select distinct uid from todolist"; | 194 | //qu += "select distinct uid from todolist"; |
195 | qu += "select uid from todolist"; | 195 | qu += "select uid from todolist"; |
196 | 196 | ||
197 | return qu; | 197 | return qu; |
198 | } | 198 | } |
199 | 199 | ||
200 | InsertQuery::InsertQuery( const OPimTodo& todo ) | 200 | InsertQuery::InsertQuery( const OPimTodo& todo ) |
201 | : OSQLQuery(), m_todo( todo ) { | 201 | : OSQLQuery(), m_todo( todo ) { |
202 | } | 202 | } |
203 | InsertQuery::~InsertQuery() { | 203 | InsertQuery::~InsertQuery() { |
204 | } | 204 | } |
205 | /* | 205 | /* |
206 | * converts from a OPimTodo to a query | 206 | * converts from a OPimTodo to a query |
207 | * we leave out X-Ref + Maintainer | 207 | * we leave out X-Ref + Maintainer |
208 | * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding | 208 | * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding |
209 | * decoding stuff there.. (eilers) | 209 | * decoding stuff there.. (eilers) |
210 | */ | 210 | */ |
211 | QString InsertQuery::query()const{ | 211 | QString InsertQuery::query()const{ |
212 | 212 | ||
213 | int year, month, day; | 213 | int year, month, day; |
214 | year = month = day = 0; | 214 | year = month = day = 0; |
215 | if (m_todo.hasDueDate() ) { | 215 | if (m_todo.hasDueDate() ) { |
216 | QDate date = m_todo.dueDate(); | 216 | QDate date = m_todo.dueDate(); |
217 | year = date.year(); | 217 | year = date.year(); |
218 | month = date.month(); | 218 | month = date.month(); |
219 | day = date.day(); | 219 | day = date.day(); |
220 | } | 220 | } |
221 | int sYear = 0, sMonth = 0, sDay = 0; | 221 | int sYear = 0, sMonth = 0, sDay = 0; |
222 | if( m_todo.hasStartDate() ){ | 222 | if( m_todo.hasStartDate() ){ |
223 | QDate sDate = m_todo.startDate(); | 223 | QDate sDate = m_todo.startDate(); |
224 | sYear = sDate.year(); | 224 | sYear = sDate.year(); |
225 | sMonth= sDate.month(); | 225 | sMonth= sDate.month(); |
226 | sDay = sDate.day(); | 226 | sDay = sDate.day(); |
227 | } | 227 | } |
228 | 228 | ||
229 | int eYear = 0, eMonth = 0, eDay = 0; | 229 | int eYear = 0, eMonth = 0, eDay = 0; |
230 | if( m_todo.hasCompletedDate() ){ | 230 | if( m_todo.hasCompletedDate() ){ |
231 | QDate eDate = m_todo.completedDate(); | 231 | QDate eDate = m_todo.completedDate(); |
232 | eYear = eDate.year(); | 232 | eYear = eDate.year(); |
233 | eMonth= eDate.month(); | 233 | eMonth= eDate.month(); |
234 | eDay = eDate.day(); | 234 | eDay = eDate.day(); |
235 | } | 235 | } |
236 | QString qu; | 236 | QString qu; |
237 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); | 237 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); |
238 | qu = "insert into todolist VALUES(" | 238 | qu = "insert into todolist VALUES(" |
239 | + QString::number( m_todo.uid() ) + "," | 239 | + QString::number( m_todo.uid() ) + "," |
240 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," | 240 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
241 | + QString::number( m_todo.isCompleted() ) + "," | 241 | + QString::number( m_todo.isCompleted() ) + "," |
242 | + "'" + m_todo.description() + "'" + "," | 242 | + "'" + m_todo.description() + "'" + "," |
243 | + "'" + m_todo.summary() + "'" + "," | 243 | + "'" + m_todo.summary() + "'" + "," |
244 | + QString::number(m_todo.priority() ) + "," | 244 | + QString::number(m_todo.priority() ) + "," |
245 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" | 245 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" |
246 | + QString::number(month).rightJustify( 2, '0' ) | 246 | + QString::number(month).rightJustify( 2, '0' ) |
247 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," | 247 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," |
248 | + QString::number( m_todo.progress() ) + "," | 248 | + QString::number( m_todo.progress() ) + "," |
249 | + QString::number( m_todo.state().state() ) + "," | 249 | + QString::number( m_todo.state().state() ) + "," |
250 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," | 250 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," |
251 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," | 251 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," |
252 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," | 252 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," |
253 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," | 253 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," |
254 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," | 254 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," |
255 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," | 255 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," |
256 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," | 256 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," |
257 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; | 257 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; |
258 | 258 | ||
259 | if ( m_todo.hasNotifiers() ) { | 259 | if ( m_todo.hasNotifiers() ) { |
260 | OPimNotifyManager manager = m_todo.notifiers(); | 260 | OPimNotifyManager manager = m_todo.notifiers(); |
261 | qu += "'" + manager.remindersToString() + "'" + "," | 261 | qu += "'" + manager.remindersToString() + "'" + "," |
262 | + "'" + manager.alarmsToString() + "'" + ","; | 262 | + "'" + manager.alarmsToString() + "'" + ","; |
263 | } | 263 | } |
264 | else{ | 264 | else{ |
265 | qu += QString( "''" ) + "," | 265 | qu += QString( "''" ) + "," |
266 | + "''" + ","; | 266 | + "''" + ","; |
267 | } | 267 | } |
268 | 268 | ||
269 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) | 269 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) |
270 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" | 270 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" |
271 | + QString::number(sMonth).rightJustify( 2, '0' ) | 271 | + QString::number(sMonth).rightJustify( 2, '0' ) |
272 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," | 272 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," |
273 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" | 273 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" |
274 | + QString::number(eMonth).rightJustify( 2, '0' ) | 274 | + QString::number(eMonth).rightJustify( 2, '0' ) |
275 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" | 275 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" |
276 | + "); "; | 276 | + "); "; |
277 | 277 | ||
278 | // Save custom Entries: | 278 | // Save custom Entries: |
279 | int id = 0; | 279 | int id = 0; |
280 | id = 0; | 280 | id = 0; |
281 | QMap<QString, QString> customMap = m_todo.toExtraMap(); | 281 | QMap<QString, QString> customMap = m_todo.toExtraMap(); |
282 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 282 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
283 | it != customMap.end(); ++it ){ | 283 | it != customMap.end(); ++it ){ |
284 | qu += "insert into custom_data VALUES(" | 284 | qu += "insert into custom_data VALUES(" |
285 | + QString::number( m_todo.uid() ) | 285 | + QString::number( m_todo.uid() ) |
286 | + "," | 286 | + "," |
287 | + QString::number( id++ ) | 287 | + QString::number( id++ ) |
288 | + ",'" | 288 | + ",'" |
289 | + it.key() | 289 | + it.key() |
290 | + "'," | 290 | + "'," |
291 | + "0" // Priority for future enhancements | 291 | + "0" // Priority for future enhancements |
292 | + ",'" | 292 | + ",'" |
293 | + it.data() | 293 | + it.data() |
294 | + "');"; | 294 | + "');"; |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
298 | odebug << "add " << qu << "" << oendl; | 298 | odebug << "add " << qu << "" << oendl; |
299 | return qu; | 299 | return qu; |
300 | } | 300 | } |
301 | 301 | ||
302 | RemoveQuery::RemoveQuery(int uid ) | 302 | RemoveQuery::RemoveQuery(int uid ) |
303 | : OSQLQuery(), m_uid( uid ) {} | 303 | : OSQLQuery(), m_uid( uid ) {} |
304 | RemoveQuery::~RemoveQuery() {} | 304 | RemoveQuery::~RemoveQuery() {} |
305 | QString RemoveQuery::query()const { | 305 | QString RemoveQuery::query()const { |
306 | QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; | 306 | QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; |
307 | qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); | 307 | qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); |
308 | return qu; | 308 | return qu; |
309 | } | 309 | } |
310 | 310 | ||
311 | 311 | ||
312 | ClearQuery::ClearQuery() | 312 | ClearQuery::ClearQuery() |
313 | : OSQLQuery() {} | 313 | : OSQLQuery() {} |
314 | ClearQuery::~ClearQuery() {} | 314 | ClearQuery::~ClearQuery() {} |
315 | QString ClearQuery::query()const { | 315 | QString ClearQuery::query()const { |
316 | QString qu = "drop table todolist"; | 316 | QString qu = "drop table todolist"; |
317 | return qu; | 317 | return qu; |
318 | } | 318 | } |
319 | FindQuery::FindQuery(int uid) | 319 | FindQuery::FindQuery(int uid) |
320 | : OSQLQuery(), m_uid(uid ) { | 320 | : OSQLQuery(), m_uid(uid ) { |
321 | } | 321 | } |
322 | FindQuery::FindQuery(const QArray<int>& ints) | 322 | FindQuery::FindQuery(const QArray<int>& ints) |
323 | : OSQLQuery(), m_uids(ints){ | 323 | : OSQLQuery(), m_uids(ints){ |
324 | } | 324 | } |
325 | FindQuery::~FindQuery() { | 325 | FindQuery::~FindQuery() { |
326 | } | 326 | } |
327 | QString FindQuery::query()const{ | 327 | QString FindQuery::query()const{ |
328 | if (m_uids.count() == 0 ) | 328 | if (m_uids.count() == 0 ) |
329 | return single(); | 329 | return single(); |
330 | else | 330 | else |
331 | return multi(); | 331 | return multi(); |
332 | } | 332 | } |
333 | QString FindQuery::single()const{ | 333 | QString FindQuery::single()const{ |
334 | QString qu = "select * from todolist where uid = " + QString::number(m_uid); | 334 | QString qu = "select * from todolist where uid = " + QString::number(m_uid); |
335 | return qu; | 335 | return qu; |
336 | } | 336 | } |
337 | QString FindQuery::multi()const { | 337 | QString FindQuery::multi()const { |
338 | QString qu = "select * from todolist where "; | 338 | QString qu = "select * from todolist where "; |
339 | for (uint i = 0; i < m_uids.count(); i++ ) { | 339 | for (uint i = 0; i < m_uids.count(); i++ ) { |
340 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 340 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
341 | } | 341 | } |
342 | qu.remove( qu.length()-2, 2 ); | 342 | qu.remove( qu.length()-2, 2 ); |
343 | return qu; | 343 | return qu; |
344 | } | 344 | } |
345 | 345 | ||
346 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 346 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
347 | OverDueQuery::~OverDueQuery() {} | 347 | OverDueQuery::~OverDueQuery() {} |
348 | QString OverDueQuery::query()const { | 348 | QString OverDueQuery::query()const { |
349 | QDate date = QDate::currentDate(); | 349 | QDate date = QDate::currentDate(); |
350 | QString str; | 350 | QString str; |
351 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'") | 351 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'") |
352 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | 352 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) |
353 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | 353 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) |
354 | .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); | 354 | .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); |
355 | 355 | ||
356 | return str; | 356 | return str; |
357 | } | 357 | } |
358 | 358 | ||
359 | 359 | ||
360 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 360 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
361 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 361 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
362 | EffQuery::~EffQuery() {} | 362 | EffQuery::~EffQuery() {} |
363 | QString EffQuery::query()const { | 363 | QString EffQuery::query()const { |
364 | return m_inc ? with() : out(); | 364 | return m_inc ? with() : out(); |
365 | } | 365 | } |
366 | QString EffQuery::with()const { | 366 | QString EffQuery::with()const { |
367 | QString str; | 367 | QString str; |
368 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 368 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
369 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) | 369 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
370 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) | 370 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
371 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | 371 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) |
372 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | 372 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) |
373 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | 373 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) |
374 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | 374 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); |
375 | return str; | 375 | return str; |
376 | } | 376 | } |
377 | QString EffQuery::out()const { | 377 | QString EffQuery::out()const { |
378 | QString str; | 378 | QString str; |
379 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 379 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
380 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) | 380 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
381 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) | 381 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
382 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | 382 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) |
383 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | 383 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) |
384 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | 384 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) |
385 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | 385 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); |
386 | 386 | ||
387 | return str; | 387 | return str; |
388 | } | 388 | } |
389 | 389 | ||
390 | FindCustomQuery::FindCustomQuery(int uid) | 390 | FindCustomQuery::FindCustomQuery(int uid) |
391 | : OSQLQuery(), m_uid( uid ) { | 391 | : OSQLQuery(), m_uid( uid ) { |
392 | } | 392 | } |
393 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) | 393 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) |
394 | : OSQLQuery(), m_uids( ints ){ | 394 | : OSQLQuery(), m_uids( ints ){ |
395 | } | 395 | } |
396 | FindCustomQuery::~FindCustomQuery() { | 396 | FindCustomQuery::~FindCustomQuery() { |
397 | } | 397 | } |
398 | QString FindCustomQuery::query()const{ | 398 | QString FindCustomQuery::query()const{ |
399 | return single(); // Multiple requests not supported ! | 399 | return single(); // Multiple requests not supported ! |
400 | } | 400 | } |
401 | QString FindCustomQuery::single()const{ | 401 | QString FindCustomQuery::single()const{ |
402 | QString qu = "select uid, type, value from custom_data where uid = "; | 402 | QString qu = "select uid, type, value from custom_data where uid = "; |
403 | qu += QString::number(m_uid); | 403 | qu += QString::number(m_uid); |
404 | return qu; | 404 | return qu; |
405 | } | 405 | } |
406 | 406 | ||
407 | }; | 407 | }; |
408 | 408 | ||
409 | 409 | ||
410 | namespace Opie { | 410 | namespace Opie { |
411 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) | 411 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) |
412 | : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) | 412 | : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) |
413 | { | 413 | { |
414 | QString fi = file; | 414 | QString fi = file; |
415 | if ( fi.isEmpty() ) | 415 | if ( fi.isEmpty() ) |
416 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 416 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
417 | OSQLManager man; | 417 | OSQLManager man; |
418 | m_driver = man.standard(); | 418 | m_driver = man.standard(); |
419 | m_driver->setUrl(fi); | 419 | m_driver->setUrl(fi); |
420 | // fillDict(); | 420 | // fillDict(); |
421 | } | 421 | } |
422 | 422 | ||
423 | OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ | 423 | OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ |
424 | if( m_driver ) | 424 | if( m_driver ) |
425 | delete m_driver; | 425 | delete m_driver; |
426 | } | 426 | } |
427 | 427 | ||
428 | bool OPimTodoAccessBackendSQL::load(){ | 428 | bool OPimTodoAccessBackendSQL::load(){ |
429 | if (!m_driver->open() ) | 429 | if (!m_driver->open() ) |
430 | return false; | 430 | return false; |
431 | 431 | ||
432 | CreateQuery creat; | 432 | CreateQuery creat; |
433 | OSQLResult res = m_driver->query(&creat ); | 433 | OSQLResult res = m_driver->query(&creat ); |
434 | 434 | ||
435 | m_dirty = true; | 435 | m_dirty = true; |
436 | return true; | 436 | return true; |
437 | } | 437 | } |
438 | bool OPimTodoAccessBackendSQL::reload(){ | 438 | bool OPimTodoAccessBackendSQL::reload(){ |
439 | return load(); | 439 | return load(); |
440 | } | 440 | } |
441 | 441 | ||
442 | bool OPimTodoAccessBackendSQL::save(){ | 442 | bool OPimTodoAccessBackendSQL::save(){ |
443 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 443 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
444 | } | 444 | } |
445 | QArray<int> OPimTodoAccessBackendSQL::allRecords()const { | 445 | QArray<int> OPimTodoAccessBackendSQL::allRecords()const { |
446 | if (m_dirty ) | 446 | if (m_dirty ) |
447 | update(); | 447 | update(); |
448 | 448 | ||
449 | return m_uids; | 449 | return m_uids; |
450 | } | 450 | } |
451 | QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ | 451 | QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ |
452 | QArray<int> ints(0); | 452 | QArray<int> ints(0); |
453 | return ints; | 453 | return ints; |
454 | } | 454 | } |
455 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ | 455 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ |
456 | FindQuery query( uid ); | 456 | FindQuery query( uid ); |
457 | return todo( m_driver->query(&query) ); | 457 | return todo( m_driver->query(&query) ); |
458 | 458 | ||
459 | } | 459 | } |
460 | |||
461 | // Remember: uid is already in the list of uids, called ints ! | ||
460 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 462 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
461 | uint cur, Frontend::CacheDirection dir ) const{ | 463 | uint cur, Frontend::CacheDirection dir ) const{ |
462 | uint CACHE = readAhead(); | 464 | uint CACHE = readAhead(); |
463 | odebug << "searching for " << uid << "" << oendl; | 465 | odebug << "searching for " << uid << "" << oendl; |
464 | QArray<int> search( CACHE ); | 466 | QArray<int> search( CACHE ); |
465 | uint size =0; | 467 | uint size =0; |
466 | OPimTodo to; | 468 | OPimTodo to; |
467 | 469 | ||
468 | // we try to cache CACHE items | 470 | // we try to cache CACHE items |
469 | switch( dir ) { | 471 | switch( dir ) { |
470 | /* forward */ | 472 | /* forward */ |
471 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) | 473 | case Frontend::Forward: |
472 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 474 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
473 | odebug << "size " << size << " " << ints[i] << "" << oendl; | 475 | odebug << "size " << size << " " << ints[i] << "" << oendl; |
474 | search[size] = ints[i]; | 476 | search[size] = ints[i]; |
475 | size++; | 477 | size++; |
476 | } | 478 | } |
477 | break; | 479 | break; |
478 | /* reverse */ | 480 | /* reverse */ |
479 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) | 481 | case Frontend::Reverse: |
480 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 482 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
481 | search[size] = ints[i]; | 483 | search[size] = ints[i]; |
482 | size++; | 484 | size++; |
483 | } | 485 | } |
484 | break; | 486 | break; |
485 | } | 487 | } |
488 | |||
486 | search.resize( size ); | 489 | search.resize( size ); |
487 | FindQuery query( search ); | 490 | FindQuery query( search ); |
488 | OSQLResult res = m_driver->query( &query ); | 491 | OSQLResult res = m_driver->query( &query ); |
489 | if ( res.state() != OSQLResult::Success ) | 492 | if ( res.state() != OSQLResult::Success ) |
490 | return to; | 493 | return to; |
491 | 494 | ||
492 | return todo( res ); | 495 | todo( res ); //FIXME: Don't like polymorphism here. It makes the code hard to read here..(eilers) |
496 | return cacheFind( uid ); | ||
493 | } | 497 | } |
498 | |||
494 | void OPimTodoAccessBackendSQL::clear() { | 499 | void OPimTodoAccessBackendSQL::clear() { |
495 | ClearQuery cle; | 500 | ClearQuery cle; |
496 | OSQLResult res = m_driver->query( &cle ); | 501 | OSQLResult res = m_driver->query( &cle ); |
497 | CreateQuery qu; | 502 | CreateQuery qu; |
498 | res = m_driver->query(&qu); | 503 | res = m_driver->query(&qu); |
499 | } | 504 | } |
500 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { | 505 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { |
501 | InsertQuery ins( t ); | 506 | InsertQuery ins( t ); |
502 | OSQLResult res = m_driver->query( &ins ); | 507 | OSQLResult res = m_driver->query( &ins ); |
503 | 508 | ||
504 | if ( res.state() == OSQLResult::Failure ) | 509 | if ( res.state() == OSQLResult::Failure ) |
505 | return false; | 510 | return false; |
506 | int c = m_uids.count(); | 511 | int c = m_uids.count(); |
507 | m_uids.resize( c+1 ); | 512 | m_uids.resize( c+1 ); |
508 | m_uids[c] = t.uid(); | 513 | m_uids[c] = t.uid(); |
509 | 514 | ||
510 | return true; | 515 | return true; |
511 | } | 516 | } |
512 | bool OPimTodoAccessBackendSQL::remove( int uid ) { | 517 | bool OPimTodoAccessBackendSQL::remove( int uid ) { |
513 | RemoveQuery rem( uid ); | 518 | RemoveQuery rem( uid ); |
514 | OSQLResult res = m_driver->query(&rem ); | 519 | OSQLResult res = m_driver->query(&rem ); |
515 | 520 | ||
516 | if ( res.state() == OSQLResult::Failure ) | 521 | if ( res.state() == OSQLResult::Failure ) |
517 | return false; | 522 | return false; |
518 | 523 | ||
519 | m_dirty = true; | 524 | m_dirty = true; |
520 | return true; | 525 | return true; |
521 | } | 526 | } |
522 | /* | 527 | /* |
523 | * FIXME better set query | 528 | * FIXME better set query |
524 | * but we need the cache for that | 529 | * but we need the cache for that |
525 | * now we remove | 530 | * now we remove |
526 | */ | 531 | */ |
527 | bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { | 532 | bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { |
528 | remove( t.uid() ); | 533 | remove( t.uid() ); |
529 | bool b= add(t); | 534 | bool b= add(t); |
530 | m_dirty = false; // we changed some stuff but the UID stayed the same | 535 | m_dirty = false; // we changed some stuff but the UID stayed the same |
531 | return b; | 536 | return b; |
532 | } | 537 | } |
533 | QArray<int> OPimTodoAccessBackendSQL::overDue() { | 538 | QArray<int> OPimTodoAccessBackendSQL::overDue() { |
534 | OverDueQuery qu; | 539 | OverDueQuery qu; |
535 | return uids( m_driver->query(&qu ) ); | 540 | return uids( m_driver->query(&qu ) ); |
536 | } | 541 | } |
537 | QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 542 | QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
538 | const QDate& t, | 543 | const QDate& t, |
539 | bool u) { | 544 | bool u) { |
540 | EffQuery ef(s, t, u ); | 545 | EffQuery ef(s, t, u ); |
541 | return uids (m_driver->query(&ef) ); | 546 | return uids (m_driver->query(&ef) ); |
542 | } | 547 | } |
543 | /* | 548 | /* |
544 | * | 549 | * |
545 | */ | 550 | */ |
546 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 551 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
547 | int sortFilter, int cat ) { | 552 | int sortFilter, int cat ) { |
548 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; | 553 | odebug << "sorted " << asc << ", " << sortOrder << "" << oendl; |
549 | QString query; | 554 | QString query; |
550 | query = "select uid from todolist WHERE "; | 555 | query = "select uid from todolist WHERE "; |
551 | 556 | ||
552 | /* | 557 | /* |
553 | * Sort Filter stuff | 558 | * Sort Filter stuff |
554 | * not that straight forward | 559 | * not that straight forward |
555 | * FIXME: Replace magic numbers | 560 | * FIXME: Replace magic numbers |
556 | * | 561 | * |
557 | */ | 562 | */ |
558 | /* Category */ | 563 | /* Category */ |
559 | if ( sortFilter & 1 ) { | 564 | if ( sortFilter & 1 ) { |
560 | QString str; | 565 | QString str; |
561 | if (cat != 0 ) str = QString::number( cat ); | 566 | if (cat != 0 ) str = QString::number( cat ); |
562 | query += " categories like '%" +str+"%' AND"; | 567 | query += " categories like '%" +str+"%' AND"; |
563 | } | 568 | } |
564 | /* Show only overdue */ | 569 | /* Show only overdue */ |
565 | if ( sortFilter & 2 ) { | 570 | if ( sortFilter & 2 ) { |
566 | QDate date = QDate::currentDate(); | 571 | QDate date = QDate::currentDate(); |
567 | QString due; | 572 | QString due; |
568 | QString base; | 573 | QString base; |
569 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") | 574 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") |
570 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | 575 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) |
571 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | 576 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) |
572 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); | 577 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); |
573 | query += " " + base + " AND"; | 578 | query += " " + base + " AND"; |
574 | } | 579 | } |
575 | /* not show completed */ | 580 | /* not show completed */ |
576 | if ( sortFilter & 4 ) { | 581 | if ( sortFilter & 4 ) { |
577 | query += " completed = 0 AND"; | 582 | query += " completed = 0 AND"; |
578 | }else{ | 583 | }else{ |
579 | query += " ( completed = 1 OR completed = 0) AND"; | 584 | query += " ( completed = 1 OR completed = 0) AND"; |
580 | } | 585 | } |
581 | /* strip the end */ | 586 | /* strip the end */ |
582 | query = query.remove( query.length()-3, 3 ); | 587 | query = query.remove( query.length()-3, 3 ); |
583 | 588 | ||
584 | 589 | ||
585 | /* | 590 | /* |
586 | * sort order stuff | 591 | * sort order stuff |
587 | * quite straight forward | 592 | * quite straight forward |
588 | */ | 593 | */ |
589 | query += "ORDER BY "; | 594 | query += "ORDER BY "; |
590 | switch( sortOrder ) { | 595 | switch( sortOrder ) { |
591 | /* completed */ | 596 | /* completed */ |
592 | case 0: | 597 | case 0: |
593 | query += "completed"; | 598 | query += "completed"; |
594 | break; | 599 | break; |
595 | case 1: | 600 | case 1: |
596 | query += "priority"; | 601 | query += "priority"; |
597 | break; | 602 | break; |
598 | case 2: | 603 | case 2: |
599 | query += "summary"; | 604 | query += "summary"; |
600 | break; | 605 | break; |
601 | case 3: | 606 | case 3: |
602 | query += "DueDate"; | 607 | query += "DueDate"; |
603 | break; | 608 | break; |
604 | } | 609 | } |
605 | 610 | ||
606 | if ( !asc ) { | 611 | if ( !asc ) { |
607 | odebug << "not ascending!" << oendl; | 612 | odebug << "not ascending!" << oendl; |
608 | query += " DESC"; | 613 | query += " DESC"; |
609 | } | 614 | } |
610 | 615 | ||
611 | odebug << query << oendl; | 616 | odebug << query << oendl; |
612 | OSQLRawQuery raw(query ); | 617 | OSQLRawQuery raw(query ); |
613 | return uids( m_driver->query(&raw) ); | 618 | return uids( m_driver->query(&raw) ); |
614 | } | 619 | } |
615 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 620 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
616 | if ( str == "0-0-0" ) | 621 | if ( str == "0-0-0" ) |
617 | return false; | 622 | return false; |
618 | else{ | 623 | else{ |
619 | int day, year, month; | 624 | int day, year, month; |
620 | QStringList list = QStringList::split("-", str ); | 625 | QStringList list = QStringList::split("-", str ); |
621 | year = list[0].toInt(); | 626 | year = list[0].toInt(); |
622 | month = list[1].toInt(); | 627 | month = list[1].toInt(); |
623 | day = list[2].toInt(); | 628 | day = list[2].toInt(); |
624 | da.setYMD( year, month, day ); | 629 | da.setYMD( year, month, day ); |
625 | return true; | 630 | return true; |
626 | } | 631 | } |
627 | } | 632 | } |
628 | OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ | 633 | OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ |
629 | if ( res.state() == OSQLResult::Failure ) { | 634 | if ( res.state() == OSQLResult::Failure ) { |
630 | OPimTodo to; | 635 | OPimTodo to; |
631 | return to; | 636 | return to; |
632 | } | 637 | } |
633 | 638 | ||
634 | OSQLResultItem::ValueList list = res.results(); | 639 | OSQLResultItem::ValueList list = res.results(); |
635 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 640 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
636 | odebug << "todo1" << oendl; | 641 | odebug << "todo1" << oendl; |
637 | OPimTodo to = todo( (*it) ); | 642 | OPimTodo to = todo( (*it) ); |
638 | cache( to ); | 643 | cache( to ); |
639 | ++it; | 644 | ++it; |
640 | 645 | ||
641 | for ( ; it != list.end(); ++it ) { | 646 | for ( ; it != list.end(); ++it ) { |
642 | odebug << "caching" << oendl; | 647 | odebug << "caching" << oendl; |
643 | cache( todo( (*it) ) ); | 648 | cache( todo( (*it) ) ); |
644 | } | 649 | } |
645 | return to; | 650 | return to; |
646 | } | 651 | } |
647 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 652 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
648 | odebug << "todo(ResultItem)" << oendl; | 653 | odebug << "todo(ResultItem)" << oendl; |
649 | 654 | ||
650 | // Request information from addressbook table and create the OPimTodo-object. | 655 | // Request information from addressbook table and create the OPimTodo-object. |
651 | 656 | ||
652 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 657 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
653 | hasDueDate = date( dueDate, item.data("DueDate") ); | 658 | hasDueDate = date( dueDate, item.data("DueDate") ); |
654 | QStringList cats = QStringList::split(";", item.data("categories") ); | 659 | QStringList cats = QStringList::split(";", item.data("categories") ); |
655 | 660 | ||
656 | odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; | 661 | odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl; |
657 | 662 | ||
658 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 663 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
659 | cats, item.data("summary"), item.data("description"), | 664 | cats, item.data("summary"), item.data("description"), |
660 | item.data("progress").toUShort(), hasDueDate, dueDate, | 665 | item.data("progress").toUShort(), hasDueDate, dueDate, |
661 | item.data("uid").toInt() ); | 666 | item.data("uid").toInt() ); |
662 | 667 | ||
663 | bool isOk; | 668 | bool isOk; |
664 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | 669 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); |
665 | if ( isOk ) | 670 | if ( isOk ) |
666 | to.setPriority( prioInt ); | 671 | to.setPriority( prioInt ); |
667 | 672 | ||
668 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | 673 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); |
669 | hasStartDate = date( startDate, item.data("startdate") ); | 674 | hasStartDate = date( startDate, item.data("startdate") ); |
670 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); | 675 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); |
671 | hasCompletedDate = date( completedDate, item.data("completeddate") ); | 676 | hasCompletedDate = date( completedDate, item.data("completeddate") ); |
672 | 677 | ||
673 | if ( hasStartDate ) | 678 | if ( hasStartDate ) |
674 | to.setStartDate( startDate ); | 679 | to.setStartDate( startDate ); |
675 | if ( hasCompletedDate ) | 680 | if ( hasCompletedDate ) |
676 | to.setCompletedDate( completedDate ); | 681 | to.setCompletedDate( completedDate ); |
677 | 682 | ||
678 | OPimNotifyManager& manager = to.notifiers(); | 683 | OPimNotifyManager& manager = to.notifiers(); |
679 | manager.alarmsFromString( item.data("alarms") ); | 684 | manager.alarmsFromString( item.data("alarms") ); |
680 | manager.remindersFromString( item.data("reminders") ); | 685 | manager.remindersFromString( item.data("reminders") ); |
681 | 686 | ||
682 | OPimState pimState; | 687 | OPimState pimState; |
683 | pimState.setState( QString( item.data("state") ).toInt() ); | 688 | pimState.setState( QString( item.data("state") ).toInt() ); |
684 | to.setState( pimState ); | 689 | to.setState( pimState ); |
685 | 690 | ||
686 | QMap<int, QString> recMap; | 691 | QMap<int, QString> recMap; |
687 | recMap.insert( OPimRecurrence::RType , item.data("RType") ); | 692 | recMap.insert( OPimRecurrence::RType , item.data("RType") ); |
688 | recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); | 693 | recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); |
689 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); | 694 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); |
690 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); | 695 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); |
691 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); | 696 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); |
692 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); | 697 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); |
693 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); | 698 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); |
694 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); | 699 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); |
695 | 700 | ||
696 | OPimRecurrence recur; | 701 | OPimRecurrence recur; |
697 | recur.fromMap( recMap ); | 702 | recur.fromMap( recMap ); |
698 | to.setRecurrence( recur ); | 703 | to.setRecurrence( recur ); |
699 | 704 | ||
700 | // Finally load the custom-entries for this UID and put it into the created object | 705 | // Finally load the custom-entries for this UID and put it into the created object |
701 | to.setExtraMap( requestCustom( to.uid() ) ); | 706 | to.setExtraMap( requestCustom( to.uid() ) ); |
702 | 707 | ||
703 | return to; | 708 | return to; |
704 | } | 709 | } |
705 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { | 710 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { |
706 | FindQuery find( uid ); | 711 | FindQuery find( uid ); |
707 | return todo( m_driver->query(&find) ); | 712 | return todo( m_driver->query(&find) ); |
708 | } | 713 | } |
709 | /* | 714 | /* |
710 | * update the dict | 715 | * update the dict |
711 | */ | 716 | */ |
712 | void OPimTodoAccessBackendSQL::fillDict() { | 717 | void OPimTodoAccessBackendSQL::fillDict() { |
713 | 718 | ||
714 | #if 0 | 719 | #if 0 |
715 | /* initialize dict */ | 720 | /* initialize dict */ |
716 | /* | 721 | /* |
717 | * UPDATE dict if you change anything!!! | 722 | * UPDATE dict if you change anything!!! |
718 | * FIXME: Isn't this dict obsolete ? (eilers) | 723 | * FIXME: Isn't this dict obsolete ? (eilers) |
719 | */ | 724 | */ |
720 | m_dict.setAutoDelete( TRUE ); | 725 | m_dict.setAutoDelete( TRUE ); |
721 | m_dict.insert("Categories" , new int(OPimTodo::Category) ); | 726 | m_dict.insert("Categories" , new int(OPimTodo::Category) ); |
722 | m_dict.insert("Uid" , new int(OPimTodo::Uid) ); | 727 | m_dict.insert("Uid" , new int(OPimTodo::Uid) ); |
723 | m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); | 728 | m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); |
724 | m_dict.insert("Completed" , new int(OPimTodo::Completed) ); | 729 | m_dict.insert("Completed" , new int(OPimTodo::Completed) ); |
725 | m_dict.insert("Description" , new int(OPimTodo::Description) ); | 730 | m_dict.insert("Description" , new int(OPimTodo::Description) ); |
726 | m_dict.insert("Summary" , new int(OPimTodo::Summary) ); | 731 | m_dict.insert("Summary" , new int(OPimTodo::Summary) ); |
727 | m_dict.insert("Priority" , new int(OPimTodo::Priority) ); | 732 | m_dict.insert("Priority" , new int(OPimTodo::Priority) ); |
728 | m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); | 733 | m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); |
729 | m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); | 734 | m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); |
730 | m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); | 735 | m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); |
731 | m_dict.insert("Progress" , new int(OPimTodo::Progress) ); | 736 | m_dict.insert("Progress" , new int(OPimTodo::Progress) ); |
732 | m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) | 737 | m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) |
733 | m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); | 738 | m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); |
734 | // m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) | 739 | // m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) |
735 | // m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) | 740 | // m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) |
736 | 741 | ||
737 | #endif | 742 | #endif |
738 | } | 743 | } |
739 | /* | 744 | /* |
740 | * need to be const so let's fool the | 745 | * need to be const so let's fool the |
741 | * compiler :( | 746 | * compiler :( |
742 | */ | 747 | */ |
743 | void OPimTodoAccessBackendSQL::update()const { | 748 | void OPimTodoAccessBackendSQL::update()const { |
744 | ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; | 749 | ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; |
745 | LoadQuery lo; | 750 | LoadQuery lo; |
746 | OSQLResult res = m_driver->query(&lo); | 751 | OSQLResult res = m_driver->query(&lo); |
747 | if ( res.state() != OSQLResult::Success ) | 752 | if ( res.state() != OSQLResult::Success ) |
748 | return; | 753 | return; |
749 | 754 | ||
750 | ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); | 755 | ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
751 | } | 756 | } |
752 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 757 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
753 | 758 | ||
754 | OSQLResultItem::ValueList list = res.results(); | 759 | OSQLResultItem::ValueList list = res.results(); |
755 | OSQLResultItem::ValueList::Iterator it; | 760 | OSQLResultItem::ValueList::Iterator it; |
756 | QArray<int> ints(list.count() ); | 761 | QArray<int> ints(list.count() ); |
757 | odebug << " count = " << list.count() << "" << oendl; | 762 | odebug << " count = " << list.count() << "" << oendl; |
758 | 763 | ||
759 | int i = 0; | 764 | int i = 0; |
760 | for (it = list.begin(); it != list.end(); ++it ) { | 765 | for (it = list.begin(); it != list.end(); ++it ) { |
761 | ints[i] = (*it).data("uid").toInt(); | 766 | ints[i] = (*it).data("uid").toInt(); |
762 | i++; | 767 | i++; |
763 | } | 768 | } |
764 | return ints; | 769 | return ints; |
765 | } | 770 | } |
766 | 771 | ||
767 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | 772 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const |
768 | { | 773 | { |
769 | 774 | ||
770 | #if 0 | 775 | #if 0 |
771 | QArray<int> empty; | 776 | QArray<int> empty; |
772 | return empty; | 777 | return empty; |
773 | 778 | ||
774 | #else | 779 | #else |
775 | QString qu = "SELECT uid FROM todolist WHERE ("; | 780 | QString qu = "SELECT uid FROM todolist WHERE ("; |
776 | 781 | ||
777 | // Do it make sense to search other fields, too ? | 782 | // Do it make sense to search other fields, too ? |
778 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; | 783 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; |
779 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; | 784 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; |
780 | 785 | ||
781 | qu += ")"; | 786 | qu += ")"; |
782 | 787 | ||
783 | odebug << "query: " << qu << "" << oendl; | 788 | odebug << "query: " << qu << "" << oendl; |
784 | 789 | ||
785 | OSQLRawQuery raw( qu ); | 790 | OSQLRawQuery raw( qu ); |
786 | OSQLResult res = m_driver->query( &raw ); | 791 | OSQLResult res = m_driver->query( &raw ); |
787 | 792 | ||
788 | return uids( res ); | 793 | return uids( res ); |
789 | 794 | ||
790 | 795 | ||
791 | #endif | 796 | #endif |
792 | 797 | ||
793 | } | 798 | } |
794 | QBitArray OPimTodoAccessBackendSQL::supports()const { | 799 | QBitArray OPimTodoAccessBackendSQL::supports()const { |
795 | 800 | ||
796 | return sup(); | 801 | return sup(); |
797 | } | 802 | } |
798 | 803 | ||
799 | QBitArray OPimTodoAccessBackendSQL::sup() const{ | 804 | QBitArray OPimTodoAccessBackendSQL::sup() const{ |
800 | 805 | ||
801 | QBitArray ar( OPimTodo::CompletedDate + 1 ); | 806 | QBitArray ar( OPimTodo::CompletedDate + 1 ); |
802 | ar.fill( true ); | 807 | ar.fill( true ); |
803 | ar[OPimTodo::CrossReference] = false; | 808 | ar[OPimTodo::CrossReference] = false; |
804 | ar[OPimTodo::State ] = false; | 809 | ar[OPimTodo::State ] = false; |
805 | ar[OPimTodo::Reminders] = false; | 810 | ar[OPimTodo::Reminders] = false; |
806 | ar[OPimTodo::Notifiers] = false; | 811 | ar[OPimTodo::Notifiers] = false; |
807 | ar[OPimTodo::Maintainer] = false; | 812 | ar[OPimTodo::Maintainer] = false; |
808 | 813 | ||
809 | return ar; | 814 | return ar; |
810 | } | 815 | } |
811 | 816 | ||
812 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ | 817 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
813 | // First we need the uids from all entries which are | 818 | // First we need the uids from all entries which are |
814 | // completed. Then, we just have to remove them... | 819 | // completed. Then, we just have to remove them... |
815 | 820 | ||
816 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; | 821 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; |
817 | 822 | ||
818 | OSQLRawQuery raw( qu ); | 823 | OSQLRawQuery raw( qu ); |
819 | OSQLResult res = m_driver->query( &raw ); | 824 | OSQLResult res = m_driver->query( &raw ); |
820 | 825 | ||
821 | QArray<int> completed_uids = uids( res ); | 826 | QArray<int> completed_uids = uids( res ); |
822 | 827 | ||
823 | odebug << "Number of completed: " << completed_uids.size() << "" << oendl; | 828 | odebug << "Number of completed: " << completed_uids.size() << "" << oendl; |
824 | 829 | ||
825 | if ( completed_uids.size() == 0 ) | 830 | if ( completed_uids.size() == 0 ) |
826 | return; | 831 | return; |
827 | 832 | ||
828 | qu = "DELETE FROM todolist WHERE ("; | 833 | qu = "DELETE FROM todolist WHERE ("; |
829 | QString query; | 834 | QString query; |
830 | 835 | ||
831 | for ( int i = 0; i < completed_uids.size(); i++ ){ | 836 | for ( int i = 0; i < completed_uids.size(); i++ ){ |
832 | if ( !query.isEmpty() ) | 837 | if ( !query.isEmpty() ) |
833 | query += " OR "; | 838 | query += " OR "; |
834 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | 839 | query += QString( "uid = %1" ).arg( completed_uids[i] ); |
835 | } | 840 | } |
836 | qu += query + " );"; | 841 | qu += query + " );"; |
837 | 842 | ||
838 | // Put remove of custom entries in this query to speed up.. | 843 | // Put remove of custom entries in this query to speed up.. |
839 | qu += "DELETE FORM custom_data WHERE ("; | 844 | qu += "DELETE FORM custom_data WHERE ("; |
840 | query = ""; | 845 | query = ""; |
841 | 846 | ||
842 | for ( int i = 0; i < completed_uids.size(); i++ ){ | 847 | for ( int i = 0; i < completed_uids.size(); i++ ){ |
843 | if ( !query.isEmpty() ) | 848 | if ( !query.isEmpty() ) |
844 | query += " OR "; | 849 | query += " OR "; |
845 | query += QString( "uid = %1" ).arg( completed_uids[i] ); | 850 | query += QString( "uid = %1" ).arg( completed_uids[i] ); |
846 | } | 851 | } |
847 | qu += query + " );"; | 852 | qu += query + " );"; |
848 | 853 | ||
849 | odebug << "query: " << qu << "" << oendl; | 854 | odebug << "query: " << qu << "" << oendl; |
850 | 855 | ||
851 | OSQLRawQuery raw2( qu ); | 856 | OSQLRawQuery raw2( qu ); |
852 | res = m_driver->query( &raw2 ); | 857 | res = m_driver->query( &raw2 ); |
853 | if ( res.state() == OSQLResult::Failure ) { | 858 | if ( res.state() == OSQLResult::Failure ) { |
854 | owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; | 859 | owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl; |
855 | } | 860 | } |
856 | } | 861 | } |
857 | 862 | ||
858 | 863 | ||
859 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const | 864 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const |
860 | { | 865 | { |
861 | QMap<QString, QString> customMap; | 866 | QMap<QString, QString> customMap; |
862 | 867 | ||
863 | FindCustomQuery query( uid ); | 868 | FindCustomQuery query( uid ); |
864 | OSQLResult res_custom = m_driver->query( &query ); | 869 | OSQLResult res_custom = m_driver->query( &query ); |
865 | 870 | ||
866 | if ( res_custom.state() == OSQLResult::Failure ) { | 871 | if ( res_custom.state() == OSQLResult::Failure ) { |
867 | owarn << "OSQLResult::Failure in find query !!" << oendl; | 872 | owarn << "OSQLResult::Failure in find query !!" << oendl; |
868 | QMap<QString, QString> empty; | 873 | QMap<QString, QString> empty; |
869 | return empty; | 874 | return empty; |
870 | } | 875 | } |
871 | 876 | ||
872 | OSQLResultItem::ValueList list = res_custom.results(); | 877 | OSQLResultItem::ValueList list = res_custom.results(); |
873 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 878 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
874 | for ( ; it != list.end(); ++it ) { | 879 | for ( ; it != list.end(); ++it ) { |
875 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 880 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
876 | } | 881 | } |
877 | 882 | ||