summaryrefslogtreecommitdiff
path: root/libopie2/opiedb/osqlitedriver.cpp
Unidiff
Diffstat (limited to 'libopie2/opiedb/osqlitedriver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index 6141504..47bc250 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -1,177 +1,180 @@
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 37
38// fromLocal8Bit() does not work as expected. Thus it 38// fromLocal8Bit() does not work as expected. Thus it
39// is replaced by fromLatin1() (eilers) 39// is replaced by fromLatin1() (eilers)
40#define __BUGGY_LOCAL8BIT_ 40#define __BUGGY_LOCAL8BIT_
41 41
42 42
43using namespace Opie::DB;
44using namespace Opie::DB::Private;
45
43namespace { 46namespace {
44 struct Query { 47 struct Query {
45 OSQLError::ValueList errors; 48 OSQLError::ValueList errors;
46 OSQLResultItem::ValueList items; 49 OSQLResultItem::ValueList items;
47 OSQLiteDriver *driver; 50 OSQLiteDriver *driver;
48 }; 51 };
49} 52}
50 53
51 54
52OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) 55OSQLiteDriver::OSQLiteDriver( QLibrary *lib )
53 : OSQLDriver( lib ) 56 : OSQLDriver( lib )
54{ 57{
55 m_sqlite = 0l; 58 m_sqlite = 0l;
56} 59}
57 60
58 61
59OSQLiteDriver::~OSQLiteDriver() { 62OSQLiteDriver::~OSQLiteDriver() {
60 close(); 63 close();
61} 64}
62 65
63 66
64QString OSQLiteDriver::id()const { 67QString OSQLiteDriver::id()const {
65 return QString::fromLatin1("SQLite"); 68 return QString::fromLatin1("SQLite");
66} 69}
67 70
68void OSQLiteDriver::setUserName( const QString& ) {} 71void OSQLiteDriver::setUserName( const QString& ) {}
69 72
70 73
71void OSQLiteDriver::setPassword( const QString& ) {} 74void OSQLiteDriver::setPassword( const QString& ) {}
72 75
73 76
74void OSQLiteDriver::setUrl( const QString& url ) { 77void OSQLiteDriver::setUrl( const QString& url ) {
75 m_url = url; 78 m_url = url;
76} 79}
77 80
78 81
79void OSQLiteDriver::setOptions( const QStringList& ) { 82void OSQLiteDriver::setOptions( const QStringList& ) {
80} 83}
81 84
82 85
83/* 86/*
84 * try to open a db specified via setUrl 87 * try to open a db specified via setUrl
85 * and options 88 * and options
86 */ 89 */
87bool OSQLiteDriver::open() { 90bool OSQLiteDriver::open() {
88 char *error; 91 char *error;
89 odebug << "OSQLiteDriver::open: about to open" << oendl; 92 qDebug("OSQLiteDriver::open: about to open");
90 m_sqlite = sqlite_open(m_url.local8Bit(), 93 m_sqlite = sqlite_open(m_url.local8Bit(),
91 0, 94 0,
92 &error ); 95 &error );
93 96
94 /* failed to open */ 97 /* failed to open */
95 if (m_sqlite == 0l ) { 98 if (m_sqlite == 0l ) {
96 // FIXME set the last error 99 // FIXME set the last error
97 owarn << "OSQLiteDriver::open: " << error << oendl; 100 qWarning("OSQLiteDriver::open: %s", error );
98 free( error ); 101 free( error );
99 return false; 102 return false;
100 } 103 }
101 return true; 104 return true;
102} 105}
103 106
104 107
105/* close the db 108/* close the db
106 * sqlite closes them without 109 * sqlite closes them without
107 * telling failure or success 110 * telling failure or success
108 */ 111 */
109bool OSQLiteDriver::close() { 112bool OSQLiteDriver::close() {
110 if (m_sqlite ) 113 if (m_sqlite )
111 sqlite_close( m_sqlite ), m_sqlite=0l; 114 sqlite_close( m_sqlite ), m_sqlite=0l;
112 115
113 return true; 116 return true;
114} 117}
115 118
116 119
117/* Query */ 120/* Query */
118OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 121OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
119 if ( !m_sqlite ) { 122 if ( !m_sqlite ) {
120 // FIXME set error code 123 // FIXME set error code
121 OSQLResult result( OSQLResult::Failure ); 124 OSQLResult result( OSQLResult::Failure );
122 return result; 125 return result;
123 } 126 }
124 Query query; 127 Query query;
125 query.driver = this; 128 query.driver = this;
126 char *err; 129 char *err;
127 /* SQLITE_OK 0 if return code > 0 == failure */ 130 /* SQLITE_OK 0 if return code > 0 == failure */
128 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { 131 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) {
129 owarn << "OSQLiteDriver::query: Error while executing" << oendl; 132 qWarning("OSQLiteDriver::query: Error while executing");
130 free(err ); 133 free(err );
131 // FixMe Errors 134 // FixMe Errors
132 } 135 }
133 136
134 OSQLResult result(OSQLResult::Success, 137 OSQLResult result(OSQLResult::Success,
135 query.items, 138 query.items,
136 query.errors ); 139 query.errors );
137 return result; 140 return result;
138} 141}
139 142
140 143
141OSQLTable::ValueList OSQLiteDriver::tables() const { 144OSQLTable::ValueList OSQLiteDriver::tables() const {
142 145
143} 146}
144 147
145 148
146OSQLError OSQLiteDriver::lastError() { 149OSQLError OSQLiteDriver::lastError() {
147 OSQLError error; 150 OSQLError error;
148 return error; 151 return error;
149}; 152};
150 153
151 154
152/* handle a callback add the row to the global 155/* handle a callback add the row to the global
153 * OSQLResultItem 156 * OSQLResultItem
154 */ 157 */
155int OSQLiteDriver::handleCallBack( int, char**, char** ) { 158int OSQLiteDriver::handleCallBack( int, char**, char** ) {
156 return 0; 159 return 0;
157} 160}
158 161
159 162
160/* callback_handler add the values to the list*/ 163/* callback_handler add the values to the list*/
161int OSQLiteDriver::call_back( void* voi, int argc, 164int OSQLiteDriver::call_back( void* voi, int argc,
162 char** argv, char** columns) { 165 char** argv, char** columns) {
163 Query* qu = (Query*)voi; 166 Query* qu = (Query*)voi;
164 167
165 //copy them over to a OSQLResultItem 168 //copy them over to a OSQLResultItem
166 QMap<QString, QString> tableString; 169 QMap<QString, QString> tableString;
167 QMap<int, QString> tableInt; 170 QMap<int, QString> tableInt;
168 for (int i = 0; i < argc; i++ ) { 171 for (int i = 0; i < argc; i++ ) {
169 172
170#ifdef __BUGGY_LOCAL8BIT_ 173#ifdef __BUGGY_LOCAL8BIT_
171 tableInt.insert( i, QString::fromLatin1( argv[i] ) ); 174 tableInt.insert( i, QString::fromLatin1( argv[i] ) );
172 tableString.insert( QString::fromLatin1( columns[i] ), 175 tableString.insert( QString::fromLatin1( columns[i] ),
173 QString::fromLatin1( argv[i] ) ); 176 QString::fromLatin1( argv[i] ) );
174#else 177#else
175 tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); 178 tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) );
176 tableString.insert( QString::fromLocal8Bit( columns[i] ), 179 tableString.insert( QString::fromLocal8Bit( columns[i] ),
177 QString::fromLocal8Bit( argv[i] ) ); 180 QString::fromLocal8Bit( argv[i] ) );