author | zecke <zecke> | 2004-03-13 19:51:45 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-13 19:51:45 (UTC) |
commit | 6d08277737e22b7a1527124623f3571969073ddf (patch) (unidiff) | |
tree | 4129e674e21df767b31299e873dd44e33a308e1b /libopie2/opiedb | |
parent | 8e28911f7199f4450ac5eef09482069f9b9caea2 (diff) | |
download | opie-6d08277737e22b7a1527124623f3571969073ddf.zip opie-6d08277737e22b7a1527124623f3571969073ddf.tar.gz opie-6d08277737e22b7a1527124623f3571969073ddf.tar.bz2 |
Move XML class to internal PIM
Add namespaces!!!
Opie::Core and Opie::Core::Private
Opie::Net and Opie::Net::Private
Opie::Ui and Opie::Ui::Private
Opie::MM and Opie::MM::Private
Opie::DB and Opie::DB::Private
PIM classes are not yet converted because we will do other work
on it as well
-rw-r--r-- | libopie2/opiedb/TODO | 1 | ||||
-rw-r--r-- | libopie2/opiedb/opiedb.pro | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlbackend.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlbackend.h | 8 | ||||
-rw-r--r-- | libopie2/opiedb/osqlbackendmanager.cpp | 8 | ||||
-rw-r--r-- | libopie2/opiedb/osqlbackendmanager.h | 6 | ||||
-rw-r--r-- | libopie2/opiedb/osqldriver.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqldriver.h | 7 | ||||
-rw-r--r-- | libopie2/opiedb/osqlerror.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlerror.h | 5 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 9 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.h | 8 | ||||
-rw-r--r-- | libopie2/opiedb/osqlmanager.cpp | 6 | ||||
-rw-r--r-- | libopie2/opiedb/osqlmanager.h | 6 | ||||
-rw-r--r-- | libopie2/opiedb/osqlquery.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlquery.h | 8 | ||||
-rw-r--r-- | libopie2/opiedb/osqlresult.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlresult.h | 8 | ||||
-rw-r--r-- | libopie2/opiedb/osqltable.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqltable.h | 7 |
20 files changed, 95 insertions, 6 deletions
diff --git a/libopie2/opiedb/TODO b/libopie2/opiedb/TODO index ca04ac6..8b86187 100644 --- a/libopie2/opiedb/TODO +++ b/libopie2/opiedb/TODO | |||
@@ -1,9 +1,10 @@ | |||
1 | * something like Capabilities of a Driver | 1 | * something like Capabilities of a Driver |
2 | - ROWID | 2 | - ROWID |
3 | - How to declare INTEGER PRIMARY KEY | 3 | - How to declare INTEGER PRIMARY KEY |
4 | - Abstract from implementation of some dbs | 4 | - Abstract from implementation of some dbs |
5 | - provides( Type::What ) | 5 | - provides( Type::What ) |
6 | - emit signals directly on arriving of data | ||
6 | 7 | ||
7 | * OSQLDriver DriverVersion - DatabaseVersion | 8 | * OSQLDriver DriverVersion - DatabaseVersion |
8 | * Better OSQLQueries | 9 | * Better OSQLQueries |
9 | - more than OSQLRawQuery \ No newline at end of file | 10 | - more than OSQLRawQuery \ No newline at end of file |
diff --git a/libopie2/opiedb/opiedb.pro b/libopie2/opiedb/opiedb.pro index c773d6c..147435a 100644 --- a/libopie2/opiedb/opiedb.pro +++ b/libopie2/opiedb/opiedb.pro | |||
@@ -1,36 +1,36 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = osqlbackend.h \ | 4 | HEADERS = osqlbackend.h \ |
5 | osqldriver.h \ | 5 | osqldriver.h \ |
6 | osqlerror.h \ | 6 | osqlerror.h \ |
7 | osqlmanager.h \ | 7 | osqlmanager.h \ |
8 | osqlquery.h \ | 8 | osqlquery.h \ |
9 | osqlresult.h \ | 9 | osqlresult.h \ |
10 | osqltable.h \ | 10 | osqltable.h \ |
11 | osqlbackendmanager.h \ | 11 | osqlbackendmanager.h \ |
12 | osqlitedriver.h | 12 | osqlitedriver.h |
13 | SOURCES = osqlbackend.cpp \ | 13 | SOURCES = osqlbackend.cpp \ |
14 | osqldriver.cpp \ | 14 | osqldriver.cpp \ |
15 | osqlerror.cpp \ | 15 | osqlerror.cpp \ |
16 | osqlmanager.cpp \ | 16 | osqlmanager.cpp \ |
17 | osqlquery.cpp \ | 17 | osqlquery.cpp \ |
18 | osqlresult.cpp \ | 18 | osqlresult.cpp \ |
19 | osqltable.cpp \ | 19 | osqltable.cpp \ |
20 | osqlbackendmanager.cpp \ | 20 | osqlbackendmanager.cpp \ |
21 | osqlitedriver.cpp | 21 | osqlitedriver.cpp |
22 | INTERFACES = | 22 | INTERFACES = |
23 | TARGET = opiedb2 | 23 | TARGET = opiedb2 |
24 | VERSION = 1.8.2 | 24 | VERSION = 1.9.0 |
25 | INCLUDEPATH = $(OPIEDIR)/include | 25 | INCLUDEPATH = $(OPIEDIR)/include |
26 | DEPENDPATH = $(OPIEDIR)/include | 26 | DEPENDPATH = $(OPIEDIR)/include |
27 | LIBS += -lopiecore2 -lqpe -lsqlite | 27 | LIBS += -lopiecore2 -lqpe -lsqlite |
28 | 28 | ||
29 | !contains( platform, x11 ) { | 29 | !contains( platform, x11 ) { |
30 | include ( $(OPIEDIR)/include.pro ) | 30 | include ( $(OPIEDIR)/include.pro ) |
31 | } | 31 | } |
32 | 32 | ||
33 | contains( platform, x11 ) { | 33 | contains( platform, x11 ) { |
34 | LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 34 | LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
35 | } | 35 | } |
36 | 36 | ||
diff --git a/libopie2/opiedb/osqlbackend.cpp b/libopie2/opiedb/osqlbackend.cpp index d6c39a9..6e5159f 100644 --- a/libopie2/opiedb/osqlbackend.cpp +++ b/libopie2/opiedb/osqlbackend.cpp | |||
@@ -1,73 +1,75 @@ | |||
1 | 1 | ||
2 | #include "osqlbackend.h" | 2 | #include "osqlbackend.h" |
3 | 3 | ||
4 | using namespace Opie::DB; | ||
5 | |||
4 | 6 | ||
5 | OSQLBackEnd::OSQLBackEnd( const QString& name, | 7 | OSQLBackEnd::OSQLBackEnd( const QString& name, |
6 | const QString& vendor, | 8 | const QString& vendor, |
7 | const QString& license, | 9 | const QString& license, |
8 | const QCString& lib ) | 10 | const QCString& lib ) |
9 | : m_name( name), m_vendor( vendor), m_license( license ), m_lib( lib ) | 11 | : m_name( name), m_vendor( vendor), m_license( license ), m_lib( lib ) |
10 | { | 12 | { |
11 | m_default = false; | 13 | m_default = false; |
12 | m_pref = -1; | 14 | m_pref = -1; |
13 | } | 15 | } |
14 | OSQLBackEnd::OSQLBackEnd( const OSQLBackEnd& back ) { | 16 | OSQLBackEnd::OSQLBackEnd( const OSQLBackEnd& back ) { |
15 | (*this) = back; | 17 | (*this) = back; |
16 | } | 18 | } |
17 | OSQLBackEnd::~OSQLBackEnd() { | 19 | OSQLBackEnd::~OSQLBackEnd() { |
18 | } | 20 | } |
19 | bool OSQLBackEnd::operator==( const OSQLBackEnd& other ) { | 21 | bool OSQLBackEnd::operator==( const OSQLBackEnd& other ) { |
20 | if ( m_pref != other.m_pref ) return false; | 22 | if ( m_pref != other.m_pref ) return false; |
21 | if ( m_default != other.m_default ) return false; | 23 | if ( m_default != other.m_default ) return false; |
22 | if ( m_name != other.m_name ) return false; | 24 | if ( m_name != other.m_name ) return false; |
23 | if ( m_vendor != other.m_vendor ) return false; | 25 | if ( m_vendor != other.m_vendor ) return false; |
24 | if ( m_license != other.m_license ) return false; | 26 | if ( m_license != other.m_license ) return false; |
25 | if ( m_lib != other.m_lib ) return false; | 27 | if ( m_lib != other.m_lib ) return false; |
26 | 28 | ||
27 | return true; | 29 | return true; |
28 | } | 30 | } |
29 | OSQLBackEnd &OSQLBackEnd::operator=(const OSQLBackEnd& back ) { | 31 | OSQLBackEnd &OSQLBackEnd::operator=(const OSQLBackEnd& back ) { |
30 | m_name = back.m_name; | 32 | m_name = back.m_name; |
31 | m_vendor = back.m_vendor; | 33 | m_vendor = back.m_vendor; |
32 | m_license = back.m_license; | 34 | m_license = back.m_license; |
33 | m_lib = back.m_lib; | 35 | m_lib = back.m_lib; |
34 | m_pref = back.m_pref; | 36 | m_pref = back.m_pref; |
35 | m_default = back.m_default; | 37 | m_default = back.m_default; |
36 | return *this; | 38 | return *this; |
37 | } | 39 | } |
38 | QString OSQLBackEnd::name() const { | 40 | QString OSQLBackEnd::name() const { |
39 | return m_name; | 41 | return m_name; |
40 | } | 42 | } |
41 | QString OSQLBackEnd::vendor() const { | 43 | QString OSQLBackEnd::vendor() const { |
42 | return m_vendor; | 44 | return m_vendor; |
43 | } | 45 | } |
44 | QString OSQLBackEnd::license() const { | 46 | QString OSQLBackEnd::license() const { |
45 | return m_license; | 47 | return m_license; |
46 | } | 48 | } |
47 | QCString OSQLBackEnd::library() const { | 49 | QCString OSQLBackEnd::library() const { |
48 | return m_lib; | 50 | return m_lib; |
49 | } | 51 | } |
50 | bool OSQLBackEnd::isDefault()const { | 52 | bool OSQLBackEnd::isDefault()const { |
51 | return m_default; | 53 | return m_default; |
52 | } | 54 | } |
53 | int OSQLBackEnd::preference()const { | 55 | int OSQLBackEnd::preference()const { |
54 | return m_pref; | 56 | return m_pref; |
55 | } | 57 | } |
56 | void OSQLBackEnd::setName( const QString& name ) { | 58 | void OSQLBackEnd::setName( const QString& name ) { |
57 | m_name = name; | 59 | m_name = name; |
58 | } | 60 | } |
59 | void OSQLBackEnd::setVendor( const QString& vendor ) { | 61 | void OSQLBackEnd::setVendor( const QString& vendor ) { |
60 | m_vendor = vendor; | 62 | m_vendor = vendor; |
61 | } | 63 | } |
62 | void OSQLBackEnd::setLicense( const QString & license ) { | 64 | void OSQLBackEnd::setLicense( const QString & license ) { |
63 | m_license = license; | 65 | m_license = license; |
64 | } | 66 | } |
65 | void OSQLBackEnd::setLibrary( const QCString& lib ) { | 67 | void OSQLBackEnd::setLibrary( const QCString& lib ) { |
66 | m_lib = lib; | 68 | m_lib = lib; |
67 | } | 69 | } |
68 | void OSQLBackEnd::setDefault( bool def) { | 70 | void OSQLBackEnd::setDefault( bool def) { |
69 | m_default = def; | 71 | m_default = def; |
70 | } | 72 | } |
71 | void OSQLBackEnd::setPreference( int pref ) { | 73 | void OSQLBackEnd::setPreference( int pref ) { |
72 | m_pref = pref; | 74 | m_pref = pref; |
73 | } | 75 | } |
diff --git a/libopie2/opiedb/osqlbackend.h b/libopie2/opiedb/osqlbackend.h index ad879a4..28451b6 100644 --- a/libopie2/opiedb/osqlbackend.h +++ b/libopie2/opiedb/osqlbackend.h | |||
@@ -1,75 +1,83 @@ | |||
1 | 1 | ||
2 | #ifndef OSQL_BACKEND_H | 2 | #ifndef OSQL_BACKEND_H |
3 | #define OSQL_BACKEND_H | 3 | #define OSQL_BACKEND_H |
4 | 4 | ||
5 | #include <qcstring.h> | 5 | #include <qcstring.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qvaluelist.h> | 7 | #include <qvaluelist.h> |
8 | 8 | ||
9 | |||
10 | namespace Opie { | ||
11 | namespace DB { | ||
9 | /** | 12 | /** |
10 | * OSQLBackEnd represents an available backend | 13 | * OSQLBackEnd represents an available backend |
11 | * to the Opie Database Service | 14 | * to the Opie Database Service |
12 | * It's used to easily extend OSQL services by | 15 | * It's used to easily extend OSQL services by |
13 | * 3rd party plugins. | 16 | * 3rd party plugins. |
14 | * It's used to show | 17 | * It's used to show |
15 | */ | 18 | */ |
16 | class OSQLBackEnd /*: public QShared */ { | 19 | class OSQLBackEnd /*: public QShared */ { |
17 | public: | 20 | public: |
18 | typedef QValueList<OSQLBackEnd> ValueList; | 21 | typedef QValueList<OSQLBackEnd> ValueList; |
19 | /** | 22 | /** |
20 | * A basic c'tor | 23 | * A basic c'tor |
21 | * @param name the user visible name of the service | 24 | * @param name the user visible name of the service |
22 | * @param vendor the vendor of the service | 25 | * @param vendor the vendor of the service |
23 | * @param license the license of the service | 26 | * @param license the license of the service |
24 | * @param library what is the name of lib if builtin it's builtin | 27 | * @param library what is the name of lib if builtin it's builtin |
25 | */ | 28 | */ |
26 | OSQLBackEnd( const QString& name = QString::null, | 29 | OSQLBackEnd( const QString& name = QString::null, |
27 | const QString& vendor = QString::null, | 30 | const QString& vendor = QString::null, |
28 | const QString& license = QString::null, | 31 | const QString& license = QString::null, |
29 | const QCString& library = QCString() ); | 32 | const QCString& library = QCString() ); |
30 | OSQLBackEnd( const OSQLBackEnd& ); | 33 | OSQLBackEnd( const OSQLBackEnd& ); |
31 | OSQLBackEnd &operator=( const OSQLBackEnd& ); | 34 | OSQLBackEnd &operator=( const OSQLBackEnd& ); |
32 | bool operator==(const OSQLBackEnd& ); | 35 | bool operator==(const OSQLBackEnd& ); |
33 | 36 | ||
34 | ~OSQLBackEnd(); | 37 | ~OSQLBackEnd(); |
35 | 38 | ||
36 | /** @return the name */ | 39 | /** @return the name */ |
37 | QString name()const; | 40 | QString name()const; |
38 | 41 | ||
39 | /** @return the vendor */ | 42 | /** @return the vendor */ |
40 | QString vendor()const; | 43 | QString vendor()const; |
41 | 44 | ||
42 | /** @return the license */ | 45 | /** @return the license */ |
43 | QString license()const; | 46 | QString license()const; |
44 | 47 | ||
45 | /** @return the name of the library */ | 48 | /** @return the name of the library */ |
46 | QCString library() const; | 49 | QCString library() const; |
47 | 50 | ||
48 | bool isDefault()const; | 51 | bool isDefault()const; |
49 | int preference()const; | 52 | int preference()const; |
50 | 53 | ||
51 | /** @param name the name to set */ | 54 | /** @param name the name to set */ |
52 | void setName( const QString& name ); | 55 | void setName( const QString& name ); |
53 | 56 | ||
54 | /** @param vendor the vendor to set */ | 57 | /** @param vendor the vendor to set */ |
55 | void setVendor( const QString& vendor ); | 58 | void setVendor( const QString& vendor ); |
56 | 59 | ||
57 | /** @param license the license applied */ | 60 | /** @param license the license applied */ |
58 | void setLicense( const QString& license ); | 61 | void setLicense( const QString& license ); |
59 | 62 | ||
60 | /** @param the lib to set */ | 63 | /** @param the lib to set */ |
61 | void setLibrary( const QCString& lib ); | 64 | void setLibrary( const QCString& lib ); |
62 | 65 | ||
63 | void setDefault( bool ); | 66 | void setDefault( bool ); |
64 | void setPreference( int ); | 67 | void setPreference( int ); |
65 | 68 | ||
66 | private: | 69 | private: |
67 | QString m_name; | 70 | QString m_name; |
68 | QString m_vendor; | 71 | QString m_vendor; |
69 | QString m_license; | 72 | QString m_license; |
70 | QCString m_lib; | 73 | QCString m_lib; |
71 | bool m_default :1; | 74 | bool m_default :1; |
72 | int m_pref; | 75 | int m_pref; |
76 | class Private; | ||
77 | Private *d; | ||
73 | }; | 78 | }; |
74 | 79 | ||
80 | } | ||
81 | } | ||
82 | |||
75 | #endif | 83 | #endif |
diff --git a/libopie2/opiedb/osqlbackendmanager.cpp b/libopie2/opiedb/osqlbackendmanager.cpp index 95ed77b..fc18e07 100644 --- a/libopie2/opiedb/osqlbackendmanager.cpp +++ b/libopie2/opiedb/osqlbackendmanager.cpp | |||
@@ -1,98 +1,106 @@ | |||
1 | #include <qdir.h> | 1 | #include <qdir.h> |
2 | #include <qmap.h> | 2 | #include <qmap.h> |
3 | 3 | ||
4 | #include "osqlbackendmanager.h" | 4 | #include "osqlbackendmanager.h" |
5 | 5 | ||
6 | /** | ||
7 | * \todo FIXME CONFIG!!! | ||
8 | */ | ||
9 | |||
6 | namespace { | 10 | namespace { |
7 | class Config { | 11 | class Config { |
8 | typedef QMap<QString, QString> List; | 12 | typedef QMap<QString, QString> List; |
9 | public: | 13 | public: |
10 | Config( const QString& fileName ); | 14 | Config( const QString& fileName ); |
11 | /** | 15 | /** |
12 | * Quite simple layout in nature | 16 | * Quite simple layout in nature |
13 | * BeginFile | 17 | * BeginFile |
14 | * Key = Value | 18 | * Key = Value |
15 | */ | 19 | */ |
16 | bool load(); | 20 | bool load(); |
17 | QString value( const QString& key ); | 21 | QString value( const QString& key ); |
18 | private: | 22 | private: |
19 | List m_list; | 23 | List m_list; |
20 | QString m_fileName; | 24 | QString m_fileName; |
21 | }; | 25 | }; |
22 | Config::Config( const QString& fileName ) | 26 | Config::Config( const QString& fileName ) |
23 | : m_fileName( fileName ) { | 27 | : m_fileName( fileName ) { |
24 | } | 28 | } |
25 | 29 | ||
26 | bool Config::load() { | 30 | bool Config::load() { |
27 | if (!QFile::exists( m_fileName ) ) | 31 | if (!QFile::exists( m_fileName ) ) |
28 | return false; | 32 | return false; |
29 | QFile file( m_fileName ); | 33 | QFile file( m_fileName ); |
30 | if (!file.open(IO_ReadOnly ) ) | 34 | if (!file.open(IO_ReadOnly ) ) |
31 | return false; | 35 | return false; |
32 | QStringList list = QStringList::split( '\n', file.readAll() ); | 36 | QStringList list = QStringList::split( '\n', file.readAll() ); |
33 | QStringList::Iterator it; | 37 | QStringList::Iterator it; |
34 | QString line; | 38 | QString line; |
35 | for (it = list.begin(); it != list.end(); ++it ) { | 39 | for (it = list.begin(); it != list.end(); ++it ) { |
36 | line = (*it).stripWhiteSpace(); | 40 | line = (*it).stripWhiteSpace(); |
37 | qWarning("Anonymous::Config:" + line ); | 41 | qWarning("Anonymous::Config:" + line ); |
38 | QStringList test = QStringList::split(' ', line ); | 42 | QStringList test = QStringList::split(' ', line ); |
39 | m_list.insert( test[0], test[2] ); | 43 | m_list.insert( test[0], test[2] ); |
40 | } | 44 | } |
41 | return true; | 45 | return true; |
42 | } | 46 | } |
43 | QString Config::value( const QString& key ) { | 47 | QString Config::value( const QString& key ) { |
44 | return m_list[key]; | 48 | return m_list[key]; |
45 | } | 49 | } |
46 | }; | 50 | }; |
51 | |||
52 | |||
53 | using namespace Opie::DB; | ||
54 | |||
47 | OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) | 55 | OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) |
48 | :m_path( path ) | 56 | :m_path( path ) |
49 | { | 57 | { |
50 | } | 58 | } |
51 | OSQLBackEndManager::~OSQLBackEndManager() { | 59 | OSQLBackEndManager::~OSQLBackEndManager() { |
52 | } | 60 | } |
53 | /** | 61 | /** |
54 | * scan dirs | 62 | * scan dirs |
55 | */ | 63 | */ |
56 | OSQLBackEnd::ValueList OSQLBackEndManager::scan() { | 64 | OSQLBackEnd::ValueList OSQLBackEndManager::scan() { |
57 | OSQLBackEnd::ValueList list; | 65 | OSQLBackEnd::ValueList list; |
58 | if (!m_path.isEmpty() ) { | 66 | if (!m_path.isEmpty() ) { |
59 | QStringList::Iterator it; | 67 | QStringList::Iterator it; |
60 | for ( it = m_path.begin(); it != m_path.end(); ++it ) { | 68 | for ( it = m_path.begin(); it != m_path.end(); ++it ) { |
61 | list += scanDir( (*it) ); | 69 | list += scanDir( (*it) ); |
62 | } | 70 | } |
63 | } | 71 | } |
64 | return list; | 72 | return list; |
65 | } | 73 | } |
66 | /** | 74 | /** |
67 | * scan a specified dir for *.osql | 75 | * scan a specified dir for *.osql |
68 | */ | 76 | */ |
69 | OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { | 77 | OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { |
70 | OSQLBackEnd::ValueList list; | 78 | OSQLBackEnd::ValueList list; |
71 | QDir dir( dirName ); | 79 | QDir dir( dirName ); |
72 | if (dir.exists() ) { | 80 | if (dir.exists() ) { |
73 | QStringList files = dir.entryList( "*.osql" ); | 81 | QStringList files = dir.entryList( "*.osql" ); |
74 | QStringList::Iterator it; | 82 | QStringList::Iterator it; |
75 | for ( it = files.begin(); it != files.end(); ++it ) { | 83 | for ( it = files.begin(); it != files.end(); ++it ) { |
76 | list.append( file2backend( (*it) ) ); | 84 | list.append( file2backend( (*it) ) ); |
77 | } | 85 | } |
78 | } | 86 | } |
79 | return list; | 87 | return list; |
80 | } | 88 | } |
81 | 89 | ||
82 | /** | 90 | /** |
83 | * read a config file and convert it to a OSQLBackEnd | 91 | * read a config file and convert it to a OSQLBackEnd |
84 | */ | 92 | */ |
85 | OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { | 93 | OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { |
86 | OSQLBackEnd end; | 94 | OSQLBackEnd end; |
87 | qWarning("fileName: " + file ); | 95 | qWarning("fileName: " + file ); |
88 | Config cfg( file ); | 96 | Config cfg( file ); |
89 | if (cfg.load() ) { | 97 | if (cfg.load() ) { |
90 | end.setName( cfg.value( "Name") ); | 98 | end.setName( cfg.value( "Name") ); |
91 | end.setVendor( cfg.value("Vendor") ); | 99 | end.setVendor( cfg.value("Vendor") ); |
92 | end.setLicense( cfg.value("License") ); | 100 | end.setLicense( cfg.value("License") ); |
93 | end.setLibrary( cfg.value("Library").local8Bit() ); | 101 | end.setLibrary( cfg.value("Library").local8Bit() ); |
94 | end.setDefault( cfg.value("Default").toInt() ); | 102 | end.setDefault( cfg.value("Default").toInt() ); |
95 | end.setPreference( cfg.value("Preference").toInt() ); | 103 | end.setPreference( cfg.value("Preference").toInt() ); |
96 | } | 104 | } |
97 | return end; | 105 | return end; |
98 | } | 106 | } |
diff --git a/libopie2/opiedb/osqlbackendmanager.h b/libopie2/opiedb/osqlbackendmanager.h index bc357a9..00e81fc 100644 --- a/libopie2/opiedb/osqlbackendmanager.h +++ b/libopie2/opiedb/osqlbackendmanager.h | |||
@@ -1,20 +1,26 @@ | |||
1 | #ifndef OSQL_BACKEND_MANAGER_H | 1 | #ifndef OSQL_BACKEND_MANAGER_H |
2 | #define OSQL_BACKEND_MANAGER_H | 2 | #define OSQL_BACKEND_MANAGER_H |
3 | 3 | ||
4 | #include <qstringlist.h> | 4 | #include <qstringlist.h> |
5 | 5 | ||
6 | #include "osqlbackend.h" | 6 | #include "osqlbackend.h" |
7 | 7 | ||
8 | namespace Opie { | ||
9 | namespace DB { | ||
10 | |||
8 | class OSQLBackEndManager { | 11 | class OSQLBackEndManager { |
9 | public: | 12 | public: |
10 | OSQLBackEndManager(const QStringList& path ); | 13 | OSQLBackEndManager(const QStringList& path ); |
11 | ~OSQLBackEndManager(); | 14 | ~OSQLBackEndManager(); |
12 | OSQLBackEnd::ValueList scan(); | 15 | OSQLBackEnd::ValueList scan(); |
13 | private: | 16 | private: |
14 | OSQLBackEnd::ValueList scanDir( const QString& dir ); | 17 | OSQLBackEnd::ValueList scanDir( const QString& dir ); |
15 | OSQLBackEnd file2backend( const QString& file ); | 18 | OSQLBackEnd file2backend( const QString& file ); |
16 | class OSQLBackEndManagerPrivate; | 19 | class OSQLBackEndManagerPrivate; |
17 | OSQLBackEndManagerPrivate* d; | 20 | OSQLBackEndManagerPrivate* d; |
18 | QStringList m_path; | 21 | QStringList m_path; |
19 | }; | 22 | }; |
23 | } | ||
24 | } | ||
25 | |||
20 | #endif | 26 | #endif |
diff --git a/libopie2/opiedb/osqldriver.cpp b/libopie2/opiedb/osqldriver.cpp index 258c116..a6dae77 100644 --- a/libopie2/opiedb/osqldriver.cpp +++ b/libopie2/opiedb/osqldriver.cpp | |||
@@ -1,13 +1,15 @@ | |||
1 | #include <qpe/qlibrary.h> | 1 | #include <qpe/qlibrary.h> |
2 | 2 | ||
3 | #include "osqldriver.h" | 3 | #include "osqldriver.h" |
4 | 4 | ||
5 | using namespace Opie::DB; | ||
6 | |||
5 | OSQLDriver::OSQLDriver( QLibrary* lib ) | 7 | OSQLDriver::OSQLDriver( QLibrary* lib ) |
6 | : QObject(), m_lib(lib) { | 8 | : QObject(), m_lib(lib) { |
7 | } | 9 | } |
8 | OSQLDriver::~OSQLDriver() { | 10 | OSQLDriver::~OSQLDriver() { |
9 | delete m_lib; | 11 | delete m_lib; |
10 | } | 12 | } |
11 | bool OSQLDriver::sync() { | 13 | bool OSQLDriver::sync() { |
12 | return true; | 14 | return true; |
13 | } | 15 | } |
diff --git a/libopie2/opiedb/osqldriver.h b/libopie2/opiedb/osqldriver.h index 68d8ee6..492b8dd 100644 --- a/libopie2/opiedb/osqldriver.h +++ b/libopie2/opiedb/osqldriver.h | |||
@@ -1,87 +1,94 @@ | |||
1 | #ifndef OSQL_DRIVER_H | 1 | #ifndef OSQL_DRIVER_H |
2 | #define OSQL_DRIVER_H | 2 | #define OSQL_DRIVER_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | #include "osqltable.h" | 7 | #include "osqltable.h" |
8 | 8 | ||
9 | class QLibrary; | 9 | class QLibrary; |
10 | |||
11 | namespace Opie { | ||
12 | namespace DB { | ||
13 | |||
10 | class OSQLResult; | 14 | class OSQLResult; |
11 | class OSQLQuery; | 15 | class OSQLQuery; |
12 | class OSQLError; | 16 | class OSQLError; |
13 | 17 | ||
14 | /** | 18 | /** |
15 | * A OSQLDriver implements the communication with | 19 | * A OSQLDriver implements the communication with |
16 | * a database. | 20 | * a database. |
17 | * After you queried and loaded a driver you can | 21 | * After you queried and loaded a driver you can |
18 | * set some informations and finally try to open | 22 | * set some informations and finally try to open |
19 | * the database | 23 | * the database |
20 | * | 24 | * |
21 | */ | 25 | */ |
22 | class OSQLDriver : public QObject{ | 26 | class OSQLDriver : public QObject{ |
23 | Q_OBJECT | 27 | Q_OBJECT |
24 | public: | 28 | public: |
25 | enum Capabilities { RowID=0 }; | 29 | enum Capabilities { RowID=0 }; |
26 | /** | 30 | /** |
27 | * OSQLDriver constructor. It takes the QLibrary | 31 | * OSQLDriver constructor. It takes the QLibrary |
28 | * as parent. | 32 | * as parent. |
29 | * | 33 | * |
30 | */ | 34 | */ |
31 | OSQLDriver( QLibrary* lib=0 ); | 35 | OSQLDriver( QLibrary* lib=0 ); |
32 | 36 | ||
33 | virtual ~OSQLDriver(); | 37 | virtual ~OSQLDriver(); |
34 | /** | 38 | /** |
35 | * Id returns the identifier of the OSQLDriver | 39 | * Id returns the identifier of the OSQLDriver |
36 | */ | 40 | */ |
37 | virtual QString id()const = 0; | 41 | virtual QString id()const = 0; |
38 | 42 | ||
39 | /** | 43 | /** |
40 | * set the UserName to the database | 44 | * set the UserName to the database |
41 | */ | 45 | */ |
42 | virtual void setUserName( const QString& ) = 0; | 46 | virtual void setUserName( const QString& ) = 0; |
43 | 47 | ||
44 | /** | 48 | /** |
45 | * set the PassWord to the database | 49 | * set the PassWord to the database |
46 | */ | 50 | */ |
47 | virtual void setPassword( const QString& )= 0; | 51 | virtual void setPassword( const QString& )= 0; |
48 | 52 | ||
49 | /** | 53 | /** |
50 | * set the Url | 54 | * set the Url |
51 | */ | 55 | */ |
52 | virtual void setUrl( const QString& ) = 0; | 56 | virtual void setUrl( const QString& ) = 0; |
53 | 57 | ||
54 | /** | 58 | /** |
55 | * setOptions | 59 | * setOptions |
56 | */ | 60 | */ |
57 | virtual void setOptions( const QStringList& ) = 0; | 61 | virtual void setOptions( const QStringList& ) = 0; |
58 | 62 | ||
59 | /** | 63 | /** |
60 | * tries to open a connection to the database | 64 | * tries to open a connection to the database |
61 | */ | 65 | */ |
62 | virtual bool open() = 0; | 66 | virtual bool open() = 0; |
63 | virtual bool close() = 0; | 67 | virtual bool close() = 0; |
64 | 68 | ||
65 | virtual OSQLError lastError() = 0; | 69 | virtual OSQLError lastError() = 0; |
66 | 70 | ||
67 | /** | 71 | /** |
68 | * Query the Database with a OSQLQuery | 72 | * Query the Database with a OSQLQuery |
69 | * OSQLResult holds the result | 73 | * OSQLResult holds the result |
70 | */ | 74 | */ |
71 | virtual OSQLResult query( OSQLQuery* ) = 0; | 75 | virtual OSQLResult query( OSQLQuery* ) = 0; |
72 | 76 | ||
73 | /** | 77 | /** |
74 | * Get a list of tables | 78 | * Get a list of tables |
75 | */ | 79 | */ |
76 | virtual OSQLTable::ValueList tables() const = 0l; | 80 | virtual OSQLTable::ValueList tables() const = 0l; |
77 | virtual bool sync(); | 81 | virtual bool sync(); |
78 | 82 | ||
79 | 83 | ||
80 | private: | 84 | private: |
81 | QLibrary* m_lib; | 85 | QLibrary* m_lib; |
82 | class OSQLDriverPrivate; | 86 | class OSQLDriverPrivate; |
83 | OSQLDriverPrivate *d; | 87 | OSQLDriverPrivate *d; |
84 | 88 | ||
85 | }; | 89 | }; |
86 | 90 | ||
91 | } | ||
92 | } | ||
93 | |||
87 | #endif | 94 | #endif |
diff --git a/libopie2/opiedb/osqlerror.cpp b/libopie2/opiedb/osqlerror.cpp index 3890a50..165ba65 100644 --- a/libopie2/opiedb/osqlerror.cpp +++ b/libopie2/opiedb/osqlerror.cpp | |||
@@ -1,23 +1,25 @@ | |||
1 | #include "osqlerror.h" | 1 | #include "osqlerror.h" |
2 | 2 | ||
3 | using namespace Opie::DB; | ||
4 | |||
3 | OSQLError::OSQLError( const QString& driverText, | 5 | OSQLError::OSQLError( const QString& driverText, |
4 | const QString& driverDatabaseText, | 6 | const QString& driverDatabaseText, |
5 | int type, int subType ) | 7 | int type, int subType ) |
6 | : m_drvText( driverText ), m_drvDBText( driverDatabaseText ), | 8 | : m_drvText( driverText ), m_drvDBText( driverDatabaseText ), |
7 | m_type( type ), m_number( subType ) | 9 | m_type( type ), m_number( subType ) |
8 | { | 10 | { |
9 | } | 11 | } |
10 | OSQLError::~OSQLError() { | 12 | OSQLError::~OSQLError() { |
11 | } | 13 | } |
12 | QString OSQLError::driverText()const { | 14 | QString OSQLError::driverText()const { |
13 | return m_drvText; | 15 | return m_drvText; |
14 | } | 16 | } |
15 | QString OSQLError::databaseText()const { | 17 | QString OSQLError::databaseText()const { |
16 | return m_drvDBText; | 18 | return m_drvDBText; |
17 | } | 19 | } |
18 | int OSQLError::type()const { | 20 | int OSQLError::type()const { |
19 | return m_type; | 21 | return m_type; |
20 | } | 22 | } |
21 | int OSQLError::subNumber()const { | 23 | int OSQLError::subNumber()const { |
22 | return m_number; | 24 | return m_number; |
23 | } | 25 | } |
diff --git a/libopie2/opiedb/osqlerror.h b/libopie2/opiedb/osqlerror.h index 35a4368..8fa973d 100644 --- a/libopie2/opiedb/osqlerror.h +++ b/libopie2/opiedb/osqlerror.h | |||
@@ -1,59 +1,64 @@ | |||
1 | #ifndef OSQL_ERROR_H | 1 | #ifndef OSQL_ERROR_H |
2 | #define OSQL_ERROR_H | 2 | #define OSQL_ERROR_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | 6 | ||
7 | |||
8 | namespace Opie { | ||
9 | namespace DB { | ||
7 | /** | 10 | /** |
8 | * OSQLError is the base class of all errors | 11 | * OSQLError is the base class of all errors |
9 | */ | 12 | */ |
10 | class OSQLError { | 13 | class OSQLError { |
11 | public: | 14 | public: |
12 | typedef QValueList<OSQLError> ValueList; | 15 | typedef QValueList<OSQLError> ValueList; |
13 | enum Type { None = 0, // NoError | 16 | enum Type { None = 0, // NoError |
14 | Internal, // Internal Error in OSQL | 17 | Internal, // Internal Error in OSQL |
15 | Unknown, // Unknown Error | 18 | Unknown, // Unknown Error |
16 | Transaction, // Transaction Error | 19 | Transaction, // Transaction Error |
17 | Statement, // Wrong Statement | 20 | Statement, // Wrong Statement |
18 | Connection, // Connection Error( lost ) | 21 | Connection, // Connection Error( lost ) |
19 | Driver // Driver Specefic error | 22 | Driver // Driver Specefic error |
20 | }; | 23 | }; |
21 | enum DriverError { | 24 | enum DriverError { |
22 | DriverInternal=0, // internal DriverError | 25 | DriverInternal=0, // internal DriverError |
23 | Permission, // Permission Problem | 26 | Permission, // Permission Problem |
24 | Abort, // Abort of the SQL | 27 | Abort, // Abort of the SQL |
25 | Busy, // Busy Error | 28 | Busy, // Busy Error |
26 | Locked, // Locked | 29 | Locked, // Locked |
27 | NoMem, // No Memory | 30 | NoMem, // No Memory |
28 | ReadOnly, // Database is read only | 31 | ReadOnly, // Database is read only |
29 | Interrupt, // Interrupt | 32 | Interrupt, // Interrupt |
30 | IOErr, // IO Error | 33 | IOErr, // IO Error |
31 | Corrupt, // Database Corruption | 34 | Corrupt, // Database Corruption |
32 | NotFound, // Table not Found | 35 | NotFound, // Table not Found |
33 | Full, // Full | 36 | Full, // Full |
34 | CantOpen, // Can not open Table/Database | 37 | CantOpen, // Can not open Table/Database |
35 | Protocol, // internal protocol error | 38 | Protocol, // internal protocol error |
36 | Schema, // schema changed | 39 | Schema, // schema changed |
37 | TooBig, // Data too big | 40 | TooBig, // Data too big |
38 | Mismatch, // Type mismatch | 41 | Mismatch, // Type mismatch |
39 | Misuse // misuse | 42 | Misuse // misuse |
40 | }; | 43 | }; |
41 | OSQLError( const QString& driverText = QString::null, | 44 | OSQLError( const QString& driverText = QString::null, |
42 | const QString& driverDatabaseText = QString::null, | 45 | const QString& driverDatabaseText = QString::null, |
43 | int type = None, int subNumber = -1 ); | 46 | int type = None, int subNumber = -1 ); |
44 | ~OSQLError(); | 47 | ~OSQLError(); |
45 | 48 | ||
46 | QString driverText()const; | 49 | QString driverText()const; |
47 | QString databaseText()const; | 50 | QString databaseText()const; |
48 | int type()const; | 51 | int type()const; |
49 | int subNumber()const; | 52 | int subNumber()const; |
50 | private: | 53 | private: |
51 | QString m_drvText; | 54 | QString m_drvText; |
52 | QString m_drvDBText; | 55 | QString m_drvDBText; |
53 | int m_type; | 56 | int m_type; |
54 | int m_number; | 57 | int m_number; |
55 | class OSQLErrorPrivate; | 58 | class OSQLErrorPrivate; |
56 | OSQLErrorPrivate* d; | 59 | OSQLErrorPrivate* d; |
57 | }; | 60 | }; |
58 | 61 | ||
62 | } | ||
63 | } | ||
59 | #endif | 64 | #endif |
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index 6141504..47bc250 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp | |||
@@ -1,188 +1,191 @@ | |||
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; | ||
44 | using namespace Opie::DB::Private; | ||
45 | |||
43 | namespace { | 46 | namespace { |
44 | struct Query { | 47 | struct Query { |
45 | OSQLError::ValueList errors; | 48 | OSQLError::ValueList errors; |
46 | OSQLResultItem::ValueList items; | 49 | OSQLResultItem::ValueList items; |
47 | OSQLiteDriver *driver; | 50 | OSQLiteDriver *driver; |
48 | }; | 51 | }; |
49 | } | 52 | } |
50 | 53 | ||
51 | 54 | ||
52 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) | 55 | OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) |
53 | : OSQLDriver( lib ) | 56 | : OSQLDriver( lib ) |
54 | { | 57 | { |
55 | m_sqlite = 0l; | 58 | m_sqlite = 0l; |
56 | } | 59 | } |
57 | 60 | ||
58 | 61 | ||
59 | OSQLiteDriver::~OSQLiteDriver() { | 62 | OSQLiteDriver::~OSQLiteDriver() { |
60 | close(); | 63 | close(); |
61 | } | 64 | } |
62 | 65 | ||
63 | 66 | ||
64 | QString OSQLiteDriver::id()const { | 67 | QString OSQLiteDriver::id()const { |
65 | return QString::fromLatin1("SQLite"); | 68 | return QString::fromLatin1("SQLite"); |
66 | } | 69 | } |
67 | 70 | ||
68 | void OSQLiteDriver::setUserName( const QString& ) {} | 71 | void OSQLiteDriver::setUserName( const QString& ) {} |
69 | 72 | ||
70 | 73 | ||
71 | void OSQLiteDriver::setPassword( const QString& ) {} | 74 | void OSQLiteDriver::setPassword( const QString& ) {} |
72 | 75 | ||
73 | 76 | ||
74 | void OSQLiteDriver::setUrl( const QString& url ) { | 77 | void OSQLiteDriver::setUrl( const QString& url ) { |
75 | m_url = url; | 78 | m_url = url; |
76 | } | 79 | } |
77 | 80 | ||
78 | 81 | ||
79 | void OSQLiteDriver::setOptions( const QStringList& ) { | 82 | void OSQLiteDriver::setOptions( const QStringList& ) { |
80 | } | 83 | } |
81 | 84 | ||
82 | 85 | ||
83 | /* | 86 | /* |
84 | * try to open a db specified via setUrl | 87 | * try to open a db specified via setUrl |
85 | * and options | 88 | * and options |
86 | */ | 89 | */ |
87 | bool OSQLiteDriver::open() { | 90 | bool OSQLiteDriver::open() { |
88 | char *error; | 91 | char *error; |
89 | odebug << "OSQLiteDriver::open: about to open" << oendl; | 92 | qDebug("OSQLiteDriver::open: about to open"); |
90 | m_sqlite = sqlite_open(m_url.local8Bit(), | 93 | m_sqlite = sqlite_open(m_url.local8Bit(), |
91 | 0, | 94 | 0, |
92 | &error ); | 95 | &error ); |
93 | 96 | ||
94 | /* failed to open */ | 97 | /* failed to open */ |
95 | if (m_sqlite == 0l ) { | 98 | if (m_sqlite == 0l ) { |
96 | // FIXME set the last error | 99 | // FIXME set the last error |
97 | owarn << "OSQLiteDriver::open: " << error << oendl; | 100 | qWarning("OSQLiteDriver::open: %s", error ); |
98 | free( error ); | 101 | free( error ); |
99 | return false; | 102 | return false; |
100 | } | 103 | } |
101 | return true; | 104 | return true; |
102 | } | 105 | } |
103 | 106 | ||
104 | 107 | ||
105 | /* close the db | 108 | /* close the db |
106 | * sqlite closes them without | 109 | * sqlite closes them without |
107 | * telling failure or success | 110 | * telling failure or success |
108 | */ | 111 | */ |
109 | bool OSQLiteDriver::close() { | 112 | bool OSQLiteDriver::close() { |
110 | if (m_sqlite ) | 113 | if (m_sqlite ) |
111 | sqlite_close( m_sqlite ), m_sqlite=0l; | 114 | sqlite_close( m_sqlite ), m_sqlite=0l; |
112 | 115 | ||
113 | return true; | 116 | return true; |
114 | } | 117 | } |
115 | 118 | ||
116 | 119 | ||
117 | /* Query */ | 120 | /* Query */ |
118 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { | 121 | OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { |
119 | if ( !m_sqlite ) { | 122 | if ( !m_sqlite ) { |
120 | // FIXME set error code | 123 | // FIXME set error code |
121 | OSQLResult result( OSQLResult::Failure ); | 124 | OSQLResult result( OSQLResult::Failure ); |
122 | return result; | 125 | return result; |
123 | } | 126 | } |
124 | Query query; | 127 | Query query; |
125 | query.driver = this; | 128 | query.driver = this; |
126 | char *err; | 129 | char *err; |
127 | /* SQLITE_OK 0 if return code > 0 == failure */ | 130 | /* SQLITE_OK 0 if return code > 0 == failure */ |
128 | 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 ) { |
129 | owarn << "OSQLiteDriver::query: Error while executing" << oendl; | 132 | qWarning("OSQLiteDriver::query: Error while executing"); |
130 | free(err ); | 133 | free(err ); |
131 | // FixMe Errors | 134 | // FixMe Errors |
132 | } | 135 | } |
133 | 136 | ||
134 | OSQLResult result(OSQLResult::Success, | 137 | OSQLResult result(OSQLResult::Success, |
135 | query.items, | 138 | query.items, |
136 | query.errors ); | 139 | query.errors ); |
137 | return result; | 140 | return result; |
138 | } | 141 | } |
139 | 142 | ||
140 | 143 | ||
141 | OSQLTable::ValueList OSQLiteDriver::tables() const { | 144 | OSQLTable::ValueList OSQLiteDriver::tables() const { |
142 | 145 | ||
143 | } | 146 | } |
144 | 147 | ||
145 | 148 | ||
146 | OSQLError OSQLiteDriver::lastError() { | 149 | OSQLError OSQLiteDriver::lastError() { |
147 | OSQLError error; | 150 | OSQLError error; |
148 | return error; | 151 | return error; |
149 | }; | 152 | }; |
150 | 153 | ||
151 | 154 | ||
152 | /* handle a callback add the row to the global | 155 | /* handle a callback add the row to the global |
153 | * OSQLResultItem | 156 | * OSQLResultItem |
154 | */ | 157 | */ |
155 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { | 158 | int OSQLiteDriver::handleCallBack( int, char**, char** ) { |
156 | return 0; | 159 | return 0; |
157 | } | 160 | } |
158 | 161 | ||
159 | 162 | ||
160 | /* callback_handler add the values to the list*/ | 163 | /* callback_handler add the values to the list*/ |
161 | int OSQLiteDriver::call_back( void* voi, int argc, | 164 | int OSQLiteDriver::call_back( void* voi, int argc, |
162 | char** argv, char** columns) { | 165 | char** argv, char** columns) { |
163 | Query* qu = (Query*)voi; | 166 | Query* qu = (Query*)voi; |
164 | 167 | ||
165 | //copy them over to a OSQLResultItem | 168 | //copy them over to a OSQLResultItem |
166 | QMap<QString, QString> tableString; | 169 | QMap<QString, QString> tableString; |
167 | QMap<int, QString> tableInt; | 170 | QMap<int, QString> tableInt; |
168 | for (int i = 0; i < argc; i++ ) { | 171 | for (int i = 0; i < argc; i++ ) { |
169 | 172 | ||
170 | #ifdef __BUGGY_LOCAL8BIT_ | 173 | #ifdef __BUGGY_LOCAL8BIT_ |
171 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); | 174 | tableInt.insert( i, QString::fromLatin1( argv[i] ) ); |
172 | tableString.insert( QString::fromLatin1( columns[i] ), | 175 | tableString.insert( QString::fromLatin1( columns[i] ), |
173 | QString::fromLatin1( argv[i] ) ); | 176 | QString::fromLatin1( argv[i] ) ); |
174 | #else | 177 | #else |
175 | tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); | 178 | tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); |
176 | tableString.insert( QString::fromLocal8Bit( columns[i] ), | 179 | tableString.insert( QString::fromLocal8Bit( columns[i] ), |
177 | QString::fromLocal8Bit( argv[i] ) ); | 180 | QString::fromLocal8Bit( argv[i] ) ); |
178 | #endif | 181 | #endif |
179 | } | 182 | } |
180 | OSQLResultItem item( tableString, tableInt ); | 183 | OSQLResultItem item( tableString, tableInt ); |
181 | qu->items.append( item ); | 184 | qu->items.append( item ); |
182 | 185 | ||
183 | return ((Query*)voi)->driver->handleCallBack( argc, | 186 | return ((Query*)voi)->driver->handleCallBack( argc, |
184 | argv, | 187 | argv, |
185 | columns ); | 188 | columns ); |
186 | 189 | ||
187 | 190 | ||
188 | } | 191 | } |
diff --git a/libopie2/opiedb/osqlitedriver.h b/libopie2/opiedb/osqlitedriver.h index 6984539..3e1325b 100644 --- a/libopie2/opiedb/osqlitedriver.h +++ b/libopie2/opiedb/osqlitedriver.h | |||
@@ -1,34 +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 { | ||
11 | namespace DB { | ||
12 | namespace Private { | ||
13 | |||
10 | class OSQLiteDriver : public OSQLDriver { | 14 | class OSQLiteDriver : public OSQLDriver { |
11 | Q_OBJECT | 15 | Q_OBJECT |
12 | public: | 16 | public: |
13 | OSQLiteDriver( QLibrary *lib = 0l ); | 17 | OSQLiteDriver( QLibrary *lib = 0l ); |
14 | ~OSQLiteDriver(); | 18 | ~OSQLiteDriver(); |
15 | QString id()const; | 19 | QString id()const; |
16 | void setUserName( const QString& ); | 20 | void setUserName( const QString& ); |
17 | void setPassword( const QString& ); | 21 | void setPassword( const QString& ); |
18 | void setUrl( const QString& url ); | 22 | void setUrl( const QString& url ); |
19 | void setOptions( const QStringList& ); | 23 | void setOptions( const QStringList& ); |
20 | bool open(); | 24 | bool open(); |
21 | bool close(); | 25 | bool close(); |
22 | OSQLError lastError(); | 26 | OSQLError lastError(); |
23 | OSQLResult query( OSQLQuery* ); | 27 | OSQLResult query( OSQLQuery* ); |
24 | OSQLTable::ValueList tables()const; | 28 | OSQLTable::ValueList tables()const; |
25 | private: | 29 | private: |
26 | OSQLError m_lastE; | 30 | OSQLError m_lastE; |
27 | OSQLResult m_result; | 31 | OSQLResult m_result; |
28 | OSQLResultItem m_items; | 32 | OSQLResultItem m_items; |
29 | int handleCallBack( int, char**, char** ); | 33 | int handleCallBack( int, char**, char** ); |
30 | static int call_back( void*, int, char**, char** ); | 34 | static int call_back( void*, int, char**, char** ); |
31 | QString m_url; | 35 | QString m_url; |
32 | sqlite *m_sqlite; | 36 | sqlite *m_sqlite; |
33 | }; | 37 | }; |
38 | } | ||
39 | } | ||
40 | } | ||
41 | |||
34 | #endif | 42 | #endif |
diff --git a/libopie2/opiedb/osqlmanager.cpp b/libopie2/opiedb/osqlmanager.cpp index 766ebe1..990d258 100644 --- a/libopie2/opiedb/osqlmanager.cpp +++ b/libopie2/opiedb/osqlmanager.cpp | |||
@@ -1,81 +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; | ||
9 | |||
8 | OSQLManager::OSQLManager() { | 10 | OSQLManager::OSQLManager() { |
9 | } | 11 | } |
10 | OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { | 12 | OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { |
11 | m_list.clear(); | 13 | m_list.clear(); |
12 | QString opie = QString::fromLatin1( getenv("OPIEDIR") ); | 14 | QString opie = QString::fromLatin1( getenv("OPIEDIR") ); |
13 | QString qpe = QString::fromLatin1( getenv("QPEDIR") ); | 15 | QString qpe = QString::fromLatin1( getenv("QPEDIR") ); |
14 | 16 | ||
15 | if ( !m_path.contains(opie) && !opie.isEmpty() ) | 17 | if ( !m_path.contains(opie) && !opie.isEmpty() ) |
16 | m_path << opie; | 18 | m_path << opie; |
17 | if ( !m_path.contains(qpe) && !qpe.isEmpty() ) | 19 | if ( !m_path.contains(qpe) && !qpe.isEmpty() ) |
18 | m_path << qpe; | 20 | m_path << qpe; |
19 | 21 | ||
20 | OSQLBackEndManager mng( m_path ); | 22 | OSQLBackEndManager mng( m_path ); |
21 | m_list = mng.scan(); | 23 | m_list = mng.scan(); |
22 | m_list += builtIn(); | 24 | m_list += builtIn(); |
23 | 25 | ||
24 | return m_list; | 26 | return m_list; |
25 | } | 27 | } |
26 | /* | 28 | /* |
27 | * loading dso's is currently not enabled due problems with QLibrary | 29 | * loading dso's is currently not enabled due problems with QLibrary |
28 | * beeing in libqpe and not libqte | 30 | * beeing in libqpe and not libqte |
29 | */ | 31 | */ |
30 | OSQLDriver* OSQLManager::load( const QString& name ) { | 32 | OSQLDriver* OSQLManager::load( const QString& name ) { |
31 | OSQLDriver* driver = 0l; | 33 | OSQLDriver* driver = 0l; |
32 | 34 | ||
33 | if ( name == "SQLite" ) { | 35 | if ( name == "SQLite" ) { |
34 | driver = new OSQLiteDriver(); | 36 | driver = new Opie::DB::Private::OSQLiteDriver; |
35 | } | 37 | } |
36 | return driver; | 38 | return driver; |
37 | } | 39 | } |
38 | /* | 40 | /* |
39 | * same as above | 41 | * same as above |
40 | */ | 42 | */ |
41 | OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { | 43 | OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { |
42 | OSQLDriver *driver = 0l; | 44 | OSQLDriver *driver = 0l; |
43 | if ( end.library() == "builtin" && | 45 | if ( end.library() == "builtin" && |
44 | end.name() == "SQLite" ) | 46 | end.name() == "SQLite" ) |
45 | driver = new OSQLiteDriver(); | 47 | driver = new Opie::DB::Private::OSQLiteDriver; |
46 | 48 | ||
47 | return driver; | 49 | return driver; |
48 | } | 50 | } |
49 | /* | 51 | /* |
50 | * let's find the a default with the highes preference | 52 | * let's find the a default with the highes preference |
51 | */ | 53 | */ |
52 | OSQLDriver* OSQLManager::standard() { | 54 | OSQLDriver* OSQLManager::standard() { |
53 | OSQLDriver* driver =0l; | 55 | OSQLDriver* driver =0l; |
54 | if ( m_list.isEmpty() ) queryBackEnd(); | 56 | if ( m_list.isEmpty() ) queryBackEnd(); |
55 | OSQLBackEnd::ValueList::Iterator it; | 57 | OSQLBackEnd::ValueList::Iterator it; |
56 | OSQLBackEnd back; | 58 | OSQLBackEnd back; |
57 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 59 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
58 | if ( (*it).isDefault() && | 60 | if ( (*it).isDefault() && |
59 | back.preference() < (*it).preference() ) { | 61 | back.preference() < (*it).preference() ) { |
60 | back = (*it); | 62 | back = (*it); |
61 | } | 63 | } |
62 | } | 64 | } |
63 | driver = load( back ); | 65 | driver = load( back ); |
64 | return driver; | 66 | return driver; |
65 | } | 67 | } |
66 | void OSQLManager::registerPath( const QString& path ) { | 68 | void OSQLManager::registerPath( const QString& path ) { |
67 | m_path << path; | 69 | m_path << path; |
68 | } | 70 | } |
69 | bool OSQLManager::unregisterPath( const QString& path ) { | 71 | bool OSQLManager::unregisterPath( const QString& path ) { |
70 | m_path.remove( path ); | 72 | m_path.remove( path ); |
71 | return true; | 73 | return true; |
72 | } | 74 | } |
73 | OSQLBackEnd::ValueList OSQLManager::builtIn()const { | 75 | OSQLBackEnd::ValueList OSQLManager::builtIn()const { |
74 | OSQLBackEnd::ValueList list; | 76 | OSQLBackEnd::ValueList list; |
75 | // create the OSQLiteBackend | 77 | // create the OSQLiteBackend |
76 | OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" ); | 78 | OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" ); |
77 | back.setDefault( true ); | 79 | back.setDefault( true ); |
78 | back.setPreference( 50 ); | 80 | back.setPreference( 50 ); |
79 | list.append( back ); | 81 | list.append( back ); |
80 | return list; | 82 | return list; |
81 | } | 83 | } |
diff --git a/libopie2/opiedb/osqlmanager.h b/libopie2/opiedb/osqlmanager.h index 5323b14..ca73c64 100644 --- a/libopie2/opiedb/osqlmanager.h +++ b/libopie2/opiedb/osqlmanager.h | |||
@@ -1,64 +1,70 @@ | |||
1 | 1 | ||
2 | #ifndef OSQL_MANAGER_H | 2 | #ifndef OSQL_MANAGER_H |
3 | #define OSQL_MANAGER_H | 3 | #define OSQL_MANAGER_H |
4 | 4 | ||
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | #include "osqlbackend.h" | 8 | #include "osqlbackend.h" |
9 | 9 | ||
10 | 10 | ||
11 | namespace Opie { | ||
12 | namespace DB { | ||
11 | /** | 13 | /** |
12 | * OSQLManager is responsible for loading | 14 | * OSQLManager is responsible for loading |
13 | * and unloading, querying different OSQL | 15 | * and unloading, querying different OSQL |
14 | * services | 16 | * services |
15 | * Load a OSQLDriver and delete it yourself | 17 | * Load a OSQLDriver and delete it yourself |
16 | * | 18 | * |
17 | */ | 19 | */ |
18 | class OSQLDriver; | 20 | class OSQLDriver; |
19 | class OSQLManager : public QObject { | 21 | class OSQLManager : public QObject { |
20 | Q_OBJECT | 22 | Q_OBJECT |
21 | public: | 23 | public: |
22 | /** | 24 | /** |
23 | * Empty c'tor | 25 | * Empty c'tor |
24 | */ | 26 | */ |
25 | OSQLManager(); | 27 | OSQLManager(); |
26 | 28 | ||
27 | /** | 29 | /** |
28 | * Query the Manager for different backends | 30 | * Query the Manager for different backends |
29 | */ | 31 | */ |
30 | OSQLBackEnd::ValueList queryBackEnd(); | 32 | OSQLBackEnd::ValueList queryBackEnd(); |
31 | 33 | ||
32 | /** | 34 | /** |
33 | * Load a backend with it's name from param name | 35 | * Load a backend with it's name from param name |
34 | */ | 36 | */ |
35 | OSQLDriver* load( const QString& name ); | 37 | OSQLDriver* load( const QString& name ); |
36 | 38 | ||
37 | /** | 39 | /** |
38 | * Load a OSQLDevice from const reference of OSQLBackEnd | 40 | * Load a OSQLDevice from const reference of OSQLBackEnd |
39 | */ | 41 | */ |
40 | OSQLDriver* load( const OSQLBackEnd& ); | 42 | OSQLDriver* load( const OSQLBackEnd& ); |
41 | 43 | ||
42 | /** | 44 | /** |
43 | * loads the Opie standard backend | 45 | * loads the Opie standard backend |
44 | */ | 46 | */ |
45 | OSQLDriver *standard(); | 47 | OSQLDriver *standard(); |
46 | 48 | ||
47 | /** | 49 | /** |
48 | * register path to the search path list | 50 | * register path to the search path list |
49 | * When querying for services we scan all the | 51 | * When querying for services we scan all the |
50 | * registered path for backends | 52 | * registered path for backends |
51 | */ | 53 | */ |
52 | void registerPath( const QString& path ); | 54 | void registerPath( const QString& path ); |
53 | 55 | ||
54 | /** | 56 | /** |
55 | * unregisterPath from the search path list | 57 | * unregisterPath from the search path list |
56 | */ | 58 | */ |
57 | bool unregisterPath( const QString& path ); | 59 | bool unregisterPath( const QString& path ); |
58 | private: | 60 | private: |
59 | OSQLBackEnd::ValueList builtIn()const; | 61 | OSQLBackEnd::ValueList builtIn()const; |
60 | OSQLBackEnd::ValueList m_list; | 62 | OSQLBackEnd::ValueList m_list; |
61 | QStringList m_path; | 63 | QStringList m_path; |
64 | class Private; | ||
65 | Private *d; | ||
62 | }; | 66 | }; |
67 | } | ||
68 | } | ||
63 | 69 | ||
64 | #endif | 70 | #endif |
diff --git a/libopie2/opiedb/osqlquery.cpp b/libopie2/opiedb/osqlquery.cpp index ecd53f2..8270c4c 100644 --- a/libopie2/opiedb/osqlquery.cpp +++ b/libopie2/opiedb/osqlquery.cpp | |||
@@ -1,17 +1,19 @@ | |||
1 | 1 | ||
2 | #include "osqlquery.h" | 2 | #include "osqlquery.h" |
3 | 3 | ||
4 | using namespace Opie::DB; | ||
5 | |||
4 | OSQLQuery::OSQLQuery() { | 6 | OSQLQuery::OSQLQuery() { |
5 | } | 7 | } |
6 | OSQLQuery::~OSQLQuery() { | 8 | OSQLQuery::~OSQLQuery() { |
7 | } | 9 | } |
8 | 10 | ||
9 | OSQLRawQuery::OSQLRawQuery(const QString& query) | 11 | OSQLRawQuery::OSQLRawQuery(const QString& query) |
10 | : OSQLQuery(), m_query( query ) { | 12 | : OSQLQuery(), m_query( query ) { |
11 | 13 | ||
12 | } | 14 | } |
13 | OSQLRawQuery::~OSQLRawQuery() { | 15 | OSQLRawQuery::~OSQLRawQuery() { |
14 | } | 16 | } |
15 | QString OSQLRawQuery::query()const { | 17 | QString OSQLRawQuery::query()const { |
16 | return m_query; | 18 | return m_query; |
17 | } | 19 | } |
diff --git a/libopie2/opiedb/osqlquery.h b/libopie2/opiedb/osqlquery.h index 63c26b0..0265d2b 100644 --- a/libopie2/opiedb/osqlquery.h +++ b/libopie2/opiedb/osqlquery.h | |||
@@ -1,122 +1,130 @@ | |||
1 | 1 | ||
2 | #ifndef OSQL_QUERY_H | 2 | #ifndef OSQL_QUERY_H |
3 | #define OSQL_QUERY_H | 3 | #define OSQL_QUERY_H |
4 | 4 | ||
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qvaluelist.h> | 6 | #include <qvaluelist.h> |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | 8 | ||
9 | 9 | ||
10 | namespace Opie { | ||
11 | namespace DB { | ||
12 | |||
10 | /** I'm not happy with them | 13 | /** I'm not happy with them |
11 | class OSQLQueryOrder { | 14 | class OSQLQueryOrder { |
12 | public: | 15 | public: |
13 | typedef QValueList<OSQLQueryOrder> ValueList; | 16 | typedef QValueList<OSQLQueryOrder> ValueList; |
14 | OSQLQueryOrder(const QString& table = QString::null ); | 17 | OSQLQueryOrder(const QString& table = QString::null ); |
15 | OSQLQueryOrder( const OSQLQueryOrder& ); | 18 | OSQLQueryOrder( const OSQLQueryOrder& ); |
16 | ~OSQLQueryOrder(); | 19 | ~OSQLQueryOrder(); |
17 | void setOrderFields( const QStringList& list ); | 20 | void setOrderFields( const QStringList& list ); |
18 | void setValue( const QString& fieldName, const QString& Value ); | 21 | void setValue( const QString& fieldName, const QString& Value ); |
19 | void setValues( const QMap<QString, QString>& ); | 22 | void setValues( const QMap<QString, QString>& ); |
20 | QMap<QString, QString> orders() const; | 23 | QMap<QString, QString> orders() const; |
21 | QString orderStatement()const; | 24 | QString orderStatement()const; |
22 | OSQLQueryOrder &operator=(const OSQLQueryOrder& ); | 25 | OSQLQueryOrder &operator=(const OSQLQueryOrder& ); |
23 | private: | 26 | private: |
24 | QMap<QString, QString> m_fields; | 27 | QMap<QString, QString> m_fields; |
25 | class OSQLQueryOrderPrivate; | 28 | class OSQLQueryOrderPrivate; |
26 | OSQLQueryOrderPrivate* d; | 29 | OSQLQueryOrderPrivate* d; |
27 | }; | 30 | }; |
28 | class OSQLWhere { | 31 | class OSQLWhere { |
29 | public: | 32 | public: |
30 | typedef QValueList<OSQLWhere> ValueList; | 33 | typedef QValueList<OSQLWhere> ValueList; |
31 | enum Vergleiche { Equal = 0, Like, Greater, GreaterEqual, | 34 | enum Vergleiche { Equal = 0, Like, Greater, GreaterEqual, |
32 | Smaller, SmallerEqual }; | 35 | Smaller, SmallerEqual }; |
33 | OSQLWhere(const QString& table = QString::null ); | 36 | OSQLWhere(const QString& table = QString::null ); |
34 | ~OSQLWhere(); | 37 | ~OSQLWhere(); |
35 | void setExpression(const QString& key, enum Vergleiche, const QString& ); | 38 | void setExpression(const QString& key, enum Vergleiche, const QString& ); |
36 | QString statement()const; | 39 | QString statement()const; |
37 | private: | 40 | private: |
38 | int m_vergleich; | 41 | int m_vergleich; |
39 | const QString& m_left; | 42 | const QString& m_left; |
40 | const QString& m_right; | 43 | const QString& m_right; |
41 | 44 | ||
42 | }; | 45 | }; |
43 | */ | 46 | */ |
44 | class OSQLQuery { | 47 | class OSQLQuery { |
45 | public: | 48 | public: |
46 | OSQLQuery(); | 49 | OSQLQuery(); |
47 | virtual ~OSQLQuery(); | 50 | virtual ~OSQLQuery(); |
48 | 51 | ||
49 | virtual QString query()const = 0; | 52 | virtual QString query()const = 0; |
53 | private: | ||
54 | class Private; | ||
55 | Private *d; | ||
50 | }; | 56 | }; |
51 | 57 | ||
52 | class OSQLRawQuery : public OSQLQuery { | 58 | class OSQLRawQuery : public OSQLQuery { |
53 | public: | 59 | public: |
54 | OSQLRawQuery( const QString& query ); | 60 | OSQLRawQuery( const QString& query ); |
55 | ~OSQLRawQuery(); | 61 | ~OSQLRawQuery(); |
56 | QString query() const; | 62 | QString query() const; |
57 | private: | 63 | private: |
58 | class OSQLRawQueryPrivate; | 64 | class OSQLRawQueryPrivate; |
59 | OSQLRawQueryPrivate* d; | 65 | OSQLRawQueryPrivate* d; |
60 | QString m_query; | 66 | QString m_query; |
61 | 67 | ||
62 | }; | 68 | }; |
63 | /* I'm not happy with them again | 69 | /* I'm not happy with them again |
64 | class OSQLSelectQuery : public OSQLQuery { | 70 | class OSQLSelectQuery : public OSQLQuery { |
65 | public: | 71 | public: |
66 | OSQLSelectQuery(); | 72 | OSQLSelectQuery(); |
67 | ~OSQLSelectQuery(); | 73 | ~OSQLSelectQuery(); |
68 | void setTables( const QStringList& allTablesToQuery ); | 74 | void setTables( const QStringList& allTablesToQuery ); |
69 | void setValues( const QString& table, const QStringList& columns ); | 75 | void setValues( const QString& table, const QStringList& columns ); |
70 | void setOrder( const OSQLSelectQuery& ); | 76 | void setOrder( const OSQLSelectQuery& ); |
71 | void setOrderList( const OSQLQueryOrder::ValueList& ); | 77 | void setOrderList( const OSQLQueryOrder::ValueList& ); |
72 | void setWhereList( const OSQLWhere& ); | 78 | void setWhereList( const OSQLWhere& ); |
73 | void setWhereList( const OSQLWhere::ValueList& ); | 79 | void setWhereList( const OSQLWhere::ValueList& ); |
74 | QString query()const; | 80 | QString query()const; |
75 | private: | 81 | private: |
76 | QStringList m_tables; | 82 | QStringList m_tables; |
77 | QMap<QString, QStringList> m_values; | 83 | QMap<QString, QStringList> m_values; |
78 | OSQLQueryOrder::ValueList m_order; | 84 | OSQLQueryOrder::ValueList m_order; |
79 | OSQLWhere::ValueList m_where; | 85 | OSQLWhere::ValueList m_where; |
80 | class OSQLSelectQueryPrivate; | 86 | class OSQLSelectQueryPrivate; |
81 | OSQLSelectQueryPrivate* d; | 87 | OSQLSelectQueryPrivate* d; |
82 | }; | 88 | }; |
83 | class OSQLInsertQuery : public OSQLQuery { | 89 | class OSQLInsertQuery : public OSQLQuery { |
84 | public: | 90 | public: |
85 | OSQLInsertQuery(const QString& table); | 91 | OSQLInsertQuery(const QString& table); |
86 | ~OSQLInsertQuery(); | 92 | ~OSQLInsertQuery(); |
87 | void setInserFields( const QStringList& ); | 93 | void setInserFields( const QStringList& ); |
88 | void setValue( const QString& field, const QString& value ); | 94 | void setValue( const QString& field, const QString& value ); |
89 | void setValues(const QMap<QString, QString>& ); | 95 | void setValues(const QMap<QString, QString>& ); |
90 | QString query()const; | 96 | QString query()const; |
91 | private: | 97 | private: |
92 | QString m_table; | 98 | QString m_table; |
93 | QStringList m_fields; | 99 | QStringList m_fields; |
94 | QMap<QString, QString> m_values; | 100 | QMap<QString, QString> m_values; |
95 | }; | 101 | }; |
96 | class OSQLDeleteQuery : public OSQLQuery { | 102 | class OSQLDeleteQuery : public OSQLQuery { |
97 | public: | 103 | public: |
98 | OSQLDeleteQuery(const QString& table); | 104 | OSQLDeleteQuery(const QString& table); |
99 | ~OSQLDeleteQuery(); | 105 | ~OSQLDeleteQuery(); |
100 | void setWhere( const OSQLWhere& ); | 106 | void setWhere( const OSQLWhere& ); |
101 | void setWheres( const OSQLWhere::ValueList& ); | 107 | void setWheres( const OSQLWhere::ValueList& ); |
102 | QString query()const; | 108 | QString query()const; |
103 | private: | 109 | private: |
104 | QString m_table; | 110 | QString m_table; |
105 | OSQLWhere::ValueList m_where; | 111 | OSQLWhere::ValueList m_where; |
106 | 112 | ||
107 | }; | 113 | }; |
108 | class OSQLUpdateQuery : public OSQLQuery { | 114 | class OSQLUpdateQuery : public OSQLQuery { |
109 | public: | 115 | public: |
110 | OSQLUpdateQuery( const QString& table ); | 116 | OSQLUpdateQuery( const QString& table ); |
111 | ~OSQLUpdateQuery(); | 117 | ~OSQLUpdateQuery(); |
112 | void setWhere( const OSQLWhere& ); | 118 | void setWhere( const OSQLWhere& ); |
113 | void setWheres( const OSQLWhere::ValueList& ); | 119 | void setWheres( const OSQLWhere::ValueList& ); |
114 | */ | 120 | */ |
115 | /* replaces all previous set Values */ | 121 | /* replaces all previous set Values */ |
116 | /* | 122 | /* |
117 | void setValue( const QString& field, const QString& value ); | 123 | void setValue( const QString& field, const QString& value ); |
118 | void setValue( const QMap<QString, QString> &fields ); | 124 | void setValue( const QMap<QString, QString> &fields ); |
119 | QString query() const; | 125 | QString query() const; |
120 | }; | 126 | }; |
121 | */ | 127 | */ |
128 | } | ||
129 | } | ||
122 | #endif | 130 | #endif |
diff --git a/libopie2/opiedb/osqlresult.cpp b/libopie2/opiedb/osqlresult.cpp index 42da356..bad7d8b 100644 --- a/libopie2/opiedb/osqlresult.cpp +++ b/libopie2/opiedb/osqlresult.cpp | |||
@@ -1,126 +1,128 @@ | |||
1 | 1 | ||
2 | #include "osqlresult.h" | 2 | #include "osqlresult.h" |
3 | 3 | ||
4 | using namespace Opie::DB; | ||
5 | |||
4 | OSQLResultItem::OSQLResultItem( const TableString& string, | 6 | OSQLResultItem::OSQLResultItem( const TableString& string, |
5 | const TableInt& Int) | 7 | const TableInt& Int) |
6 | : m_string( string ), m_int( Int ) | 8 | : m_string( string ), m_int( Int ) |
7 | { | 9 | { |
8 | 10 | ||
9 | } | 11 | } |
10 | OSQLResultItem::~OSQLResultItem() { | 12 | OSQLResultItem::~OSQLResultItem() { |
11 | } | 13 | } |
12 | OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { | 14 | OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { |
13 | *this = item; | 15 | *this = item; |
14 | } | 16 | } |
15 | OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { | 17 | OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { |
16 | m_string = other.m_string; | 18 | m_string = other.m_string; |
17 | m_int = other.m_int; | 19 | m_int = other.m_int; |
18 | return *this; | 20 | return *this; |
19 | } | 21 | } |
20 | OSQLResultItem::TableString OSQLResultItem::tableString()const{ | 22 | OSQLResultItem::TableString OSQLResultItem::tableString()const{ |
21 | return m_string; | 23 | return m_string; |
22 | } | 24 | } |
23 | OSQLResultItem::TableInt OSQLResultItem::tableInt()const { | 25 | OSQLResultItem::TableInt OSQLResultItem::tableInt()const { |
24 | return m_int; | 26 | return m_int; |
25 | } | 27 | } |
26 | QString OSQLResultItem::data( const QString& columnName, bool *ok ) { | 28 | QString OSQLResultItem::data( const QString& columnName, bool *ok ) { |
27 | TableString::Iterator it = m_string.find( columnName ); | 29 | TableString::Iterator it = m_string.find( columnName ); |
28 | 30 | ||
29 | /* if found */ | 31 | /* if found */ |
30 | if ( it != m_string.end() ) { | 32 | if ( it != m_string.end() ) { |
31 | if ( ok ) *ok = true; | 33 | if ( ok ) *ok = true; |
32 | return it.data(); | 34 | return it.data(); |
33 | }else{ | 35 | }else{ |
34 | if ( ok ) *ok = false; | 36 | if ( ok ) *ok = false; |
35 | return QString::null; | 37 | return QString::null; |
36 | } | 38 | } |
37 | 39 | ||
38 | } | 40 | } |
39 | QString OSQLResultItem::data( int column, bool *ok ) { | 41 | QString OSQLResultItem::data( int column, bool *ok ) { |
40 | TableInt::Iterator it = m_int.find( column ); | 42 | TableInt::Iterator it = m_int.find( column ); |
41 | 43 | ||
42 | /* if found */ | 44 | /* if found */ |
43 | if ( it != m_int.end() ) { | 45 | if ( it != m_int.end() ) { |
44 | if ( ok ) *ok = true; | 46 | if ( ok ) *ok = true; |
45 | return it.data(); | 47 | return it.data(); |
46 | }else{ | 48 | }else{ |
47 | if ( ok ) *ok = false; | 49 | if ( ok ) *ok = false; |
48 | return QString::null; | 50 | return QString::null; |
49 | } | 51 | } |
50 | } | 52 | } |
51 | /* | 53 | /* |
52 | * DateFormat is 'YYYY-MM-DD' | 54 | * DateFormat is 'YYYY-MM-DD' |
53 | */ | 55 | */ |
54 | QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) { | 56 | QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) { |
55 | QDate date = QDate::currentDate(); | 57 | QDate date = QDate::currentDate(); |
56 | QString str = data( column, ok ); | 58 | QString str = data( column, ok ); |
57 | if (!str.isEmpty() ) { | 59 | if (!str.isEmpty() ) { |
58 | ;// convert | 60 | ;// convert |
59 | } | 61 | } |
60 | return date; | 62 | return date; |
61 | } | 63 | } |
62 | QDate OSQLResultItem::dataToDate( int column, bool *ok ) { | 64 | QDate OSQLResultItem::dataToDate( int column, bool *ok ) { |
63 | QDate date = QDate::currentDate(); | 65 | QDate date = QDate::currentDate(); |
64 | QString str = data( column, ok ); | 66 | QString str = data( column, ok ); |
65 | if (!str.isEmpty() ) { | 67 | if (!str.isEmpty() ) { |
66 | ;// convert | 68 | ;// convert |
67 | } | 69 | } |
68 | return date; | 70 | return date; |
69 | 71 | ||
70 | } | 72 | } |
71 | QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) { | 73 | QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) { |
72 | QDateTime time = QDateTime::currentDateTime(); | 74 | QDateTime time = QDateTime::currentDateTime(); |
73 | return time; | 75 | return time; |
74 | } | 76 | } |
75 | QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) { | 77 | QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) { |
76 | QDateTime time = QDateTime::currentDateTime(); | 78 | QDateTime time = QDateTime::currentDateTime(); |
77 | return time; | 79 | return time; |
78 | } | 80 | } |
79 | 81 | ||
80 | OSQLResult::OSQLResult( enum State state, | 82 | OSQLResult::OSQLResult( enum State state, |
81 | const OSQLResultItem::ValueList& list, | 83 | const OSQLResultItem::ValueList& list, |
82 | const OSQLError::ValueList& error ) | 84 | const OSQLError::ValueList& error ) |
83 | : m_state( state ), m_list( list ), m_error( error ) | 85 | : m_state( state ), m_list( list ), m_error( error ) |
84 | { | 86 | { |
85 | 87 | ||
86 | } | 88 | } |
87 | OSQLResult::~OSQLResult() { | 89 | OSQLResult::~OSQLResult() { |
88 | 90 | ||
89 | } | 91 | } |
90 | OSQLResult::State OSQLResult::state()const { | 92 | OSQLResult::State OSQLResult::state()const { |
91 | return m_state; | 93 | return m_state; |
92 | } | 94 | } |
93 | void OSQLResult::setState( OSQLResult::State state ) { | 95 | void OSQLResult::setState( OSQLResult::State state ) { |
94 | m_state = state; | 96 | m_state = state; |
95 | } | 97 | } |
96 | OSQLError::ValueList OSQLResult::errors()const { | 98 | OSQLError::ValueList OSQLResult::errors()const { |
97 | return m_error; | 99 | return m_error; |
98 | } | 100 | } |
99 | void OSQLResult::setErrors( const OSQLError::ValueList& err ) { | 101 | void OSQLResult::setErrors( const OSQLError::ValueList& err ) { |
100 | m_error = err; | 102 | m_error = err; |
101 | } | 103 | } |
102 | OSQLResultItem::ValueList OSQLResult::results()const { | 104 | OSQLResultItem::ValueList OSQLResult::results()const { |
103 | return m_list; | 105 | return m_list; |
104 | } | 106 | } |
105 | void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) { | 107 | void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) { |
106 | m_list = result; | 108 | m_list = result; |
107 | } | 109 | } |
108 | OSQLResultItem OSQLResult::first() { | 110 | OSQLResultItem OSQLResult::first() { |
109 | it = m_list.begin(); | 111 | it = m_list.begin(); |
110 | return (*it); | 112 | return (*it); |
111 | } | 113 | } |
112 | OSQLResultItem OSQLResult::next(){ | 114 | OSQLResultItem OSQLResult::next(){ |
113 | ++it; | 115 | ++it; |
114 | return (*it); | 116 | return (*it); |
115 | } | 117 | } |
116 | bool OSQLResult::atEnd(){ | 118 | bool OSQLResult::atEnd(){ |
117 | if ( it == m_list.end() ) | 119 | if ( it == m_list.end() ) |
118 | return true; | 120 | return true; |
119 | 121 | ||
120 | return false; | 122 | return false; |
121 | } | 123 | } |
122 | OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const { | 124 | OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const { |
123 | OSQLResultItem::ValueList::ConstIterator it; | 125 | OSQLResultItem::ValueList::ConstIterator it; |
124 | it = m_list.begin(); | 126 | it = m_list.begin(); |
125 | return it; | 127 | return it; |
126 | } | 128 | } |
diff --git a/libopie2/opiedb/osqlresult.h b/libopie2/opiedb/osqlresult.h index 9c9efa2..fc6f01a 100644 --- a/libopie2/opiedb/osqlresult.h +++ b/libopie2/opiedb/osqlresult.h | |||
@@ -1,112 +1,120 @@ | |||
1 | #ifndef OSQL_RESULT_H | 1 | #ifndef OSQL_RESULT_H |
2 | #define OSQL_RESULT_H | 2 | #define OSQL_RESULT_H |
3 | 3 | ||
4 | #include <qdatetime.h> | 4 | #include <qdatetime.h> |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qvaluelist.h> | 6 | #include <qvaluelist.h> |
7 | 7 | ||
8 | 8 | ||
9 | #include "osqlerror.h" | 9 | #include "osqlerror.h" |
10 | |||
11 | namespace Opie { | ||
12 | namespace DB { | ||
13 | |||
10 | /** | 14 | /** |
11 | * ResultItem represents one row of the resulting answer | 15 | * ResultItem represents one row of the resulting answer |
12 | */ | 16 | */ |
13 | class OSQLResultItem { | 17 | class OSQLResultItem { |
14 | public: | 18 | public: |
15 | typedef QValueList<OSQLResultItem> ValueList; | 19 | typedef QValueList<OSQLResultItem> ValueList; |
16 | /** | 20 | /** |
17 | * TableString is used to establish the relations | 21 | * TableString is used to establish the relations |
18 | * between the column name and the real item | 22 | * between the column name and the real item |
19 | */ | 23 | */ |
20 | typedef QMap<QString, QString> TableString; | 24 | typedef QMap<QString, QString> TableString; |
21 | 25 | ||
22 | /** | 26 | /** |
23 | * TableInt is used to establish a relation between a | 27 | * TableInt is used to establish a relation between a |
24 | * position of a column and the row value | 28 | * position of a column and the row value |
25 | */ | 29 | */ |
26 | typedef QMap<int, QString> TableInt; | 30 | typedef QMap<int, QString> TableInt; |
27 | 31 | ||
28 | /** | 32 | /** |
29 | * Default c'tor. It has a TableString and a TableInt | 33 | * Default c'tor. It has a TableString and a TableInt |
30 | */ | 34 | */ |
31 | OSQLResultItem(const TableString& = TableString(), | 35 | OSQLResultItem(const TableString& = TableString(), |
32 | const TableInt& = TableInt() ); | 36 | const TableInt& = TableInt() ); |
33 | OSQLResultItem( const OSQLResultItem& ); | 37 | OSQLResultItem( const OSQLResultItem& ); |
34 | ~OSQLResultItem(); | 38 | ~OSQLResultItem(); |
35 | OSQLResultItem &operator=( const OSQLResultItem& ); | 39 | OSQLResultItem &operator=( const OSQLResultItem& ); |
36 | /** | 40 | /** |
37 | * returns the TableString | 41 | * returns the TableString |
38 | */ | 42 | */ |
39 | TableString tableString()const; | 43 | TableString tableString()const; |
40 | 44 | ||
41 | /** | 45 | /** |
42 | * returns the TableInt | 46 | * returns the TableInt |
43 | */ | 47 | */ |
44 | TableInt tableInt() const; | 48 | TableInt tableInt() const; |
45 | 49 | ||
46 | /** | 50 | /** |
47 | * retrieves the Data from columnName | 51 | * retrieves the Data from columnName |
48 | * | 52 | * |
49 | */ | 53 | */ |
50 | QString data( const QString& columnName, bool *ok = 0); | 54 | QString data( const QString& columnName, bool *ok = 0); |
51 | 55 | ||
52 | /** | 56 | /** |
53 | * QString for column number | 57 | * QString for column number |
54 | */ | 58 | */ |
55 | QString data(int columnNumber, bool *ok = 0); | 59 | QString data(int columnNumber, bool *ok = 0); |
56 | 60 | ||
57 | /** | 61 | /** |
58 | * Date conversion from columnName | 62 | * Date conversion from columnName |
59 | */ | 63 | */ |
60 | QDate dataToDate( const QString& columnName, bool *ok = 0 ); | 64 | QDate dataToDate( const QString& columnName, bool *ok = 0 ); |
61 | 65 | ||
62 | /** | 66 | /** |
63 | * Date conversion from column-number | 67 | * Date conversion from column-number |
64 | */ | 68 | */ |
65 | QDate dataToDate( int columnNumber, bool *ok = 0 ); | 69 | QDate dataToDate( int columnNumber, bool *ok = 0 ); |
66 | 70 | ||
67 | QDateTime dataToDateTime( const QString& columName, bool *ok = 0 ); | 71 | QDateTime dataToDateTime( const QString& columName, bool *ok = 0 ); |
68 | QDateTime dataToDateTime( int columnNumber, bool *ok = 0 ); | 72 | QDateTime dataToDateTime( int columnNumber, bool *ok = 0 ); |
69 | private: | 73 | private: |
70 | TableString m_string; | 74 | TableString m_string; |
71 | TableInt m_int; | 75 | TableInt m_int; |
72 | }; | 76 | }; |
73 | 77 | ||
74 | /** | 78 | /** |
75 | * the OSQLResult | 79 | * the OSQLResult |
76 | * either a SQL statement failed or succeeded | 80 | * either a SQL statement failed or succeeded |
77 | */ | 81 | */ |
78 | class OSQLResult { | 82 | class OSQLResult { |
79 | public: | 83 | public: |
80 | /** The State of a Result */ | 84 | /** The State of a Result */ |
81 | enum State{ Success = 0, Failure,Undefined }; | 85 | enum State{ Success = 0, Failure,Undefined }; |
82 | 86 | ||
83 | /** | 87 | /** |
84 | * default c'tor | 88 | * default c'tor |
85 | * @param state The State of the Result | 89 | * @param state The State of the Result |
86 | * @param r ResultItems | 90 | * @param r ResultItems |
87 | * @prarm errors the Errors a OSQLResult created | 91 | * @prarm errors the Errors a OSQLResult created |
88 | */ | 92 | */ |
89 | OSQLResult( enum State state = Undefined, | 93 | OSQLResult( enum State state = Undefined, |
90 | const OSQLResultItem::ValueList& r= OSQLResultItem::ValueList(), | 94 | const OSQLResultItem::ValueList& r= OSQLResultItem::ValueList(), |
91 | const OSQLError::ValueList& errors = OSQLError::ValueList() ); | 95 | const OSQLError::ValueList& errors = OSQLError::ValueList() ); |
92 | ~OSQLResult(); | 96 | ~OSQLResult(); |
93 | State state()const; | 97 | State state()const; |
94 | OSQLError::ValueList errors()const; | 98 | OSQLError::ValueList errors()const; |
95 | OSQLResultItem::ValueList results()const; | 99 | OSQLResultItem::ValueList results()const; |
96 | 100 | ||
97 | void setState( enum State state ); | 101 | void setState( enum State state ); |
98 | void setErrors( const OSQLError::ValueList& error ); | 102 | void setErrors( const OSQLError::ValueList& error ); |
99 | void setResults( const OSQLResultItem::ValueList& result ); | 103 | void setResults( const OSQLResultItem::ValueList& result ); |
100 | 104 | ||
101 | OSQLResultItem first(); | 105 | OSQLResultItem first(); |
102 | OSQLResultItem next(); | 106 | OSQLResultItem next(); |
103 | bool atEnd(); | 107 | bool atEnd(); |
104 | OSQLResultItem::ValueList::ConstIterator iterator()const; | 108 | OSQLResultItem::ValueList::ConstIterator iterator()const; |
105 | private: | 109 | private: |
106 | enum State m_state; | 110 | enum State m_state; |
107 | OSQLResultItem::ValueList m_list; | 111 | OSQLResultItem::ValueList m_list; |
108 | OSQLError::ValueList m_error; | 112 | OSQLError::ValueList m_error; |
109 | OSQLResultItem::ValueList::Iterator it; | 113 | OSQLResultItem::ValueList::Iterator it; |
114 | class Private; | ||
115 | Private *d; | ||
110 | }; | 116 | }; |
111 | 117 | ||
118 | } | ||
119 | } | ||
112 | #endif | 120 | #endif |
diff --git a/libopie2/opiedb/osqltable.cpp b/libopie2/opiedb/osqltable.cpp index cde40f4..117cf21 100644 --- a/libopie2/opiedb/osqltable.cpp +++ b/libopie2/opiedb/osqltable.cpp | |||
@@ -1,46 +1,48 @@ | |||
1 | #include "osqltable.h" | 1 | #include "osqltable.h" |
2 | 2 | ||
3 | using namespace Opie::DB; | ||
4 | |||
3 | OSQLTableItem::OSQLTableItem() {} | 5 | OSQLTableItem::OSQLTableItem() {} |
4 | OSQLTableItem::OSQLTableItem( enum Type type, | 6 | OSQLTableItem::OSQLTableItem( enum Type type, |
5 | const QString& field, | 7 | const QString& field, |
6 | const QVariant& var) | 8 | const QVariant& var) |
7 | : m_type( type ), m_field( field ), m_var( var ) | 9 | : m_type( type ), m_field( field ), m_var( var ) |
8 | { | 10 | { |
9 | 11 | ||
10 | } | 12 | } |
11 | OSQLTableItem::~OSQLTableItem() {} | 13 | OSQLTableItem::~OSQLTableItem() {} |
12 | OSQLTableItem::OSQLTableItem( const OSQLTableItem& item) { | 14 | OSQLTableItem::OSQLTableItem( const OSQLTableItem& item) { |
13 | *this = item; | 15 | *this = item; |
14 | } | 16 | } |
15 | OSQLTableItem &OSQLTableItem::operator=(const OSQLTableItem& other) { | 17 | OSQLTableItem &OSQLTableItem::operator=(const OSQLTableItem& other) { |
16 | m_var = other.m_var; | 18 | m_var = other.m_var; |
17 | m_field = other.m_field; | 19 | m_field = other.m_field; |
18 | m_type = other.m_type; | 20 | m_type = other.m_type; |
19 | return *this; | 21 | return *this; |
20 | } | 22 | } |
21 | QString OSQLTableItem::fieldName()const{ | 23 | QString OSQLTableItem::fieldName()const{ |
22 | return m_field; | 24 | return m_field; |
23 | } | 25 | } |
24 | OSQLTableItem::Type OSQLTableItem::type()const { | 26 | OSQLTableItem::Type OSQLTableItem::type()const { |
25 | return m_type; | 27 | return m_type; |
26 | } | 28 | } |
27 | QVariant OSQLTableItem::more()const { | 29 | QVariant OSQLTableItem::more()const { |
28 | return m_var; | 30 | return m_var; |
29 | } | 31 | } |
30 | 32 | ||
31 | OSQLTable::OSQLTable( const QString& tableName ) | 33 | OSQLTable::OSQLTable( const QString& tableName ) |
32 | : m_table( tableName ) | 34 | : m_table( tableName ) |
33 | { | 35 | { |
34 | 36 | ||
35 | } | 37 | } |
36 | OSQLTable::~OSQLTable() { | 38 | OSQLTable::~OSQLTable() { |
37 | } | 39 | } |
38 | void OSQLTable::setColumns( const OSQLTableItem::ValueList& list) { | 40 | void OSQLTable::setColumns( const OSQLTableItem::ValueList& list) { |
39 | m_list = list; | 41 | m_list = list; |
40 | } | 42 | } |
41 | OSQLTableItem::ValueList OSQLTable::columns()const { | 43 | OSQLTableItem::ValueList OSQLTable::columns()const { |
42 | return m_list; | 44 | return m_list; |
43 | } | 45 | } |
44 | QString OSQLTable::tableName()const { | 46 | QString OSQLTable::tableName()const { |
45 | return m_table; | 47 | return m_table; |
46 | } | 48 | } |
diff --git a/libopie2/opiedb/osqltable.h b/libopie2/opiedb/osqltable.h index 87f7e74..86c30dd 100644 --- a/libopie2/opiedb/osqltable.h +++ b/libopie2/opiedb/osqltable.h | |||
@@ -1,95 +1,102 @@ | |||
1 | #ifndef OSQL_TABLE_H | 1 | #ifndef OSQL_TABLE_H |
2 | #define OSQL_TABLE_H | 2 | #define OSQL_TABLE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | #include <qvariant.h> | 6 | #include <qvariant.h> |
7 | 7 | ||
8 | namespace Opie { | ||
9 | namespace DB { | ||
8 | /** | 10 | /** |
9 | * OSQLTableItem saves one column of a complete | 11 | * OSQLTableItem saves one column of a complete |
10 | * table | 12 | * table |
11 | */ | 13 | */ |
12 | class OSQLTableItem { | 14 | class OSQLTableItem { |
13 | public: | 15 | public: |
14 | typedef QValueList<OSQLTableItem> ValueList; | 16 | typedef QValueList<OSQLTableItem> ValueList; |
15 | /** | 17 | /** |
16 | * Type kinds ( to be extended ) | 18 | * Type kinds ( to be extended ) |
17 | */ | 19 | */ |
18 | enum Type { Undefined=-1, Integer=0, BigInteger =1, | 20 | enum Type { Undefined=-1, Integer=0, BigInteger =1, |
19 | Float = 2, VarChar = 4 }; | 21 | Float = 2, VarChar = 4 }; |
20 | /** | 22 | /** |
21 | * A constructor | 23 | * A constructor |
22 | * @param type the Type of the Column | 24 | * @param type the Type of the Column |
23 | * @param fieldName the Name of the Column | 25 | * @param fieldName the Name of the Column |
24 | * @param var a Variant | 26 | * @param var a Variant |
25 | */ | 27 | */ |
26 | OSQLTableItem(); | 28 | OSQLTableItem(); |
27 | OSQLTableItem( enum Type type, | 29 | OSQLTableItem( enum Type type, |
28 | const QString& fieldName, | 30 | const QString& fieldName, |
29 | const QVariant& var= QVariant() ); | 31 | const QVariant& var= QVariant() ); |
30 | 32 | ||
31 | /** | 33 | /** |
32 | * copy c'tor | 34 | * copy c'tor |
33 | */ | 35 | */ |
34 | OSQLTableItem( const OSQLTableItem& ); | 36 | OSQLTableItem( const OSQLTableItem& ); |
35 | 37 | ||
36 | /** | 38 | /** |
37 | * d'tor | 39 | * d'tor |
38 | */ | 40 | */ |
39 | ~OSQLTableItem(); | 41 | ~OSQLTableItem(); |
40 | 42 | ||
41 | OSQLTableItem& operator=( const OSQLTableItem& ); | 43 | OSQLTableItem& operator=( const OSQLTableItem& ); |
42 | 44 | ||
43 | /** | 45 | /** |
44 | * the fieldName | 46 | * the fieldName |
45 | */ | 47 | */ |
46 | QString fieldName() const; | 48 | QString fieldName() const; |
47 | 49 | ||
48 | /** | 50 | /** |
49 | * the field Type | 51 | * the field Type |
50 | */ | 52 | */ |
51 | Type type() const; | 53 | Type type() const; |
52 | QVariant more() const; | 54 | QVariant more() const; |
53 | private: | 55 | private: |
54 | class OSQLTableItemPrivate; | 56 | class OSQLTableItemPrivate; |
55 | OSQLTableItemPrivate* d; | 57 | OSQLTableItemPrivate* d; |
56 | Type m_type; | 58 | Type m_type; |
57 | QString m_field; | 59 | QString m_field; |
58 | QVariant m_var; | 60 | QVariant m_var; |
59 | }; | 61 | }; |
60 | 62 | ||
61 | /** | 63 | /** |
62 | * A OSQLTable consists of OSQLTableItems | 64 | * A OSQLTable consists of OSQLTableItems |
63 | */ | 65 | */ |
64 | class OSQLTable { | 66 | class OSQLTable { |
65 | public: | 67 | public: |
66 | typedef QValueList<OSQLTable> ValueList; | 68 | typedef QValueList<OSQLTable> ValueList; |
67 | 69 | ||
68 | /** | 70 | /** |
69 | * @param tableName the Name of the Table | 71 | * @param tableName the Name of the Table |
70 | */ | 72 | */ |
71 | OSQLTable(const QString& tableName); | 73 | OSQLTable(const QString& tableName); |
72 | 74 | ||
73 | /** | 75 | /** |
74 | * d'tor | 76 | * d'tor |
75 | */ | 77 | */ |
76 | ~OSQLTable(); | 78 | ~OSQLTable(); |
77 | 79 | ||
78 | /** | 80 | /** |
79 | * setColumns sets the Columns of the Table | 81 | * setColumns sets the Columns of the Table |
80 | */ | 82 | */ |
81 | void setColumns( const OSQLTableItem::ValueList& ); | 83 | void setColumns( const OSQLTableItem::ValueList& ); |
82 | 84 | ||
83 | /** | 85 | /** |
84 | * returns all columns of the table | 86 | * returns all columns of the table |
85 | */ | 87 | */ |
86 | OSQLTableItem::ValueList columns() const; | 88 | OSQLTableItem::ValueList columns() const; |
87 | 89 | ||
88 | QString tableName()const; | 90 | QString tableName()const; |
89 | 91 | ||
90 | private: | 92 | private: |
91 | QString m_table; | 93 | QString m_table; |
92 | OSQLTableItem::ValueList m_list; | 94 | OSQLTableItem::ValueList m_list; |
95 | class Private; | ||
96 | Private *d; | ||
93 | }; | 97 | }; |
94 | 98 | ||
99 | } | ||
100 | } | ||
101 | |||
95 | #endif | 102 | #endif |