summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp44
-rw-r--r--libopie2/opiedb/osqlitedriver.h8
2 files changed, 32 insertions, 20 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index 4eda9b9..f07d520 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -43,5 +43,2 @@
- char *regex_raw;
- regex_t regex_c;
-
using namespace Opie::DB;
@@ -91,16 +88,17 @@ void OSQLiteDriver::setOptions( const QStringList& ) {
*/
-int sqliteRlikeCompare(const char *zPattern, const char *zString){
+int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){
int res;
- if (regex_raw == NULL || (strcmp (zPattern, regex_raw) != 0)){
- if (regex_raw != NULL) {
- free(regex_raw);
- regfree(&regex_c);
+
+ if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){
+ if (reg->regex_raw != NULL) {
+ free(reg->regex_raw);
+ regfree(&reg->regex_c);
}
- regex_raw = (char *)malloc(strlen(zPattern)+1);
- strncpy(regex_raw, zPattern, strlen(zPattern)+1);
- res = regcomp(&regex_c, zPattern, REG_EXTENDED);
+ reg->regex_raw = (char *)malloc(strlen(zPattern)+1);
+ strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1);
+ res = regcomp(&reg->regex_c, zPattern, REG_EXTENDED);
if ( res != 0 ) {
printf("Regcomp failed with code %u on string %s\n",res,zPattern);
- free(regex_raw);
- regex_raw=NULL;
+ free(reg->regex_raw);
+ reg->regex_raw=NULL;
return 0;
@@ -108,3 +106,3 @@ int sqliteRlikeCompare(const char *zPattern, const char *zString){
}
- res = (regexec(&regex_c, zString, 0, NULL, 0)==0);
+ res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0);
return res;
@@ -113,6 +111,9 @@ int sqliteRlikeCompare(const char *zPattern, const char *zString){
void rlikeFunc(sqlite_func *context, int arg, const char **argv){
- if( argv[0]==0 || argv[1]==0 ) return;
+ if( argv[0]==0 || argv[1]==0 || argv[2]==0){
+ printf("One of arguments Null!!\n");
+ return;
+ }
sqlite_set_result_int(context,
sqliteRlikeCompare((const char*)argv[0],
- (const char*)argv[1]));
+ (const char*)argv[1], (sqregex*)argv[2]));
}
@@ -137,3 +138,4 @@ bool OSQLiteDriver::open() {
}
- sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,NULL);
+ sqreg = (sqregex *)malloc(sizeof(sqreg));
+ sqlite_create_function(m_sqlite,"rlike",3,rlikeFunc,&sqreg);
return true;
@@ -149,5 +151,7 @@ bool OSQLiteDriver::close() {
sqlite_close( m_sqlite ), m_sqlite=0l;
- free(regex_raw);
- regex_raw=NULL;
- regfree(&regex_c);
+ if (sqreg->regex_raw != NULL){
+ free(sqreg->regex_raw);
+ sqreg->regex_raw=NULL;
+ regfree(&sqreg->regex_c);
+ }
return true;
diff --git a/libopie2/opiedb/osqlitedriver.h b/libopie2/opiedb/osqlitedriver.h
index 9064e52..95c9e2f 100644
--- a/libopie2/opiedb/osqlitedriver.h
+++ b/libopie2/opiedb/osqlitedriver.h
@@ -4,2 +4,3 @@
#include <sqlite.h>
+#include <regex.h>
@@ -13,2 +14,7 @@ namespace Internal {
+struct sqregex {
+ char *regex_raw;
+ regex_t regex_c;
+};
+
class OSQLiteDriver : public OSQLDriver {
@@ -28,2 +34,3 @@ public:
OSQLTable::ValueList tables()const;
+
private:
@@ -36,2 +43,3 @@ private:
sqlite *m_sqlite;
+ sqregex *sqreg;
};