summaryrefslogtreecommitdiff
path: root/libopie2/opiedb
Unidiff
Diffstat (limited to 'libopie2/opiedb') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiedb/config.in2
-rw-r--r--libopie2/opiedb/libopiedb2.control4
-rw-r--r--libopie2/opiedb/opiedb.pro2
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp42
-rw-r--r--libopie2/opiedb/osqlitedriver.h4
5 files changed, 29 insertions, 25 deletions
diff --git a/libopie2/opiedb/config.in b/libopie2/opiedb/config.in
index 4d85609..0d74887 100644
--- a/libopie2/opiedb/config.in
+++ b/libopie2/opiedb/config.in
@@ -1,7 +1,7 @@
1 config LIBOPIE2DB 1 config LIBOPIE2DB
2 boolean "libopie2db (database related classes)" 2 boolean "libopie2db (database related classes)"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP
5 comment "libopie2db needs a libqpe, sqlite and libopie2core" 5 comment "libopie2db needs a libqpe, libsqlite3 and libopie2core"
6 depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP) 6 depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP)
7 7
diff --git a/libopie2/opiedb/libopiedb2.control b/libopie2/opiedb/libopiedb2.control
index 4859c46..29fae78 100644
--- a/libopie2/opiedb/libopiedb2.control
+++ b/libopie2/opiedb/libopiedb2.control
@@ -2,9 +2,9 @@ Package: libopiedb2
2Files: lib/libopiedb2.so* 2Files: lib/libopiedb2.so*
3Priority: optional 3Priority: optional
4Section: opie/system 4Section: opie/system
5Maintainer: Opie Team <opie@handhelds.org> 5Maintainer: Opie Team <opie@handhelds.org>
6Architecture: arm 6Architecture: arm
7Version: 1.8.2-$SUB_VERSION.2 7Version: 1.8.2-$SUB_VERSION.2
8Depends: libqpe1, libopiecore2 (1.8.2), libsqlite0 | sqlite 8Depends: libqpe1, libopiecore2 (1.8.2), libsqlite3 | sqlite3
9Provides: libopiedb2 9Provides: libopiedb2
10Description: Opie library 2.0 DB 10Description: Opie library 2.1 DB
diff --git a/libopie2/opiedb/opiedb.pro b/libopie2/opiedb/opiedb.pro
index 8432674..f727995 100644
--- a/libopie2/opiedb/opiedb.pro
+++ b/libopie2/opiedb/opiedb.pro
@@ -22,13 +22,13 @@ SOURCES = osqlbackend.cpp \
22 osqlitedriver.cpp 22 osqlitedriver.cpp
23 23
24TARGET = opiedb2 24TARGET = opiedb2
25VERSION = 1.9.0 25VERSION = 1.9.0
26INCLUDEPATH = $(OPIEDIR)/include 26INCLUDEPATH = $(OPIEDIR)/include
27DEPENDPATH = $(OPIEDIR)/include 27DEPENDPATH = $(OPIEDIR)/include
28LIBS += -lopiecore2 -lqpe -lsqlite 28LIBS += -lopiecore2 -lqpe -lsqlite3
29 29
30!contains( platform, x11 ) { 30!contains( platform, x11 ) {
31 include ( $(OPIEDIR)/include.pro ) 31 include ( $(OPIEDIR)/include.pro )
32} 32}
33 33
34contains( platform, x11 ) { 34contains( platform, x11 ) {
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index c8b560f..816223e 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -100,57 +100,61 @@ int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){
100 } 100 }
101 } 101 }
102 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0); 102 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0);
103 return res; 103 return res;
104} 104}
105 105
106void rlikeFunc(sqlite_func *context, int arg, const char **argv){ 106void rlikeFunc( sqlite3_context* context, int count, sqlite3_value** values ){
107 if( arg < 2 || argv[0]==0 || argv[1]==0 ){ 107 const unsigned char* argv0 = sqlite3_value_text( values[0] );
108 printf("One of arguments Null!!\n"); 108 const unsigned char* argv1 = sqlite3_value_text( values[1] );
109 if( count < 2 || argv0 == 0 || argv1 == 0 ){
110 qWarning( "One of arguments Null!!\n" );
109 return; 111 return;
110 } 112 }
111 sqlite_set_result_int(context, 113 sqlite3_result_int(context, sqliteRlikeCompare((const char*)argv0,
112 sqliteRlikeCompare((const char*)argv[0], 114 (const char*)argv1,
113 (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); 115 (sqregex *) sqlite3_user_data( context ) ));
114} 116}
115 117
116/* 118/*
117 * try to open a db specified via setUrl 119 * try to open a db specified via setUrl
118 * and options 120 * and options
119 */ 121 */
120bool OSQLiteDriver::open() { 122bool OSQLiteDriver::open() {
121 char *error;
122
123 odebug << "OSQLiteDriver::open: about to open" << oendl; 123 odebug << "OSQLiteDriver::open: about to open" << oendl;
124 m_sqlite = sqlite_open(m_url.local8Bit(), 124
125 0, 125 int error = sqlite3_open( m_url.utf8(),
126 &error ); 126 &m_sqlite );
127 127
128 /* failed to open */ 128 /* failed to open */
129 if (m_sqlite == 0l ) { 129 if ( error != SQLITE_OK ) {
130 // FIXME set the last error 130 // FIXME set the last error
131 owarn << "OSQLiteDriver::open: " << error << "" << oendl; 131 owarn << "OSQLiteDriver::open: " << error << "" << oendl;
132 free( error ); 132 sqlite3_close( m_sqlite );
133 return false; 133 return false;
134 } 134 }
135 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) 135 if ( sqlite3_create_function( m_sqlite, "rlike", 2, SQLITE_UTF8, &sqreg, rlikeFunc, NULL, NULL ) != SQLITE_OK ){
136 odebug << "Unable to create user defined function!" << oendl; 136 odebug << "Unable to create user defined function!" << oendl;
137 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) 137 return false;
138 odebug << "Unable to set rlike function result type!" << oendl; 138 }
139
139 sqreg.regex_raw = NULL; 140 sqreg.regex_raw = NULL;
141
140 return true; 142 return true;
141} 143}
142 144
143 145
144/* close the db 146/* close the db
145 * sqlite closes them without 147 * sqlite closes them without
146 * telling failure or success 148 * telling failure or success
147 */ 149 */
148bool OSQLiteDriver::close() { 150bool OSQLiteDriver::close() {
149 if (m_sqlite ) 151 if ( m_sqlite ){
150 sqlite_close( m_sqlite ), m_sqlite=0l; 152 sqlite3_close( m_sqlite );
153 m_sqlite=0l;
154 }
151 if (sqreg.regex_raw != NULL){ 155 if (sqreg.regex_raw != NULL){
152 odebug << "Freeing regex on close" << oendl; 156 odebug << "Freeing regex on close" << oendl;
153 free(sqreg.regex_raw); 157 free(sqreg.regex_raw);
154 sqreg.regex_raw=NULL; 158 sqreg.regex_raw=NULL;
155 regfree(&sqreg.regex_c); 159 regfree(&sqreg.regex_c);
156 } 160 }
@@ -166,13 +170,13 @@ OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
166 return result; 170 return result;
167 } 171 }
168 Query query; 172 Query query;
169 query.driver = this; 173 query.driver = this;
170 char *err; 174 char *err;
171 /* SQLITE_OK 0 if return code > 0 == failure */ 175 /* SQLITE_OK 0 if return code > 0 == failure */
172 if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { 176 if ( sqlite3_exec( m_sqlite, qu->query().utf8(), &call_back, &query, &err ) > SQLITE_OK ) {
173 owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; 177 owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl;
174 free( err ); 178 free( err );
175 // FixMe Errors 179 // FixMe Errors
176 } 180 }
177 181
178 OSQLResult result(OSQLResult::Success, 182 OSQLResult result(OSQLResult::Success,
diff --git a/libopie2/opiedb/osqlitedriver.h b/libopie2/opiedb/osqlitedriver.h
index e38fd52..4990a11 100644
--- a/libopie2/opiedb/osqlitedriver.h
+++ b/libopie2/opiedb/osqlitedriver.h
@@ -1,10 +1,10 @@
1#ifndef OSQL_LITE_DRIVER_H 1#ifndef OSQL_LITE_DRIVER_H
2#define OSQL_LITE_DRIVER_H 2#define OSQL_LITE_DRIVER_H
3 3
4#include <sqlite.h> 4#include <sqlite3.h>
5#include <sys/types.h> 5#include <sys/types.h>
6#include <regex.h> 6#include <regex.h>
7 7
8#include "osqldriver.h" 8#include "osqldriver.h"
9#include "osqlerror.h" 9#include "osqlerror.h"
10#include "osqlresult.h" 10#include "osqlresult.h"
@@ -38,13 +38,13 @@ private:
38 OSQLError m_lastE; 38 OSQLError m_lastE;
39 OSQLResult m_result; 39 OSQLResult m_result;
40 OSQLResultItem m_items; 40 OSQLResultItem m_items;
41 int handleCallBack( int, char**, char** ); 41 int handleCallBack( int, char**, char** );
42 static int call_back( void*, int, char**, char** ); 42 static int call_back( void*, int, char**, char** );
43 QString m_url; 43 QString m_url;
44 sqlite *m_sqlite; 44 sqlite3 *m_sqlite;
45 sqregex sqreg; 45 sqregex sqreg;
46}; 46};
47} 47}
48} 48}
49} 49}
50 50