author | zecke <zecke> | 2002-10-10 20:16:15 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-10 20:16:15 (UTC) |
commit | 48b06312289a90ad38278d3adb0bce5e9e0bd67e (patch) (unidiff) | |
tree | e5123b76d501eeb669ac6b43b8da746eae36e638 | |
parent | c90676c42c7be606a9fc690278b67909ba6a9c99 (diff) | |
download | opie-48b06312289a90ad38278d3adb0bce5e9e0bd67e.zip opie-48b06312289a90ad38278d3adb0bce5e9e0bd67e.tar.gz opie-48b06312289a90ad38278d3adb0bce5e9e0bd67e.tar.bz2 |
Implement read ahead on the XML resource...
Scrolling is now noticeable faster with 10.000 items
but not as fast the XML backend...
OPimCache can be tuned and Query->OTodo too
-rw-r--r-- | libopie/pim/opimcache.h | 4 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 81 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 81 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimcache.h | 4 |
6 files changed, 162 insertions, 14 deletions
diff --git a/libopie/pim/opimcache.h b/libopie/pim/opimcache.h index 067f6e7..839550c 100644 --- a/libopie/pim/opimcache.h +++ b/libopie/pim/opimcache.h | |||
@@ -16,97 +16,99 @@ public: | |||
16 | private: | 16 | private: |
17 | T m_t; | 17 | T m_t; |
18 | }; | 18 | }; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * OPimCache for caching the items | 21 | * OPimCache for caching the items |
22 | * We support adding, removing | 22 | * We support adding, removing |
23 | * and finding | 23 | * and finding |
24 | */ | 24 | */ |
25 | template <class T = OPimRecord> | 25 | template <class T = OPimRecord> |
26 | class OPimCache { | 26 | class OPimCache { |
27 | public: | 27 | public: |
28 | typedef OPimCacheItem<T> Item; | 28 | typedef OPimCacheItem<T> Item; |
29 | OPimCache(); | 29 | OPimCache(); |
30 | ~OPimCache(); | 30 | ~OPimCache(); |
31 | 31 | ||
32 | bool contains(int uid)const; | 32 | bool contains(int uid)const; |
33 | void invalidate(); | 33 | void invalidate(); |
34 | void setSize( int size ); | 34 | void setSize( int size ); |
35 | 35 | ||
36 | T find(int uid )const; | 36 | T find(int uid )const; |
37 | void add( const T& ); | 37 | void add( const T& ); |
38 | void remove( int uid ); | 38 | void remove( int uid ); |
39 | void replace( const T& ); | 39 | void replace( const T& ); |
40 | 40 | ||
41 | private: | 41 | private: |
42 | QIntCache<Item> m_cache; | 42 | QIntCache<Item> m_cache; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | // Implementation | 45 | // Implementation |
46 | template <class T> | 46 | template <class T> |
47 | OPimCacheItem<T>::OPimCacheItem( const T& t ) | 47 | OPimCacheItem<T>::OPimCacheItem( const T& t ) |
48 | : m_t(t) { | 48 | : m_t(t) { |
49 | } | 49 | } |
50 | template <class T> | 50 | template <class T> |
51 | OPimCacheItem<T>::~OPimCacheItem() { | 51 | OPimCacheItem<T>::~OPimCacheItem() { |
52 | 52 | ||
53 | } | 53 | } |
54 | template <class T> | 54 | template <class T> |
55 | T OPimCacheItem<T>::record()const { | 55 | T OPimCacheItem<T>::record()const { |
56 | return m_t; | 56 | return m_t; |
57 | } | 57 | } |
58 | template <class T> | 58 | template <class T> |
59 | void OPimCacheItem<T>::setRecord( const T& t ) { | 59 | void OPimCacheItem<T>::setRecord( const T& t ) { |
60 | m_t = t; | 60 | m_t = t; |
61 | } | 61 | } |
62 | // Cache | 62 | // Cache |
63 | template <class T> | 63 | template <class T> |
64 | OPimCache<T>::OPimCache() { | 64 | OPimCache<T>::OPimCache() |
65 | : m_cache(100, 53 ) | ||
66 | { | ||
65 | m_cache.setAutoDelete( TRUE ); | 67 | m_cache.setAutoDelete( TRUE ); |
66 | } | 68 | } |
67 | template <class T> | 69 | template <class T> |
68 | OPimCache<T>::~OPimCache() { | 70 | OPimCache<T>::~OPimCache() { |
69 | 71 | ||
70 | } | 72 | } |
71 | template <class T> | 73 | template <class T> |
72 | bool OPimCache<T>::contains(int uid )const { | 74 | bool OPimCache<T>::contains(int uid )const { |
73 | Item* it = m_cache.find( uid, FALSE ); | 75 | Item* it = m_cache.find( uid, FALSE ); |
74 | if (!it) | 76 | if (!it) |
75 | return false; | 77 | return false; |
76 | return true; | 78 | return true; |
77 | } | 79 | } |
78 | template <class T> | 80 | template <class T> |
79 | void OPimCache<T>::invalidate() { | 81 | void OPimCache<T>::invalidate() { |
80 | m_cache.clear(); | 82 | m_cache.clear(); |
81 | } | 83 | } |
82 | template <class T> | 84 | template <class T> |
83 | void OPimCache<T>::setSize( int size ) { | 85 | void OPimCache<T>::setSize( int size ) { |
84 | m_cache.setMaxCost( size ); | 86 | m_cache.setMaxCost( size ); |
85 | } | 87 | } |
86 | template <class T> | 88 | template <class T> |
87 | T OPimCache<T>::find(int uid )const { | 89 | T OPimCache<T>::find(int uid )const { |
88 | Item *it = m_cache.find( uid ); | 90 | Item *it = m_cache.find( uid ); |
89 | if (it) | 91 | if (it) |
90 | return it->record(); | 92 | return it->record(); |
91 | return T(); | 93 | return T(); |
92 | } | 94 | } |
93 | template <class T> | 95 | template <class T> |
94 | void OPimCache<T>::add( const T& t ) { | 96 | void OPimCache<T>::add( const T& t ) { |
95 | Item* it = 0l; | 97 | Item* it = 0l; |
96 | it = m_cache.find(t.uid(), FALSE ); | 98 | it = m_cache.find(t.uid(), FALSE ); |
97 | 99 | ||
98 | if (it ) | 100 | if (it ) |
99 | it->setRecord( t ); | 101 | it->setRecord( t ); |
100 | 102 | ||
101 | it = new Item( t ); | 103 | it = new Item( t ); |
102 | if (!m_cache.insert( t.uid(), it ) ) | 104 | if (!m_cache.insert( t.uid(), it ) ) |
103 | delete it; | 105 | delete it; |
104 | } | 106 | } |
105 | template <class T> | 107 | template <class T> |
106 | void OPimCache<T>::remove( int uid ) { | 108 | void OPimCache<T>::remove( int uid ) { |
107 | m_cache.remove( uid ); | 109 | m_cache.remove( uid ); |
108 | } | 110 | } |
109 | template <class T> | 111 | template <class T> |
110 | void OPimCache<T>::replace( const T& t) { | 112 | void OPimCache<T>::replace( const T& t) { |
111 | Item *it = m_cache.find( t.uid() ); | 113 | Item *it = m_cache.find( t.uid() ); |
112 | if ( it ) { | 114 | if ( it ) { |
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 8add9f7..a059dab 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -36,276 +36,332 @@ namespace { | |||
36 | class LoadQuery : public OSQLQuery { | 36 | class LoadQuery : public OSQLQuery { |
37 | public: | 37 | public: |
38 | LoadQuery(); | 38 | LoadQuery(); |
39 | ~LoadQuery(); | 39 | ~LoadQuery(); |
40 | QString query()const; | 40 | QString query()const; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * inserts/adds a OTodo to the table | 44 | * inserts/adds a OTodo to the table |
45 | */ | 45 | */ |
46 | class InsertQuery : public OSQLQuery { | 46 | class InsertQuery : public OSQLQuery { |
47 | public: | 47 | public: |
48 | InsertQuery(const OTodo& ); | 48 | InsertQuery(const OTodo& ); |
49 | ~InsertQuery(); | 49 | ~InsertQuery(); |
50 | QString query()const; | 50 | QString query()const; |
51 | private: | 51 | private: |
52 | OTodo m_todo; | 52 | OTodo m_todo; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * removes one from the table | 56 | * removes one from the table |
57 | */ | 57 | */ |
58 | class RemoveQuery : public OSQLQuery { | 58 | class RemoveQuery : public OSQLQuery { |
59 | public: | 59 | public: |
60 | RemoveQuery(int uid ); | 60 | RemoveQuery(int uid ); |
61 | ~RemoveQuery(); | 61 | ~RemoveQuery(); |
62 | QString query()const; | 62 | QString query()const; |
63 | private: | 63 | private: |
64 | int m_uid; | 64 | int m_uid; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Clears (delete) a Table | 68 | * Clears (delete) a Table |
69 | */ | 69 | */ |
70 | class ClearQuery : public OSQLQuery { | 70 | class ClearQuery : public OSQLQuery { |
71 | public: | 71 | public: |
72 | ClearQuery(); | 72 | ClearQuery(); |
73 | ~ClearQuery(); | 73 | ~ClearQuery(); |
74 | QString query()const; | 74 | QString query()const; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * a find query | 79 | * a find query |
80 | */ | 80 | */ |
81 | class FindQuery : public OSQLQuery { | 81 | class FindQuery : public OSQLQuery { |
82 | public: | 82 | public: |
83 | FindQuery(int uid); | 83 | FindQuery(int uid); |
84 | FindQuery(const QArray<int>& ); | ||
84 | ~FindQuery(); | 85 | ~FindQuery(); |
85 | QString query()const; | 86 | QString query()const; |
86 | private: | 87 | private: |
88 | QString single()const; | ||
89 | QString multi()const; | ||
90 | QArray<int> m_uids; | ||
87 | int m_uid; | 91 | int m_uid; |
88 | }; | 92 | }; |
89 | 93 | ||
90 | /** | 94 | /** |
91 | * overdue query | 95 | * overdue query |
92 | */ | 96 | */ |
93 | class OverDueQuery : public OSQLQuery { | 97 | class OverDueQuery : public OSQLQuery { |
94 | public: | 98 | public: |
95 | OverDueQuery(); | 99 | OverDueQuery(); |
96 | ~OverDueQuery(); | 100 | ~OverDueQuery(); |
97 | QString query()const; | 101 | QString query()const; |
98 | }; | 102 | }; |
99 | class EffQuery : public OSQLQuery { | 103 | class EffQuery : public OSQLQuery { |
100 | public: | 104 | public: |
101 | EffQuery( const QDate&, const QDate&, bool inc ); | 105 | EffQuery( const QDate&, const QDate&, bool inc ); |
102 | ~EffQuery(); | 106 | ~EffQuery(); |
103 | QString query()const; | 107 | QString query()const; |
104 | private: | 108 | private: |
105 | QString with()const; | 109 | QString with()const; |
106 | QString out()const; | 110 | QString out()const; |
107 | QDate m_start; | 111 | QDate m_start; |
108 | QDate m_end; | 112 | QDate m_end; |
109 | bool m_inc :1; | 113 | bool m_inc :1; |
110 | }; | 114 | }; |
111 | 115 | ||
112 | 116 | ||
113 | CreateQuery::CreateQuery() : OSQLQuery() {} | 117 | CreateQuery::CreateQuery() : OSQLQuery() {} |
114 | CreateQuery::~CreateQuery() {} | 118 | CreateQuery::~CreateQuery() {} |
115 | QString CreateQuery::query()const { | 119 | QString CreateQuery::query()const { |
116 | QString qu; | 120 | QString qu; |
117 | qu += "create table todolist( uid, categories, completed, progress, "; | 121 | qu += "create table todolist( uid, categories, completed, progress, "; |
118 | qu += "summary, DueDate, priority, description )"; | 122 | qu += "summary, DueDate, priority, description )"; |
119 | return qu; | 123 | return qu; |
120 | } | 124 | } |
121 | 125 | ||
122 | LoadQuery::LoadQuery() : OSQLQuery() {} | 126 | LoadQuery::LoadQuery() : OSQLQuery() {} |
123 | LoadQuery::~LoadQuery() {} | 127 | LoadQuery::~LoadQuery() {} |
124 | QString LoadQuery::query()const { | 128 | QString LoadQuery::query()const { |
125 | QString qu; | 129 | QString qu; |
126 | qu += "select distinct uid from todolist"; | 130 | qu += "select distinct uid from todolist"; |
127 | 131 | ||
128 | return qu; | 132 | return qu; |
129 | } | 133 | } |
130 | 134 | ||
131 | InsertQuery::InsertQuery( const OTodo& todo ) | 135 | InsertQuery::InsertQuery( const OTodo& todo ) |
132 | : OSQLQuery(), m_todo( todo ) { | 136 | : OSQLQuery(), m_todo( todo ) { |
133 | } | 137 | } |
134 | InsertQuery::~InsertQuery() { | 138 | InsertQuery::~InsertQuery() { |
135 | } | 139 | } |
136 | /* | 140 | /* |
137 | * converts from a OTodo to a query | 141 | * converts from a OTodo to a query |
138 | * we leave out X-Ref + Alarms | 142 | * we leave out X-Ref + Alarms |
139 | */ | 143 | */ |
140 | QString InsertQuery::query()const{ | 144 | QString InsertQuery::query()const{ |
145 | |||
141 | int year, month, day; | 146 | int year, month, day; |
142 | year = month = day = 0; | 147 | year = month = day = 0; |
143 | if (m_todo.hasDueDate() ) { | 148 | if (m_todo.hasDueDate() ) { |
144 | QDate date = m_todo.dueDate(); | 149 | QDate date = m_todo.dueDate(); |
145 | year = date.year(); | 150 | year = date.year(); |
146 | month = date.month(); | 151 | month = date.month(); |
147 | day = date.day(); | 152 | day = date.day(); |
148 | } | 153 | } |
149 | QString qu; | 154 | QString qu; |
150 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; | 155 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; |
151 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; | 156 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; |
152 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; | 157 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; |
153 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; | 158 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; |
154 | 159 | ||
155 | qWarning("add %s", qu.latin1() ); | 160 | qWarning("add %s", qu.latin1() ); |
156 | return qu; | 161 | return qu; |
157 | } | 162 | } |
158 | 163 | ||
159 | RemoveQuery::RemoveQuery(int uid ) | 164 | RemoveQuery::RemoveQuery(int uid ) |
160 | : OSQLQuery(), m_uid( uid ) {} | 165 | : OSQLQuery(), m_uid( uid ) {} |
161 | RemoveQuery::~RemoveQuery() {} | 166 | RemoveQuery::~RemoveQuery() {} |
162 | QString RemoveQuery::query()const { | 167 | QString RemoveQuery::query()const { |
163 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); | 168 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); |
164 | return qu; | 169 | return qu; |
165 | } | 170 | } |
166 | 171 | ||
167 | 172 | ||
168 | ClearQuery::ClearQuery() | 173 | ClearQuery::ClearQuery() |
169 | : OSQLQuery() {} | 174 | : OSQLQuery() {} |
170 | ClearQuery::~ClearQuery() {} | 175 | ClearQuery::~ClearQuery() {} |
171 | QString ClearQuery::query()const { | 176 | QString ClearQuery::query()const { |
172 | QString qu = "drop table todolist"; | 177 | QString qu = "drop table todolist"; |
173 | return qu; | 178 | return qu; |
174 | } | 179 | } |
175 | FindQuery::FindQuery(int uid) | 180 | FindQuery::FindQuery(int uid) |
176 | : OSQLQuery(), m_uid(uid ) { | 181 | : OSQLQuery(), m_uid(uid ) { |
177 | } | 182 | } |
183 | FindQuery::FindQuery(const QArray<int>& ints) | ||
184 | : OSQLQuery(), m_uids(ints){ | ||
185 | } | ||
178 | FindQuery::~FindQuery() { | 186 | FindQuery::~FindQuery() { |
179 | } | 187 | } |
180 | QString FindQuery::query()const{ | 188 | QString FindQuery::query()const{ |
189 | if (m_uids.count() == 0 ) | ||
190 | return single(); | ||
191 | else | ||
192 | return multi(); | ||
193 | } | ||
194 | QString FindQuery::single()const{ | ||
181 | QString qu = "select uid, categories, completed, progress, summary, "; | 195 | QString qu = "select uid, categories, completed, progress, summary, "; |
182 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); | 196 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); |
183 | return qu; | 197 | return qu; |
184 | } | 198 | } |
199 | QString FindQuery::multi()const { | ||
200 | QString qu = "select uid, categories, completed, progress, summary, "; | ||
201 | qu += "DueDate, priority, description from todolist where "; | ||
202 | for (uint i = 0; i < m_uids.count(); i++ ) { | ||
203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | ||
204 | } | ||
205 | qu.remove( qu.length()-2, 2 ); | ||
206 | return qu; | ||
207 | } | ||
185 | 208 | ||
186 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 209 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
187 | OverDueQuery::~OverDueQuery() {} | 210 | OverDueQuery::~OverDueQuery() {} |
188 | QString OverDueQuery::query()const { | 211 | QString OverDueQuery::query()const { |
189 | QDate date = QDate::currentDate(); | 212 | QDate date = QDate::currentDate(); |
190 | QString str; | 213 | QString str; |
191 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); | 214 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); |
192 | 215 | ||
193 | return str; | 216 | return str; |
194 | } | 217 | } |
195 | 218 | ||
196 | 219 | ||
197 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 220 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
198 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 221 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
199 | EffQuery::~EffQuery() {} | 222 | EffQuery::~EffQuery() {} |
200 | QString EffQuery::query()const { | 223 | QString EffQuery::query()const { |
201 | return m_inc ? with() : out(); | 224 | return m_inc ? with() : out(); |
202 | } | 225 | } |
203 | QString EffQuery::with()const { | 226 | QString EffQuery::with()const { |
204 | QString str; | 227 | QString str; |
205 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 228 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
206 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) | 229 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) |
207 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); | 230 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); |
208 | return str; | 231 | return str; |
209 | } | 232 | } |
210 | QString EffQuery::out()const { | 233 | QString EffQuery::out()const { |
211 | QString str; | 234 | QString str; |
212 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 235 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
213 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
214 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
215 | 238 | ||
216 | return str; | 239 | return str; |
217 | } | 240 | } |
218 | }; | 241 | }; |
219 | 242 | ||
220 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
221 | : OTodoAccessBackend(), m_dict(15) | 244 | : OTodoAccessBackend(), m_dict(15) |
222 | { | 245 | { |
223 | QString fi = file; | 246 | QString fi = file; |
224 | if ( fi.isEmpty() ) | 247 | if ( fi.isEmpty() ) |
225 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
226 | OSQLManager man; | 249 | OSQLManager man; |
227 | m_driver = man.standard(); | 250 | m_driver = man.standard(); |
228 | m_driver->setUrl(fi); | 251 | m_driver->setUrl(fi); |
229 | fillDict(); | 252 | fillDict(); |
230 | } | 253 | } |
231 | 254 | ||
232 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
233 | } | 256 | } |
234 | bool OTodoAccessBackendSQL::load(){ | 257 | bool OTodoAccessBackendSQL::load(){ |
235 | if (!m_driver->open() ) | 258 | if (!m_driver->open() ) |
236 | return false; | 259 | return false; |
237 | 260 | ||
238 | CreateQuery creat; | 261 | CreateQuery creat; |
239 | OSQLResult res = m_driver->query(&creat ); | 262 | OSQLResult res = m_driver->query(&creat ); |
240 | 263 | ||
241 | update(); | 264 | update(); |
242 | qWarning("loaded %d", m_uids.count() ); | 265 | qWarning("loaded %d", m_uids.count() ); |
243 | return true; | 266 | return true; |
244 | } | 267 | } |
245 | bool OTodoAccessBackendSQL::reload(){ | 268 | bool OTodoAccessBackendSQL::reload(){ |
246 | return load(); | 269 | return load(); |
247 | } | 270 | } |
248 | 271 | ||
249 | bool OTodoAccessBackendSQL::save(){ | 272 | bool OTodoAccessBackendSQL::save(){ |
250 | return m_driver->close(); | 273 | return m_driver->close(); |
251 | } | 274 | } |
252 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 275 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
253 | return m_uids; | 276 | return m_uids; |
254 | } | 277 | } |
255 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 278 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
256 | QArray<int> ints(0); | 279 | QArray<int> ints(0); |
257 | return ints; | 280 | return ints; |
258 | } | 281 | } |
259 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 282 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
260 | FindQuery query( uid ); | 283 | FindQuery query( uid ); |
261 | return todo( m_driver->query(&query) ); | 284 | return todo( m_driver->query(&query) ); |
262 | 285 | ||
263 | } | 286 | } |
287 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | ||
288 | uint cur, Frontend::CacheDirection dir ) const{ | ||
289 | qWarning("searching for %d", uid ); | ||
290 | QArray<int> search( 8 ); | ||
291 | uint size =0; | ||
292 | OTodo to; | ||
293 | |||
294 | // we try to cache 8 items | ||
295 | switch( dir ) { | ||
296 | /* forward */ | ||
297 | case 0: | ||
298 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { | ||
299 | qWarning("size %d %d", size, ints[i] ); | ||
300 | search[size] = ints[i]; | ||
301 | size++; | ||
302 | } | ||
303 | break; | ||
304 | /* reverse */ | ||
305 | case 1: | ||
306 | for (uint i = cur; i >= 0 && size < 8; i-- ) { | ||
307 | search[size] = ints[i]; | ||
308 | size++; | ||
309 | } | ||
310 | break; | ||
311 | } | ||
312 | search.resize( size ); | ||
313 | FindQuery query( search ); | ||
314 | OSQLResult res = m_driver->query( &query ); | ||
315 | if ( res.state() != OSQLResult::Success ) | ||
316 | return to; | ||
317 | |||
318 | return todo( res ); | ||
319 | } | ||
264 | void OTodoAccessBackendSQL::clear() { | 320 | void OTodoAccessBackendSQL::clear() { |
265 | ClearQuery cle; | 321 | ClearQuery cle; |
266 | OSQLResult res = m_driver->query( &cle ); | 322 | OSQLResult res = m_driver->query( &cle ); |
267 | CreateQuery qu; | 323 | CreateQuery qu; |
268 | res = m_driver->query(&qu); | 324 | res = m_driver->query(&qu); |
269 | } | 325 | } |
270 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 326 | bool OTodoAccessBackendSQL::add( const OTodo& t) { |
271 | InsertQuery ins( t ); | 327 | InsertQuery ins( t ); |
272 | OSQLResult res = m_driver->query( &ins ); | 328 | OSQLResult res = m_driver->query( &ins ); |
273 | 329 | ||
274 | if ( res.state() == OSQLResult::Failure ) | 330 | if ( res.state() == OSQLResult::Failure ) |
275 | return false; | 331 | return false; |
276 | int c = m_uids.count(); | 332 | int c = m_uids.count(); |
277 | m_uids.resize( c+1 ); | 333 | m_uids.resize( c+1 ); |
278 | m_uids[c] = t.uid(); | 334 | m_uids[c] = t.uid(); |
279 | 335 | ||
280 | return true; | 336 | return true; |
281 | } | 337 | } |
282 | bool OTodoAccessBackendSQL::remove( int uid ) { | 338 | bool OTodoAccessBackendSQL::remove( int uid ) { |
283 | RemoveQuery rem( uid ); | 339 | RemoveQuery rem( uid ); |
284 | OSQLResult res = m_driver->query(&rem ); | 340 | OSQLResult res = m_driver->query(&rem ); |
285 | 341 | ||
286 | if ( res.state() == OSQLResult::Failure ) | 342 | if ( res.state() == OSQLResult::Failure ) |
287 | return false; | 343 | return false; |
288 | 344 | ||
289 | update(); | 345 | update(); |
290 | return true; | 346 | return true; |
291 | } | 347 | } |
292 | /* | 348 | /* |
293 | * FIXME better set query | 349 | * FIXME better set query |
294 | * but we need the cache for that | 350 | * but we need the cache for that |
295 | * now we remove | 351 | * now we remove |
296 | */ | 352 | */ |
297 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 353 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
298 | remove( t.uid() ); | 354 | remove( t.uid() ); |
299 | return add(t); | 355 | return add(t); |
300 | } | 356 | } |
301 | QArray<int> OTodoAccessBackendSQL::overDue() { | 357 | QArray<int> OTodoAccessBackendSQL::overDue() { |
302 | OverDueQuery qu; | 358 | OverDueQuery qu; |
303 | return uids( m_driver->query(&qu ) ); | 359 | return uids( m_driver->query(&qu ) ); |
304 | } | 360 | } |
305 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 361 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
306 | const QDate& t, | 362 | const QDate& t, |
307 | bool u) { | 363 | bool u) { |
308 | EffQuery ef(s, t, u ); | 364 | EffQuery ef(s, t, u ); |
309 | return uids (m_driver->query(&ef) ); | 365 | return uids (m_driver->query(&ef) ); |
310 | } | 366 | } |
311 | /* | 367 | /* |
@@ -348,104 +404,117 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
348 | /* | 404 | /* |
349 | * sort order stuff | 405 | * sort order stuff |
350 | * quite straight forward | 406 | * quite straight forward |
351 | */ | 407 | */ |
352 | query += "ORDER BY "; | 408 | query += "ORDER BY "; |
353 | switch( sortOrder ) { | 409 | switch( sortOrder ) { |
354 | /* completed */ | 410 | /* completed */ |
355 | case 0: | 411 | case 0: |
356 | query += "completed"; | 412 | query += "completed"; |
357 | break; | 413 | break; |
358 | case 1: | 414 | case 1: |
359 | query += "priority"; | 415 | query += "priority"; |
360 | break; | 416 | break; |
361 | case 2: | 417 | case 2: |
362 | query += "description"; | 418 | query += "description"; |
363 | break; | 419 | break; |
364 | case 3: | 420 | case 3: |
365 | query += "DueDate"; | 421 | query += "DueDate"; |
366 | break; | 422 | break; |
367 | } | 423 | } |
368 | if ( !asc ) | 424 | if ( !asc ) |
369 | query += " DESC"; | 425 | query += " DESC"; |
370 | 426 | ||
371 | qWarning( query ); | 427 | qWarning( query ); |
372 | OSQLRawQuery raw(query ); | 428 | OSQLRawQuery raw(query ); |
373 | return uids( m_driver->query(&raw) ); | 429 | return uids( m_driver->query(&raw) ); |
374 | } | 430 | } |
375 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 431 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
376 | if ( str == "0-0-0" ) | 432 | if ( str == "0-0-0" ) |
377 | return false; | 433 | return false; |
378 | else{ | 434 | else{ |
379 | int day, year, month; | 435 | int day, year, month; |
380 | QStringList list = QStringList::split("-", str ); | 436 | QStringList list = QStringList::split("-", str ); |
381 | year = list[0].toInt(); | 437 | year = list[0].toInt(); |
382 | month = list[1].toInt(); | 438 | month = list[1].toInt(); |
383 | day = list[2].toInt(); | 439 | day = list[2].toInt(); |
384 | da.setYMD( year, month, day ); | 440 | da.setYMD( year, month, day ); |
385 | return true; | 441 | return true; |
386 | } | 442 | } |
387 | } | 443 | } |
388 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 444 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
389 | if ( res.state() == OSQLResult::Failure ) { | 445 | if ( res.state() == OSQLResult::Failure ) { |
390 | OTodo to; | 446 | OTodo to; |
391 | return to; | 447 | return to; |
392 | } | 448 | } |
393 | 449 | ||
394 | OSQLResultItem::ValueList list = res.results(); | 450 | OSQLResultItem::ValueList list = res.results(); |
395 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 451 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
396 | 452 | qWarning("todo1"); | |
453 | OTodo to = todo( (*it) ); | ||
454 | cache( to ); | ||
455 | ++it; | ||
456 | |||
457 | for ( ; it != list.end(); ++it ) { | ||
458 | qWarning("caching"); | ||
459 | cache( todo( (*it) ) ); | ||
460 | } | ||
461 | return to; | ||
462 | } | ||
463 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | ||
464 | qWarning("todo"); | ||
397 | bool has = false; QDate da = QDate::currentDate(); | 465 | bool has = false; QDate da = QDate::currentDate(); |
398 | has = date( da, (*it).data("DueDate") ); | 466 | has = date( da, item.data("DueDate") ); |
399 | QStringList cats = QStringList::split(";", (*it).data("categories") ); | 467 | QStringList cats = QStringList::split(";", item.data("categories") ); |
400 | 468 | ||
401 | OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), | 469 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
402 | cats, (*it).data("summary"), (*it).data("description"), | 470 | cats, item.data("summary"), item.data("description"), |
403 | (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); | 471 | item.data("progress").toUShort(), has, da, |
472 | item.data("uid").toInt() ); | ||
404 | return to; | 473 | return to; |
405 | } | 474 | } |
406 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 475 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
407 | FindQuery find( uid ); | 476 | FindQuery find( uid ); |
408 | return todo( m_driver->query(&find) ); | 477 | return todo( m_driver->query(&find) ); |
409 | } | 478 | } |
410 | /* | 479 | /* |
411 | * update the dict | 480 | * update the dict |
412 | */ | 481 | */ |
413 | void OTodoAccessBackendSQL::fillDict() { | 482 | void OTodoAccessBackendSQL::fillDict() { |
414 | /* initialize dict */ | 483 | /* initialize dict */ |
415 | /* | 484 | /* |
416 | * UPDATE dict if you change anything!!! | 485 | * UPDATE dict if you change anything!!! |
417 | */ | 486 | */ |
418 | m_dict.setAutoDelete( TRUE ); | 487 | m_dict.setAutoDelete( TRUE ); |
419 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 488 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
420 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 489 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
421 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 490 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
422 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 491 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
423 | m_dict.insert("Description" , new int(OTodo::Description) ); | 492 | m_dict.insert("Description" , new int(OTodo::Description) ); |
424 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 493 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
425 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 494 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
426 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 495 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
427 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 496 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
428 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 497 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
429 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 498 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
430 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 499 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
431 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 500 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
432 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 501 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
433 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 502 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
434 | } | 503 | } |
435 | void OTodoAccessBackendSQL::update() { | 504 | void OTodoAccessBackendSQL::update() { |
436 | LoadQuery lo; | 505 | LoadQuery lo; |
437 | OSQLResult res = m_driver->query(&lo); | 506 | OSQLResult res = m_driver->query(&lo); |
438 | if ( res.state() != OSQLResult::Success ) | 507 | if ( res.state() != OSQLResult::Success ) |
439 | return; | 508 | return; |
440 | 509 | ||
441 | m_uids = uids( res ); | 510 | m_uids = uids( res ); |
442 | } | 511 | } |
443 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 512 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
444 | 513 | ||
445 | OSQLResultItem::ValueList list = res.results(); | 514 | OSQLResultItem::ValueList list = res.results(); |
446 | OSQLResultItem::ValueList::Iterator it; | 515 | OSQLResultItem::ValueList::Iterator it; |
447 | QArray<int> ints(list.count() ); | 516 | QArray<int> ints(list.count() ); |
448 | qWarning(" count = %d", list.count() ); | 517 | qWarning(" count = %d", list.count() ); |
449 | 518 | ||
450 | int i = 0; | 519 | int i = 0; |
451 | for (it = list.begin(); it != list.end(); ++it ) { | 520 | for (it = list.begin(); it != list.end(); ++it ) { |
diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index 6c5f50a..c1aa2ed 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h | |||
@@ -1,46 +1,49 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_SQL_H | 1 | #ifndef OPIE_PIM_ACCESS_SQL_H |
2 | #define OPIE_PIM_ACCESS_SQL_H | 2 | #define OPIE_PIM_ACCESS_SQL_H |
3 | 3 | ||
4 | #include <qasciidict.h> | 4 | #include <qasciidict.h> |
5 | 5 | ||
6 | #include "otodoaccessbackend.h" | 6 | #include "otodoaccessbackend.h" |
7 | 7 | ||
8 | class OSQLDriver; | 8 | class OSQLDriver; |
9 | class OSQLResult; | 9 | class OSQLResult; |
10 | class OSQLResultItem; | ||
10 | class OTodoAccessBackendSQL : public OTodoAccessBackend { | 11 | class OTodoAccessBackendSQL : public OTodoAccessBackend { |
11 | public: | 12 | public: |
12 | OTodoAccessBackendSQL( const QString& file ); | 13 | OTodoAccessBackendSQL( const QString& file ); |
13 | ~OTodoAccessBackendSQL(); | 14 | ~OTodoAccessBackendSQL(); |
14 | 15 | ||
15 | bool load(); | 16 | bool load(); |
16 | bool reload(); | 17 | bool reload(); |
17 | bool save(); | 18 | bool save(); |
18 | QArray<int> allRecords()const; | 19 | QArray<int> allRecords()const; |
19 | 20 | ||
20 | QArray<int> queryByExample( const OTodo& t, int sort ); | 21 | QArray<int> queryByExample( const OTodo& t, int sort ); |
21 | OTodo find(int uid)const; | 22 | OTodo find(int uid)const; |
23 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; | ||
22 | void clear(); | 24 | void clear(); |
23 | bool add( const OTodo& t ); | 25 | bool add( const OTodo& t ); |
24 | bool remove( int uid ); | 26 | bool remove( int uid ); |
25 | bool replace( const OTodo& t ); | 27 | bool replace( const OTodo& t ); |
26 | 28 | ||
27 | QArray<int> overDue(); | 29 | QArray<int> overDue(); |
28 | QArray<int> effectiveToDos( const QDate& start, | 30 | QArray<int> effectiveToDos( const QDate& start, |
29 | const QDate& end, bool includeNoDates ); | 31 | const QDate& end, bool includeNoDates ); |
30 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
31 | 33 | ||
32 | private: | 34 | private: |
33 | void update(); | 35 | void update(); |
34 | void fillDict(); | 36 | void fillDict(); |
35 | inline bool date( QDate& date, const QString& )const; | 37 | inline bool date( QDate& date, const QString& )const; |
36 | inline OTodo todo( const OSQLResult& )const; | 38 | inline OTodo todo( const OSQLResult& )const; |
39 | inline OTodo todo( OSQLResultItem& )const; | ||
37 | inline QArray<int> uids( const OSQLResult& )const; | 40 | inline QArray<int> uids( const OSQLResult& )const; |
38 | OTodo todo( int uid )const; | 41 | OTodo todo( int uid )const; |
39 | 42 | ||
40 | QAsciiDict<int> m_dict; | 43 | QAsciiDict<int> m_dict; |
41 | OSQLDriver* m_driver; | 44 | OSQLDriver* m_driver; |
42 | QArray<int> m_uids; | 45 | QArray<int> m_uids; |
43 | }; | 46 | }; |
44 | 47 | ||
45 | 48 | ||
46 | #endif | 49 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 8add9f7..a059dab 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -36,276 +36,332 @@ namespace { | |||
36 | class LoadQuery : public OSQLQuery { | 36 | class LoadQuery : public OSQLQuery { |
37 | public: | 37 | public: |
38 | LoadQuery(); | 38 | LoadQuery(); |
39 | ~LoadQuery(); | 39 | ~LoadQuery(); |
40 | QString query()const; | 40 | QString query()const; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * inserts/adds a OTodo to the table | 44 | * inserts/adds a OTodo to the table |
45 | */ | 45 | */ |
46 | class InsertQuery : public OSQLQuery { | 46 | class InsertQuery : public OSQLQuery { |
47 | public: | 47 | public: |
48 | InsertQuery(const OTodo& ); | 48 | InsertQuery(const OTodo& ); |
49 | ~InsertQuery(); | 49 | ~InsertQuery(); |
50 | QString query()const; | 50 | QString query()const; |
51 | private: | 51 | private: |
52 | OTodo m_todo; | 52 | OTodo m_todo; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * removes one from the table | 56 | * removes one from the table |
57 | */ | 57 | */ |
58 | class RemoveQuery : public OSQLQuery { | 58 | class RemoveQuery : public OSQLQuery { |
59 | public: | 59 | public: |
60 | RemoveQuery(int uid ); | 60 | RemoveQuery(int uid ); |
61 | ~RemoveQuery(); | 61 | ~RemoveQuery(); |
62 | QString query()const; | 62 | QString query()const; |
63 | private: | 63 | private: |
64 | int m_uid; | 64 | int m_uid; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Clears (delete) a Table | 68 | * Clears (delete) a Table |
69 | */ | 69 | */ |
70 | class ClearQuery : public OSQLQuery { | 70 | class ClearQuery : public OSQLQuery { |
71 | public: | 71 | public: |
72 | ClearQuery(); | 72 | ClearQuery(); |
73 | ~ClearQuery(); | 73 | ~ClearQuery(); |
74 | QString query()const; | 74 | QString query()const; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * a find query | 79 | * a find query |
80 | */ | 80 | */ |
81 | class FindQuery : public OSQLQuery { | 81 | class FindQuery : public OSQLQuery { |
82 | public: | 82 | public: |
83 | FindQuery(int uid); | 83 | FindQuery(int uid); |
84 | FindQuery(const QArray<int>& ); | ||
84 | ~FindQuery(); | 85 | ~FindQuery(); |
85 | QString query()const; | 86 | QString query()const; |
86 | private: | 87 | private: |
88 | QString single()const; | ||
89 | QString multi()const; | ||
90 | QArray<int> m_uids; | ||
87 | int m_uid; | 91 | int m_uid; |
88 | }; | 92 | }; |
89 | 93 | ||
90 | /** | 94 | /** |
91 | * overdue query | 95 | * overdue query |
92 | */ | 96 | */ |
93 | class OverDueQuery : public OSQLQuery { | 97 | class OverDueQuery : public OSQLQuery { |
94 | public: | 98 | public: |
95 | OverDueQuery(); | 99 | OverDueQuery(); |
96 | ~OverDueQuery(); | 100 | ~OverDueQuery(); |
97 | QString query()const; | 101 | QString query()const; |
98 | }; | 102 | }; |
99 | class EffQuery : public OSQLQuery { | 103 | class EffQuery : public OSQLQuery { |
100 | public: | 104 | public: |
101 | EffQuery( const QDate&, const QDate&, bool inc ); | 105 | EffQuery( const QDate&, const QDate&, bool inc ); |
102 | ~EffQuery(); | 106 | ~EffQuery(); |
103 | QString query()const; | 107 | QString query()const; |
104 | private: | 108 | private: |
105 | QString with()const; | 109 | QString with()const; |
106 | QString out()const; | 110 | QString out()const; |
107 | QDate m_start; | 111 | QDate m_start; |
108 | QDate m_end; | 112 | QDate m_end; |
109 | bool m_inc :1; | 113 | bool m_inc :1; |
110 | }; | 114 | }; |
111 | 115 | ||
112 | 116 | ||
113 | CreateQuery::CreateQuery() : OSQLQuery() {} | 117 | CreateQuery::CreateQuery() : OSQLQuery() {} |
114 | CreateQuery::~CreateQuery() {} | 118 | CreateQuery::~CreateQuery() {} |
115 | QString CreateQuery::query()const { | 119 | QString CreateQuery::query()const { |
116 | QString qu; | 120 | QString qu; |
117 | qu += "create table todolist( uid, categories, completed, progress, "; | 121 | qu += "create table todolist( uid, categories, completed, progress, "; |
118 | qu += "summary, DueDate, priority, description )"; | 122 | qu += "summary, DueDate, priority, description )"; |
119 | return qu; | 123 | return qu; |
120 | } | 124 | } |
121 | 125 | ||
122 | LoadQuery::LoadQuery() : OSQLQuery() {} | 126 | LoadQuery::LoadQuery() : OSQLQuery() {} |
123 | LoadQuery::~LoadQuery() {} | 127 | LoadQuery::~LoadQuery() {} |
124 | QString LoadQuery::query()const { | 128 | QString LoadQuery::query()const { |
125 | QString qu; | 129 | QString qu; |
126 | qu += "select distinct uid from todolist"; | 130 | qu += "select distinct uid from todolist"; |
127 | 131 | ||
128 | return qu; | 132 | return qu; |
129 | } | 133 | } |
130 | 134 | ||
131 | InsertQuery::InsertQuery( const OTodo& todo ) | 135 | InsertQuery::InsertQuery( const OTodo& todo ) |
132 | : OSQLQuery(), m_todo( todo ) { | 136 | : OSQLQuery(), m_todo( todo ) { |
133 | } | 137 | } |
134 | InsertQuery::~InsertQuery() { | 138 | InsertQuery::~InsertQuery() { |
135 | } | 139 | } |
136 | /* | 140 | /* |
137 | * converts from a OTodo to a query | 141 | * converts from a OTodo to a query |
138 | * we leave out X-Ref + Alarms | 142 | * we leave out X-Ref + Alarms |
139 | */ | 143 | */ |
140 | QString InsertQuery::query()const{ | 144 | QString InsertQuery::query()const{ |
145 | |||
141 | int year, month, day; | 146 | int year, month, day; |
142 | year = month = day = 0; | 147 | year = month = day = 0; |
143 | if (m_todo.hasDueDate() ) { | 148 | if (m_todo.hasDueDate() ) { |
144 | QDate date = m_todo.dueDate(); | 149 | QDate date = m_todo.dueDate(); |
145 | year = date.year(); | 150 | year = date.year(); |
146 | month = date.month(); | 151 | month = date.month(); |
147 | day = date.day(); | 152 | day = date.day(); |
148 | } | 153 | } |
149 | QString qu; | 154 | QString qu; |
150 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; | 155 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; |
151 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; | 156 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; |
152 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; | 157 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; |
153 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; | 158 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; |
154 | 159 | ||
155 | qWarning("add %s", qu.latin1() ); | 160 | qWarning("add %s", qu.latin1() ); |
156 | return qu; | 161 | return qu; |
157 | } | 162 | } |
158 | 163 | ||
159 | RemoveQuery::RemoveQuery(int uid ) | 164 | RemoveQuery::RemoveQuery(int uid ) |
160 | : OSQLQuery(), m_uid( uid ) {} | 165 | : OSQLQuery(), m_uid( uid ) {} |
161 | RemoveQuery::~RemoveQuery() {} | 166 | RemoveQuery::~RemoveQuery() {} |
162 | QString RemoveQuery::query()const { | 167 | QString RemoveQuery::query()const { |
163 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); | 168 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); |
164 | return qu; | 169 | return qu; |
165 | } | 170 | } |
166 | 171 | ||
167 | 172 | ||
168 | ClearQuery::ClearQuery() | 173 | ClearQuery::ClearQuery() |
169 | : OSQLQuery() {} | 174 | : OSQLQuery() {} |
170 | ClearQuery::~ClearQuery() {} | 175 | ClearQuery::~ClearQuery() {} |
171 | QString ClearQuery::query()const { | 176 | QString ClearQuery::query()const { |
172 | QString qu = "drop table todolist"; | 177 | QString qu = "drop table todolist"; |
173 | return qu; | 178 | return qu; |
174 | } | 179 | } |
175 | FindQuery::FindQuery(int uid) | 180 | FindQuery::FindQuery(int uid) |
176 | : OSQLQuery(), m_uid(uid ) { | 181 | : OSQLQuery(), m_uid(uid ) { |
177 | } | 182 | } |
183 | FindQuery::FindQuery(const QArray<int>& ints) | ||
184 | : OSQLQuery(), m_uids(ints){ | ||
185 | } | ||
178 | FindQuery::~FindQuery() { | 186 | FindQuery::~FindQuery() { |
179 | } | 187 | } |
180 | QString FindQuery::query()const{ | 188 | QString FindQuery::query()const{ |
189 | if (m_uids.count() == 0 ) | ||
190 | return single(); | ||
191 | else | ||
192 | return multi(); | ||
193 | } | ||
194 | QString FindQuery::single()const{ | ||
181 | QString qu = "select uid, categories, completed, progress, summary, "; | 195 | QString qu = "select uid, categories, completed, progress, summary, "; |
182 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); | 196 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); |
183 | return qu; | 197 | return qu; |
184 | } | 198 | } |
199 | QString FindQuery::multi()const { | ||
200 | QString qu = "select uid, categories, completed, progress, summary, "; | ||
201 | qu += "DueDate, priority, description from todolist where "; | ||
202 | for (uint i = 0; i < m_uids.count(); i++ ) { | ||
203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | ||
204 | } | ||
205 | qu.remove( qu.length()-2, 2 ); | ||
206 | return qu; | ||
207 | } | ||
185 | 208 | ||
186 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 209 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
187 | OverDueQuery::~OverDueQuery() {} | 210 | OverDueQuery::~OverDueQuery() {} |
188 | QString OverDueQuery::query()const { | 211 | QString OverDueQuery::query()const { |
189 | QDate date = QDate::currentDate(); | 212 | QDate date = QDate::currentDate(); |
190 | QString str; | 213 | QString str; |
191 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); | 214 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); |
192 | 215 | ||
193 | return str; | 216 | return str; |
194 | } | 217 | } |
195 | 218 | ||
196 | 219 | ||
197 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 220 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
198 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 221 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
199 | EffQuery::~EffQuery() {} | 222 | EffQuery::~EffQuery() {} |
200 | QString EffQuery::query()const { | 223 | QString EffQuery::query()const { |
201 | return m_inc ? with() : out(); | 224 | return m_inc ? with() : out(); |
202 | } | 225 | } |
203 | QString EffQuery::with()const { | 226 | QString EffQuery::with()const { |
204 | QString str; | 227 | QString str; |
205 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 228 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
206 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) | 229 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) |
207 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); | 230 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); |
208 | return str; | 231 | return str; |
209 | } | 232 | } |
210 | QString EffQuery::out()const { | 233 | QString EffQuery::out()const { |
211 | QString str; | 234 | QString str; |
212 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 235 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
213 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
214 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
215 | 238 | ||
216 | return str; | 239 | return str; |
217 | } | 240 | } |
218 | }; | 241 | }; |
219 | 242 | ||
220 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
221 | : OTodoAccessBackend(), m_dict(15) | 244 | : OTodoAccessBackend(), m_dict(15) |
222 | { | 245 | { |
223 | QString fi = file; | 246 | QString fi = file; |
224 | if ( fi.isEmpty() ) | 247 | if ( fi.isEmpty() ) |
225 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
226 | OSQLManager man; | 249 | OSQLManager man; |
227 | m_driver = man.standard(); | 250 | m_driver = man.standard(); |
228 | m_driver->setUrl(fi); | 251 | m_driver->setUrl(fi); |
229 | fillDict(); | 252 | fillDict(); |
230 | } | 253 | } |
231 | 254 | ||
232 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
233 | } | 256 | } |
234 | bool OTodoAccessBackendSQL::load(){ | 257 | bool OTodoAccessBackendSQL::load(){ |
235 | if (!m_driver->open() ) | 258 | if (!m_driver->open() ) |
236 | return false; | 259 | return false; |
237 | 260 | ||
238 | CreateQuery creat; | 261 | CreateQuery creat; |
239 | OSQLResult res = m_driver->query(&creat ); | 262 | OSQLResult res = m_driver->query(&creat ); |
240 | 263 | ||
241 | update(); | 264 | update(); |
242 | qWarning("loaded %d", m_uids.count() ); | 265 | qWarning("loaded %d", m_uids.count() ); |
243 | return true; | 266 | return true; |
244 | } | 267 | } |
245 | bool OTodoAccessBackendSQL::reload(){ | 268 | bool OTodoAccessBackendSQL::reload(){ |
246 | return load(); | 269 | return load(); |
247 | } | 270 | } |
248 | 271 | ||
249 | bool OTodoAccessBackendSQL::save(){ | 272 | bool OTodoAccessBackendSQL::save(){ |
250 | return m_driver->close(); | 273 | return m_driver->close(); |
251 | } | 274 | } |
252 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 275 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
253 | return m_uids; | 276 | return m_uids; |
254 | } | 277 | } |
255 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 278 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
256 | QArray<int> ints(0); | 279 | QArray<int> ints(0); |
257 | return ints; | 280 | return ints; |
258 | } | 281 | } |
259 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 282 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
260 | FindQuery query( uid ); | 283 | FindQuery query( uid ); |
261 | return todo( m_driver->query(&query) ); | 284 | return todo( m_driver->query(&query) ); |
262 | 285 | ||
263 | } | 286 | } |
287 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | ||
288 | uint cur, Frontend::CacheDirection dir ) const{ | ||
289 | qWarning("searching for %d", uid ); | ||
290 | QArray<int> search( 8 ); | ||
291 | uint size =0; | ||
292 | OTodo to; | ||
293 | |||
294 | // we try to cache 8 items | ||
295 | switch( dir ) { | ||
296 | /* forward */ | ||
297 | case 0: | ||
298 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { | ||
299 | qWarning("size %d %d", size, ints[i] ); | ||
300 | search[size] = ints[i]; | ||
301 | size++; | ||
302 | } | ||
303 | break; | ||
304 | /* reverse */ | ||
305 | case 1: | ||
306 | for (uint i = cur; i >= 0 && size < 8; i-- ) { | ||
307 | search[size] = ints[i]; | ||
308 | size++; | ||
309 | } | ||
310 | break; | ||
311 | } | ||
312 | search.resize( size ); | ||
313 | FindQuery query( search ); | ||
314 | OSQLResult res = m_driver->query( &query ); | ||
315 | if ( res.state() != OSQLResult::Success ) | ||
316 | return to; | ||
317 | |||
318 | return todo( res ); | ||
319 | } | ||
264 | void OTodoAccessBackendSQL::clear() { | 320 | void OTodoAccessBackendSQL::clear() { |
265 | ClearQuery cle; | 321 | ClearQuery cle; |
266 | OSQLResult res = m_driver->query( &cle ); | 322 | OSQLResult res = m_driver->query( &cle ); |
267 | CreateQuery qu; | 323 | CreateQuery qu; |
268 | res = m_driver->query(&qu); | 324 | res = m_driver->query(&qu); |
269 | } | 325 | } |
270 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 326 | bool OTodoAccessBackendSQL::add( const OTodo& t) { |
271 | InsertQuery ins( t ); | 327 | InsertQuery ins( t ); |
272 | OSQLResult res = m_driver->query( &ins ); | 328 | OSQLResult res = m_driver->query( &ins ); |
273 | 329 | ||
274 | if ( res.state() == OSQLResult::Failure ) | 330 | if ( res.state() == OSQLResult::Failure ) |
275 | return false; | 331 | return false; |
276 | int c = m_uids.count(); | 332 | int c = m_uids.count(); |
277 | m_uids.resize( c+1 ); | 333 | m_uids.resize( c+1 ); |
278 | m_uids[c] = t.uid(); | 334 | m_uids[c] = t.uid(); |
279 | 335 | ||
280 | return true; | 336 | return true; |
281 | } | 337 | } |
282 | bool OTodoAccessBackendSQL::remove( int uid ) { | 338 | bool OTodoAccessBackendSQL::remove( int uid ) { |
283 | RemoveQuery rem( uid ); | 339 | RemoveQuery rem( uid ); |
284 | OSQLResult res = m_driver->query(&rem ); | 340 | OSQLResult res = m_driver->query(&rem ); |
285 | 341 | ||
286 | if ( res.state() == OSQLResult::Failure ) | 342 | if ( res.state() == OSQLResult::Failure ) |
287 | return false; | 343 | return false; |
288 | 344 | ||
289 | update(); | 345 | update(); |
290 | return true; | 346 | return true; |
291 | } | 347 | } |
292 | /* | 348 | /* |
293 | * FIXME better set query | 349 | * FIXME better set query |
294 | * but we need the cache for that | 350 | * but we need the cache for that |
295 | * now we remove | 351 | * now we remove |
296 | */ | 352 | */ |
297 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 353 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
298 | remove( t.uid() ); | 354 | remove( t.uid() ); |
299 | return add(t); | 355 | return add(t); |
300 | } | 356 | } |
301 | QArray<int> OTodoAccessBackendSQL::overDue() { | 357 | QArray<int> OTodoAccessBackendSQL::overDue() { |
302 | OverDueQuery qu; | 358 | OverDueQuery qu; |
303 | return uids( m_driver->query(&qu ) ); | 359 | return uids( m_driver->query(&qu ) ); |
304 | } | 360 | } |
305 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 361 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
306 | const QDate& t, | 362 | const QDate& t, |
307 | bool u) { | 363 | bool u) { |
308 | EffQuery ef(s, t, u ); | 364 | EffQuery ef(s, t, u ); |
309 | return uids (m_driver->query(&ef) ); | 365 | return uids (m_driver->query(&ef) ); |
310 | } | 366 | } |
311 | /* | 367 | /* |
@@ -348,104 +404,117 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
348 | /* | 404 | /* |
349 | * sort order stuff | 405 | * sort order stuff |
350 | * quite straight forward | 406 | * quite straight forward |
351 | */ | 407 | */ |
352 | query += "ORDER BY "; | 408 | query += "ORDER BY "; |
353 | switch( sortOrder ) { | 409 | switch( sortOrder ) { |
354 | /* completed */ | 410 | /* completed */ |
355 | case 0: | 411 | case 0: |
356 | query += "completed"; | 412 | query += "completed"; |
357 | break; | 413 | break; |
358 | case 1: | 414 | case 1: |
359 | query += "priority"; | 415 | query += "priority"; |
360 | break; | 416 | break; |
361 | case 2: | 417 | case 2: |
362 | query += "description"; | 418 | query += "description"; |
363 | break; | 419 | break; |
364 | case 3: | 420 | case 3: |
365 | query += "DueDate"; | 421 | query += "DueDate"; |
366 | break; | 422 | break; |
367 | } | 423 | } |
368 | if ( !asc ) | 424 | if ( !asc ) |
369 | query += " DESC"; | 425 | query += " DESC"; |
370 | 426 | ||
371 | qWarning( query ); | 427 | qWarning( query ); |
372 | OSQLRawQuery raw(query ); | 428 | OSQLRawQuery raw(query ); |
373 | return uids( m_driver->query(&raw) ); | 429 | return uids( m_driver->query(&raw) ); |
374 | } | 430 | } |
375 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 431 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
376 | if ( str == "0-0-0" ) | 432 | if ( str == "0-0-0" ) |
377 | return false; | 433 | return false; |
378 | else{ | 434 | else{ |
379 | int day, year, month; | 435 | int day, year, month; |
380 | QStringList list = QStringList::split("-", str ); | 436 | QStringList list = QStringList::split("-", str ); |
381 | year = list[0].toInt(); | 437 | year = list[0].toInt(); |
382 | month = list[1].toInt(); | 438 | month = list[1].toInt(); |
383 | day = list[2].toInt(); | 439 | day = list[2].toInt(); |
384 | da.setYMD( year, month, day ); | 440 | da.setYMD( year, month, day ); |
385 | return true; | 441 | return true; |
386 | } | 442 | } |
387 | } | 443 | } |
388 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 444 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
389 | if ( res.state() == OSQLResult::Failure ) { | 445 | if ( res.state() == OSQLResult::Failure ) { |
390 | OTodo to; | 446 | OTodo to; |
391 | return to; | 447 | return to; |
392 | } | 448 | } |
393 | 449 | ||
394 | OSQLResultItem::ValueList list = res.results(); | 450 | OSQLResultItem::ValueList list = res.results(); |
395 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 451 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
396 | 452 | qWarning("todo1"); | |
453 | OTodo to = todo( (*it) ); | ||
454 | cache( to ); | ||
455 | ++it; | ||
456 | |||
457 | for ( ; it != list.end(); ++it ) { | ||
458 | qWarning("caching"); | ||
459 | cache( todo( (*it) ) ); | ||
460 | } | ||
461 | return to; | ||
462 | } | ||
463 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | ||
464 | qWarning("todo"); | ||
397 | bool has = false; QDate da = QDate::currentDate(); | 465 | bool has = false; QDate da = QDate::currentDate(); |
398 | has = date( da, (*it).data("DueDate") ); | 466 | has = date( da, item.data("DueDate") ); |
399 | QStringList cats = QStringList::split(";", (*it).data("categories") ); | 467 | QStringList cats = QStringList::split(";", item.data("categories") ); |
400 | 468 | ||
401 | OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), | 469 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
402 | cats, (*it).data("summary"), (*it).data("description"), | 470 | cats, item.data("summary"), item.data("description"), |
403 | (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); | 471 | item.data("progress").toUShort(), has, da, |
472 | item.data("uid").toInt() ); | ||
404 | return to; | 473 | return to; |
405 | } | 474 | } |
406 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 475 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
407 | FindQuery find( uid ); | 476 | FindQuery find( uid ); |
408 | return todo( m_driver->query(&find) ); | 477 | return todo( m_driver->query(&find) ); |
409 | } | 478 | } |
410 | /* | 479 | /* |
411 | * update the dict | 480 | * update the dict |
412 | */ | 481 | */ |
413 | void OTodoAccessBackendSQL::fillDict() { | 482 | void OTodoAccessBackendSQL::fillDict() { |
414 | /* initialize dict */ | 483 | /* initialize dict */ |
415 | /* | 484 | /* |
416 | * UPDATE dict if you change anything!!! | 485 | * UPDATE dict if you change anything!!! |
417 | */ | 486 | */ |
418 | m_dict.setAutoDelete( TRUE ); | 487 | m_dict.setAutoDelete( TRUE ); |
419 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 488 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
420 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 489 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
421 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 490 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
422 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 491 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
423 | m_dict.insert("Description" , new int(OTodo::Description) ); | 492 | m_dict.insert("Description" , new int(OTodo::Description) ); |
424 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 493 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
425 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 494 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
426 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 495 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
427 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 496 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
428 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 497 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
429 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 498 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
430 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 499 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
431 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 500 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
432 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 501 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
433 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 502 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
434 | } | 503 | } |
435 | void OTodoAccessBackendSQL::update() { | 504 | void OTodoAccessBackendSQL::update() { |
436 | LoadQuery lo; | 505 | LoadQuery lo; |
437 | OSQLResult res = m_driver->query(&lo); | 506 | OSQLResult res = m_driver->query(&lo); |
438 | if ( res.state() != OSQLResult::Success ) | 507 | if ( res.state() != OSQLResult::Success ) |
439 | return; | 508 | return; |
440 | 509 | ||
441 | m_uids = uids( res ); | 510 | m_uids = uids( res ); |
442 | } | 511 | } |
443 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 512 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
444 | 513 | ||
445 | OSQLResultItem::ValueList list = res.results(); | 514 | OSQLResultItem::ValueList list = res.results(); |
446 | OSQLResultItem::ValueList::Iterator it; | 515 | OSQLResultItem::ValueList::Iterator it; |
447 | QArray<int> ints(list.count() ); | 516 | QArray<int> ints(list.count() ); |
448 | qWarning(" count = %d", list.count() ); | 517 | qWarning(" count = %d", list.count() ); |
449 | 518 | ||
450 | int i = 0; | 519 | int i = 0; |
451 | for (it = list.begin(); it != list.end(); ++it ) { | 520 | for (it = list.begin(); it != list.end(); ++it ) { |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index 6c5f50a..c1aa2ed 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h | |||
@@ -1,46 +1,49 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_SQL_H | 1 | #ifndef OPIE_PIM_ACCESS_SQL_H |
2 | #define OPIE_PIM_ACCESS_SQL_H | 2 | #define OPIE_PIM_ACCESS_SQL_H |
3 | 3 | ||
4 | #include <qasciidict.h> | 4 | #include <qasciidict.h> |
5 | 5 | ||
6 | #include "otodoaccessbackend.h" | 6 | #include "otodoaccessbackend.h" |
7 | 7 | ||
8 | class OSQLDriver; | 8 | class OSQLDriver; |
9 | class OSQLResult; | 9 | class OSQLResult; |
10 | class OSQLResultItem; | ||
10 | class OTodoAccessBackendSQL : public OTodoAccessBackend { | 11 | class OTodoAccessBackendSQL : public OTodoAccessBackend { |
11 | public: | 12 | public: |
12 | OTodoAccessBackendSQL( const QString& file ); | 13 | OTodoAccessBackendSQL( const QString& file ); |
13 | ~OTodoAccessBackendSQL(); | 14 | ~OTodoAccessBackendSQL(); |
14 | 15 | ||
15 | bool load(); | 16 | bool load(); |
16 | bool reload(); | 17 | bool reload(); |
17 | bool save(); | 18 | bool save(); |
18 | QArray<int> allRecords()const; | 19 | QArray<int> allRecords()const; |
19 | 20 | ||
20 | QArray<int> queryByExample( const OTodo& t, int sort ); | 21 | QArray<int> queryByExample( const OTodo& t, int sort ); |
21 | OTodo find(int uid)const; | 22 | OTodo find(int uid)const; |
23 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; | ||
22 | void clear(); | 24 | void clear(); |
23 | bool add( const OTodo& t ); | 25 | bool add( const OTodo& t ); |
24 | bool remove( int uid ); | 26 | bool remove( int uid ); |
25 | bool replace( const OTodo& t ); | 27 | bool replace( const OTodo& t ); |
26 | 28 | ||
27 | QArray<int> overDue(); | 29 | QArray<int> overDue(); |
28 | QArray<int> effectiveToDos( const QDate& start, | 30 | QArray<int> effectiveToDos( const QDate& start, |
29 | const QDate& end, bool includeNoDates ); | 31 | const QDate& end, bool includeNoDates ); |
30 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
31 | 33 | ||
32 | private: | 34 | private: |
33 | void update(); | 35 | void update(); |
34 | void fillDict(); | 36 | void fillDict(); |
35 | inline bool date( QDate& date, const QString& )const; | 37 | inline bool date( QDate& date, const QString& )const; |
36 | inline OTodo todo( const OSQLResult& )const; | 38 | inline OTodo todo( const OSQLResult& )const; |
39 | inline OTodo todo( OSQLResultItem& )const; | ||
37 | inline QArray<int> uids( const OSQLResult& )const; | 40 | inline QArray<int> uids( const OSQLResult& )const; |
38 | OTodo todo( int uid )const; | 41 | OTodo todo( int uid )const; |
39 | 42 | ||
40 | QAsciiDict<int> m_dict; | 43 | QAsciiDict<int> m_dict; |
41 | OSQLDriver* m_driver; | 44 | OSQLDriver* m_driver; |
42 | QArray<int> m_uids; | 45 | QArray<int> m_uids; |
43 | }; | 46 | }; |
44 | 47 | ||
45 | 48 | ||
46 | #endif | 49 | #endif |
diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h index 067f6e7..839550c 100644 --- a/libopie2/opiepim/core/opimcache.h +++ b/libopie2/opiepim/core/opimcache.h | |||
@@ -16,97 +16,99 @@ public: | |||
16 | private: | 16 | private: |
17 | T m_t; | 17 | T m_t; |
18 | }; | 18 | }; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * OPimCache for caching the items | 21 | * OPimCache for caching the items |
22 | * We support adding, removing | 22 | * We support adding, removing |
23 | * and finding | 23 | * and finding |
24 | */ | 24 | */ |
25 | template <class T = OPimRecord> | 25 | template <class T = OPimRecord> |
26 | class OPimCache { | 26 | class OPimCache { |
27 | public: | 27 | public: |
28 | typedef OPimCacheItem<T> Item; | 28 | typedef OPimCacheItem<T> Item; |
29 | OPimCache(); | 29 | OPimCache(); |
30 | ~OPimCache(); | 30 | ~OPimCache(); |
31 | 31 | ||
32 | bool contains(int uid)const; | 32 | bool contains(int uid)const; |
33 | void invalidate(); | 33 | void invalidate(); |
34 | void setSize( int size ); | 34 | void setSize( int size ); |
35 | 35 | ||
36 | T find(int uid )const; | 36 | T find(int uid )const; |
37 | void add( const T& ); | 37 | void add( const T& ); |
38 | void remove( int uid ); | 38 | void remove( int uid ); |
39 | void replace( const T& ); | 39 | void replace( const T& ); |
40 | 40 | ||
41 | private: | 41 | private: |
42 | QIntCache<Item> m_cache; | 42 | QIntCache<Item> m_cache; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | // Implementation | 45 | // Implementation |
46 | template <class T> | 46 | template <class T> |
47 | OPimCacheItem<T>::OPimCacheItem( const T& t ) | 47 | OPimCacheItem<T>::OPimCacheItem( const T& t ) |
48 | : m_t(t) { | 48 | : m_t(t) { |
49 | } | 49 | } |
50 | template <class T> | 50 | template <class T> |
51 | OPimCacheItem<T>::~OPimCacheItem() { | 51 | OPimCacheItem<T>::~OPimCacheItem() { |
52 | 52 | ||
53 | } | 53 | } |
54 | template <class T> | 54 | template <class T> |
55 | T OPimCacheItem<T>::record()const { | 55 | T OPimCacheItem<T>::record()const { |
56 | return m_t; | 56 | return m_t; |
57 | } | 57 | } |
58 | template <class T> | 58 | template <class T> |
59 | void OPimCacheItem<T>::setRecord( const T& t ) { | 59 | void OPimCacheItem<T>::setRecord( const T& t ) { |
60 | m_t = t; | 60 | m_t = t; |
61 | } | 61 | } |
62 | // Cache | 62 | // Cache |
63 | template <class T> | 63 | template <class T> |
64 | OPimCache<T>::OPimCache() { | 64 | OPimCache<T>::OPimCache() |
65 | : m_cache(100, 53 ) | ||
66 | { | ||
65 | m_cache.setAutoDelete( TRUE ); | 67 | m_cache.setAutoDelete( TRUE ); |
66 | } | 68 | } |
67 | template <class T> | 69 | template <class T> |
68 | OPimCache<T>::~OPimCache() { | 70 | OPimCache<T>::~OPimCache() { |
69 | 71 | ||
70 | } | 72 | } |
71 | template <class T> | 73 | template <class T> |
72 | bool OPimCache<T>::contains(int uid )const { | 74 | bool OPimCache<T>::contains(int uid )const { |
73 | Item* it = m_cache.find( uid, FALSE ); | 75 | Item* it = m_cache.find( uid, FALSE ); |
74 | if (!it) | 76 | if (!it) |
75 | return false; | 77 | return false; |
76 | return true; | 78 | return true; |
77 | } | 79 | } |
78 | template <class T> | 80 | template <class T> |
79 | void OPimCache<T>::invalidate() { | 81 | void OPimCache<T>::invalidate() { |
80 | m_cache.clear(); | 82 | m_cache.clear(); |
81 | } | 83 | } |
82 | template <class T> | 84 | template <class T> |
83 | void OPimCache<T>::setSize( int size ) { | 85 | void OPimCache<T>::setSize( int size ) { |
84 | m_cache.setMaxCost( size ); | 86 | m_cache.setMaxCost( size ); |
85 | } | 87 | } |
86 | template <class T> | 88 | template <class T> |
87 | T OPimCache<T>::find(int uid )const { | 89 | T OPimCache<T>::find(int uid )const { |
88 | Item *it = m_cache.find( uid ); | 90 | Item *it = m_cache.find( uid ); |
89 | if (it) | 91 | if (it) |
90 | return it->record(); | 92 | return it->record(); |
91 | return T(); | 93 | return T(); |
92 | } | 94 | } |
93 | template <class T> | 95 | template <class T> |
94 | void OPimCache<T>::add( const T& t ) { | 96 | void OPimCache<T>::add( const T& t ) { |
95 | Item* it = 0l; | 97 | Item* it = 0l; |
96 | it = m_cache.find(t.uid(), FALSE ); | 98 | it = m_cache.find(t.uid(), FALSE ); |
97 | 99 | ||
98 | if (it ) | 100 | if (it ) |
99 | it->setRecord( t ); | 101 | it->setRecord( t ); |
100 | 102 | ||
101 | it = new Item( t ); | 103 | it = new Item( t ); |
102 | if (!m_cache.insert( t.uid(), it ) ) | 104 | if (!m_cache.insert( t.uid(), it ) ) |
103 | delete it; | 105 | delete it; |
104 | } | 106 | } |
105 | template <class T> | 107 | template <class T> |
106 | void OPimCache<T>::remove( int uid ) { | 108 | void OPimCache<T>::remove( int uid ) { |
107 | m_cache.remove( uid ); | 109 | m_cache.remove( uid ); |
108 | } | 110 | } |
109 | template <class T> | 111 | template <class T> |
110 | void OPimCache<T>::replace( const T& t) { | 112 | void OPimCache<T>::replace( const T& t) { |
111 | Item *it = m_cache.find( t.uid() ); | 113 | Item *it = m_cache.find( t.uid() ); |
112 | if ( it ) { | 114 | if ( it ) { |