author | eilers <eilers> | 2004-06-27 17:20:04 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-06-27 17:20:04 (UTC) |
commit | e211aea3b9201920f442b36f6726d10c09b63154 (patch) (unidiff) | |
tree | a65a20ae610bf053c0ff4dd561759a3369784d39 /libopie2/opiedb | |
parent | b394de64efa36eb463148da1409c87e8537c0dd9 (diff) | |
download | opie-e211aea3b9201920f442b36f6726d10c09b63154.zip opie-e211aea3b9201920f442b36f6726d10c09b63154.tar.gz opie-e211aea3b9201920f442b36f6726d10c09b63154.tar.bz2 |
Fixing Bug #1328:
VCards: Real encoding in UTF-8. Now even chars > 0xff are supported.
SQL: Switching form latin1 encoding to UTF-8 encoding. We are now fully
Unicode compliant !
Sorry for all users already using the SQL interface for loosing their special
characters. There was no other way !
All other should export its SQL database to xml before updating and reimporting afterwards !
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index 69eddfe..b9a491e 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -1,92 +1,88 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "osqlquery.h" | 31 | #include "osqlquery.h" |
32 | #include "osqlitedriver.h" | 32 | #include "osqlitedriver.h" |
33 | 33 | ||
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | 35 | ||
36 | #include <stdlib.h> | 36 | #include <stdlib.h> |
37 | #include <stdio.h> | 37 | #include <stdio.h> |
38 | 38 | ||
39 | // fromLocal8Bit() does not work as expected. Thus it | 39 | namespace Opie { |
40 | // is replaced by fromLatin1() (eilers) | 40 | namespace DB { |
41 | #define __BUGGY_LOCAL8BIT_ | ||
42 | |||
43 | namespace Opie { | ||
44 | namespace DB { | ||
45 | namespace Internal { | 41 | namespace Internal { |
46 | 42 | ||
47 | namespace { | 43 | namespace { |
48 | struct Query { | 44 | struct Query { |
49 | OSQLError::ValueList errors; | 45 | OSQLError::ValueList errors; |
50 | OSQLResultItem::ValueList items; | 46 | OSQLResultItem::ValueList items; |
51 | OSQLiteDriver *driver; | 47 | OSQLiteDriver *driver; |
52 | }; | 48 | }; |
53 | } | 49 | } |
54 | 50 | ||
55 | 51 | ||
56 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) | 52 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) |
57 | : OSQLDriver( lib ) | 53 | : OSQLDriver( lib ) |
58 | { | 54 | { |
59 | m_sqlite = 0l; | 55 | m_sqlite = 0l; |
60 | } | 56 | } |
61 | 57 | ||
62 | 58 | ||
63 | OSQLiteDriver::~OSQLiteDriver() { | 59 | OSQLiteDriver::~OSQLiteDriver() { |
64 | close(); | 60 | close(); |
65 | } | 61 | } |
66 | 62 | ||
67 | 63 | ||
68 | QString OSQLiteDriver::id()const { | 64 | QString OSQLiteDriver::id()const { |
69 | return QString::fromLatin1("SQLite"); | 65 | return QString::fromLatin1("SQLite"); |
70 | } | 66 | } |
71 | 67 | ||
72 | void OSQLiteDriver::setUserName( const QString& ) {} | 68 | void OSQLiteDriver::setUserName( const QString& ) {} |
73 | 69 | ||
74 | 70 | ||
75 | void OSQLiteDriver::setPassword( const QString& ) {} | 71 | void OSQLiteDriver::setPassword( const QString& ) {} |
76 | 72 | ||
77 | 73 | ||
78 | void OSQLiteDriver::setUrl( const QString& url ) { | 74 | void OSQLiteDriver::setUrl( const QString& url ) { |
79 | m_url = url; | 75 | m_url = url; |
80 | } | 76 | } |
81 | 77 | ||
82 | 78 | ||
83 | void OSQLiteDriver::setOptions( const QStringList& ) { | 79 | void OSQLiteDriver::setOptions( const QStringList& ) { |
84 | } | 80 | } |
85 | 81 | ||
86 | /* | 82 | /* |
87 | * Functions to patch a regex search into sqlite | 83 | * Functions to patch a regex search into sqlite |
88 | */ | 84 | */ |
89 | int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ | 85 | int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ |
90 | int res; | 86 | int res; |
91 | if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ | 87 | if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ |
92 | if (reg->regex_raw != NULL) { | 88 | if (reg->regex_raw != NULL) { |
@@ -128,111 +124,105 @@ bool OSQLiteDriver::open() { | |||
128 | m_sqlite = sqlite_open(m_url.local8Bit(), | 124 | m_sqlite = sqlite_open(m_url.local8Bit(), |
129 | 0, | 125 | 0, |
130 | &error ); | 126 | &error ); |
131 | 127 | ||
132 | /* failed to open */ | 128 | /* failed to open */ |
133 | if (m_sqlite == 0l ) { | 129 | if (m_sqlite == 0l ) { |
134 | // FIXME set the last error | 130 | // FIXME set the last error |
135 | owarn << "OSQLiteDriver::open: " << error << "" << oendl; | 131 | owarn << "OSQLiteDriver::open: " << error << "" << oendl; |
136 | free( error ); | 132 | free( error ); |
137 | return false; | 133 | return false; |
138 | } | 134 | } |
139 | if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) | 135 | if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) |
140 | odebug << "Unable to create user defined function!" << oendl; | 136 | odebug << "Unable to create user defined function!" << oendl; |
141 | if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) | 137 | if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) |
142 | odebug << "Unable to set rlike function result type!" << oendl; | 138 | odebug << "Unable to set rlike function result type!" << oendl; |
143 | sqreg.regex_raw = NULL; | 139 | sqreg.regex_raw = NULL; |
144 | return true; | 140 | return true; |
145 | } | 141 | } |
146 | 142 | ||
147 | 143 | ||
148 | /* close the db | 144 | /* close the db |
149 | * sqlite closes them without | 145 | * sqlite closes them without |
150 | * telling failure or success | 146 | * telling failure or success |
151 | */ | 147 | */ |
152 | bool OSQLiteDriver::close() { | 148 | bool OSQLiteDriver::close() { |
153 | if (m_sqlite ) | 149 | if (m_sqlite ) |
154 | sqlite_close( m_sqlite ), m_sqlite=0l; | 150 | sqlite_close( m_sqlite ), m_sqlite=0l; |
155 | if (sqreg.regex_raw != NULL){ | 151 | if (sqreg.regex_raw != NULL){ |
156 | odebug << "Freeing regex on close" << oendl; | 152 | odebug << "Freeing regex on close" << oendl; |
157 | free(sqreg.regex_raw); | 153 | free(sqreg.regex_raw); |
158 | sqreg.regex_raw=NULL; | 154 | sqreg.regex_raw=NULL; |
159 | regfree(&sqreg.regex_c); | 155 | regfree(&sqreg.regex_c); |
160 | } | 156 | } |
161 | return true; | 157 | return true; |
162 | } | 158 | } |
163 | 159 | ||
164 | 160 | ||
165 | /* Query */ | 161 | /* Query */ |
166 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 162 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
167 | if ( !m_sqlite ) { | 163 | if ( !m_sqlite ) { |
168 | // FIXME set error code | 164 | // FIXME set error code |
169 | OSQLResult result( OSQLResult::Failure ); | 165 | OSQLResult result( OSQLResult::Failure ); |
170 | return result; | 166 | return result; |
171 | } | 167 | } |
172 | Query query; | 168 | Query query; |
173 | query.driver = this; | 169 | query.driver = this; |
174 | char *err; | 170 | char *err; |
175 | /* SQLITE_OK 0 if return code > 0 == failure */ | 171 | /* SQLITE_OK 0 if return code > 0 == failure */ |
176 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { | 172 | if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { |
177 | owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; | 173 | qWarning("OSQLiteDriver::query: Error while executing %s",err); |
178 | free(err ); | 174 | free(err ); |
179 | // FixMe Errors | 175 | // FixMe Errors |
180 | } | 176 | } |
181 | 177 | ||
182 | OSQLResult result(OSQLResult::Success, | 178 | OSQLResult result(OSQLResult::Success, |
183 | query.items, | 179 | query.items, |
184 | query.errors ); | 180 | query.errors ); |
185 | return result; | 181 | return result; |
186 | } | 182 | } |
187 | 183 | ||
188 | 184 | ||
189 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 185 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
190 | 186 | ||
191 | } | 187 | } |
192 | 188 | ||
193 | 189 | ||
194 | OSQLError OSQLiteDriver::lastError() { | 190 | OSQLError OSQLiteDriver::lastError() { |
195 | OSQLError error; | 191 | OSQLError error; |
196 | return error; | 192 | return error; |
197 | }; | 193 | }; |
198 | 194 | ||
199 | 195 | ||
200 | /* handle a callback add the row to the global | 196 | /* handle a callback add the row to the global |
201 | * OSQLResultItem | 197 | * OSQLResultItem |
202 | */ | 198 | */ |
203 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 199 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
204 | return 0; | 200 | return 0; |
205 | } | 201 | } |
206 | 202 | ||
207 | 203 | ||
208 | /* callback_handler add the values to the list*/ | 204 | /* callback_handler add the values to the list*/ |
209 | int OSQLiteDriver::call_back( void* voi, int argc, | 205 | int OSQLiteDriver::call_back( void* voi, int argc, |
210 | char** argv, char** columns) { | 206 | char** argv, char** columns) { |
211 | Query* qu = (Query*)voi; | 207 | Query* qu = (Query*)voi; |
212 | 208 | ||
213 | //copy them over to a OSQLResultItem | 209 | //copy them over to a OSQLResultItem |
214 | QMap<QString, QString> tableString; | 210 | QMap<QString, QString> tableString; |
215 | QMap<int, QString> tableInt; | 211 | QMap<int, QString> tableInt; |
216 | for (int i = 0; i < argc; i++ ) { | 212 | for (int i = 0; i < argc; i++ ) { |
217 | 213 | ||
218 | #ifdef __BUGGY_LOCAL8BIT_ | 214 | tableInt.insert( i, QString::fromUtf8( argv[i] ) ); |
219 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); | 215 | tableString.insert( QString::fromUtf8( columns[i] ), |
220 | tableString.insert( QString::fromLatin1( columns[i] ), | 216 | QString::fromUtf8( argv[i] ) ); |
221 | QString::fromLatin1( argv[i] ) ); | ||
222 | #else | ||
223 | tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); | ||
224 | tableString.insert( QString::fromLocal8Bit( columns[i] ), | ||
225 | QString::fromLocal8Bit( argv[i] ) ); | ||
226 | #endif | ||
227 | } | 217 | } |
228 | OSQLResultItem item( tableString, tableInt ); | 218 | OSQLResultItem item( tableString, tableInt ); |
229 | qu->items.append( item ); | 219 | qu->items.append( item ); |
230 | 220 | ||
231 | return ((Query*)voi)->driver->handleCallBack( argc, | 221 | return ((Query*)voi)->driver->handleCallBack( argc, |
232 | argv, | 222 | argv, |
233 | columns ); | 223 | columns ); |
234 | 224 | ||
235 | 225 | ||
236 | } | 226 | } |
237 | 227 | ||
238 | }}} // namespace OPIE::DB::Internal | 228 | }}} // namespace OPIE::DB::Internal |