-rw-r--r-- | libopie2/opiedb/osqlbackendmanager.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiedb/osqlmanager.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlresult.cpp | 1 |
4 files changed, 0 insertions, 5 deletions
diff --git a/libopie2/opiedb/osqlbackendmanager.cpp b/libopie2/opiedb/osqlbackendmanager.cpp index 0f261b9..95ed77b 100644 --- a/libopie2/opiedb/osqlbackendmanager.cpp +++ b/libopie2/opiedb/osqlbackendmanager.cpp | |||
@@ -1,99 +1,98 @@ | |||
1 | #include <qdir.h> | 1 | #include <qdir.h> |
2 | #include <qfile.h> | ||
3 | #include <qmap.h> | 2 | #include <qmap.h> |
4 | 3 | ||
5 | #include "osqlbackendmanager.h" | 4 | #include "osqlbackendmanager.h" |
6 | 5 | ||
7 | namespace { | 6 | namespace { |
8 | class Config { | 7 | class Config { |
9 | typedef QMap<QString, QString> List; | 8 | typedef QMap<QString, QString> List; |
10 | public: | 9 | public: |
11 | Config( const QString& fileName ); | 10 | Config( const QString& fileName ); |
12 | /** | 11 | /** |
13 | * Quite simple layout in nature | 12 | * Quite simple layout in nature |
14 | * BeginFile | 13 | * BeginFile |
15 | * Key = Value | 14 | * Key = Value |
16 | */ | 15 | */ |
17 | bool load(); | 16 | bool load(); |
18 | QString value( const QString& key ); | 17 | QString value( const QString& key ); |
19 | private: | 18 | private: |
20 | List m_list; | 19 | List m_list; |
21 | QString m_fileName; | 20 | QString m_fileName; |
22 | }; | 21 | }; |
23 | Config::Config( const QString& fileName ) | 22 | Config::Config( const QString& fileName ) |
24 | : m_fileName( fileName ) { | 23 | : m_fileName( fileName ) { |
25 | } | 24 | } |
26 | 25 | ||
27 | bool Config::load() { | 26 | bool Config::load() { |
28 | if (!QFile::exists( m_fileName ) ) | 27 | if (!QFile::exists( m_fileName ) ) |
29 | return false; | 28 | return false; |
30 | QFile file( m_fileName ); | 29 | QFile file( m_fileName ); |
31 | if (!file.open(IO_ReadOnly ) ) | 30 | if (!file.open(IO_ReadOnly ) ) |
32 | return false; | 31 | return false; |
33 | QStringList list = QStringList::split( '\n', file.readAll() ); | 32 | QStringList list = QStringList::split( '\n', file.readAll() ); |
34 | QStringList::Iterator it; | 33 | QStringList::Iterator it; |
35 | QString line; | 34 | QString line; |
36 | for (it = list.begin(); it != list.end(); ++it ) { | 35 | for (it = list.begin(); it != list.end(); ++it ) { |
37 | line = (*it).stripWhiteSpace(); | 36 | line = (*it).stripWhiteSpace(); |
38 | qWarning("Anonymous::Config:" + line ); | 37 | qWarning("Anonymous::Config:" + line ); |
39 | QStringList test = QStringList::split(' ', line ); | 38 | QStringList test = QStringList::split(' ', line ); |
40 | m_list.insert( test[0], test[2] ); | 39 | m_list.insert( test[0], test[2] ); |
41 | } | 40 | } |
42 | return true; | 41 | return true; |
43 | } | 42 | } |
44 | QString Config::value( const QString& key ) { | 43 | QString Config::value( const QString& key ) { |
45 | return m_list[key]; | 44 | return m_list[key]; |
46 | } | 45 | } |
47 | }; | 46 | }; |
48 | OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) | 47 | OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) |
49 | :m_path( path ) | 48 | :m_path( path ) |
50 | { | 49 | { |
51 | } | 50 | } |
52 | OSQLBackEndManager::~OSQLBackEndManager() { | 51 | OSQLBackEndManager::~OSQLBackEndManager() { |
53 | } | 52 | } |
54 | /** | 53 | /** |
55 | * scan dirs | 54 | * scan dirs |
56 | */ | 55 | */ |
57 | OSQLBackEnd::ValueList OSQLBackEndManager::scan() { | 56 | OSQLBackEnd::ValueList OSQLBackEndManager::scan() { |
58 | OSQLBackEnd::ValueList list; | 57 | OSQLBackEnd::ValueList list; |
59 | if (!m_path.isEmpty() ) { | 58 | if (!m_path.isEmpty() ) { |
60 | QStringList::Iterator it; | 59 | QStringList::Iterator it; |
61 | for ( it = m_path.begin(); it != m_path.end(); ++it ) { | 60 | for ( it = m_path.begin(); it != m_path.end(); ++it ) { |
62 | list += scanDir( (*it) ); | 61 | list += scanDir( (*it) ); |
63 | } | 62 | } |
64 | } | 63 | } |
65 | return list; | 64 | return list; |
66 | } | 65 | } |
67 | /** | 66 | /** |
68 | * scan a specified dir for *.osql | 67 | * scan a specified dir for *.osql |
69 | */ | 68 | */ |
70 | OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { | 69 | OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { |
71 | OSQLBackEnd::ValueList list; | 70 | OSQLBackEnd::ValueList list; |
72 | QDir dir( dirName ); | 71 | QDir dir( dirName ); |
73 | if (dir.exists() ) { | 72 | if (dir.exists() ) { |
74 | QStringList files = dir.entryList( "*.osql" ); | 73 | QStringList files = dir.entryList( "*.osql" ); |
75 | QStringList::Iterator it; | 74 | QStringList::Iterator it; |
76 | for ( it = files.begin(); it != files.end(); ++it ) { | 75 | for ( it = files.begin(); it != files.end(); ++it ) { |
77 | list.append( file2backend( (*it) ) ); | 76 | list.append( file2backend( (*it) ) ); |
78 | } | 77 | } |
79 | } | 78 | } |
80 | return list; | 79 | return list; |
81 | } | 80 | } |
82 | 81 | ||
83 | /** | 82 | /** |
84 | * read a config file and convert it to a OSQLBackEnd | 83 | * read a config file and convert it to a OSQLBackEnd |
85 | */ | 84 | */ |
86 | OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { | 85 | OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { |
87 | OSQLBackEnd end; | 86 | OSQLBackEnd end; |
88 | qWarning("fileName: " + file ); | 87 | qWarning("fileName: " + file ); |
89 | Config cfg( file ); | 88 | Config cfg( file ); |
90 | if (cfg.load() ) { | 89 | if (cfg.load() ) { |
91 | end.setName( cfg.value( "Name") ); | 90 | end.setName( cfg.value( "Name") ); |
92 | end.setVendor( cfg.value("Vendor") ); | 91 | end.setVendor( cfg.value("Vendor") ); |
93 | end.setLicense( cfg.value("License") ); | 92 | end.setLicense( cfg.value("License") ); |
94 | end.setLibrary( cfg.value("Library").local8Bit() ); | 93 | end.setLibrary( cfg.value("Library").local8Bit() ); |
95 | end.setDefault( cfg.value("Default").toInt() ); | 94 | end.setDefault( cfg.value("Default").toInt() ); |
96 | end.setPreference( cfg.value("Preference").toInt() ); | 95 | end.setPreference( cfg.value("Preference").toInt() ); |
97 | } | 96 | } |
98 | return end; | 97 | return end; |
99 | } | 98 | } |
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index b857534..6141504 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -1,189 +1,188 @@ | |||
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 "osqlresult.h" | ||
32 | #include "osqlquery.h" | 31 | #include "osqlquery.h" |
33 | #include "osqlitedriver.h" | 32 | #include "osqlitedriver.h" |
34 | 33 | ||
35 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
36 | 35 | ||
37 | #include <stdlib.h> | 36 | #include <stdlib.h> |
38 | 37 | ||
39 | // fromLocal8Bit() does not work as expected. Thus it | 38 | // fromLocal8Bit() does not work as expected. Thus it |
40 | // is replaced by fromLatin1() (eilers) | 39 | // is replaced by fromLatin1() (eilers) |
41 | #define __BUGGY_LOCAL8BIT_ | 40 | #define __BUGGY_LOCAL8BIT_ |
42 | 41 | ||
43 | 42 | ||
44 | namespace { | 43 | namespace { |
45 | struct Query { | 44 | struct Query { |
46 | OSQLError::ValueList errors; | 45 | OSQLError::ValueList errors; |
47 | OSQLResultItem::ValueList items; | 46 | OSQLResultItem::ValueList items; |
48 | OSQLiteDriver *driver; | 47 | OSQLiteDriver *driver; |
49 | }; | 48 | }; |
50 | } | 49 | } |
51 | 50 | ||
52 | 51 | ||
53 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) | 52 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) |
54 | : OSQLDriver( lib ) | 53 | : OSQLDriver( lib ) |
55 | { | 54 | { |
56 | m_sqlite = 0l; | 55 | m_sqlite = 0l; |
57 | } | 56 | } |
58 | 57 | ||
59 | 58 | ||
60 | OSQLiteDriver::~OSQLiteDriver() { | 59 | OSQLiteDriver::~OSQLiteDriver() { |
61 | close(); | 60 | close(); |
62 | } | 61 | } |
63 | 62 | ||
64 | 63 | ||
65 | QString OSQLiteDriver::id()const { | 64 | QString OSQLiteDriver::id()const { |
66 | return QString::fromLatin1("SQLite"); | 65 | return QString::fromLatin1("SQLite"); |
67 | } | 66 | } |
68 | 67 | ||
69 | void OSQLiteDriver::setUserName( const QString& ) {} | 68 | void OSQLiteDriver::setUserName( const QString& ) {} |
70 | 69 | ||
71 | 70 | ||
72 | void OSQLiteDriver::setPassword( const QString& ) {} | 71 | void OSQLiteDriver::setPassword( const QString& ) {} |
73 | 72 | ||
74 | 73 | ||
75 | void OSQLiteDriver::setUrl( const QString& url ) { | 74 | void OSQLiteDriver::setUrl( const QString& url ) { |
76 | m_url = url; | 75 | m_url = url; |
77 | } | 76 | } |
78 | 77 | ||
79 | 78 | ||
80 | void OSQLiteDriver::setOptions( const QStringList& ) { | 79 | void OSQLiteDriver::setOptions( const QStringList& ) { |
81 | } | 80 | } |
82 | 81 | ||
83 | 82 | ||
84 | /* | 83 | /* |
85 | * try to open a db specified via setUrl | 84 | * try to open a db specified via setUrl |
86 | * and options | 85 | * and options |
87 | */ | 86 | */ |
88 | bool OSQLiteDriver::open() { | 87 | bool OSQLiteDriver::open() { |
89 | char *error; | 88 | char *error; |
90 | odebug << "OSQLiteDriver::open: about to open" << oendl; | 89 | odebug << "OSQLiteDriver::open: about to open" << oendl; |
91 | m_sqlite = sqlite_open(m_url.local8Bit(), | 90 | m_sqlite = sqlite_open(m_url.local8Bit(), |
92 | 0, | 91 | 0, |
93 | &error ); | 92 | &error ); |
94 | 93 | ||
95 | /* failed to open */ | 94 | /* failed to open */ |
96 | if (m_sqlite == 0l ) { | 95 | if (m_sqlite == 0l ) { |
97 | // FIXME set the last error | 96 | // FIXME set the last error |
98 | owarn << "OSQLiteDriver::open: " << error << oendl; | 97 | owarn << "OSQLiteDriver::open: " << error << oendl; |
99 | free( error ); | 98 | free( error ); |
100 | return false; | 99 | return false; |
101 | } | 100 | } |
102 | return true; | 101 | return true; |
103 | } | 102 | } |
104 | 103 | ||
105 | 104 | ||
106 | /* close the db | 105 | /* close the db |
107 | * sqlite closes them without | 106 | * sqlite closes them without |
108 | * telling failure or success | 107 | * telling failure or success |
109 | */ | 108 | */ |
110 | bool OSQLiteDriver::close() { | 109 | bool OSQLiteDriver::close() { |
111 | if (m_sqlite ) | 110 | if (m_sqlite ) |
112 | sqlite_close( m_sqlite ), m_sqlite=0l; | 111 | sqlite_close( m_sqlite ), m_sqlite=0l; |
113 | 112 | ||
114 | return true; | 113 | return true; |
115 | } | 114 | } |
116 | 115 | ||
117 | 116 | ||
118 | /* Query */ | 117 | /* Query */ |
119 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 118 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
120 | if ( !m_sqlite ) { | 119 | if ( !m_sqlite ) { |
121 | // FIXME set error code | 120 | // FIXME set error code |
122 | OSQLResult result( OSQLResult::Failure ); | 121 | OSQLResult result( OSQLResult::Failure ); |
123 | return result; | 122 | return result; |
124 | } | 123 | } |
125 | Query query; | 124 | Query query; |
126 | query.driver = this; | 125 | query.driver = this; |
127 | char *err; | 126 | char *err; |
128 | /* SQLITE_OK 0 if return code > 0 == failure */ | 127 | /* SQLITE_OK 0 if return code > 0 == failure */ |
129 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { | 128 | if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { |
130 | owarn << "OSQLiteDriver::query: Error while executing" << oendl; | 129 | owarn << "OSQLiteDriver::query: Error while executing" << oendl; |
131 | free(err ); | 130 | free(err ); |
132 | // FixMe Errors | 131 | // FixMe Errors |
133 | } | 132 | } |
134 | 133 | ||
135 | OSQLResult result(OSQLResult::Success, | 134 | OSQLResult result(OSQLResult::Success, |
136 | query.items, | 135 | query.items, |
137 | query.errors ); | 136 | query.errors ); |
138 | return result; | 137 | return result; |
139 | } | 138 | } |
140 | 139 | ||
141 | 140 | ||
142 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 141 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
143 | 142 | ||
144 | } | 143 | } |
145 | 144 | ||
146 | 145 | ||
147 | OSQLError OSQLiteDriver::lastError() { | 146 | OSQLError OSQLiteDriver::lastError() { |
148 | OSQLError error; | 147 | OSQLError error; |
149 | return error; | 148 | return error; |
150 | }; | 149 | }; |
151 | 150 | ||
152 | 151 | ||
153 | /* handle a callback add the row to the global | 152 | /* handle a callback add the row to the global |
154 | * OSQLResultItem | 153 | * OSQLResultItem |
155 | */ | 154 | */ |
156 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 155 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
157 | return 0; | 156 | return 0; |
158 | } | 157 | } |
159 | 158 | ||
160 | 159 | ||
161 | /* callback_handler add the values to the list*/ | 160 | /* callback_handler add the values to the list*/ |
162 | int OSQLiteDriver::call_back( void* voi, int argc, | 161 | int OSQLiteDriver::call_back( void* voi, int argc, |
163 | char** argv, char** columns) { | 162 | char** argv, char** columns) { |
164 | Query* qu = (Query*)voi; | 163 | Query* qu = (Query*)voi; |
165 | 164 | ||
166 | //copy them over to a OSQLResultItem | 165 | //copy them over to a OSQLResultItem |
167 | QMap<QString, QString> tableString; | 166 | QMap<QString, QString> tableString; |
168 | QMap<int, QString> tableInt; | 167 | QMap<int, QString> tableInt; |
169 | for (int i = 0; i < argc; i++ ) { | 168 | for (int i = 0; i < argc; i++ ) { |
170 | 169 | ||
171 | #ifdef __BUGGY_LOCAL8BIT_ | 170 | #ifdef __BUGGY_LOCAL8BIT_ |
172 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); | 171 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); |
173 | tableString.insert( QString::fromLatin1( columns[i] ), | 172 | tableString.insert( QString::fromLatin1( columns[i] ), |
174 | QString::fromLatin1( argv[i] ) ); | 173 | QString::fromLatin1( argv[i] ) ); |
175 | #else | 174 | #else |
176 | tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); | 175 | tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); |
177 | tableString.insert( QString::fromLocal8Bit( columns[i] ), | 176 | tableString.insert( QString::fromLocal8Bit( columns[i] ), |
178 | QString::fromLocal8Bit( argv[i] ) ); | 177 | QString::fromLocal8Bit( argv[i] ) ); |
179 | #endif | 178 | #endif |
180 | } | 179 | } |
181 | OSQLResultItem item( tableString, tableInt ); | 180 | OSQLResultItem item( tableString, tableInt ); |
182 | qu->items.append( item ); | 181 | qu->items.append( item ); |
183 | 182 | ||
184 | return ((Query*)voi)->driver->handleCallBack( argc, | 183 | return ((Query*)voi)->driver->handleCallBack( argc, |
185 | argv, | 184 | argv, |
186 | columns ); | 185 | columns ); |
187 | 186 | ||
188 | 187 | ||
189 | } | 188 | } |
diff --git a/libopie2/opiedb/osqlmanager.cpp b/libopie2/opiedb/osqlmanager.cpp index b0fea04..766ebe1 100644 --- a/libopie2/opiedb/osqlmanager.cpp +++ b/libopie2/opiedb/osqlmanager.cpp | |||
@@ -1,83 +1,81 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include "osqlbackend.h" | ||
5 | #include "osqldriver.h" | ||
6 | #include "osqlmanager.h" | 4 | #include "osqlmanager.h" |
7 | #include "osqlbackendmanager.h" | 5 | #include "osqlbackendmanager.h" |
8 | #include "osqlitedriver.h" | 6 | #include "osqlitedriver.h" |
9 | 7 | ||
10 | OSQLManager::OSQLManager() { | 8 | OSQLManager::OSQLManager() { |
11 | } | 9 | } |
12 | OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { | 10 | OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { |
13 | m_list.clear(); | 11 | m_list.clear(); |
14 | QString opie = QString::fromLatin1( getenv("OPIEDIR") ); | 12 | QString opie = QString::fromLatin1( getenv("OPIEDIR") ); |
15 | QString qpe = QString::fromLatin1( getenv("QPEDIR") ); | 13 | QString qpe = QString::fromLatin1( getenv("QPEDIR") ); |
16 | 14 | ||
17 | if ( !m_path.contains(opie) && !opie.isEmpty() ) | 15 | if ( !m_path.contains(opie) && !opie.isEmpty() ) |
18 | m_path << opie; | 16 | m_path << opie; |
19 | if ( !m_path.contains(qpe) && !qpe.isEmpty() ) | 17 | if ( !m_path.contains(qpe) && !qpe.isEmpty() ) |
20 | m_path << qpe; | 18 | m_path << qpe; |
21 | 19 | ||
22 | OSQLBackEndManager mng( m_path ); | 20 | OSQLBackEndManager mng( m_path ); |
23 | m_list = mng.scan(); | 21 | m_list = mng.scan(); |
24 | m_list += builtIn(); | 22 | m_list += builtIn(); |
25 | 23 | ||
26 | return m_list; | 24 | return m_list; |
27 | } | 25 | } |
28 | /* | 26 | /* |
29 | * loading dso's is currently not enabled due problems with QLibrary | 27 | * loading dso's is currently not enabled due problems with QLibrary |
30 | * beeing in libqpe and not libqte | 28 | * beeing in libqpe and not libqte |
31 | */ | 29 | */ |
32 | OSQLDriver* OSQLManager::load( const QString& name ) { | 30 | OSQLDriver* OSQLManager::load( const QString& name ) { |
33 | OSQLDriver* driver = 0l; | 31 | OSQLDriver* driver = 0l; |
34 | 32 | ||
35 | if ( name == "SQLite" ) { | 33 | if ( name == "SQLite" ) { |
36 | driver = new OSQLiteDriver(); | 34 | driver = new OSQLiteDriver(); |
37 | } | 35 | } |
38 | return driver; | 36 | return driver; |
39 | } | 37 | } |
40 | /* | 38 | /* |
41 | * same as above | 39 | * same as above |
42 | */ | 40 | */ |
43 | OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { | 41 | OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { |
44 | OSQLDriver *driver = 0l; | 42 | OSQLDriver *driver = 0l; |
45 | if ( end.library() == "builtin" && | 43 | if ( end.library() == "builtin" && |
46 | end.name() == "SQLite" ) | 44 | end.name() == "SQLite" ) |
47 | driver = new OSQLiteDriver(); | 45 | driver = new OSQLiteDriver(); |
48 | 46 | ||
49 | return driver; | 47 | return driver; |
50 | } | 48 | } |
51 | /* | 49 | /* |
52 | * let's find the a default with the highes preference | 50 | * let's find the a default with the highes preference |
53 | */ | 51 | */ |
54 | OSQLDriver* OSQLManager::standard() { | 52 | OSQLDriver* OSQLManager::standard() { |
55 | OSQLDriver* driver =0l; | 53 | OSQLDriver* driver =0l; |
56 | if ( m_list.isEmpty() ) queryBackEnd(); | 54 | if ( m_list.isEmpty() ) queryBackEnd(); |
57 | OSQLBackEnd::ValueList::Iterator it; | 55 | OSQLBackEnd::ValueList::Iterator it; |
58 | OSQLBackEnd back; | 56 | OSQLBackEnd back; |
59 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 57 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
60 | if ( (*it).isDefault() && | 58 | if ( (*it).isDefault() && |
61 | back.preference() < (*it).preference() ) { | 59 | back.preference() < (*it).preference() ) { |
62 | back = (*it); | 60 | back = (*it); |
63 | } | 61 | } |
64 | } | 62 | } |
65 | driver = load( back ); | 63 | driver = load( back ); |
66 | return driver; | 64 | return driver; |
67 | } | 65 | } |
68 | void OSQLManager::registerPath( const QString& path ) { | 66 | void OSQLManager::registerPath( const QString& path ) { |
69 | m_path << path; | 67 | m_path << path; |
70 | } | 68 | } |
71 | bool OSQLManager::unregisterPath( const QString& path ) { | 69 | bool OSQLManager::unregisterPath( const QString& path ) { |
72 | m_path.remove( path ); | 70 | m_path.remove( path ); |
73 | return true; | 71 | return true; |
74 | } | 72 | } |
75 | OSQLBackEnd::ValueList OSQLManager::builtIn()const { | 73 | OSQLBackEnd::ValueList OSQLManager::builtIn()const { |
76 | OSQLBackEnd::ValueList list; | 74 | OSQLBackEnd::ValueList list; |
77 | // create the OSQLiteBackend | 75 | // create the OSQLiteBackend |
78 | OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" ); | 76 | OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" ); |
79 | back.setDefault( true ); | 77 | back.setDefault( true ); |
80 | back.setPreference( 50 ); | 78 | back.setPreference( 50 ); |
81 | list.append( back ); | 79 | list.append( back ); |
82 | return list; | 80 | return list; |
83 | } | 81 | } |
diff --git a/libopie2/opiedb/osqlresult.cpp b/libopie2/opiedb/osqlresult.cpp index 490fb45..42da356 100644 --- a/libopie2/opiedb/osqlresult.cpp +++ b/libopie2/opiedb/osqlresult.cpp | |||
@@ -1,127 +1,126 @@ | |||
1 | 1 | ||
2 | #include "osqlquery.h" | ||
3 | #include "osqlresult.h" | 2 | #include "osqlresult.h" |
4 | 3 | ||
5 | OSQLResultItem::OSQLResultItem( const TableString& string, | 4 | OSQLResultItem::OSQLResultItem( const TableString& string, |
6 | const TableInt& Int) | 5 | const TableInt& Int) |
7 | : m_string( string ), m_int( Int ) | 6 | : m_string( string ), m_int( Int ) |
8 | { | 7 | { |
9 | 8 | ||
10 | } | 9 | } |
11 | OSQLResultItem::~OSQLResultItem() { | 10 | OSQLResultItem::~OSQLResultItem() { |
12 | } | 11 | } |
13 | OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { | 12 | OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { |
14 | *this = item; | 13 | *this = item; |
15 | } | 14 | } |
16 | OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { | 15 | OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { |
17 | m_string = other.m_string; | 16 | m_string = other.m_string; |
18 | m_int = other.m_int; | 17 | m_int = other.m_int; |
19 | return *this; | 18 | return *this; |
20 | } | 19 | } |
21 | OSQLResultItem::TableString OSQLResultItem::tableString()const{ | 20 | OSQLResultItem::TableString OSQLResultItem::tableString()const{ |
22 | return m_string; | 21 | return m_string; |
23 | } | 22 | } |
24 | OSQLResultItem::TableInt OSQLResultItem::tableInt()const { | 23 | OSQLResultItem::TableInt OSQLResultItem::tableInt()const { |
25 | return m_int; | 24 | return m_int; |
26 | } | 25 | } |
27 | QString OSQLResultItem::data( const QString& columnName, bool *ok ) { | 26 | QString OSQLResultItem::data( const QString& columnName, bool *ok ) { |
28 | TableString::Iterator it = m_string.find( columnName ); | 27 | TableString::Iterator it = m_string.find( columnName ); |
29 | 28 | ||
30 | /* if found */ | 29 | /* if found */ |
31 | if ( it != m_string.end() ) { | 30 | if ( it != m_string.end() ) { |
32 | if ( ok ) *ok = true; | 31 | if ( ok ) *ok = true; |
33 | return it.data(); | 32 | return it.data(); |
34 | }else{ | 33 | }else{ |
35 | if ( ok ) *ok = false; | 34 | if ( ok ) *ok = false; |
36 | return QString::null; | 35 | return QString::null; |
37 | } | 36 | } |
38 | 37 | ||
39 | } | 38 | } |
40 | QString OSQLResultItem::data( int column, bool *ok ) { | 39 | QString OSQLResultItem::data( int column, bool *ok ) { |
41 | TableInt::Iterator it = m_int.find( column ); | 40 | TableInt::Iterator it = m_int.find( column ); |
42 | 41 | ||
43 | /* if found */ | 42 | /* if found */ |
44 | if ( it != m_int.end() ) { | 43 | if ( it != m_int.end() ) { |
45 | if ( ok ) *ok = true; | 44 | if ( ok ) *ok = true; |
46 | return it.data(); | 45 | return it.data(); |
47 | }else{ | 46 | }else{ |
48 | if ( ok ) *ok = false; | 47 | if ( ok ) *ok = false; |
49 | return QString::null; | 48 | return QString::null; |
50 | } | 49 | } |
51 | } | 50 | } |
52 | /* | 51 | /* |
53 | * DateFormat is 'YYYY-MM-DD' | 52 | * DateFormat is 'YYYY-MM-DD' |
54 | */ | 53 | */ |
55 | QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) { | 54 | QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) { |
56 | QDate date = QDate::currentDate(); | 55 | QDate date = QDate::currentDate(); |
57 | QString str = data( column, ok ); | 56 | QString str = data( column, ok ); |
58 | if (!str.isEmpty() ) { | 57 | if (!str.isEmpty() ) { |
59 | ;// convert | 58 | ;// convert |
60 | } | 59 | } |
61 | return date; | 60 | return date; |
62 | } | 61 | } |
63 | QDate OSQLResultItem::dataToDate( int column, bool *ok ) { | 62 | QDate OSQLResultItem::dataToDate( int column, bool *ok ) { |
64 | QDate date = QDate::currentDate(); | 63 | QDate date = QDate::currentDate(); |
65 | QString str = data( column, ok ); | 64 | QString str = data( column, ok ); |
66 | if (!str.isEmpty() ) { | 65 | if (!str.isEmpty() ) { |
67 | ;// convert | 66 | ;// convert |
68 | } | 67 | } |
69 | return date; | 68 | return date; |
70 | 69 | ||
71 | } | 70 | } |
72 | QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) { | 71 | QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) { |
73 | QDateTime time = QDateTime::currentDateTime(); | 72 | QDateTime time = QDateTime::currentDateTime(); |
74 | return time; | 73 | return time; |
75 | } | 74 | } |
76 | QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) { | 75 | QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) { |
77 | QDateTime time = QDateTime::currentDateTime(); | 76 | QDateTime time = QDateTime::currentDateTime(); |
78 | return time; | 77 | return time; |
79 | } | 78 | } |
80 | 79 | ||
81 | OSQLResult::OSQLResult( enum State state, | 80 | OSQLResult::OSQLResult( enum State state, |
82 | const OSQLResultItem::ValueList& list, | 81 | const OSQLResultItem::ValueList& list, |
83 | const OSQLError::ValueList& error ) | 82 | const OSQLError::ValueList& error ) |
84 | : m_state( state ), m_list( list ), m_error( error ) | 83 | : m_state( state ), m_list( list ), m_error( error ) |
85 | { | 84 | { |
86 | 85 | ||
87 | } | 86 | } |
88 | OSQLResult::~OSQLResult() { | 87 | OSQLResult::~OSQLResult() { |
89 | 88 | ||
90 | } | 89 | } |
91 | OSQLResult::State OSQLResult::state()const { | 90 | OSQLResult::State OSQLResult::state()const { |
92 | return m_state; | 91 | return m_state; |
93 | } | 92 | } |
94 | void OSQLResult::setState( OSQLResult::State state ) { | 93 | void OSQLResult::setState( OSQLResult::State state ) { |
95 | m_state = state; | 94 | m_state = state; |
96 | } | 95 | } |
97 | OSQLError::ValueList OSQLResult::errors()const { | 96 | OSQLError::ValueList OSQLResult::errors()const { |
98 | return m_error; | 97 | return m_error; |
99 | } | 98 | } |
100 | void OSQLResult::setErrors( const OSQLError::ValueList& err ) { | 99 | void OSQLResult::setErrors( const OSQLError::ValueList& err ) { |
101 | m_error = err; | 100 | m_error = err; |
102 | } | 101 | } |
103 | OSQLResultItem::ValueList OSQLResult::results()const { | 102 | OSQLResultItem::ValueList OSQLResult::results()const { |
104 | return m_list; | 103 | return m_list; |
105 | } | 104 | } |
106 | void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) { | 105 | void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) { |
107 | m_list = result; | 106 | m_list = result; |
108 | } | 107 | } |
109 | OSQLResultItem OSQLResult::first() { | 108 | OSQLResultItem OSQLResult::first() { |
110 | it = m_list.begin(); | 109 | it = m_list.begin(); |
111 | return (*it); | 110 | return (*it); |
112 | } | 111 | } |
113 | OSQLResultItem OSQLResult::next(){ | 112 | OSQLResultItem OSQLResult::next(){ |
114 | ++it; | 113 | ++it; |
115 | return (*it); | 114 | return (*it); |
116 | } | 115 | } |
117 | bool OSQLResult::atEnd(){ | 116 | bool OSQLResult::atEnd(){ |
118 | if ( it == m_list.end() ) | 117 | if ( it == m_list.end() ) |
119 | return true; | 118 | return true; |
120 | 119 | ||
121 | return false; | 120 | return false; |
122 | } | 121 | } |
123 | OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const { | 122 | OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const { |
124 | OSQLResultItem::ValueList::ConstIterator it; | 123 | OSQLResultItem::ValueList::ConstIterator it; |
125 | it = m_list.begin(); | 124 | it = m_list.begin(); |
126 | return it; | 125 | return it; |
127 | } | 126 | } |