author | eilers <eilers> | 2003-12-08 15:18:10 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-12-08 15:18:10 (UTC) |
commit | 6974a4bbdc674a2a5d41d801f80035a183faedb5 (patch) (unidiff) | |
tree | 09a719ef263047e92ffb866da13168b7f7d41f23 /libopie2/opiepim/backend | |
parent | 7f2f736597490fd1592d7ed1f40e4abf824673c0 (diff) | |
download | opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.zip opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.tar.gz opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.tar.bz2 |
Committing unfinished sql implementation before merging to libopie2 starts..
6 files changed, 309 insertions, 5 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 132c9fc..dd9dbde 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -16,2 +16,5 @@ | |||
16 | * $Log$ | 16 | * $Log$ |
17 | * Revision 1.3 2003/12/08 15:18:10 eilers | ||
18 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
19 | * | ||
17 | * Revision 1.2 2003/09/29 07:44:26 eilers | 20 | * Revision 1.2 2003/09/29 07:44:26 eilers |
@@ -456,3 +459,4 @@ namespace { | |||
456 | OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, | 459 | OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, |
457 | const QString& filename ): m_changed(false) | 460 | const QString& filename ): |
461 | OContactAccessBackend(), m_changed(false), m_driver( NULL ) | ||
458 | { | 462 | { |
@@ -478,2 +482,7 @@ OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname | |||
478 | 482 | ||
483 | OContactAccessBackend_SQL::~OContactAccessBackend_SQL () | ||
484 | { | ||
485 | if( m_driver ) | ||
486 | delete m_driver; | ||
487 | } | ||
479 | 488 | ||
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h index bb22551..b8f1d8d 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h | |||
@@ -18,2 +18,5 @@ | |||
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.2 2003/12/08 15:18:11 eilers | ||
20 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
21 | * | ||
19 | * Revision 1.1 2003/09/22 14:31:16 eilers | 22 | * Revision 1.1 2003/09/22 14:31:16 eilers |
@@ -49,2 +52,4 @@ class OContactAccessBackend_SQL : public OContactAccessBackend { | |||
49 | 52 | ||
53 | ~OContactAccessBackend_SQL (); | ||
54 | |||
50 | bool save(); | 55 | bool save(); |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp new file mode 100644 index 0000000..9769bf7 --- a/dev/null +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -0,0 +1,221 @@ | |||
1 | /* | ||
2 | * SQL Backend for the OPIE-Calender Database. | ||
3 | * | ||
4 | * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * ===================================================================== | ||
13 | * Version: $Id$ | ||
14 | * ===================================================================== | ||
15 | * History: | ||
16 | * $Log$ | ||
17 | * Revision 1.1 2003/12/08 15:18:12 eilers | ||
18 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
19 | * | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | |||
26 | #include <qarray.h> | ||
27 | #include <qstringlist.h> | ||
28 | |||
29 | #include "orecur.h" | ||
30 | #include "odatebookaccessbackend_sql.h" | ||
31 | |||
32 | #include <opie2/osqldriver.h> | ||
33 | #include <opie2/osqlresult.h> | ||
34 | #include <opie2/osqlmanager.h> | ||
35 | #include <opie2/osqlquery.h> | ||
36 | |||
37 | namespace { | ||
38 | |||
39 | |||
40 | |||
41 | }; | ||
42 | |||
43 | ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | ||
44 | const QString& fileName ) | ||
45 | : ODateBookAccessBackend(), m_driver( NULL ) | ||
46 | { | ||
47 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; | ||
48 | |||
49 | // Get the standart sql-driver from the OSQLManager.. | ||
50 | OSQLManager man; | ||
51 | m_driver = man.standard(); | ||
52 | m_driver->setUrl( m_fileName ); | ||
53 | |||
54 | initFields(); | ||
55 | |||
56 | load(); | ||
57 | } | ||
58 | |||
59 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { | ||
60 | } | ||
61 | |||
62 | void ODateBookAccessBackend_SQL::initFields() | ||
63 | { | ||
64 | |||
65 | // This map contains the translation of the fieldtype id's to | ||
66 | // the names of the table columns | ||
67 | m_fieldMap.insert( OEvent::FUid, "uid" ); | ||
68 | m_fieldMap.insert( OEvent::FCategories, "Categories" ); | ||
69 | m_fieldMap.insert( OEvent::FDescription, "Description" ); | ||
70 | m_fieldMap.insert( OEvent::FLocation, "Location" ); | ||
71 | m_fieldMap.insert( OEvent::FType, "Type" ); | ||
72 | m_fieldMap.insert( OEvent::FAlarm, "Alarm" ); | ||
73 | m_fieldMap.insert( OEvent::FSound, "Sound" ); | ||
74 | m_fieldMap.insert( OEvent::FRType, "RType" ); | ||
75 | m_fieldMap.insert( OEvent::FRWeekdays, "RWeekdays" ); | ||
76 | m_fieldMap.insert( OEvent::FRPosition, "RPosition" ); | ||
77 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); | ||
78 | m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); | ||
79 | m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); | ||
80 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); | ||
81 | m_fieldMap.insert( OEvent::FRExeptions, "RExceptions" ); | ||
82 | m_fieldMap.insert( OEvent::FStart, "Start" ); | ||
83 | m_fieldMap.insert( OEvent::FEnd, "End" ); | ||
84 | m_fieldMap.insert( OEvent::FNote, "Note" ); | ||
85 | m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); | ||
86 | m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); | ||
87 | m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); | ||
88 | } | ||
89 | |||
90 | bool ODateBookAccessBackend_SQL::load() | ||
91 | { | ||
92 | if (!m_driver->open() ) | ||
93 | return false; | ||
94 | |||
95 | // Don't expect that the database exists. | ||
96 | // It is save here to create the table, even if it | ||
97 | // do exist. ( Is that correct for all databases ?? ) | ||
98 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; | ||
99 | |||
100 | QMap<int, QString>::Iterator it; | ||
101 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | ||
102 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( it.data() ); | ||
103 | } | ||
104 | qu += " );"; | ||
105 | |||
106 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; | ||
107 | |||
108 | OSQLRawQuery raw( qu ); | ||
109 | OSQLResult res = m_driver->query( &raw ); | ||
110 | if ( res.state() != OSQLResult::Success ) | ||
111 | return false; | ||
112 | |||
113 | update(); | ||
114 | |||
115 | return true; | ||
116 | } | ||
117 | |||
118 | void ODateBookAccessBackend_SQL::update() | ||
119 | { | ||
120 | |||
121 | QString qu = "select uid from datebook"; | ||
122 | OSQLRawQuery raw( qu ); | ||
123 | OSQLResult res = m_driver->query( &raw ); | ||
124 | if ( res.state() != OSQLResult::Success ){ | ||
125 | m_uids.clear(); | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | m_uids = extractUids( res ); | ||
130 | |||
131 | } | ||
132 | |||
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 | { | ||
154 | return load(); | ||
155 | } | ||
156 | |||
157 | bool ODateBookAccessBackend_SQL::save() | ||
158 | { | ||
159 | return m_driver->close(); | ||
160 | } | ||
161 | |||
162 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const | ||
163 | { | ||
164 | return m_uids; | ||
165 | } | ||
166 | |||
167 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { | ||
168 | return QArray<int>(); | ||
169 | } | ||
170 | |||
171 | void ODateBookAccessBackend_SQL::clear() | ||
172 | { | ||
173 | QString qu = "drop table datebook;"; | ||
174 | qu += "drop table custom_data;"; | ||
175 | |||
176 | OSQLRawQuery raw( qu ); | ||
177 | OSQLResult res = m_driver->query( &raw ); | ||
178 | |||
179 | } | ||
180 | |||
181 | |||
182 | OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | ||
183 | } | ||
184 | |||
185 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) { | ||
186 | return true; | ||
187 | } | ||
188 | bool ODateBookAccessBackend_SQL::remove( int uid ) { | ||
189 | |||
190 | return true; | ||
191 | } | ||
192 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) { | ||
193 | remove( ev.uid() ); | ||
194 | return add( ev ); | ||
195 | } | ||
196 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const { | ||
197 | return allRecords(); | ||
198 | } | ||
199 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const { | ||
200 | |||
201 | return ints; | ||
202 | } | ||
203 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const { | ||
204 | |||
205 | return ints; | ||
206 | } | ||
207 | OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() { | ||
208 | |||
209 | return list; | ||
210 | } | ||
211 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() { | ||
212 | |||
213 | return list; | ||
214 | } | ||
215 | |||
216 | |||
217 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | ||
218 | { | ||
219 | |||
220 | return m_currentQuery; | ||
221 | } | ||
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h new file mode 100644 index 0000000..85e0d4f --- a/dev/null +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h | |||
@@ -0,0 +1,60 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H | ||
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H | ||
3 | |||
4 | #include <qmap.h> | ||
5 | |||
6 | #include "odatebookaccessbackend.h" | ||
7 | |||
8 | class OSQLDriver; | ||
9 | |||
10 | /** | ||
11 | * This is the default SQL implementation for DateBoook SQL storage | ||
12 | * It fully implements the interface | ||
13 | * @see ODateBookAccessBackend | ||
14 | * @see OPimAccessBackend | ||
15 | */ | ||
16 | class ODateBookAccessBackend_SQL : public ODateBookAccessBackend { | ||
17 | public: | ||
18 | ODateBookAccessBackend_SQL( const QString& appName, | ||
19 | const QString& fileName = QString::null); | ||
20 | ~ODateBookAccessBackend_SQL(); | ||
21 | |||
22 | bool load(); | ||
23 | bool reload(); | ||
24 | bool save(); | ||
25 | |||
26 | QArray<int> allRecords()const; | ||
27 | QArray<int> matchRegexp(const QRegExp &r) const; | ||
28 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); | ||
29 | OEvent find( int uid )const; | ||
30 | void clear(); | ||
31 | bool add( const OEvent& ev ); | ||
32 | bool remove( int uid ); | ||
33 | bool replace( const OEvent& ev ); | ||
34 | |||
35 | QArray<UID> rawEvents()const; | ||
36 | QArray<UID> rawRepeats()const; | ||
37 | QArray<UID> nonRepeats()const; | ||
38 | |||
39 | OEvent::ValueList directNonRepeats(); | ||
40 | OEvent::ValueList directRawRepeats(); | ||
41 | |||
42 | private: | ||
43 | bool loadFile(); | ||
44 | QString m_fileName; | ||
45 | QArray<int> m_uids; | ||
46 | |||
47 | QMap<int, QString> m_fieldMap; | ||
48 | |||
49 | OSQLDriver* m_driver; | ||
50 | |||
51 | class Private; | ||
52 | Private *d; | ||
53 | |||
54 | void initFields(); | ||
55 | void update(); | ||
56 | QArray<int> extractUids( OSQLResult& res ) const; | ||
57 | |||
58 | }; | ||
59 | |||
60 | #endif | ||
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp index 39c43c5..929d004 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |||
@@ -79,3 +79,3 @@ namespace { | |||
79 | FNote, | 79 | FNote, |
80 | FCreated, | 80 | FCreated, // Should't this be called FRCreated ? |
81 | FTimeZone, | 81 | FTimeZone, |
@@ -85,2 +85,4 @@ namespace { | |||
85 | }; | 85 | }; |
86 | |||
87 | // FIXME: Use OEvent::toMap() here !! (eilers) | ||
86 | inline void save( const OEvent& ev, QString& buf ) { | 88 | inline void save( const OEvent& ev, QString& buf ) { |
@@ -277,3 +279,3 @@ bool ODateBookAccessBackend_XML::remove( int uid ) { | |||
277 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 279 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
278 | replace( ev.uid() ); | 280 | replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers) |
279 | return add( ev ); | 281 | return add( ev ); |
@@ -323,2 +325,4 @@ OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | |||
323 | } | 325 | } |
326 | |||
327 | // FIXME: Use OEvent::fromMap() (eilers) | ||
324 | bool ODateBookAccessBackend_XML::loadFile() { | 328 | bool ODateBookAccessBackend_XML::loadFile() { |
@@ -361,3 +365,3 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
361 | dict.insert( "note", new int(FNote) ); | 365 | dict.insert( "note", new int(FNote) ); |
362 | dict.insert( "created", new int(FCreated) ); | 366 | dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? |
363 | dict.insert( "recparent", new int(FRecParent) ); | 367 | dict.insert( "recparent", new int(FRecParent) ); |
@@ -446,2 +450,4 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
446 | } | 450 | } |
451 | |||
452 | // FIXME: Use OEvent::fromMap() which makes this obsolete.. (eilers) | ||
447 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 453 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 3913661..75a0860 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -301,3 +301,3 @@ namespace { | |||
301 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 301 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
302 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) | 302 | : OTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) |
303 | { | 303 | { |
@@ -313,3 +313,6 @@ OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | |||
313 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 313 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
314 | if( m_driver ) | ||
315 | delete m_driver; | ||
314 | } | 316 | } |
317 | |||
315 | bool OTodoAccessBackendSQL::load(){ | 318 | bool OTodoAccessBackendSQL::load(){ |