Diffstat (limited to 'libopie/pim/otodoaccesssql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 90 |
1 files changed, 74 insertions, 16 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 23e0c3e..d255c66 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -119,6 +119,7 @@ namespace { | |||
119 | QString CreateQuery::query()const { | 119 | QString CreateQuery::query()const { |
120 | QString qu; | 120 | QString qu; |
121 | qu += "create table todolist( uid, categories, completed, progress, "; | 121 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
122 | qu += "summary, DueDate, priority, description )"; | 122 | qu += "description, summary, priority, DueDate, progress , state, "; |
123 | qu += "Recurrence, notifiers, maintainer, startdate, completeddate)"; | ||
123 | return qu; | 124 | return qu; |
124 | } | 125 | } |
@@ -128,5 +129,7 @@ namespace { | |||
128 | QString LoadQuery::query()const { | 129 | QString LoadQuery::query()const { |
129 | QString qu; | 130 | QString qu; |
130 | qu += "select distinct uid from todolist"; | 131 | // We do not need "distinct" here. The primary key is always unique.. |
132 | //qu += "select distinct uid from todolist"; | ||
133 | qu += "select uid from todolist"; | ||
131 | 134 | ||
132 | return qu; | 135 | return qu; |
@@ -152,9 +155,43 @@ namespace { | |||
152 | day = date.day(); | 155 | day = date.day(); |
153 | } | 156 | } |
157 | int sYear = 0, sMonth = 0, sDay = 0; | ||
158 | if( m_todo.hasStartDate() ){ | ||
159 | QDate sDate = m_todo.startDate(); | ||
160 | sYear = sDate.year(); | ||
161 | sMonth= sDate.month(); | ||
162 | sDay = sDate.day(); | ||
163 | } | ||
164 | |||
165 | int eYear = 0, eMonth = 0, eDay = 0; | ||
166 | if( m_todo.hasCompletedDate() ){ | ||
167 | QDate eDate = m_todo.completedDate(); | ||
168 | eYear = eDate.year(); | ||
169 | eMonth= eDate.month(); | ||
170 | eDay = eDate.day(); | ||
171 | } | ||
154 | QString qu; | 172 | QString qu; |
155 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; | 173 | qu = "insert into todolist VALUES(" |
156 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; | 174 | + QString::number( m_todo.uid() ) + "," |
157 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; | 175 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
158 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; | 176 | + QString::number( m_todo.isCompleted() ) + "," |
177 | + "'" + m_todo.description() + "'" + "," | ||
178 | + "'" + m_todo.summary() + "'" + "," | ||
179 | + QString::number(m_todo.priority() ) + "," | ||
180 | + "'" + QString::number(year) + "-" | ||
181 | + QString::number(month) | ||
182 | + "-" + QString::number( day ) + "'" + "," | ||
183 | + QString::number( m_todo.progress() ) + "," | ||
184 | + "''" + "," // state (conversion needed) | ||
185 | // + QString::number( m_todo.state() ) + "," | ||
186 | + "''" + "," // Recurrence (conversion needed) | ||
187 | + "''" + "," // Notifiers (conversion needed) | ||
188 | + "''" + "," // Maintainers (conversion needed) | ||
189 | + "'" + QString::number(sYear) + "-" | ||
190 | + QString::number(sMonth) | ||
191 | + "-" + QString::number(sDay) + "'" + "," | ||
192 | + "'" + QString::number(eYear) + "-" | ||
193 | + QString::number(eMonth) | ||
194 | + "-"+QString::number(eDay) + "'" | ||
195 | + ")"; | ||
159 | 196 | ||
160 | qWarning("add %s", qu.latin1() ); | 197 | qWarning("add %s", qu.latin1() ); |
@@ -193,11 +230,9 @@ namespace { | |||
193 | } | 230 | } |
194 | QString FindQuery::single()const{ | 231 | QString FindQuery::single()const{ |
195 | QString qu = "select uid, categories, completed, progress, summary, "; | 232 | QString qu = "select * from todolist where uid = " + QString::number(m_uid); |
196 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); | ||
197 | return qu; | 233 | return qu; |
198 | } | 234 | } |
199 | QString FindQuery::multi()const { | 235 | QString FindQuery::multi()const { |
200 | QString qu = "select uid, categories, completed, progress, summary, "; | 236 | QString qu = "select * from todolist where "; |
201 | qu += "DueDate, priority, description from todolist where "; | ||
202 | for (uint i = 0; i < m_uids.count(); i++ ) { | 237 | for (uint i = 0; i < m_uids.count(); i++ ) { |
203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 238 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
@@ -289,5 +324,5 @@ OTodo OTodoAccessBackendSQL::find(int uid ) const{ | |||
289 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 324 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
290 | uint cur, Frontend::CacheDirection dir ) const{ | 325 | uint cur, Frontend::CacheDirection dir ) const{ |
291 | int CACHE = readAhead(); | 326 | uint CACHE = readAhead(); |
292 | qWarning("searching for %d", uid ); | 327 | qWarning("searching for %d", uid ); |
293 | QArray<int> search( CACHE ); | 328 | QArray<int> search( CACHE ); |
@@ -473,12 +508,28 @@ OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | |||
473 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 508 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
474 | qWarning("todo"); | 509 | qWarning("todo"); |
475 | bool has = false; QDate da = QDate::currentDate(); | 510 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
476 | has = date( da, item.data("DueDate") ); | 511 | hasDueDate = date( dueDate, item.data("DueDate") ); |
477 | QStringList cats = QStringList::split(";", item.data("categories") ); | 512 | QStringList cats = QStringList::split(";", item.data("categories") ); |
478 | 513 | ||
479 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 514 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
480 | cats, item.data("summary"), item.data("description"), | 515 | cats, item.data("summary"), item.data("description"), |
481 | item.data("progress").toUShort(), has, da, | 516 | item.data("progress").toUShort(), hasDueDate, dueDate, |
482 | item.data("uid").toInt() ); | 517 | item.data("uid").toInt() ); |
518 | |||
519 | bool isOk; | ||
520 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | ||
521 | if ( isOk ) | ||
522 | to.setPriority( prioInt ); | ||
523 | |||
524 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | ||
525 | hasStartDate = date( startDate, item.data("startdate") ); | ||
526 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); | ||
527 | hasCompletedDate = date( completedDate, item.data("completeddate") ); | ||
528 | |||
529 | if ( hasStartDate ) | ||
530 | to.setStartDate( startDate ); | ||
531 | if ( hasCompletedDate ) | ||
532 | to.setCompletedDate( completedDate ); | ||
533 | |||
483 | return to; | 534 | return to; |
484 | } | 535 | } |
@@ -571,5 +622,12 @@ QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | |||
571 | QBitArray OTodoAccessBackendSQL::supports()const { | 622 | QBitArray OTodoAccessBackendSQL::supports()const { |
572 | 623 | ||
573 | static QBitArray ar = sup(); | 624 | QBitArray ar( OTodo::CompletedDate + 1 ); |
625 | ar.fill( true ); | ||
626 | ar[OTodo::CrossReference] = false; | ||
627 | ar[OTodo::State ] = false; | ||
628 | ar[OTodo::Reminders] = false; | ||
629 | ar[OTodo::Notifiers] = false; | ||
630 | ar[OTodo::Maintainer] = false; | ||
631 | |||
574 | return ar; | 632 | return ar; |
575 | } | 633 | } |