-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index b9a491e..92f89cf 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -109,120 +109,120 @@ void rlikeFunc(sqlite_func *context, int arg, const char **argv){ | |||
109 | return; | 109 | return; |
110 | } | 110 | } |
111 | sqlite_set_result_int(context, | 111 | sqlite_set_result_int(context, |
112 | sqliteRlikeCompare((const char*)argv[0], | 112 | sqliteRlikeCompare((const char*)argv[0], |
113 | (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); | 113 | (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); |
114 | } | 114 | } |
115 | 115 | ||
116 | /* | 116 | /* |
117 | * try to open a db specified via setUrl | 117 | * try to open a db specified via setUrl |
118 | * and options | 118 | * and options |
119 | */ | 119 | */ |
120 | bool OSQLiteDriver::open() { | 120 | bool OSQLiteDriver::open() { |
121 | char *error; | 121 | char *error; |
122 | 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 | m_sqlite = sqlite_open(m_url.local8Bit(), |
125 | 0, | 125 | 0, |
126 | &error ); | 126 | &error ); |
127 | 127 | ||
128 | /* failed to open */ | 128 | /* failed to open */ |
129 | if (m_sqlite == 0l ) { | 129 | if (m_sqlite == 0l ) { |
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 | free( error ); |
133 | return false; | 133 | return false; |
134 | } | 134 | } |
135 | if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) | 135 | if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) |
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 | if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) |
138 | odebug << "Unable to set rlike function result type!" << oendl; | 138 | odebug << "Unable to set rlike function result type!" << oendl; |
139 | sqreg.regex_raw = NULL; | 139 | sqreg.regex_raw = NULL; |
140 | return true; | 140 | return true; |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | /* close the db | 144 | /* close the db |
145 | * sqlite closes them without | 145 | * sqlite closes them without |
146 | * telling failure or success | 146 | * telling failure or success |
147 | */ | 147 | */ |
148 | bool OSQLiteDriver::close() { | 148 | bool OSQLiteDriver::close() { |
149 | if (m_sqlite ) | 149 | if (m_sqlite ) |
150 | sqlite_close( m_sqlite ), m_sqlite=0l; | 150 | sqlite_close( m_sqlite ), m_sqlite=0l; |
151 | if (sqreg.regex_raw != NULL){ | 151 | if (sqreg.regex_raw != NULL){ |
152 | odebug << "Freeing regex on close" << oendl; | 152 | odebug << "Freeing regex on close" << oendl; |
153 | free(sqreg.regex_raw); | 153 | free(sqreg.regex_raw); |
154 | sqreg.regex_raw=NULL; | 154 | sqreg.regex_raw=NULL; |
155 | regfree(&sqreg.regex_c); | 155 | regfree(&sqreg.regex_c); |
156 | } | 156 | } |
157 | return true; | 157 | return true; |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | /* Query */ | 161 | /* Query */ |
162 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 162 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
163 | if ( !m_sqlite ) { | 163 | if ( !m_sqlite ) { |
164 | // FIXME set error code | 164 | // FIXME set error code |
165 | OSQLResult result( OSQLResult::Failure ); | 165 | OSQLResult result( OSQLResult::Failure ); |
166 | return result; | 166 | return result; |
167 | } | 167 | } |
168 | Query query; | 168 | Query query; |
169 | query.driver = this; | 169 | query.driver = this; |
170 | char *err; | 170 | char *err; |
171 | /* SQLITE_OK 0 if return code > 0 == failure */ | 171 | /* SQLITE_OK 0 if return code > 0 == failure */ |
172 | if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { | 172 | if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { |
173 | qWarning("OSQLiteDriver::query: Error while executing %s",err); | 173 | owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; |
174 | free(err ); | 174 | free( err ); |
175 | // FixMe Errors | 175 | // FixMe Errors |
176 | } | 176 | } |
177 | 177 | ||
178 | OSQLResult result(OSQLResult::Success, | 178 | OSQLResult result(OSQLResult::Success, |
179 | query.items, | 179 | query.items, |
180 | query.errors ); | 180 | query.errors ); |
181 | return result; | 181 | return result; |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 185 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
186 | 186 | ||
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | OSQLError OSQLiteDriver::lastError() { | 190 | OSQLError OSQLiteDriver::lastError() { |
191 | OSQLError error; | 191 | OSQLError error; |
192 | return error; | 192 | return error; |
193 | }; | 193 | }; |
194 | 194 | ||
195 | 195 | ||
196 | /* handle a callback add the row to the global | 196 | /* handle a callback add the row to the global |
197 | * OSQLResultItem | 197 | * OSQLResultItem |
198 | */ | 198 | */ |
199 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 199 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
200 | return 0; | 200 | return 0; |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
204 | /* callback_handler add the values to the list*/ | 204 | /* callback_handler add the values to the list*/ |
205 | int OSQLiteDriver::call_back( void* voi, int argc, | 205 | int OSQLiteDriver::call_back( void* voi, int argc, |
206 | char** argv, char** columns) { | 206 | char** argv, char** columns) { |
207 | Query* qu = (Query*)voi; | 207 | Query* qu = (Query*)voi; |
208 | 208 | ||
209 | //copy them over to a OSQLResultItem | 209 | //copy them over to a OSQLResultItem |
210 | QMap<QString, QString> tableString; | 210 | QMap<QString, QString> tableString; |
211 | QMap<int, QString> tableInt; | 211 | QMap<int, QString> tableInt; |
212 | for (int i = 0; i < argc; i++ ) { | 212 | for (int i = 0; i < argc; i++ ) { |
213 | 213 | ||
214 | tableInt.insert( i, QString::fromUtf8( argv[i] ) ); | 214 | tableInt.insert( i, QString::fromUtf8( argv[i] ) ); |
215 | tableString.insert( QString::fromUtf8( columns[i] ), | 215 | tableString.insert( QString::fromUtf8( columns[i] ), |
216 | QString::fromUtf8( argv[i] ) ); | 216 | QString::fromUtf8( argv[i] ) ); |
217 | } | 217 | } |
218 | OSQLResultItem item( tableString, tableInt ); | 218 | OSQLResultItem item( tableString, tableInt ); |
219 | qu->items.append( item ); | 219 | qu->items.append( item ); |
220 | 220 | ||
221 | return ((Query*)voi)->driver->handleCallBack( argc, | 221 | return ((Query*)voi)->driver->handleCallBack( argc, |
222 | argv, | 222 | argv, |
223 | columns ); | 223 | columns ); |
224 | 224 | ||
225 | 225 | ||
226 | } | 226 | } |
227 | 227 | ||
228 | }}} // namespace OPIE::DB::Internal | 228 | }}} // namespace OPIE::DB::Internal |