summaryrefslogtreecommitdiff
path: root/libopie2/opiedb/osqlitedriver.cpp
authormickeyl <mickeyl>2003-08-10 15:40:31 (UTC)
committer mickeyl <mickeyl>2003-08-10 15:40:31 (UTC)
commit616e919ff6aea6a30e18edb37128c229e806beae (patch) (unidiff)
tree31e36f7d631b3dc55460aefd05bc6a455e73ace1 /libopie2/opiedb/osqlitedriver.cpp
parentdfcbe21d8b263c13283e226bd16596c2d7c2f9a3 (diff)
downloadopie-616e919ff6aea6a30e18edb37128c229e806beae.zip
opie-616e919ff6aea6a30e18edb37128c229e806beae.tar.gz
opie-616e919ff6aea6a30e18edb37128c229e806beae.tar.bz2
merge zeckes libsql into libopie2
Diffstat (limited to 'libopie2/opiedb/osqlitedriver.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
new file mode 100644
index 0000000..9214ad3
--- a/dev/null
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -0,0 +1,126 @@
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}