summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index e79696c..2ee76cc 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -34,25 +34,25 @@
34#include <stdio.h> 34#include <stdio.h>
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37#include <qarray.h> 37#include <qarray.h>
38#include <qstringlist.h> 38#include <qstringlist.h>
39 39
40#include <qpe/global.h> 40#include <qpe/global.h>
41 41
42#include <opie2/osqldriver.h> 42#include <opie2/osqldriver.h>
43#include <opie2/osqlmanager.h> 43#include <opie2/osqlmanager.h>
44#include <opie2/osqlquery.h> 44#include <opie2/osqlquery.h>
45 45
46#include <opie2/orecur.h> 46#include <opie2/opimrecurrence.h>
47#include <opie2/odatebookaccessbackend_sql.h> 47#include <opie2/odatebookaccessbackend_sql.h>
48 48
49namespace Opie { 49namespace Opie {
50 50
51 51
52ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 52ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
53 const QString& fileName ) 53 const QString& fileName )
54 : ODateBookAccessBackend(), m_driver( NULL ) 54 : ODateBookAccessBackend(), m_driver( NULL )
55{ 55{
56 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; 56 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName;
57 57
58 // Get the standart sql-driver from the OSQLManager.. 58 // Get the standart sql-driver from the OSQLManager..
@@ -66,45 +66,45 @@ ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
66} 66}
67 67
68ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { 68ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() {
69 if( m_driver ) 69 if( m_driver )
70 delete m_driver; 70 delete m_driver;
71} 71}
72 72
73void ODateBookAccessBackend_SQL::initFields() 73void ODateBookAccessBackend_SQL::initFields()
74{ 74{
75 75
76 // This map contains the translation of the fieldtype id's to 76 // This map contains the translation of the fieldtype id's to
77 // the names of the table columns 77 // the names of the table columns
78 m_fieldMap.insert( OEvent::FUid, "uid" ); 78 m_fieldMap.insert( OPimEvent::FUid, "uid" );
79 m_fieldMap.insert( OEvent::FCategories, "Categories" ); 79 m_fieldMap.insert( OPimEvent::FCategories, "Categories" );
80 m_fieldMap.insert( OEvent::FDescription, "Description" ); 80 m_fieldMap.insert( OPimEvent::FDescription, "Description" );
81 m_fieldMap.insert( OEvent::FLocation, "Location" ); 81 m_fieldMap.insert( OPimEvent::FLocation, "Location" );
82 m_fieldMap.insert( OEvent::FType, "Type" ); 82 m_fieldMap.insert( OPimEvent::FType, "Type" );
83 m_fieldMap.insert( OEvent::FAlarm, "Alarm" ); 83 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" );
84 m_fieldMap.insert( OEvent::FSound, "Sound" ); 84 m_fieldMap.insert( OPimEvent::FSound, "Sound" );
85 m_fieldMap.insert( OEvent::FRType, "RType" ); 85 m_fieldMap.insert( OPimEvent::FRType, "RType" );
86 m_fieldMap.insert( OEvent::FRWeekdays, "RWeekdays" ); 86 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" );
87 m_fieldMap.insert( OEvent::FRPosition, "RPosition" ); 87 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" );
88 m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); 88 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" );
89 m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); 89 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" );
90 m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); 90 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" );
91 m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); 91 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" );
92 m_fieldMap.insert( OEvent::FRExceptions, "RExceptions" ); 92 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" );
93 m_fieldMap.insert( OEvent::FStart, "Start" ); 93 m_fieldMap.insert( OPimEvent::FStart, "Start" );
94 m_fieldMap.insert( OEvent::FEnd, "End" ); 94 m_fieldMap.insert( OPimEvent::FEnd, "End" );
95 m_fieldMap.insert( OEvent::FNote, "Note" ); 95 m_fieldMap.insert( OPimEvent::FNote, "Note" );
96 m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); 96 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" );
97 m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); 97 m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" );
98 m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); 98 m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" );
99 99
100 // Create a map that maps the column name to the id 100 // Create a map that maps the column name to the id
101 QMapConstIterator<int, QString> it; 101 QMapConstIterator<int, QString> it;
102 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 102 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
103 m_reverseFieldMap.insert( it.data(), it.key() ); 103 m_reverseFieldMap.insert( it.data(), it.key() );
104 } 104 }
105 105
106} 106}
107 107
108bool ODateBookAccessBackend_SQL::load() 108bool ODateBookAccessBackend_SQL::load()
109{ 109{
110 if (!m_driver->open() ) 110 if (!m_driver->open() )
@@ -156,67 +156,67 @@ bool ODateBookAccessBackend_SQL::reload()
156} 156}
157 157
158bool ODateBookAccessBackend_SQL::save() 158bool ODateBookAccessBackend_SQL::save()
159{ 159{
160 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 160 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
161} 161}
162 162
163QArray<int> ODateBookAccessBackend_SQL::allRecords()const 163QArray<int> ODateBookAccessBackend_SQL::allRecords()const
164{ 164{
165 return m_uids; 165 return m_uids;
166} 166}
167 167
168QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { 168QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) {
169 return QArray<int>(); 169 return QArray<int>();
170} 170}
171 171
172void ODateBookAccessBackend_SQL::clear() 172void ODateBookAccessBackend_SQL::clear()
173{ 173{
174 QString qu = "drop table datebook;"; 174 QString qu = "drop table datebook;";
175 qu += "drop table custom_data;"; 175 qu += "drop table custom_data;";
176 176
177 OSQLRawQuery raw( qu ); 177 OSQLRawQuery raw( qu );
178 OSQLResult res = m_driver->query( &raw ); 178 OSQLResult res = m_driver->query( &raw );
179 179
180 reload(); 180 reload();
181} 181}
182 182
183 183
184OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ 184OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
185 QString qu = "select *"; 185 QString qu = "select *";
186 qu += "from datebook where uid = " + QString::number(uid); 186 qu += "from datebook where uid = " + QString::number(uid);
187 187
188 OSQLRawQuery raw( qu ); 188 OSQLRawQuery raw( qu );
189 OSQLResult res = m_driver->query( &raw ); 189 OSQLResult res = m_driver->query( &raw );
190 190
191 OSQLResultItem resItem = res.first(); 191 OSQLResultItem resItem = res.first();
192 192
193 // Create Map for date event and insert UID 193 // Create Map for date event and insert UID
194 QMap<int,QString> dateEventMap; 194 QMap<int,QString> dateEventMap;
195 dateEventMap.insert( OEvent::FUid, QString::number( uid ) ); 195 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) );
196 196
197 // Now insert the data out of the columns into the map. 197 // Now insert the data out of the columns into the map.
198 QMapConstIterator<int, QString> it; 198 QMapConstIterator<int, QString> it;
199 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 199 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
200 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); 200 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
201 } 201 }
202 202
203 // Last step: Put map into date event and return it 203 // Last step: Put map into date event and return it
204 OEvent retDate( dateEventMap ); 204 OPimEvent retDate( dateEventMap );
205 205
206 return retDate; 206 return retDate;
207} 207}
208 208
209// FIXME: Speed up update of uid's.. 209// FIXME: Speed up update of uid's..
210bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) 210bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
211{ 211{
212 QMap<int,QString> eventMap = ev.toMap(); 212 QMap<int,QString> eventMap = ev.toMap();
213 213
214 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); 214 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
215 QMap<int, QString>::Iterator it; 215 QMap<int, QString>::Iterator it;
216 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 216 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
217 if ( !eventMap[it.key()].isEmpty() ) 217 if ( !eventMap[it.key()].isEmpty() )
218 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); 218 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
219 else 219 else
220 qu += QString( ",\"\"" ); 220 qu += QString( ",\"\"" );
221 } 221 }
222 qu += " );"; 222 qu += " );";
@@ -263,25 +263,25 @@ bool ODateBookAccessBackend_SQL::remove( int uid )
263 OSQLRawQuery raw( qu ); 263 OSQLRawQuery raw( qu );
264 OSQLResult res = m_driver->query( &raw ); 264 OSQLResult res = m_driver->query( &raw );
265 if ( res.state() != OSQLResult::Success ){ 265 if ( res.state() != OSQLResult::Success ){
266 return false; 266 return false;
267 } 267 }
268 268
269 // Update list of uid's 269 // Update list of uid's
270 update(); 270 update();
271 271
272 return true; 272 return true;
273} 273}
274 274
275bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) 275bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
276{ 276{
277 remove( ev.uid() ); 277 remove( ev.uid() );
278 return add( ev ); 278 return add( ev );
279} 279}
280 280
281QArray<int> ODateBookAccessBackend_SQL::rawEvents()const 281QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
282{ 282{
283 return allRecords(); 283 return allRecords();
284} 284}
285 285
286QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 286QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
287{ 287{
@@ -300,40 +300,40 @@ QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
300{ 300{
301 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; 301 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\"";
302 OSQLRawQuery raw( qu ); 302 OSQLRawQuery raw( qu );
303 OSQLResult res = m_driver->query( &raw ); 303 OSQLResult res = m_driver->query( &raw );
304 if ( res.state() != OSQLResult::Success ){ 304 if ( res.state() != OSQLResult::Success ){
305 QArray<int> nix; 305 QArray<int> nix;
306 return nix; 306 return nix;
307 } 307 }
308 308
309 return extractUids( res ); 309 return extractUids( res );
310} 310}
311 311
312OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() 312OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
313{ 313{
314 QArray<int> nonRepUids = nonRepeats(); 314 QArray<int> nonRepUids = nonRepeats();
315 OEvent::ValueList list; 315 OPimEvent::ValueList list;
316 316
317 for (uint i = 0; i < nonRepUids.count(); ++i ){ 317 for (uint i = 0; i < nonRepUids.count(); ++i ){
318 list.append( find( nonRepUids[i] ) ); 318 list.append( find( nonRepUids[i] ) );
319 } 319 }
320 320
321 return list; 321 return list;
322 322
323} 323}
324OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() 324OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
325{ 325{
326 QArray<int> rawRepUids = rawRepeats(); 326 QArray<int> rawRepUids = rawRepeats();
327 OEvent::ValueList list; 327 OPimEvent::ValueList list;
328 328
329 for (uint i = 0; i < rawRepUids.count(); ++i ){ 329 for (uint i = 0; i < rawRepUids.count(); ++i ){
330 list.append( find( rawRepUids[i] ) ); 330 list.append( find( rawRepUids[i] ) );
331 } 331 }
332 332
333 return list; 333 return list;
334} 334}
335 335
336 336
337QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 337QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
338{ 338{
339 QArray<int> null; 339 QArray<int> null;