summaryrefslogtreecommitdiff
path: root/libopie2/opiedb
authormickeyl <mickeyl>2003-12-20 17:24:21 (UTC)
committer mickeyl <mickeyl>2003-12-20 17:24:21 (UTC)
commitdd5c40a4fa4d73ca1f5234502c7ba67675c5b7f9 (patch) (unidiff)
tree9711dbc6de8605887fd1a0062c5fbf17c6207398 /libopie2/opiedb
parent33dfe08454a70d3f9dd6dd154385c40adf6df918 (diff)
downloadopie-dd5c40a4fa4d73ca1f5234502c7ba67675c5b7f9.zip
opie-dd5c40a4fa4d73ca1f5234502c7ba67675c5b7f9.tar.gz
opie-dd5c40a4fa4d73ca1f5234502c7ba67675c5b7f9.tar.bz2
use odebug classes
Diffstat (limited to 'libopie2/opiedb') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/opiedb.pro51
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp69
2 files changed, 84 insertions, 36 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,41 +1,36 @@
1TEMPLATE = lib 1TEMPLATE = lib
2#CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3CONFIG += qt warn_on release
4DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
5HEADERS = osqlbackend.h \ 4HEADERS = osqlbackend.h \
6 osqldriver.h \ 5 osqldriver.h \
7 osqlerror.h \ 6 osqlerror.h \
8 osqlmanager.h \ 7 osqlmanager.h \
9 osqlquery.h \ 8 osqlquery.h \
10 osqlresult.h \ 9 osqlresult.h \
11 osqltable.h \ 10 osqltable.h \
12 osqlbackendmanager.h \ 11 osqlbackendmanager.h \
13 osqlitedriver.h 12 osqlitedriver.h
14SOURCES = osqlbackend.cpp \ 13SOURCES = osqlbackend.cpp \
15 osqldriver.cpp \ 14 osqldriver.cpp \
16 osqlerror.cpp \ 15 osqlerror.cpp \
17 osqlmanager.cpp \ 16 osqlmanager.cpp \
18 osqlquery.cpp \ 17 osqlquery.cpp \
19 osqlresult.cpp \ 18 osqlresult.cpp \
20 osqltable.cpp \ 19 osqltable.cpp \
21 osqlbackendmanager.cpp \ 20 osqlbackendmanager.cpp \
22 osqlitedriver.cpp 21 osqlitedriver.cpp
23INTERFACES = 22INTERFACES =
24TARGET = opiedb2 23TARGET = opiedb2
25VERSION = 1.8.2 24VERSION = 1.8.2
26INCLUDEPATH += $(OPIEDIR)/include 25INCLUDEPATH = $(OPIEDIR)/include
27DEPENDPATH += $(OPIEDIR)/include 26DEPENDPATH = $(OPIEDIR)/include
28 27LIBS += -lsqlite -lqpe
29MOC_DIR = moc
30OBJECTS_DIR = obj
31
32LIBS += -lsqlite -lqpe
33 28
34!contains( platform, x11 ) { 29!contains( platform, x11 ) {
35 include ( $(OPIEDIR)/include.pro ) 30 include ( $(OPIEDIR)/include.pro )
36} 31}
37 32
38contains( platform, x11 ) { 33contains( platform, x11 ) {
39 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 34 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
40} 35}
41 36
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,10 +1,42 @@
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
7// fromLocal8Bit() does not work as expected. Thus it 35#include <opie2/odebug.h>
36
37#include <stdlib.h>
38
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_
10 42
@@ -17,34 +49,45 @@ namespace {
17 }; 49 };
18} 50}
19 51
52
20OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) 53OSQLiteDriver::OSQLiteDriver( QLibrary *lib )
21 : OSQLDriver( lib ) 54 : OSQLDriver( lib )
22{ 55{
23 m_sqlite = 0l; 56 m_sqlite = 0l;
24} 57}
58
59
25OSQLiteDriver::~OSQLiteDriver() { 60OSQLiteDriver::~OSQLiteDriver() {
26 close(); 61 close();
27} 62}
28 63
64
29QString OSQLiteDriver::id()const { 65QString OSQLiteDriver::id()const {
30 return QString::fromLatin1("SQLite"); 66 return QString::fromLatin1("SQLite");
31} 67}
32 68
33void OSQLiteDriver::setUserName( const QString& ) {} 69void OSQLiteDriver::setUserName( const QString& ) {}
70
71
34void OSQLiteDriver::setPassword( const QString& ) {} 72void OSQLiteDriver::setPassword( const QString& ) {}
35 73
74
36void OSQLiteDriver::setUrl( const QString& url ) { 75void OSQLiteDriver::setUrl( const QString& url ) {
37 m_url = url; 76 m_url = url;
38} 77}
78
79
39void OSQLiteDriver::setOptions( const QStringList& ) { 80void 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 */
45bool OSQLiteDriver::open() { 88bool 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 */
72OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 119OSQLResult 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
93OSQLTable::ValueList OSQLiteDriver::tables() const { 142OSQLTable::ValueList OSQLiteDriver::tables() const {
94 143
95} 144}
145
146
96OSQLError OSQLiteDriver::lastError() { 147OSQLError 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 */
103int OSQLiteDriver::handleCallBack( int, char**, char** ) { 156int 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*/
107int OSQLiteDriver::call_back( void* voi, int argc, 162int 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] ) );