-rw-r--r-- | libopie2/opiedb/opiedb.pro | 11 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 67 |
2 files changed, 63 insertions, 15 deletions
diff --git a/libopie2/opiedb/opiedb.pro b/libopie2/opiedb/opiedb.pro index d869e6f..249d8b5 100644 --- a/libopie2/opiedb/opiedb.pro +++ b/libopie2/opiedb/opiedb.pro | |||
@@ -1,6 +1,5 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | #CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | CONFIG += qt warn_on release | ||
4 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
5 | HEADERS = osqlbackend.h \ | 4 | HEADERS = osqlbackend.h \ |
6 | osqldriver.h \ | 5 | osqldriver.h \ |
@@ -23,12 +22,8 @@ SOURCES = osqlbackend.cpp \ | |||
23 | INTERFACES = | 22 | INTERFACES = |
24 | TARGET = opiedb2 | 23 | TARGET = opiedb2 |
25 | VERSION = 1.8.2 | 24 | VERSION = 1.8.2 |
26 | INCLUDEPATH += $(OPIEDIR)/include | 25 | INCLUDEPATH = $(OPIEDIR)/include |
27 | DEPENDPATH += $(OPIEDIR)/include | 26 | DEPENDPATH = $(OPIEDIR)/include |
28 | |||
29 | MOC_DIR = moc | ||
30 | OBJECTS_DIR = obj | ||
31 | |||
32 | LIBS += -lsqlite -lqpe | 27 | LIBS += -lsqlite -lqpe |
33 | 28 | ||
34 | !contains( platform, x11 ) { | 29 | !contains( platform, x11 ) { |
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index 99fd218..b857534 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -1,9 +1,41 @@ | |||
1 | #include <stdlib.h> | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | |||
4 | =. | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | |||
29 | */ | ||
2 | 30 | ||
3 | #include "osqlresult.h" | 31 | #include "osqlresult.h" |
4 | #include "osqlquery.h" | 32 | #include "osqlquery.h" |
5 | #include "osqlitedriver.h" | 33 | #include "osqlitedriver.h" |
6 | 34 | ||
35 | #include <opie2/odebug.h> | ||
36 | |||
37 | #include <stdlib.h> | ||
38 | |||
7 | // fromLocal8Bit() does not work as expected. Thus it | 39 | // fromLocal8Bit() does not work as expected. Thus it |
8 | // is replaced by fromLatin1() (eilers) | 40 | // is replaced by fromLatin1() (eilers) |
9 | #define __BUGGY_LOCAL8BIT_ | 41 | #define __BUGGY_LOCAL8BIT_ |
@@ -17,34 +49,45 @@ namespace { | |||
17 | }; | 49 | }; |
18 | } | 50 | } |
19 | 51 | ||
52 | |||
20 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) | 53 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) |
21 | : OSQLDriver( lib ) | 54 | : OSQLDriver( lib ) |
22 | { | 55 | { |
23 | m_sqlite = 0l; | 56 | m_sqlite = 0l; |
24 | } | 57 | } |
58 | |||
59 | |||
25 | OSQLiteDriver::~OSQLiteDriver() { | 60 | OSQLiteDriver::~OSQLiteDriver() { |
26 | close(); | 61 | close(); |
27 | } | 62 | } |
28 | 63 | ||
64 | |||
29 | QString OSQLiteDriver::id()const { | 65 | QString OSQLiteDriver::id()const { |
30 | return QString::fromLatin1("SQLite"); | 66 | return QString::fromLatin1("SQLite"); |
31 | } | 67 | } |
32 | 68 | ||
33 | void OSQLiteDriver::setUserName( const QString& ) {} | 69 | void OSQLiteDriver::setUserName( const QString& ) {} |
70 | |||
71 | |||
34 | void OSQLiteDriver::setPassword( const QString& ) {} | 72 | void OSQLiteDriver::setPassword( const QString& ) {} |
35 | 73 | ||
74 | |||
36 | void OSQLiteDriver::setUrl( const QString& url ) { | 75 | void OSQLiteDriver::setUrl( const QString& url ) { |
37 | m_url = url; | 76 | m_url = url; |
38 | } | 77 | } |
78 | |||
79 | |||
39 | void OSQLiteDriver::setOptions( const QStringList& ) { | 80 | void OSQLiteDriver::setOptions( const QStringList& ) { |
40 | } | 81 | } |
82 | |||
83 | |||
41 | /* | 84 | /* |
42 | * try to open a db specified via setUrl | 85 | * try to open a db specified via setUrl |
43 | * and options | 86 | * and options |
44 | */ | 87 | */ |
45 | bool OSQLiteDriver::open() { | 88 | bool OSQLiteDriver::open() { |
46 | char *error; | 89 | char *error; |
47 | qWarning("about to open"); | 90 | odebug << "OSQLiteDriver::open: about to open" << oendl; |
48 | m_sqlite = sqlite_open(m_url.local8Bit(), | 91 | m_sqlite = sqlite_open(m_url.local8Bit(), |
49 | 0, | 92 | 0, |
50 | &error ); | 93 | &error ); |
@@ -52,12 +95,14 @@ bool OSQLiteDriver::open() { | |||
52 | /* failed to open */ | 95 | /* failed to open */ |
53 | if (m_sqlite == 0l ) { | 96 | if (m_sqlite == 0l ) { |
54 | // FIXME set the last error | 97 | // FIXME set the last error |
55 | qWarning("error:%s", error ); | 98 | owarn << "OSQLiteDriver::open: " << error << oendl; |
56 | free( error ); | 99 | free( error ); |
57 | return false; | 100 | return false; |
58 | } | 101 | } |
59 | return true; | 102 | return true; |
60 | } | 103 | } |
104 | |||
105 | |||
61 | /* close the db | 106 | /* close the db |
62 | * sqlite closes them without | 107 | * sqlite closes them without |
63 | * telling failure or success | 108 | * telling failure or success |
@@ -68,6 +113,8 @@ bool OSQLiteDriver::close() { | |||
68 | 113 | ||
69 | return true; | 114 | return true; |
70 | } | 115 | } |
116 | |||
117 | |||
71 | /* Query */ | 118 | /* Query */ |
72 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 119 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
73 | if ( !m_sqlite ) { | 120 | if ( !m_sqlite ) { |
@@ -80,40 +127,46 @@ OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | |||
80 | char *err; | 127 | char *err; |
81 | /* SQLITE_OK 0 if return code > 0 == failure */ | 128 | /* SQLITE_OK 0 if return code > 0 == failure */ |
82 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { | 129 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { |
83 | qWarning("Error while executing"); | 130 | owarn << "OSQLiteDriver::query: Error while executing" << oendl; |
84 | free(err ); | 131 | free(err ); |
85 | // FixMe Errors | 132 | // FixMe Errors |
86 | } | 133 | } |
87 | // qWarning("Item count is %d", query.items.count() ); | 134 | |
88 | OSQLResult result(OSQLResult::Success, | 135 | OSQLResult result(OSQLResult::Success, |
89 | query.items, | 136 | query.items, |
90 | query.errors ); | 137 | query.errors ); |
91 | return result; | 138 | return result; |
92 | } | 139 | } |
140 | |||
141 | |||
93 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 142 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
94 | 143 | ||
95 | } | 144 | } |
145 | |||
146 | |||
96 | OSQLError OSQLiteDriver::lastError() { | 147 | OSQLError OSQLiteDriver::lastError() { |
97 | OSQLError error; | 148 | OSQLError error; |
98 | return error; | 149 | return error; |
99 | }; | 150 | }; |
151 | |||
152 | |||
100 | /* handle a callback add the row to the global | 153 | /* handle a callback add the row to the global |
101 | * OSQLResultItem | 154 | * OSQLResultItem |
102 | */ | 155 | */ |
103 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 156 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
104 | return 0; | 157 | return 0; |
105 | } | 158 | } |
159 | |||
160 | |||
106 | /* callback_handler add the values to the list*/ | 161 | /* callback_handler add the values to the list*/ |
107 | int OSQLiteDriver::call_back( void* voi, int argc, | 162 | int OSQLiteDriver::call_back( void* voi, int argc, |
108 | char** argv, char** columns) { | 163 | char** argv, char** columns) { |
109 | // qWarning("Callback with %d items", argc ); | ||
110 | Query* qu = (Query*)voi; | 164 | Query* qu = (Query*)voi; |
111 | 165 | ||
112 | //copy them over to a OSQLResultItem | 166 | //copy them over to a OSQLResultItem |
113 | QMap<QString, QString> tableString; | 167 | QMap<QString, QString> tableString; |
114 | QMap<int, QString> tableInt; | 168 | QMap<int, QString> tableInt; |
115 | for (int i = 0; i < argc; i++ ) { | 169 | for (int i = 0; i < argc; i++ ) { |
116 | //qWarning("%s|%s", columns[i], argv[i] ); | ||
117 | 170 | ||
118 | #ifdef __BUGGY_LOCAL8BIT_ | 171 | #ifdef __BUGGY_LOCAL8BIT_ |
119 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); | 172 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); |