summaryrefslogtreecommitdiff
authorzecke <zecke>2004-05-22 10:17:20 (UTC)
committer zecke <zecke>2004-05-22 10:17:20 (UTC)
commit77f189ec4b959a2874942b00b070ea60c091a7fa (patch) (unidiff)
tree57e36d30a275db1b139ccc5995080b553f33b0f0
parent35b6ab7a844145378a6e427c4666fa65b63d3cfd (diff)
downloadopie-77f189ec4b959a2874942b00b070ea60c091a7fa.zip
opie-77f189ec4b959a2874942b00b070ea60c091a7fa.tar.gz
opie-77f189ec4b959a2874942b00b070ea60c091a7fa.tar.bz2
Fix inserting data with custom tables
Also I don't like the string comparsions. Are they really needed?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp54
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
@@ -157,35 +157,35 @@ namespace {
157 class FindCustomQuery : public OSQLQuery { 157 class FindCustomQuery : public OSQLQuery {
158 public: 158 public:
159 FindCustomQuery(int uid); 159 FindCustomQuery(int uid);
160 FindCustomQuery(const QArray<int>& ); 160 FindCustomQuery(const QArray<int>& );
161 ~FindCustomQuery(); 161 ~FindCustomQuery();
162 QString query()const; 162 QString query()const;
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() {}
186 LoadQuery::~LoadQuery() {} 186 LoadQuery::~LoadQuery() {}
187 QString LoadQuery::query()const { 187 QString LoadQuery::query()const {
188 QString qu; 188 QString qu;
189 // We do not need "distinct" here. The primary key is always unique.. 189 // We do not need "distinct" here. The primary key is always unique..
190 //qu += "select distinct uid from todolist"; 190 //qu += "select distinct uid from todolist";
191 qu += "select uid from todolist"; 191 qu += "select uid from todolist";
@@ -211,94 +211,94 @@ namespace {
211 if (m_todo.hasDueDate() ) { 211 if (m_todo.hasDueDate() ) {
212 QDate date = m_todo.dueDate(); 212 QDate date = m_todo.dueDate();
213 year = date.year(); 213 year = date.year();
214 month = date.month(); 214 month = date.month();
215 day = date.day(); 215 day = date.day();
216 } 216 }
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 )
299 : OSQLQuery(), m_uid( uid ) {} 299 : OSQLQuery(), m_uid( uid ) {}
300 RemoveQuery::~RemoveQuery() {} 300 RemoveQuery::~RemoveQuery() {}
301 QString RemoveQuery::query()const { 301 QString RemoveQuery::query()const {
302 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; 302 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
303 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); 303 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
304 return qu; 304 return qu;
@@ -635,25 +635,25 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{
635 ++it; 635 ++it;
636 636
637 for ( ; it != list.end(); ++it ) { 637 for ( ; it != list.end(); ++it ) {
638 qDebug("caching"); 638 qDebug("caching");
639 cache( todo( (*it) ) ); 639 cache( todo( (*it) ) );
640 } 640 }
641 return to; 641 return to;
642} 642}
643OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 643OPimTodo 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
654 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 654 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
655 cats, item.data("summary"), item.data("description"), 655 cats, item.data("summary"), item.data("description"),
656 item.data("progress").toUShort(), hasDueDate, dueDate, 656 item.data("progress").toUShort(), hasDueDate, dueDate,
657 item.data("uid").toInt() ); 657 item.data("uid").toInt() );
658 658
659 bool isOk; 659 bool isOk;
@@ -661,43 +661,43 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
661 if ( isOk ) 661 if ( isOk )
662 to.setPriority( prioInt ); 662 to.setPriority( prioInt );
663 663
664 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 664 bool hasStartDate = false; QDate startDate = QDate::currentDate();
665 hasStartDate = date( startDate, item.data("startdate") ); 665 hasStartDate = date( startDate, item.data("startdate") );
666 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); 666 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
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() );
680 to.setState( pimState ); 680 to.setState( pimState );
681 681
682 QMap<int, QString> recMap; 682 QMap<int, QString> recMap;
683 recMap.insert( OPimRecurrence::RType , item.data("RType") ); 683 recMap.insert( OPimRecurrence::RType , item.data("RType") );
684 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); 684 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") );
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() ) );
698 698
699 return to; 699 return to;
700} 700}
701OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { 701OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
702 FindQuery find( uid ); 702 FindQuery find( uid );
703 return todo( m_driver->query(&find) ); 703 return todo( m_driver->query(&find) );
@@ -764,25 +764,25 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
764{ 764{
765 765
766#if 0 766#if 0
767 QArray<int> empty; 767 QArray<int> empty;
768 return empty; 768 return empty;
769 769
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 );
783 783
784 return uids( res ); 784 return uids( res );
785 785
786 786
787#endif 787#endif
788 788
@@ -792,30 +792,30 @@ QBitArray OPimTodoAccessBackendSQL::supports()const {
792 return sup(); 792 return sup();
793} 793}
794 794
795QBitArray OPimTodoAccessBackendSQL::sup() const{ 795QBitArray OPimTodoAccessBackendSQL::sup() const{
796 796
797 QBitArray ar( OPimTodo::CompletedDate + 1 ); 797 QBitArray ar( OPimTodo::CompletedDate + 1 );
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
808void OPimTodoAccessBackendSQL::removeAllCompleted(){ 808void 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 );
816 816
817 QArray<int> completed_uids = uids( res ); 817 QArray<int> completed_uids = uids( res );
818 818
819 qDebug( "Number of completed: %d", completed_uids.size() ); 819 qDebug( "Number of completed: %d", completed_uids.size() );
820 820
821 if ( completed_uids.size() == 0 ) 821 if ( completed_uids.size() == 0 )
@@ -846,25 +846,25 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
846 846
847 OSQLRawQuery raw2( qu ); 847 OSQLRawQuery raw2( qu );
848 res = m_driver->query( &raw2 ); 848 res = m_driver->query( &raw2 );
849 if ( res.state() == OSQLResult::Failure ) { 849 if ( res.state() == OSQLResult::Failure ) {
850 qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() ); 850 qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() );
851 } 851 }
852} 852}
853 853
854 854
855QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const 855QMap<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;
865 return empty; 865 return empty;
866 } 866 }
867 867
868 OSQLResultItem::ValueList list = res_custom.results(); 868 OSQLResultItem::ValueList list = res_custom.results();
869 OSQLResultItem::ValueList::Iterator it = list.begin(); 869 OSQLResultItem::ValueList::Iterator it = list.begin();
870 for ( ; it != list.end(); ++it ) { 870 for ( ; it != list.end(); ++it ) {