summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp9
-rw-r--r--libopie2/opiedb/osqlitedriver.h2
2 files changed, 5 insertions, 6 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index f07d520..3ba161e 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -91,113 +91,112 @@ int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){
91 91
92 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ 92 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){
93 if (reg->regex_raw != NULL) { 93 if (reg->regex_raw != NULL) {
94 free(reg->regex_raw); 94 free(reg->regex_raw);
95 regfree(&reg->regex_c); 95 regfree(&reg->regex_c);
96 } 96 }
97 reg->regex_raw = (char *)malloc(strlen(zPattern)+1); 97 reg->regex_raw = (char *)malloc(strlen(zPattern)+1);
98 strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1); 98 strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1);
99 res = regcomp(&reg->regex_c, zPattern, REG_EXTENDED); 99 res = regcomp(&reg->regex_c, zPattern, REG_EXTENDED);
100 if ( res != 0 ) { 100 if ( res != 0 ) {
101 printf("Regcomp failed with code %u on string %s\n",res,zPattern); 101 printf("Regcomp failed with code %u on string %s\n",res,zPattern);
102 free(reg->regex_raw); 102 free(reg->regex_raw);
103 reg->regex_raw=NULL; 103 reg->regex_raw=NULL;
104 return 0; 104 return 0;
105 } 105 }
106 } 106 }
107 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0); 107 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0);
108 return res; 108 return res;
109} 109}
110 110
111void rlikeFunc(sqlite_func *context, int arg, const char **argv){ 111void rlikeFunc(sqlite_func *context, int arg, const char **argv){
112 if( argv[0]==0 || argv[1]==0 || argv[2]==0){ 112 if( argv[0]==0 || argv[1]==0 || argv[2]==0){
113 printf("One of arguments Null!!\n"); 113 printf("One of arguments Null!!\n");
114 return; 114 return;
115 } 115 }
116 sqlite_set_result_int(context, 116 sqlite_set_result_int(context,
117 sqliteRlikeCompare((const char*)argv[0], 117 sqliteRlikeCompare((const char*)argv[0],
118 (const char*)argv[1], (sqregex*)argv[2])); 118 (const char*)argv[1], (sqregex*)argv[2]));
119} 119}
120 120
121/* 121/*
122 * try to open a db specified via setUrl 122 * try to open a db specified via setUrl
123 * and options 123 * and options
124 */ 124 */
125bool OSQLiteDriver::open() { 125bool OSQLiteDriver::open() {
126 char *error; 126 char *error;
127 qDebug("OSQLiteDriver::open: about to open"); 127 qDebug("OSQLiteDriver::open: about to open");
128 m_sqlite = sqlite_open(m_url.local8Bit(), 128 m_sqlite = sqlite_open(m_url.local8Bit(),
129 0, 129 0,
130 &error ); 130 &error );
131 131
132 /* failed to open */ 132 /* failed to open */
133 if (m_sqlite == 0l ) { 133 if (m_sqlite == 0l ) {
134 // FIXME set the last error 134 // FIXME set the last error
135 qWarning("OSQLiteDriver::open: %s", error ); 135 qWarning("OSQLiteDriver::open: %s", error );
136 free( error ); 136 free( error );
137 return false; 137 return false;
138 } 138 }
139 sqreg = (sqregex *)malloc(sizeof(sqreg));
140 sqlite_create_function(m_sqlite,"rlike",3,rlikeFunc,&sqreg); 139 sqlite_create_function(m_sqlite,"rlike",3,rlikeFunc,&sqreg);
141 return true; 140 return true;
142} 141}
143 142
144 143
145/* close the db 144/* close the db
146 * sqlite closes them without 145 * sqlite closes them without
147 * telling failure or success 146 * telling failure or success
148 */ 147 */
149bool OSQLiteDriver::close() { 148bool OSQLiteDriver::close() {
150 if (m_sqlite ) 149 if (m_sqlite )
151 sqlite_close( m_sqlite ), m_sqlite=0l; 150 sqlite_close( m_sqlite ), m_sqlite=0l;
152 if (sqreg->regex_raw != NULL){ 151 if (sqreg.regex_raw != NULL){
153 free(sqreg->regex_raw); 152 free(sqreg.regex_raw);
154 sqreg->regex_raw=NULL; 153 sqreg.regex_raw=NULL;
155 regfree(&sqreg->regex_c); 154 regfree(&sqreg.regex_c);
156 } 155 }
157 return true; 156 return true;
158} 157}
159 158
160 159
161/* Query */ 160/* Query */
162OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 161OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
163 if ( !m_sqlite ) { 162 if ( !m_sqlite ) {
164 // FIXME set error code 163 // FIXME set error code
165 OSQLResult result( OSQLResult::Failure ); 164 OSQLResult result( OSQLResult::Failure );
166 return result; 165 return result;
167 } 166 }
168 Query query; 167 Query query;
169 query.driver = this; 168 query.driver = this;
170 char *err; 169 char *err;
171 /* SQLITE_OK 0 if return code > 0 == failure */ 170 /* SQLITE_OK 0 if return code > 0 == failure */
172 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { 171 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) {
173 qWarning("OSQLiteDriver::query: Error while executing"); 172 qWarning("OSQLiteDriver::query: Error while executing");
174 free(err ); 173 free(err );
175 // FixMe Errors 174 // FixMe Errors
176 } 175 }
177 176
178 OSQLResult result(OSQLResult::Success, 177 OSQLResult result(OSQLResult::Success,
179 query.items, 178 query.items,
180 query.errors ); 179 query.errors );
181 return result; 180 return result;
182} 181}
183 182
184 183
185OSQLTable::ValueList OSQLiteDriver::tables() const { 184OSQLTable::ValueList OSQLiteDriver::tables() const {
186 185
187} 186}
188 187
189 188
190OSQLError OSQLiteDriver::lastError() { 189OSQLError OSQLiteDriver::lastError() {
191 OSQLError error; 190 OSQLError error;
192 return error; 191 return error;
193}; 192};
194 193
195 194
196/* handle a callback add the row to the global 195/* handle a callback add the row to the global
197 * OSQLResultItem 196 * OSQLResultItem
198 */ 197 */
199int OSQLiteDriver::handleCallBack( int, char**, char** ) { 198int OSQLiteDriver::handleCallBack( int, char**, char** ) {
200 return 0; 199 return 0;
201} 200}
202 201
203 202
diff --git a/libopie2/opiedb/osqlitedriver.h b/libopie2/opiedb/osqlitedriver.h
index 95c9e2f..adec331 100644
--- a/libopie2/opiedb/osqlitedriver.h
+++ b/libopie2/opiedb/osqlitedriver.h
@@ -1,50 +1,50 @@
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 <sqlite.h>
5#include <regex.h> 5#include <regex.h>
6 6
7#include "osqldriver.h" 7#include "osqldriver.h"
8#include "osqlerror.h" 8#include "osqlerror.h"
9#include "osqlresult.h" 9#include "osqlresult.h"
10 10
11namespace Opie { 11namespace Opie {
12namespace DB { 12namespace DB {
13namespace Internal { 13namespace Internal {
14 14
15struct sqregex { 15struct sqregex {
16 char *regex_raw; 16 char *regex_raw;
17 regex_t regex_c; 17 regex_t regex_c;
18}; 18};
19 19
20class OSQLiteDriver : public OSQLDriver { 20class OSQLiteDriver : public OSQLDriver {
21 Q_OBJECT 21 Q_OBJECT
22public: 22public:
23 OSQLiteDriver( QLibrary *lib = 0l ); 23 OSQLiteDriver( QLibrary *lib = 0l );
24 ~OSQLiteDriver(); 24 ~OSQLiteDriver();
25 QString id()const; 25 QString id()const;
26 void setUserName( const QString& ); 26 void setUserName( const QString& );
27 void setPassword( const QString& ); 27 void setPassword( const QString& );
28 void setUrl( const QString& url ); 28 void setUrl( const QString& url );
29 void setOptions( const QStringList& ); 29 void setOptions( const QStringList& );
30 bool open(); 30 bool open();
31 bool close(); 31 bool close();
32 OSQLError lastError(); 32 OSQLError lastError();
33 OSQLResult query( OSQLQuery* ); 33 OSQLResult query( OSQLQuery* );
34 OSQLTable::ValueList tables()const; 34 OSQLTable::ValueList tables()const;
35 35
36private: 36private:
37 OSQLError m_lastE; 37 OSQLError m_lastE;
38 OSQLResult m_result; 38 OSQLResult m_result;
39 OSQLResultItem m_items; 39 OSQLResultItem m_items;
40 int handleCallBack( int, char**, char** ); 40 int handleCallBack( int, char**, char** );
41 static int call_back( void*, int, char**, char** ); 41 static int call_back( void*, int, char**, char** );
42 QString m_url; 42 QString m_url;
43 sqlite *m_sqlite; 43 sqlite *m_sqlite;
44 sqregex *sqreg; 44 sqregex sqreg;
45}; 45};
46} 46}
47} 47}
48} 48}
49 49
50#endif 50#endif