author | eilers <eilers> | 2003-12-22 10:19:25 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-12-22 10:19:25 (UTC) |
commit | ae70312b1613e26b4ef89a2c9821d9531b82e987 (patch) (unidiff) | |
tree | 7eb70bc45ee29e94da27a18b0136eb4a14e59fa6 /libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |
parent | 9e7aafdb7c76d29fee742d53131a73dd60aded2b (diff) | |
download | opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.zip opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.tar.gz opie-ae70312b1613e26b4ef89a2c9821d9531b82e987.tar.bz2 |
Finishing implementation of sql-backend for datebook. But I have to
port the PIM datebook application to use it, before I could debug the
whole stuff.
Thus, PIM-Database backend is finished, but highly experimental. And some
parts are still generic. For instance, the "queryByExample()" methods are
not (or not fully) implemented. Todo: custom-entries not stored.
The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
expression search in the database, which is not supported by sqlite !
Therefore we need either an extended sqlite or a workaround which would
be very slow and memory consuming..
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 215 |
1 files changed, 175 insertions, 40 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 9769bf7..e893b38 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -16,2 +16,14 @@ | |||
16 | * $Log$ | 16 | * $Log$ |
17 | * Revision 1.2 2003/12/22 10:19:26 eilers | ||
18 | * Finishing implementation of sql-backend for datebook. But I have to | ||
19 | * port the PIM datebook application to use it, before I could debug the | ||
20 | * whole stuff. | ||
21 | * Thus, PIM-Database backend is finished, but highly experimental. And some | ||
22 | * parts are still generic. For instance, the "queryByExample()" methods are | ||
23 | * not (or not fully) implemented. Todo: custom-entries not stored. | ||
24 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | ||
25 | * expression search in the database, which is not supported by sqlite ! | ||
26 | * Therefore we need either an extended sqlite or a workaround which would | ||
27 | * be very slow and memory consuming.. | ||
28 | * | ||
17 | * Revision 1.1 2003/12/08 15:18:12 eilers | 29 | * Revision 1.1 2003/12/08 15:18:12 eilers |
@@ -28,7 +40,5 @@ | |||
28 | 40 | ||
29 | #include "orecur.h" | 41 | #include <qpe/global.h> |
30 | #include "odatebookaccessbackend_sql.h" | ||
31 | 42 | ||
32 | #include <opie2/osqldriver.h> | 43 | #include <opie2/osqldriver.h> |
33 | #include <opie2/osqlresult.h> | ||
34 | #include <opie2/osqlmanager.h> | 44 | #include <opie2/osqlmanager.h> |
@@ -36,7 +46,6 @@ | |||
36 | 46 | ||
37 | namespace { | 47 | #include "orecur.h" |
38 | 48 | #include "odatebookaccessbackend_sql.h" | |
39 | 49 | ||
40 | 50 | ||
41 | }; | ||
42 | 51 | ||
@@ -59,2 +68,4 @@ ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | |||
59 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { | 68 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { |
69 | if( m_driver ) | ||
70 | delete m_driver; | ||
60 | } | 71 | } |
@@ -80,3 +91,3 @@ void ODateBookAccessBackend_SQL::initFields() | |||
80 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); | 91 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); |
81 | m_fieldMap.insert( OEvent::FRExeptions, "RExceptions" ); | 92 | m_fieldMap.insert( OEvent::FRExceptions, "RExceptions" ); |
82 | m_fieldMap.insert( OEvent::FStart, "Start" ); | 93 | m_fieldMap.insert( OEvent::FStart, "Start" ); |
@@ -87,2 +98,9 @@ void ODateBookAccessBackend_SQL::initFields() | |||
87 | m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); | 98 | m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); |
99 | |||
100 | // Create a map that maps the column name to the id | ||
101 | QMapConstIterator<int, QString> it; | ||
102 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | ||
103 | m_reverseFieldMap.insert( it.data(), it.key() ); | ||
104 | } | ||
105 | |||
88 | } | 106 | } |
@@ -101,3 +119,3 @@ bool ODateBookAccessBackend_SQL::load() | |||
101 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 119 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
102 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( it.data() ); | 120 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); |
103 | } | 121 | } |
@@ -107,2 +125,4 @@ bool ODateBookAccessBackend_SQL::load() | |||
107 | 125 | ||
126 | qWarning( "command: %s", qu.latin1() ); | ||
127 | |||
108 | OSQLRawQuery raw( qu ); | 128 | OSQLRawQuery raw( qu ); |
@@ -124,3 +144,3 @@ void ODateBookAccessBackend_SQL::update() | |||
124 | if ( res.state() != OSQLResult::Success ){ | 144 | if ( res.state() != OSQLResult::Success ){ |
125 | m_uids.clear(); | 145 | // m_uids.clear(); |
126 | return; | 146 | return; |
@@ -132,21 +152,2 @@ void ODateBookAccessBackend_SQL::update() | |||
132 | 152 | ||
133 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const | ||
134 | { | ||
135 | qWarning("extractUids"); | ||
136 | |||
137 | OSQLResultItem::ValueList list = res.results(); | ||
138 | OSQLResultItem::ValueList::Iterator it; | ||
139 | QArray<int> ints(list.count() ); | ||
140 | qWarning(" count = %d", list.count() ); | ||
141 | |||
142 | int i = 0; | ||
143 | for (it = list.begin(); it != list.end(); ++it ) { | ||
144 | ints[i] = (*it).data("uid").toInt(); | ||
145 | i++; | ||
146 | } | ||
147 | |||
148 | return ints; | ||
149 | |||
150 | } | ||
151 | |||
152 | bool ODateBookAccessBackend_SQL::reload() | 153 | bool ODateBookAccessBackend_SQL::reload() |
@@ -158,3 +159,3 @@ bool ODateBookAccessBackend_SQL::save() | |||
158 | { | 159 | { |
159 | return m_driver->close(); | 160 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
160 | } | 161 | } |
@@ -178,2 +179,3 @@ void ODateBookAccessBackend_SQL::clear() | |||
178 | 179 | ||
180 | reload(); | ||
179 | } | 181 | } |
@@ -182,8 +184,80 @@ void ODateBookAccessBackend_SQL::clear() | |||
182 | OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | 184 | OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ |
185 | QString qu = "select *"; | ||
186 | qu += "from datebook where uid = " + QString::number(uid); | ||
187 | |||
188 | OSQLRawQuery raw( qu ); | ||
189 | OSQLResult res = m_driver->query( &raw ); | ||
190 | |||
191 | OSQLResultItem resItem = res.first(); | ||
192 | |||
193 | // Create Map for date event and insert UID | ||
194 | QMap<int,QString> dateEventMap; | ||
195 | dateEventMap.insert( OEvent::FUid, QString::number( uid ) ); | ||
196 | |||
197 | // Now insert the data out of the columns into the map. | ||
198 | QMapConstIterator<int, QString> it; | ||
199 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | ||
200 | dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); | ||
201 | } | ||
202 | |||
203 | // Last step: Put map into date event and return it | ||
204 | OEvent retDate( dateEventMap ); | ||
205 | |||
206 | return retDate; | ||
207 | } | ||
208 | |||
209 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) | ||
210 | { | ||
211 | QMap<int,QString> eventMap = ev.toMap(); | ||
212 | |||
213 | QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); | ||
214 | QMap<int, QString>::Iterator it; | ||
215 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | ||
216 | if ( !eventMap[it.key()].isEmpty() ) | ||
217 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); | ||
218 | else | ||
219 | qu += QString( ",\"\"" ); | ||
220 | } | ||
221 | qu += " );"; | ||
222 | |||
223 | // Add custom entries | ||
224 | int id = 0; | ||
225 | QMap<QString, QString> customMap = ev.toExtraMap(); | ||
226 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | ||
227 | it != customMap.end(); ++it ){ | ||
228 | qu += "insert into custom_data VALUES(" | ||
229 | + QString::number( ev.uid() ) | ||
230 | + "," | ||
231 | + QString::number( id++ ) | ||
232 | + ",'" | ||
233 | + it.key() //.latin1() | ||
234 | + "'," | ||
235 | + "0" // Priority for future enhancements | ||
236 | + ",'" | ||
237 | + it.data() //.latin1() | ||
238 | + "');"; | ||
239 | } | ||
240 | qWarning("add %s", qu.latin1() ); | ||
241 | |||
242 | OSQLRawQuery raw( qu ); | ||
243 | OSQLResult res = m_driver->query( &raw ); | ||
244 | if ( res.state() != OSQLResult::Success ){ | ||
245 | return false; | ||
183 | } | 246 | } |
184 | 247 | ||
185 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) { | ||
186 | return true; | 248 | return true; |
187 | } | 249 | } |
188 | bool ODateBookAccessBackend_SQL::remove( int uid ) { | 250 | |
251 | bool ODateBookAccessBackend_SQL::remove( int uid ) | ||
252 | { | ||
253 | QString qu = "DELETE from datebook where uid = " | ||
254 | + QString::number( uid ) + ";"; | ||
255 | qu += "DELETE from custom_data where uid = " | ||
256 | + QString::number( uid ) + ";"; | ||
257 | |||
258 | OSQLRawQuery raw( qu ); | ||
259 | OSQLResult res = m_driver->query( &raw ); | ||
260 | if ( res.state() != OSQLResult::Success ){ | ||
261 | return false; | ||
262 | } | ||
189 | 263 | ||
@@ -191,3 +265,5 @@ bool ODateBookAccessBackend_SQL::remove( int uid ) { | |||
191 | } | 265 | } |
192 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) { | 266 | |
267 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) | ||
268 | { | ||
193 | remove( ev.uid() ); | 269 | remove( ev.uid() ); |
@@ -195,18 +271,54 @@ bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) { | |||
195 | } | 271 | } |
196 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const { | 272 | |
273 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const | ||
274 | { | ||
197 | return allRecords(); | 275 | return allRecords(); |
198 | } | 276 | } |
199 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const { | ||
200 | 277 | ||
201 | return ints; | 278 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const |
279 | { | ||
280 | QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; | ||
281 | OSQLRawQuery raw( qu ); | ||
282 | OSQLResult res = m_driver->query( &raw ); | ||
283 | if ( res.state() != OSQLResult::Success ){ | ||
284 | QArray<int> nix; | ||
285 | return nix; | ||
202 | } | 286 | } |
203 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const { | ||
204 | 287 | ||
205 | return ints; | 288 | return extractUids( res ); |
289 | } | ||
290 | |||
291 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const | ||
292 | { | ||
293 | QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; | ||
294 | OSQLRawQuery raw( qu ); | ||
295 | OSQLResult res = m_driver->query( &raw ); | ||
296 | if ( res.state() != OSQLResult::Success ){ | ||
297 | QArray<int> nix; | ||
298 | return nix; | ||
299 | } | ||
300 | |||
301 | return extractUids( res ); | ||
302 | } | ||
303 | |||
304 | OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() | ||
305 | { | ||
306 | QArray<int> nonRepUids = nonRepeats(); | ||
307 | OEvent::ValueList list; | ||
308 | |||
309 | for (uint i = 0; i < nonRepUids.count(); ++i ){ | ||
310 | list.append( find( nonRepUids[i] ) ); | ||
206 | } | 311 | } |
207 | OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() { | ||
208 | 312 | ||
209 | return list; | 313 | return list; |
314 | |||
315 | } | ||
316 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() | ||
317 | { | ||
318 | QArray<int> rawRepUids = rawRepeats(); | ||
319 | OEvent::ValueList list; | ||
320 | |||
321 | for (uint i = 0; i < rawRepUids.count(); ++i ){ | ||
322 | list.append( find( rawRepUids[i] ) ); | ||
210 | } | 323 | } |
211 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() { | ||
212 | 324 | ||
@@ -218,4 +330,27 @@ QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | |||
218 | { | 330 | { |
331 | QArray<int> null; | ||
332 | return null; | ||
333 | } | ||
334 | |||
335 | /* ===== Private Functions ========================================== */ | ||
336 | |||
337 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const | ||
338 | { | ||
339 | qWarning("extractUids"); | ||
340 | QTime t; | ||
341 | t.start(); | ||
342 | OSQLResultItem::ValueList list = res.results(); | ||
343 | OSQLResultItem::ValueList::Iterator it; | ||
344 | QArray<int> ints(list.count() ); | ||
345 | qWarning(" count = %d", list.count() ); | ||
346 | |||
347 | int i = 0; | ||
348 | for (it = list.begin(); it != list.end(); ++it ) { | ||
349 | ints[i] = (*it).data("uid").toInt(); | ||
350 | i++; | ||
351 | } | ||
352 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); | ||
353 | |||
354 | return ints; | ||
219 | 355 | ||
220 | return m_currentQuery; | ||
221 | } | 356 | } |