author | eilers <eilers> | 2004-10-27 14:28:16 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-10-27 14:28:16 (UTC) |
commit | 03adfc8b698fbed4b6f31c8320f510eb6da0d51d (patch) (side-by-side diff) | |
tree | cb2faa9af5eedab6c816ca81433f457e8930cfc2 /libopie2 | |
parent | e44d35ca3fd26ef7a3184b07516f6535d8844a83 (diff) | |
download | opie-03adfc8b698fbed4b6f31c8320f510eb6da0d51d.zip opie-03adfc8b698fbed4b6f31c8320f510eb6da0d51d.tar.gz opie-03adfc8b698fbed4b6f31c8320f510eb6da0d51d.tar.bz2 |
Switching to sqlite3
Please read the following page for upgrade your old sqlite V2 database:
http://opie.handhelds.org/cgi-bin/moin.cgi/SqlBackends
-rw-r--r-- | libopie2/opiedb/config.in | 2 | ||||
-rw-r--r-- | libopie2/opiedb/libopiedb2.control | 4 | ||||
-rw-r--r-- | libopie2/opiedb/opiedb.pro | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 98 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimcontactfields.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 6 |
8 files changed, 58 insertions, 67 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 @@ -4,3 +4,3 @@ depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP - comment "libopie2db needs a libqpe, sqlite and libopie2core" + comment "libopie2db needs a libqpe, libsqlite3 and libopie2core" depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBSQLITE_DEP) 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 @@ -7,4 +7,4 @@ Architecture: arm Version: 1.8.2-$SUB_VERSION.2 -Depends: libqpe1, libopiecore2 (1.8.2), libsqlite0 | sqlite +Depends: libqpe1, libopiecore2 (1.8.2), libsqlite3 | sqlite3 Provides: libopiedb2 -Description: Opie library 2.0 DB +Description: 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 @@ -27,3 +27,3 @@ INCLUDEPATH = $(OPIEDIR)/include DEPENDPATH = $(OPIEDIR)/include -LIBS += -lopiecore2 -lqpe -lsqlite +LIBS += -lopiecore2 -lqpe -lsqlite3 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 @@ -105,10 +105,12 @@ int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ -void rlikeFunc(sqlite_func *context, int arg, const char **argv){ - if( arg < 2 || argv[0]==0 || argv[1]==0 ){ - printf("One of arguments Null!!\n"); - return; +void rlikeFunc( sqlite3_context* context, int count, sqlite3_value** values ){ + const unsigned char* argv0 = sqlite3_value_text( values[0] ); + const unsigned char* argv1 = sqlite3_value_text( values[1] ); + if( count < 2 || argv0 == 0 || argv1 == 0 ){ + qWarning( "One of arguments Null!!\n" ); + return; } - sqlite_set_result_int(context, - sqliteRlikeCompare((const char*)argv[0], - (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); + sqlite3_result_int(context, sqliteRlikeCompare((const char*)argv0, + (const char*)argv1, + (sqregex *) sqlite3_user_data( context ) )); } @@ -120,21 +122,21 @@ void rlikeFunc(sqlite_func *context, int arg, const char **argv){ bool OSQLiteDriver::open() { - char *error; - odebug << "OSQLiteDriver::open: about to open" << oendl; - m_sqlite = sqlite_open(m_url.local8Bit(), - 0, - &error ); + + int error = sqlite3_open( m_url.utf8(), + &m_sqlite ); /* failed to open */ - if (m_sqlite == 0l ) { + if ( error != SQLITE_OK ) { // FIXME set the last error owarn << "OSQLiteDriver::open: " << error << "" << oendl; - free( error ); + sqlite3_close( m_sqlite ); return false; } - if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) - odebug << "Unable to create user defined function!" << oendl; - if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) - odebug << "Unable to set rlike function result type!" << oendl; + if ( sqlite3_create_function( m_sqlite, "rlike", 2, SQLITE_UTF8, &sqreg, rlikeFunc, NULL, NULL ) != SQLITE_OK ){ + odebug << "Unable to create user defined function!" << oendl; + return false; + } + sqreg.regex_raw = NULL; + return true; @@ -148,11 +150,13 @@ bool OSQLiteDriver::open() { bool OSQLiteDriver::close() { - if (m_sqlite ) - sqlite_close( m_sqlite ), m_sqlite=0l; - if (sqreg.regex_raw != NULL){ - odebug << "Freeing regex on close" << oendl; - free(sqreg.regex_raw); - sqreg.regex_raw=NULL; - regfree(&sqreg.regex_c); - } - return true; + if ( m_sqlite ){ + sqlite3_close( m_sqlite ); + m_sqlite=0l; + } + if ( sqreg.regex_raw != NULL){ + odebug << "Freeing regex on close" << oendl; + free( sqreg.regex_raw ); + sqreg.regex_raw = NULL; + regfree( &sqreg.regex_c ); + } + return true; } @@ -162,21 +166,21 @@ bool OSQLiteDriver::close() { OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { - if ( !m_sqlite ) { - // FIXME set error code - OSQLResult result( OSQLResult::Failure ); - return result; - } - Query query; - query.driver = this; - char *err; - /* SQLITE_OK 0 if return code > 0 == failure */ - if ( sqlite_exec(m_sqlite, qu->query().utf8(),&call_back, &query, &err) > 0 ) { - owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; - free( err ); - // FixMe Errors - } - - OSQLResult result(OSQLResult::Success, - query.items, - query.errors ); - return result; + if ( !m_sqlite ) { + // FIXME set error code + OSQLResult result( OSQLResult::Failure ); + return result; + } + Query query; + query.driver = this; + char *err; + /* SQLITE_OK 0 if return code > 0 == failure */ + if ( sqlite3_exec( m_sqlite, qu->query().utf8(), &call_back, &query, &err ) > SQLITE_OK ) { + owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl; + free( err ); + // FixMe Errors + } + + OSQLResult result(OSQLResult::Success, + query.items, + query.errors ); + return result; } @@ -205,3 +209,3 @@ int OSQLiteDriver::handleCallBack( int, char**, char** ) { int OSQLiteDriver::call_back( void* voi, int argc, - char** argv, char** columns) { + char** argv, char** columns ) { Query* qu = (Query*)voi; 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 @@ -3,3 +3,3 @@ -#include <sqlite.h> +#include <sqlite3.h> #include <sys/types.h> @@ -43,3 +43,3 @@ private: QString m_url; - sqlite *m_sqlite; + sqlite3 *m_sqlite; sqregex sqreg; diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 7ab1ea5..f936d4e 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -180,3 +180,2 @@ public: */ - virtual T cacheFind( int uid )const; void cache( const T& )const; @@ -268,8 +267,2 @@ T OPimAccessTemplate<T>::find( int uid ) const{ template <class T> -T OPimAccessTemplate<T>::cacheFind( int uid ) const -{ - return m_cache.find( uid ); -} - -template <class T> T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, diff --git a/libopie2/opiepim/core/opimcontactfields.h b/libopie2/opiepim/core/opimcontactfields.h index 3aa3894..2e42951 100644 --- a/libopie2/opiepim/core/opimcontactfields.h +++ b/libopie2/opiepim/core/opimcontactfields.h @@ -2,3 +2,3 @@ This file is part of the Opie Project - Copyright (C) The Main Author <main-author@whereever.org> + Copyright (C) Stefan Eielrs <eilers.stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index ec9a94e..787486c 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h @@ -95,8 +95,2 @@ public: /** - * Find in Cache.. - * Returns empty object if nothing found. - */ - virtual T cacheFind( int uid )const = 0; - - /** * Put element into Cache |