summaryrefslogtreecommitdiff
path: root/libopie2/opiedb
authorbrad <brad>2004-04-06 11:58:24 (UTC)
committer brad <brad>2004-04-06 11:58:24 (UTC)
commit74c9cbe70b2a2530aad5e5a3cc8e0c946c560e95 (patch) (unidiff)
treeaf55d362e359414b2b18cef0c979d7e71e6a7d96 /libopie2/opiedb
parent52b7f68dd9435286a2d0b53fc8649b4323b8af38 (diff)
downloadopie-74c9cbe70b2a2530aad5e5a3cc8e0c946c560e95.zip
opie-74c9cbe70b2a2530aad5e5a3cc8e0c946c560e95.tar.gz
opie-74c9cbe70b2a2530aad5e5a3cc8e0c946c560e95.tar.bz2
Fix memleak
Diffstat (limited to 'libopie2/opiedb') (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
@@ -115,65 +115,64 @@ void rlikeFunc(sqlite_func *context, int arg, const char **argv){
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,
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
@@ -20,31 +20,31 @@ struct sqregex {
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