-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.h | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlmanager.cpp | 4 |
3 files changed, 4 insertions, 4 deletions
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index 47bc250..2c53248 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -1,172 +1,172 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "osqlquery.h" | 31 | #include "osqlquery.h" |
32 | #include "osqlitedriver.h" | 32 | #include "osqlitedriver.h" |
33 | 33 | ||
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | 35 | ||
36 | #include <stdlib.h> | 36 | #include <stdlib.h> |
37 | 37 | ||
38 | // fromLocal8Bit() does not work as expected. Thus it | 38 | // fromLocal8Bit() does not work as expected. Thus it |
39 | // is replaced by fromLatin1() (eilers) | 39 | // is replaced by fromLatin1() (eilers) |
40 | #define __BUGGY_LOCAL8BIT_ | 40 | #define __BUGGY_LOCAL8BIT_ |
41 | 41 | ||
42 | 42 | ||
43 | using namespace Opie::DB; | 43 | using namespace Opie::DB; |
44 | using namespace Opie::DB::Private; | 44 | using namespace Opie::DB::Internal; |
45 | 45 | ||
46 | namespace { | 46 | namespace { |
47 | struct Query { | 47 | struct Query { |
48 | OSQLError::ValueList errors; | 48 | OSQLError::ValueList errors; |
49 | OSQLResultItem::ValueList items; | 49 | OSQLResultItem::ValueList items; |
50 | OSQLiteDriver *driver; | 50 | OSQLiteDriver *driver; |
51 | }; | 51 | }; |
52 | } | 52 | } |
53 | 53 | ||
54 | 54 | ||
55 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) | 55 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) |
56 | : OSQLDriver( lib ) | 56 | : OSQLDriver( lib ) |
57 | { | 57 | { |
58 | m_sqlite = 0l; | 58 | m_sqlite = 0l; |
59 | } | 59 | } |
60 | 60 | ||
61 | 61 | ||
62 | OSQLiteDriver::~OSQLiteDriver() { | 62 | OSQLiteDriver::~OSQLiteDriver() { |
63 | close(); | 63 | close(); |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | QString OSQLiteDriver::id()const { | 67 | QString OSQLiteDriver::id()const { |
68 | return QString::fromLatin1("SQLite"); | 68 | return QString::fromLatin1("SQLite"); |
69 | } | 69 | } |
70 | 70 | ||
71 | void OSQLiteDriver::setUserName( const QString& ) {} | 71 | void OSQLiteDriver::setUserName( const QString& ) {} |
72 | 72 | ||
73 | 73 | ||
74 | void OSQLiteDriver::setPassword( const QString& ) {} | 74 | void OSQLiteDriver::setPassword( const QString& ) {} |
75 | 75 | ||
76 | 76 | ||
77 | void OSQLiteDriver::setUrl( const QString& url ) { | 77 | void OSQLiteDriver::setUrl( const QString& url ) { |
78 | m_url = url; | 78 | m_url = url; |
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | void OSQLiteDriver::setOptions( const QStringList& ) { | 82 | void OSQLiteDriver::setOptions( const QStringList& ) { |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | /* | 86 | /* |
87 | * try to open a db specified via setUrl | 87 | * try to open a db specified via setUrl |
88 | * and options | 88 | * and options |
89 | */ | 89 | */ |
90 | bool OSQLiteDriver::open() { | 90 | bool OSQLiteDriver::open() { |
91 | char *error; | 91 | char *error; |
92 | qDebug("OSQLiteDriver::open: about to open"); | 92 | qDebug("OSQLiteDriver::open: about to open"); |
93 | m_sqlite = sqlite_open(m_url.local8Bit(), | 93 | m_sqlite = sqlite_open(m_url.local8Bit(), |
94 | 0, | 94 | 0, |
95 | &error ); | 95 | &error ); |
96 | 96 | ||
97 | /* failed to open */ | 97 | /* failed to open */ |
98 | if (m_sqlite == 0l ) { | 98 | if (m_sqlite == 0l ) { |
99 | // FIXME set the last error | 99 | // FIXME set the last error |
100 | qWarning("OSQLiteDriver::open: %s", error ); | 100 | qWarning("OSQLiteDriver::open: %s", error ); |
101 | free( error ); | 101 | free( error ); |
102 | return false; | 102 | return false; |
103 | } | 103 | } |
104 | return true; | 104 | return true; |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | /* close the db | 108 | /* close the db |
109 | * sqlite closes them without | 109 | * sqlite closes them without |
110 | * telling failure or success | 110 | * telling failure or success |
111 | */ | 111 | */ |
112 | bool OSQLiteDriver::close() { | 112 | bool OSQLiteDriver::close() { |
113 | if (m_sqlite ) | 113 | if (m_sqlite ) |
114 | sqlite_close( m_sqlite ), m_sqlite=0l; | 114 | sqlite_close( m_sqlite ), m_sqlite=0l; |
115 | 115 | ||
116 | return true; | 116 | return true; |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | /* Query */ | 120 | /* Query */ |
121 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 121 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
122 | if ( !m_sqlite ) { | 122 | if ( !m_sqlite ) { |
123 | // FIXME set error code | 123 | // FIXME set error code |
124 | OSQLResult result( OSQLResult::Failure ); | 124 | OSQLResult result( OSQLResult::Failure ); |
125 | return result; | 125 | return result; |
126 | } | 126 | } |
127 | Query query; | 127 | Query query; |
128 | query.driver = this; | 128 | query.driver = this; |
129 | char *err; | 129 | char *err; |
130 | /* SQLITE_OK 0 if return code > 0 == failure */ | 130 | /* SQLITE_OK 0 if return code > 0 == failure */ |
131 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { | 131 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { |
132 | qWarning("OSQLiteDriver::query: Error while executing"); | 132 | qWarning("OSQLiteDriver::query: Error while executing"); |
133 | free(err ); | 133 | free(err ); |
134 | // FixMe Errors | 134 | // FixMe Errors |
135 | } | 135 | } |
136 | 136 | ||
137 | OSQLResult result(OSQLResult::Success, | 137 | OSQLResult result(OSQLResult::Success, |
138 | query.items, | 138 | query.items, |
139 | query.errors ); | 139 | query.errors ); |
140 | return result; | 140 | return result; |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 144 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
145 | 145 | ||
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
149 | OSQLError OSQLiteDriver::lastError() { | 149 | OSQLError OSQLiteDriver::lastError() { |
150 | OSQLError error; | 150 | OSQLError error; |
151 | return error; | 151 | return error; |
152 | }; | 152 | }; |
153 | 153 | ||
154 | 154 | ||
155 | /* handle a callback add the row to the global | 155 | /* handle a callback add the row to the global |
156 | * OSQLResultItem | 156 | * OSQLResultItem |
157 | */ | 157 | */ |
158 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 158 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
159 | return 0; | 159 | return 0; |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | /* callback_handler add the values to the list*/ | 163 | /* callback_handler add the values to the list*/ |
164 | int OSQLiteDriver::call_back( void* voi, int argc, | 164 | int OSQLiteDriver::call_back( void* voi, int argc, |
165 | char** argv, char** columns) { | 165 | char** argv, char** columns) { |
166 | Query* qu = (Query*)voi; | 166 | Query* qu = (Query*)voi; |
167 | 167 | ||
168 | //copy them over to a OSQLResultItem | 168 | //copy them over to a OSQLResultItem |
169 | QMap<QString, QString> tableString; | 169 | QMap<QString, QString> tableString; |
170 | QMap<int, QString> tableInt; | 170 | QMap<int, QString> tableInt; |
171 | for (int i = 0; i < argc; i++ ) { | 171 | for (int i = 0; i < argc; i++ ) { |
172 | 172 | ||
diff --git a/libopie2/opiedb/osqlitedriver.h b/libopie2/opiedb/osqlitedriver.h index 3e1325b..9064e52 100644 --- a/libopie2/opiedb/osqlitedriver.h +++ b/libopie2/opiedb/osqlitedriver.h | |||
@@ -1,42 +1,42 @@ | |||
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 | 5 | ||
6 | #include "osqldriver.h" | 6 | #include "osqldriver.h" |
7 | #include "osqlerror.h" | 7 | #include "osqlerror.h" |
8 | #include "osqlresult.h" | 8 | #include "osqlresult.h" |
9 | 9 | ||
10 | namespace Opie { | 10 | namespace Opie { |
11 | namespace DB { | 11 | namespace DB { |
12 | namespace Private { | 12 | namespace Internal { |
13 | 13 | ||
14 | class OSQLiteDriver : public OSQLDriver { | 14 | class OSQLiteDriver : public OSQLDriver { |
15 | Q_OBJECT | 15 | Q_OBJECT |
16 | public: | 16 | public: |
17 | OSQLiteDriver( QLibrary *lib = 0l ); | 17 | OSQLiteDriver( QLibrary *lib = 0l ); |
18 | ~OSQLiteDriver(); | 18 | ~OSQLiteDriver(); |
19 | QString id()const; | 19 | QString id()const; |
20 | void setUserName( const QString& ); | 20 | void setUserName( const QString& ); |
21 | void setPassword( const QString& ); | 21 | void setPassword( const QString& ); |
22 | void setUrl( const QString& url ); | 22 | void setUrl( const QString& url ); |
23 | void setOptions( const QStringList& ); | 23 | void setOptions( const QStringList& ); |
24 | bool open(); | 24 | bool open(); |
25 | bool close(); | 25 | bool close(); |
26 | OSQLError lastError(); | 26 | OSQLError lastError(); |
27 | OSQLResult query( OSQLQuery* ); | 27 | OSQLResult query( OSQLQuery* ); |
28 | OSQLTable::ValueList tables()const; | 28 | OSQLTable::ValueList tables()const; |
29 | private: | 29 | private: |
30 | OSQLError m_lastE; | 30 | OSQLError m_lastE; |
31 | OSQLResult m_result; | 31 | OSQLResult m_result; |
32 | OSQLResultItem m_items; | 32 | OSQLResultItem m_items; |
33 | int handleCallBack( int, char**, char** ); | 33 | int handleCallBack( int, char**, char** ); |
34 | static int call_back( void*, int, char**, char** ); | 34 | static int call_back( void*, int, char**, char** ); |
35 | QString m_url; | 35 | QString m_url; |
36 | sqlite *m_sqlite; | 36 | sqlite *m_sqlite; |
37 | }; | 37 | }; |
38 | } | 38 | } |
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | #endif | 42 | #endif |
diff --git a/libopie2/opiedb/osqlmanager.cpp b/libopie2/opiedb/osqlmanager.cpp index 990d258..a6498df 100644 --- a/libopie2/opiedb/osqlmanager.cpp +++ b/libopie2/opiedb/osqlmanager.cpp | |||
@@ -1,83 +1,83 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "osqlmanager.h" | 4 | #include "osqlmanager.h" |
5 | #include "osqlbackendmanager.h" | 5 | #include "osqlbackendmanager.h" |
6 | #include "osqlitedriver.h" | 6 | #include "osqlitedriver.h" |
7 | 7 | ||
8 | using namespace Opie::DB; | 8 | using namespace Opie::DB; |
9 | 9 | ||
10 | OSQLManager::OSQLManager() { | 10 | OSQLManager::OSQLManager() { |
11 | } | 11 | } |
12 | OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { | 12 | OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { |
13 | m_list.clear(); | 13 | m_list.clear(); |
14 | QString opie = QString::fromLatin1( getenv("OPIEDIR") ); | 14 | QString opie = QString::fromLatin1( getenv("OPIEDIR") ); |
15 | QString qpe = QString::fromLatin1( getenv("QPEDIR") ); | 15 | QString qpe = QString::fromLatin1( getenv("QPEDIR") ); |
16 | 16 | ||
17 | if ( !m_path.contains(opie) && !opie.isEmpty() ) | 17 | if ( !m_path.contains(opie) && !opie.isEmpty() ) |
18 | m_path << opie; | 18 | m_path << opie; |
19 | if ( !m_path.contains(qpe) && !qpe.isEmpty() ) | 19 | if ( !m_path.contains(qpe) && !qpe.isEmpty() ) |
20 | m_path << qpe; | 20 | m_path << qpe; |
21 | 21 | ||
22 | OSQLBackEndManager mng( m_path ); | 22 | OSQLBackEndManager mng( m_path ); |
23 | m_list = mng.scan(); | 23 | m_list = mng.scan(); |
24 | m_list += builtIn(); | 24 | m_list += builtIn(); |
25 | 25 | ||
26 | return m_list; | 26 | return m_list; |
27 | } | 27 | } |
28 | /* | 28 | /* |
29 | * loading dso's is currently not enabled due problems with QLibrary | 29 | * loading dso's is currently not enabled due problems with QLibrary |
30 | * beeing in libqpe and not libqte | 30 | * beeing in libqpe and not libqte |
31 | */ | 31 | */ |
32 | OSQLDriver* OSQLManager::load( const QString& name ) { | 32 | OSQLDriver* OSQLManager::load( const QString& name ) { |
33 | OSQLDriver* driver = 0l; | 33 | OSQLDriver* driver = 0l; |
34 | 34 | ||
35 | if ( name == "SQLite" ) { | 35 | if ( name == "SQLite" ) { |
36 | driver = new Opie::DB::Private::OSQLiteDriver; | 36 | driver = new Opie::DB::Internal::OSQLiteDriver; |
37 | } | 37 | } |
38 | return driver; | 38 | return driver; |
39 | } | 39 | } |
40 | /* | 40 | /* |
41 | * same as above | 41 | * same as above |
42 | */ | 42 | */ |
43 | OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { | 43 | OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { |
44 | OSQLDriver *driver = 0l; | 44 | OSQLDriver *driver = 0l; |
45 | if ( end.library() == "builtin" && | 45 | if ( end.library() == "builtin" && |
46 | end.name() == "SQLite" ) | 46 | end.name() == "SQLite" ) |
47 | driver = new Opie::DB::Private::OSQLiteDriver; | 47 | driver = new Opie::DB::Internal::OSQLiteDriver; |
48 | 48 | ||
49 | return driver; | 49 | return driver; |
50 | } | 50 | } |
51 | /* | 51 | /* |
52 | * let's find the a default with the highes preference | 52 | * let's find the a default with the highes preference |
53 | */ | 53 | */ |
54 | OSQLDriver* OSQLManager::standard() { | 54 | OSQLDriver* OSQLManager::standard() { |
55 | OSQLDriver* driver =0l; | 55 | OSQLDriver* driver =0l; |
56 | if ( m_list.isEmpty() ) queryBackEnd(); | 56 | if ( m_list.isEmpty() ) queryBackEnd(); |
57 | OSQLBackEnd::ValueList::Iterator it; | 57 | OSQLBackEnd::ValueList::Iterator it; |
58 | OSQLBackEnd back; | 58 | OSQLBackEnd back; |
59 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 59 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
60 | if ( (*it).isDefault() && | 60 | if ( (*it).isDefault() && |
61 | back.preference() < (*it).preference() ) { | 61 | back.preference() < (*it).preference() ) { |
62 | back = (*it); | 62 | back = (*it); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | driver = load( back ); | 65 | driver = load( back ); |
66 | return driver; | 66 | return driver; |
67 | } | 67 | } |
68 | void OSQLManager::registerPath( const QString& path ) { | 68 | void OSQLManager::registerPath( const QString& path ) { |
69 | m_path << path; | 69 | m_path << path; |
70 | } | 70 | } |
71 | bool OSQLManager::unregisterPath( const QString& path ) { | 71 | bool OSQLManager::unregisterPath( const QString& path ) { |
72 | m_path.remove( path ); | 72 | m_path.remove( path ); |
73 | return true; | 73 | return true; |
74 | } | 74 | } |
75 | OSQLBackEnd::ValueList OSQLManager::builtIn()const { | 75 | OSQLBackEnd::ValueList OSQLManager::builtIn()const { |
76 | OSQLBackEnd::ValueList list; | 76 | OSQLBackEnd::ValueList list; |
77 | // create the OSQLiteBackend | 77 | // create the OSQLiteBackend |
78 | OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" ); | 78 | OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" ); |
79 | back.setDefault( true ); | 79 | back.setDefault( true ); |
80 | back.setPreference( 50 ); | 80 | back.setPreference( 50 ); |
81 | list.append( back ); | 81 | list.append( back ); |
82 | return list; | 82 | return list; |
83 | } | 83 | } |