-rw-r--r-- | libopie2/opiedb/opiedb.pro | 3 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 18 |
2 files changed, 16 insertions, 5 deletions
diff --git a/libopie2/opiedb/opiedb.pro b/libopie2/opiedb/opiedb.pro index 3612f0e..bf547ab 100644 --- a/libopie2/opiedb/opiedb.pro +++ b/libopie2/opiedb/opiedb.pro | |||
@@ -1,38 +1,39 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on debug | 2 | #CONFIG += qt warn_on debug |
3 | CONFIG += qt warn_on release | ||
3 | DESTDIR = $(OPIEDIR)/lib | 4 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = osqlbackend.h \ | 5 | HEADERS = osqlbackend.h \ |
5 | osqldriver.h \ | 6 | osqldriver.h \ |
6 | osqlerror.h \ | 7 | osqlerror.h \ |
7 | osqlmanager.h \ | 8 | osqlmanager.h \ |
8 | osqlquery.h \ | 9 | osqlquery.h \ |
9 | osqlresult.h \ | 10 | osqlresult.h \ |
10 | osqltable.h \ | 11 | osqltable.h \ |
11 | osqlbackendmanager.h \ | 12 | osqlbackendmanager.h \ |
12 | osqlitedriver.h | 13 | osqlitedriver.h |
13 | SOURCES = osqlbackend.cpp \ | 14 | SOURCES = osqlbackend.cpp \ |
14 | osqldriver.cpp \ | 15 | osqldriver.cpp \ |
15 | osqlerror.cpp \ | 16 | osqlerror.cpp \ |
16 | osqlmanager.cpp \ | 17 | osqlmanager.cpp \ |
17 | osqlquery.cpp \ | 18 | osqlquery.cpp \ |
18 | osqlresult.cpp \ | 19 | osqlresult.cpp \ |
19 | osqltable.cpp \ | 20 | osqltable.cpp \ |
20 | osqlbackendmanager.cpp \ | 21 | osqlbackendmanager.cpp \ |
21 | osqlitedriver.cpp | 22 | osqlitedriver.cpp |
22 | INTERFACES = | 23 | INTERFACES = |
23 | TARGET = opiedb2 | 24 | TARGET = opiedb2 |
24 | VERSION = 1.8.1 | 25 | VERSION = 1.8.1 |
25 | INCLUDEPATH += $(OPIEDIR)/include | 26 | INCLUDEPATH += $(OPIEDIR)/include |
26 | DEPENDPATH += $(OPIEDIR)/include | 27 | DEPENDPATH += $(OPIEDIR)/include |
27 | 28 | ||
28 | MOC_DIR = moc | 29 | MOC_DIR = moc |
29 | OBJECTS_DIR = obj | 30 | OBJECTS_DIR = obj |
30 | 31 | ||
31 | !contains( platform, x11 ) { | 32 | !contains( platform, x11 ) { |
32 | include ( $(OPIEDIR)/include.pro ) | 33 | include ( $(OPIEDIR)/include.pro ) |
33 | } | 34 | } |
34 | 35 | ||
35 | contains( platform, x11 ) { | 36 | contains( platform, x11 ) { |
36 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 37 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
37 | } | 38 | } |
38 | 39 | ||
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index 9214ad3..99fd218 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -1,126 +1,136 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | 2 | ||
3 | #include "osqlresult.h" | 3 | #include "osqlresult.h" |
4 | #include "osqlquery.h" | 4 | #include "osqlquery.h" |
5 | #include "osqlitedriver.h" | 5 | #include "osqlitedriver.h" |
6 | 6 | ||
7 | // fromLocal8Bit() does not work as expected. Thus it | ||
8 | // is replaced by fromLatin1() (eilers) | ||
9 | #define __BUGGY_LOCAL8BIT_ | ||
10 | |||
7 | 11 | ||
8 | namespace { | 12 | namespace { |
9 | struct Query { | 13 | struct Query { |
10 | OSQLError::ValueList errors; | 14 | OSQLError::ValueList errors; |
11 | OSQLResultItem::ValueList items; | 15 | OSQLResultItem::ValueList items; |
12 | OSQLiteDriver *driver; | 16 | OSQLiteDriver *driver; |
13 | }; | 17 | }; |
14 | } | 18 | } |
15 | 19 | ||
16 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) | 20 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) |
17 | : OSQLDriver( lib ) | 21 | : OSQLDriver( lib ) |
18 | { | 22 | { |
19 | m_sqlite = 0l; | 23 | m_sqlite = 0l; |
20 | } | 24 | } |
21 | OSQLiteDriver::~OSQLiteDriver() { | 25 | OSQLiteDriver::~OSQLiteDriver() { |
22 | close(); | 26 | close(); |
23 | } | 27 | } |
24 | 28 | ||
25 | QString OSQLiteDriver::id()const { | 29 | QString OSQLiteDriver::id()const { |
26 | return QString::fromLatin1("SQLite"); | 30 | return QString::fromLatin1("SQLite"); |
27 | } | 31 | } |
28 | 32 | ||
29 | void OSQLiteDriver::setUserName( const QString& ) {} | 33 | void OSQLiteDriver::setUserName( const QString& ) {} |
30 | void OSQLiteDriver::setPassword( const QString& ) {} | 34 | void OSQLiteDriver::setPassword( const QString& ) {} |
31 | 35 | ||
32 | void OSQLiteDriver::setUrl( const QString& url ) { | 36 | void OSQLiteDriver::setUrl( const QString& url ) { |
33 | m_url = url; | 37 | m_url = url; |
34 | } | 38 | } |
35 | void OSQLiteDriver::setOptions( const QStringList& ) { | 39 | void OSQLiteDriver::setOptions( const QStringList& ) { |
36 | } | 40 | } |
37 | /* | 41 | /* |
38 | * try to open a db specified via setUrl | 42 | * try to open a db specified via setUrl |
39 | * and options | 43 | * and options |
40 | */ | 44 | */ |
41 | bool OSQLiteDriver::open() { | 45 | bool OSQLiteDriver::open() { |
42 | char *error; | 46 | char *error; |
43 | qWarning("about to open"); | 47 | qWarning("about to open"); |
44 | m_sqlite = sqlite_open(m_url.local8Bit(), | 48 | m_sqlite = sqlite_open(m_url.local8Bit(), |
45 | 0, | 49 | 0, |
46 | &error ); | 50 | &error ); |
47 | 51 | ||
48 | /* failed to open */ | 52 | /* failed to open */ |
49 | if (m_sqlite == 0l ) { | 53 | if (m_sqlite == 0l ) { |
50 | // FIXME set the last error | 54 | // FIXME set the last error |
51 | qWarning("error:%s", error ); | 55 | qWarning("error:%s", error ); |
52 | free( error ); | 56 | free( error ); |
53 | return false; | 57 | return false; |
54 | } | 58 | } |
55 | return true; | 59 | return true; |
56 | } | 60 | } |
57 | /* close the db | 61 | /* close the db |
58 | * sqlite closes them without | 62 | * sqlite closes them without |
59 | * telling failure or success | 63 | * telling failure or success |
60 | */ | 64 | */ |
61 | bool OSQLiteDriver::close() { | 65 | bool OSQLiteDriver::close() { |
62 | if (m_sqlite ) | 66 | if (m_sqlite ) |
63 | sqlite_close( m_sqlite ), m_sqlite=0l; | 67 | sqlite_close( m_sqlite ), m_sqlite=0l; |
64 | 68 | ||
65 | return true; | 69 | return true; |
66 | } | 70 | } |
67 | /* Query */ | 71 | /* Query */ |
68 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 72 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
69 | if ( !m_sqlite ) { | 73 | if ( !m_sqlite ) { |
70 | // FIXME set error code | 74 | // FIXME set error code |
71 | OSQLResult result( OSQLResult::Failure ); | 75 | OSQLResult result( OSQLResult::Failure ); |
72 | return result; | 76 | return result; |
73 | } | 77 | } |
74 | Query query; | 78 | Query query; |
75 | query.driver = this; | 79 | query.driver = this; |
76 | char *err; | 80 | char *err; |
77 | /* SQLITE_OK 0 if return code > 0 == failure */ | 81 | /* SQLITE_OK 0 if return code > 0 == failure */ |
78 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { | 82 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { |
79 | qWarning("Error while executing"); | 83 | qWarning("Error while executing"); |
80 | free(err ); | 84 | free(err ); |
81 | // FixMe Errors | 85 | // FixMe Errors |
82 | } | 86 | } |
83 | qWarning("Item count is %d", query.items.count() ); | 87 | // qWarning("Item count is %d", query.items.count() ); |
84 | OSQLResult result(OSQLResult::Success, | 88 | OSQLResult result(OSQLResult::Success, |
85 | query.items, | 89 | query.items, |
86 | query.errors ); | 90 | query.errors ); |
87 | return result; | 91 | return result; |
88 | } | 92 | } |
89 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 93 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
90 | 94 | ||
91 | } | 95 | } |
92 | OSQLError OSQLiteDriver::lastError() { | 96 | OSQLError OSQLiteDriver::lastError() { |
93 | OSQLError error; | 97 | OSQLError error; |
94 | return error; | 98 | return error; |
95 | }; | 99 | }; |
96 | /* handle a callback add the row to the global | 100 | /* handle a callback add the row to the global |
97 | * OSQLResultItem | 101 | * OSQLResultItem |
98 | */ | 102 | */ |
99 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 103 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
100 | return 0; | 104 | return 0; |
101 | } | 105 | } |
102 | /* callback_handler add the values to the list*/ | 106 | /* callback_handler add the values to the list*/ |
103 | int OSQLiteDriver::call_back( void* voi, int argc, | 107 | int OSQLiteDriver::call_back( void* voi, int argc, |
104 | char** argv, char** columns) { | 108 | char** argv, char** columns) { |
105 | qWarning("Callback with %d items", argc ); | 109 | // qWarning("Callback with %d items", argc ); |
106 | Query* qu = (Query*)voi; | 110 | Query* qu = (Query*)voi; |
107 | 111 | ||
108 | //copy them over to a OSQLResultItem | 112 | //copy them over to a OSQLResultItem |
109 | QMap<QString, QString> tableString; | 113 | QMap<QString, QString> tableString; |
110 | QMap<int, QString> tableInt; | 114 | QMap<int, QString> tableInt; |
111 | for (int i = 0; i < argc; i++ ) { | 115 | for (int i = 0; i < argc; i++ ) { |
112 | qWarning("%s|%s", columns[i], argv[i] ); | 116 | //qWarning("%s|%s", columns[i], argv[i] ); |
117 | |||
118 | #ifdef __BUGGY_LOCAL8BIT_ | ||
119 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); | ||
120 | tableString.insert( QString::fromLatin1( columns[i] ), | ||
121 | QString::fromLatin1( argv[i] ) ); | ||
122 | #else | ||
113 | tableInt.insert( i, QString::fromLocal8Bit(argv[i] ) ); | 123 | tableInt.insert( i, QString::fromLocal8Bit(argv[i] ) ); |
114 | tableString.insert( QString::fromLocal8Bit( columns[i]), | 124 | tableString.insert( QString::fromLocal8Bit( columns[i]), |
115 | QString::fromLocal8Bit( argv[i] ) ); | 125 | QString::fromLocal8Bit( argv[i] ) ); |
116 | 126 | #endif | |
117 | } | 127 | } |
118 | OSQLResultItem item( tableString, tableInt ); | 128 | OSQLResultItem item( tableString, tableInt ); |
119 | qu->items.append( item ); | 129 | qu->items.append( item ); |
120 | 130 | ||
121 | return ((Query*)voi)->driver->handleCallBack( argc, | 131 | return ((Query*)voi)->driver->handleCallBack( argc, |
122 | argv, | 132 | argv, |
123 | columns ); | 133 | columns ); |
124 | 134 | ||
125 | 135 | ||
126 | } | 136 | } |