summaryrefslogtreecommitdiff
path: root/libsql/osqlitedriver.cpp
authormickeyl <mickeyl>2003-08-10 15:42:26 (UTC)
committer mickeyl <mickeyl>2003-08-10 15:42:26 (UTC)
commit90dbd3e9e7139c1280e71f9c77ed4362b8d0f367 (patch) (unidiff)
tree22f0947337ea9b21a1d8f56d04ce3292c9d6f19e /libsql/osqlitedriver.cpp
parent616e919ff6aea6a30e18edb37128c229e806beae (diff)
downloadopie-90dbd3e9e7139c1280e71f9c77ed4362b8d0f367.zip
opie-90dbd3e9e7139c1280e71f9c77ed4362b8d0f367.tar.gz
opie-90dbd3e9e7139c1280e71f9c77ed4362b8d0f367.tar.bz2
libsql is now a part of libopie2
Diffstat (limited to 'libsql/osqlitedriver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libsql/osqlitedriver.cpp126
1 files changed, 0 insertions, 126 deletions
diff --git a/libsql/osqlitedriver.cpp b/libsql/osqlitedriver.cpp
deleted file mode 100644
index 9214ad3..0000000
--- a/libsql/osqlitedriver.cpp
+++ b/dev/null
@@ -1,126 +0,0 @@
1#include <stdlib.h>
2
3#include "osqlresult.h"
4#include "osqlquery.h"
5#include "osqlitedriver.h"
6
7
8namespace {
9 struct Query {
10 OSQLError::ValueList errors;
11 OSQLResultItem::ValueList items;
12 OSQLiteDriver *driver;
13 };
14}
15
16OSQLiteDriver::OSQLiteDriver( QLibrary *lib )
17 : OSQLDriver( lib )
18{
19 m_sqlite = 0l;
20}
21OSQLiteDriver::~OSQLiteDriver() {
22 close();
23}
24
25QString OSQLiteDriver::id()const {
26 return QString::fromLatin1("SQLite");
27}
28
29void OSQLiteDriver::setUserName( const QString& ) {}
30void OSQLiteDriver::setPassword( const QString& ) {}
31
32void OSQLiteDriver::setUrl( const QString& url ) {
33 m_url = url;
34}
35void OSQLiteDriver::setOptions( const QStringList& ) {
36}
37/*
38 * try to open a db specified via setUrl
39 * and options
40 */
41bool OSQLiteDriver::open() {
42 char *error;
43 qWarning("about to open");
44 m_sqlite = sqlite_open(m_url.local8Bit(),
45 0,
46 &error );
47
48 /* failed to open */
49 if (m_sqlite == 0l ) {
50 // FIXME set the last error
51 qWarning("error:%s", error );
52 free( error );
53 return false;
54 }
55 return true;
56}
57/* close the db
58 * sqlite closes them without
59 * telling failure or success
60 */
61bool OSQLiteDriver::close() {
62 if (m_sqlite )
63 sqlite_close( m_sqlite ), m_sqlite=0l;
64
65 return true;
66}
67/* Query */
68OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
69 if ( !m_sqlite ) {
70 // FIXME set error code
71 OSQLResult result( OSQLResult::Failure );
72 return result;
73 }
74 Query query;
75 query.driver = this;
76 char *err;
77 /* SQLITE_OK 0 if return code > 0 == failure */
78 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) {
79 qWarning("Error while executing");
80 free(err );
81 // FixMe Errors
82 }
83 qWarning("Item count is %d", query.items.count() );
84 OSQLResult result(OSQLResult::Success,
85 query.items,
86 query.errors );
87 return result;
88}
89OSQLTable::ValueList OSQLiteDriver::tables() const {
90
91}
92OSQLError OSQLiteDriver::lastError() {
93 OSQLError error;
94 return error;
95};
96/* handle a callback add the row to the global
97 * OSQLResultItem
98 */
99int OSQLiteDriver::handleCallBack( int, char**, char** ) {
100 return 0;
101}
102/* callback_handler add the values to the list*/
103int OSQLiteDriver::call_back( void* voi, int argc,
104 char** argv, char** columns) {
105 qWarning("Callback with %d items", argc );
106 Query* qu = (Query*)voi;
107
108 //copy them over to a OSQLResultItem
109 QMap<QString, QString> tableString;
110 QMap<int, QString> tableInt;
111 for (int i = 0; i < argc; i++ ) {
112 qWarning("%s|%s", columns[i], argv[i] );
113 tableInt.insert( i, QString::fromLocal8Bit(argv[i] ) );
114 tableString.insert( QString::fromLocal8Bit( columns[i]),
115 QString::fromLocal8Bit( argv[i] ) );
116
117 }
118 OSQLResultItem item( tableString, tableInt );
119 qu->items.append( item );
120
121 return ((Query*)voi)->driver->handleCallBack( argc,
122 argv,
123 columns );
124
125
126}