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 | |||
@@ -15,54 +15,50 @@ | |||
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 { |
@@ -152,87 +148,81 @@ bool OSQLiteDriver::open() { | |||
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 |