-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index ef036d5..132b5a6 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -163,23 +163,23 @@ namespace { | |||
163 | private: | 163 | private: |
164 | QString single()const; | 164 | QString single()const; |
165 | QString multi()const; | 165 | QString multi()const; |
166 | QArray<int> m_uids; | 166 | QArray<int> m_uids; |
167 | int m_uid; | 167 | int m_uid; |
168 | }; | 168 | }; |
169 | 169 | ||
170 | 170 | ||
171 | 171 | ||
172 | CreateQuery::CreateQuery() : OSQLQuery() {} | 172 | CreateQuery::CreateQuery() : OSQLQuery() {} |
173 | CreateQuery::~CreateQuery() {} | 173 | CreateQuery::~CreateQuery() {} |
174 | QString CreateQuery::query()const { | 174 | QString CreateQuery::query()const { |
175 | QString qu; | 175 | QString qu; |
176 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; | 176 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
177 | qu += "description, summary, priority, DueDate, progress , state, "; | 177 | qu += "description, summary, priority, DueDate, progress , state, "; |
178 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) | 178 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) |
179 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; | 179 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; |
180 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; | 180 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; |
181 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 181 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
182 | return qu; | 182 | return qu; |
183 | } | 183 | } |
184 | 184 | ||
185 | LoadQuery::LoadQuery() : OSQLQuery() {} | 185 | LoadQuery::LoadQuery() : OSQLQuery() {} |
@@ -217,82 +217,82 @@ namespace { | |||
217 | int sYear = 0, sMonth = 0, sDay = 0; | 217 | int sYear = 0, sMonth = 0, sDay = 0; |
218 | if( m_todo.hasStartDate() ){ | 218 | if( m_todo.hasStartDate() ){ |
219 | QDate sDate = m_todo.startDate(); | 219 | QDate sDate = m_todo.startDate(); |
220 | sYear = sDate.year(); | 220 | sYear = sDate.year(); |
221 | sMonth= sDate.month(); | 221 | sMonth= sDate.month(); |
222 | sDay = sDate.day(); | 222 | sDay = sDate.day(); |
223 | } | 223 | } |
224 | 224 | ||
225 | int eYear = 0, eMonth = 0, eDay = 0; | 225 | int eYear = 0, eMonth = 0, eDay = 0; |
226 | if( m_todo.hasCompletedDate() ){ | 226 | if( m_todo.hasCompletedDate() ){ |
227 | QDate eDate = m_todo.completedDate(); | 227 | QDate eDate = m_todo.completedDate(); |
228 | eYear = eDate.year(); | 228 | eYear = eDate.year(); |
229 | eMonth= eDate.month(); | 229 | eMonth= eDate.month(); |
230 | eDay = eDate.day(); | 230 | eDay = eDate.day(); |
231 | } | 231 | } |
232 | QString qu; | 232 | QString qu; |
233 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); | 233 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); |
234 | qu = "insert into todolist VALUES(" | 234 | qu = "insert into todolist VALUES(" |
235 | + QString::number( m_todo.uid() ) + "," | 235 | + QString::number( m_todo.uid() ) + "," |
236 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," | 236 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
237 | + QString::number( m_todo.isCompleted() ) + "," | 237 | + QString::number( m_todo.isCompleted() ) + "," |
238 | + "'" + m_todo.description() + "'" + "," | 238 | + "'" + m_todo.description() + "'" + "," |
239 | + "'" + m_todo.summary() + "'" + "," | 239 | + "'" + m_todo.summary() + "'" + "," |
240 | + QString::number(m_todo.priority() ) + "," | 240 | + QString::number(m_todo.priority() ) + "," |
241 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" | 241 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" |
242 | + QString::number(month).rightJustify( 2, '0' ) | 242 | + QString::number(month).rightJustify( 2, '0' ) |
243 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," | 243 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," |
244 | + QString::number( m_todo.progress() ) + "," | 244 | + QString::number( m_todo.progress() ) + "," |
245 | + QString::number( m_todo.state().state() ) + "," | 245 | + QString::number( m_todo.state().state() ) + "," |
246 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," | 246 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," |
247 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," | 247 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," |
248 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," | 248 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," |
249 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," | 249 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," |
250 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," | 250 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," |
251 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," | 251 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," |
252 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," | 252 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," |
253 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; | 253 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; |
254 | 254 | ||
255 | if ( m_todo.hasNotifiers() ) { | 255 | if ( m_todo.hasNotifiers() ) { |
256 | OPimNotifyManager manager = m_todo.notifiers(); | 256 | OPimNotifyManager manager = m_todo.notifiers(); |
257 | qu += "'" + manager.remindersToString() + "'" + "," | 257 | qu += "'" + manager.remindersToString() + "'" + "," |
258 | + "'" + manager.alarmsToString() + "'" + ","; | 258 | + "'" + manager.alarmsToString() + "'" + ","; |
259 | } | 259 | } |
260 | else{ | 260 | else{ |
261 | qu += QString( "''" ) + "," | 261 | qu += QString( "''" ) + "," |
262 | + "''" + ","; | 262 | + "''" + ","; |
263 | } | 263 | } |
264 | 264 | ||
265 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) | 265 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) |
266 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" | 266 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" |
267 | + QString::number(sMonth).rightJustify( 2, '0' ) | 267 | + QString::number(sMonth).rightJustify( 2, '0' ) |
268 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," | 268 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," |
269 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" | 269 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" |
270 | + QString::number(eMonth).rightJustify( 2, '0' ) | 270 | + QString::number(eMonth).rightJustify( 2, '0' ) |
271 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" | 271 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" |
272 | + ")"; | 272 | + "); "; |
273 | 273 | ||
274 | // Save custom Entries: | 274 | // Save custom Entries: |
275 | int id = 0; | 275 | int id = 0; |
276 | id = 0; | 276 | id = 0; |
277 | QMap<QString, QString> customMap = m_todo.toExtraMap(); | 277 | QMap<QString, QString> customMap = m_todo.toExtraMap(); |
278 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 278 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
279 | it != customMap.end(); ++it ){ | 279 | it != customMap.end(); ++it ){ |
280 | qu += "insert into custom_data VALUES(" | 280 | qu += "insert into custom_data VALUES(" |
281 | + QString::number( m_todo.uid() ) | 281 | + QString::number( m_todo.uid() ) |
282 | + "," | 282 | + "," |
283 | + QString::number( id++ ) | 283 | + QString::number( id++ ) |
284 | + ",'" | 284 | + ",'" |
285 | + it.key() | 285 | + it.key() |
286 | + "'," | 286 | + "'," |
287 | + "0" // Priority for future enhancements | 287 | + "0" // Priority for future enhancements |
288 | + ",'" | 288 | + ",'" |
289 | + it.data() | 289 | + it.data() |
290 | + "');"; | 290 | + "');"; |
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | qDebug("add %s", qu.latin1() ); | 294 | qDebug("add %s", qu.latin1() ); |
295 | return qu; | 295 | return qu; |
296 | } | 296 | } |
297 | 297 | ||
298 | RemoveQuery::RemoveQuery(int uid ) | 298 | RemoveQuery::RemoveQuery(int uid ) |
@@ -641,13 +641,13 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ | |||
641 | return to; | 641 | return to; |
642 | } | 642 | } |
643 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 643 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
644 | qDebug("todo(ResultItem)"); | 644 | qDebug("todo(ResultItem)"); |
645 | 645 | ||
646 | // Request information from addressbook table and create the OPimTodo-object. | 646 | // Request information from addressbook table and create the OPimTodo-object. |
647 | 647 | ||
648 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 648 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
649 | hasDueDate = date( dueDate, item.data("DueDate") ); | 649 | hasDueDate = date( dueDate, item.data("DueDate") ); |
650 | QStringList cats = QStringList::split(";", item.data("categories") ); | 650 | QStringList cats = QStringList::split(";", item.data("categories") ); |
651 | 651 | ||
652 | qDebug("Item is completed: %d", item.data("completed").toInt() ); | 652 | qDebug("Item is completed: %d", item.data("completed").toInt() ); |
653 | 653 | ||
@@ -667,13 +667,13 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
667 | hasCompletedDate = date( completedDate, item.data("completeddate") ); | 667 | hasCompletedDate = date( completedDate, item.data("completeddate") ); |
668 | 668 | ||
669 | if ( hasStartDate ) | 669 | if ( hasStartDate ) |
670 | to.setStartDate( startDate ); | 670 | to.setStartDate( startDate ); |
671 | if ( hasCompletedDate ) | 671 | if ( hasCompletedDate ) |
672 | to.setCompletedDate( completedDate ); | 672 | to.setCompletedDate( completedDate ); |
673 | 673 | ||
674 | OPimNotifyManager& manager = to.notifiers(); | 674 | OPimNotifyManager& manager = to.notifiers(); |
675 | manager.alarmsFromString( item.data("alarms") ); | 675 | manager.alarmsFromString( item.data("alarms") ); |
676 | manager.remindersFromString( item.data("reminders") ); | 676 | manager.remindersFromString( item.data("reminders") ); |
677 | 677 | ||
678 | OPimState pimState; | 678 | OPimState pimState; |
679 | pimState.setState( QString( item.data("state") ).toInt() ); | 679 | pimState.setState( QString( item.data("state") ).toInt() ); |
@@ -685,13 +685,13 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
685 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); | 685 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); |
686 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); | 686 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); |
687 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); | 687 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); |
688 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); | 688 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); |
689 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); | 689 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); |
690 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); | 690 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); |
691 | 691 | ||
692 | OPimRecurrence recur; | 692 | OPimRecurrence recur; |
693 | recur.fromMap( recMap ); | 693 | recur.fromMap( recMap ); |
694 | to.setRecurrence( recur ); | 694 | to.setRecurrence( recur ); |
695 | 695 | ||
696 | // Finally load the custom-entries for this UID and put it into the created object | 696 | // Finally load the custom-entries for this UID and put it into the created object |
697 | to.setExtraMap( requestCustom( to.uid() ) ); | 697 | to.setExtraMap( requestCustom( to.uid() ) ); |
@@ -770,13 +770,13 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | |||
770 | #else | 770 | #else |
771 | QString qu = "SELECT uid FROM todolist WHERE ("; | 771 | QString qu = "SELECT uid FROM todolist WHERE ("; |
772 | 772 | ||
773 | // Do it make sense to search other fields, too ? | 773 | // Do it make sense to search other fields, too ? |
774 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; | 774 | qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; |
775 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; | 775 | qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; |
776 | 776 | ||
777 | qu += ")"; | 777 | qu += ")"; |
778 | 778 | ||
779 | qDebug( "query: %s", qu.latin1() ); | 779 | qDebug( "query: %s", qu.latin1() ); |
780 | 780 | ||
781 | OSQLRawQuery raw( qu ); | 781 | OSQLRawQuery raw( qu ); |
782 | OSQLResult res = m_driver->query( &raw ); | 782 | OSQLResult res = m_driver->query( &raw ); |
@@ -798,18 +798,18 @@ QBitArray OPimTodoAccessBackendSQL::sup() const{ | |||
798 | ar.fill( true ); | 798 | ar.fill( true ); |
799 | ar[OPimTodo::CrossReference] = false; | 799 | ar[OPimTodo::CrossReference] = false; |
800 | ar[OPimTodo::State ] = false; | 800 | ar[OPimTodo::State ] = false; |
801 | ar[OPimTodo::Reminders] = false; | 801 | ar[OPimTodo::Reminders] = false; |
802 | ar[OPimTodo::Notifiers] = false; | 802 | ar[OPimTodo::Notifiers] = false; |
803 | ar[OPimTodo::Maintainer] = false; | 803 | ar[OPimTodo::Maintainer] = false; |
804 | 804 | ||
805 | return ar; | 805 | return ar; |
806 | } | 806 | } |
807 | 807 | ||
808 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ | 808 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
809 | // First we need the uids from all entries which are | 809 | // First we need the uids from all entries which are |
810 | // completed. Then, we just have to remove them... | 810 | // completed. Then, we just have to remove them... |
811 | 811 | ||
812 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; | 812 | QString qu = "SELECT uid FROM todolist WHERE completed = 1"; |
813 | 813 | ||
814 | OSQLRawQuery raw( qu ); | 814 | OSQLRawQuery raw( qu ); |
815 | OSQLResult res = m_driver->query( &raw ); | 815 | OSQLResult res = m_driver->query( &raw ); |
@@ -852,13 +852,13 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){ | |||
852 | } | 852 | } |
853 | 853 | ||
854 | 854 | ||
855 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const | 855 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const |
856 | { | 856 | { |
857 | QMap<QString, QString> customMap; | 857 | QMap<QString, QString> customMap; |
858 | 858 | ||
859 | FindCustomQuery query( uid ); | 859 | FindCustomQuery query( uid ); |
860 | OSQLResult res_custom = m_driver->query( &query ); | 860 | OSQLResult res_custom = m_driver->query( &query ); |
861 | 861 | ||
862 | if ( res_custom.state() == OSQLResult::Failure ) { | 862 | if ( res_custom.state() == OSQLResult::Failure ) { |
863 | qWarning("OSQLResult::Failure in find query !!"); | 863 | qWarning("OSQLResult::Failure in find query !!"); |
864 | QMap<QString, QString> empty; | 864 | QMap<QString, QString> empty; |