summaryrefslogtreecommitdiff
path: root/libopie2/opiedb
authorzecke <zecke>2004-03-13 19:51:45 (UTC)
committer zecke <zecke>2004-03-13 19:51:45 (UTC)
commit6d08277737e22b7a1527124623f3571969073ddf (patch) (unidiff)
tree4129e674e21df767b31299e873dd44e33a308e1b /libopie2/opiedb
parent8e28911f7199f4450ac5eef09482069f9b9caea2 (diff)
downloadopie-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
Diffstat (limited to 'libopie2/opiedb') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/TODO1
-rw-r--r--libopie2/opiedb/opiedb.pro2
-rw-r--r--libopie2/opiedb/osqlbackend.cpp2
-rw-r--r--libopie2/opiedb/osqlbackend.h8
-rw-r--r--libopie2/opiedb/osqlbackendmanager.cpp8
-rw-r--r--libopie2/opiedb/osqlbackendmanager.h6
-rw-r--r--libopie2/opiedb/osqldriver.cpp2
-rw-r--r--libopie2/opiedb/osqldriver.h7
-rw-r--r--libopie2/opiedb/osqlerror.cpp2
-rw-r--r--libopie2/opiedb/osqlerror.h5
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp9
-rw-r--r--libopie2/opiedb/osqlitedriver.h8
-rw-r--r--libopie2/opiedb/osqlmanager.cpp6
-rw-r--r--libopie2/opiedb/osqlmanager.h6
-rw-r--r--libopie2/opiedb/osqlquery.cpp2
-rw-r--r--libopie2/opiedb/osqlquery.h8
-rw-r--r--libopie2/opiedb/osqlresult.cpp2
-rw-r--r--libopie2/opiedb/osqlresult.h8
-rw-r--r--libopie2/opiedb/osqltable.cpp2
-rw-r--r--libopie2/opiedb/osqltable.h7
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 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = osqlbackend.h \ 4HEADERS = 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
13SOURCES = osqlbackend.cpp \ 13SOURCES = 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
22INTERFACES = 22INTERFACES =
23TARGET = opiedb2 23TARGET = opiedb2
24VERSION = 1.8.2 24VERSION = 1.9.0
25INCLUDEPATH = $(OPIEDIR)/include 25INCLUDEPATH = $(OPIEDIR)/include
26DEPENDPATH = $(OPIEDIR)/include 26DEPENDPATH = $(OPIEDIR)/include
27LIBS += -lopiecore2 -lqpe -lsqlite 27LIBS += -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
33contains( platform, x11 ) { 33contains( 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,27 +1,29 @@
1 1
2#include "osqlbackend.h" 2#include "osqlbackend.h"
3 3
4using namespace Opie::DB;
5
4 6
5OSQLBackEnd::OSQLBackEnd( const QString& name, 7OSQLBackEnd::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}
14OSQLBackEnd::OSQLBackEnd( const OSQLBackEnd& back ) { 16OSQLBackEnd::OSQLBackEnd( const OSQLBackEnd& back ) {
15 (*this) = back; 17 (*this) = back;
16} 18}
17OSQLBackEnd::~OSQLBackEnd() { 19OSQLBackEnd::~OSQLBackEnd() {
18} 20}
19bool OSQLBackEnd::operator==( const OSQLBackEnd& other ) { 21bool 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;
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,32 +1,35 @@
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
10namespace Opie {
11namespace 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 */
16class OSQLBackEnd /*: public QShared */ { 19class OSQLBackEnd /*: public QShared */ {
17public: 20public:
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& );
@@ -49,27 +52,32 @@ public:
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
66private: 69private:
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,70 +1,78 @@
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
6namespace { 10namespace {
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
53using namespace Opie::DB;
54
47OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) 55OSQLBackEndManager::OSQLBackEndManager( const QStringList& path )
48 :m_path( path ) 56 :m_path( path )
49{ 57{
50} 58}
51OSQLBackEndManager::~OSQLBackEndManager() { 59OSQLBackEndManager::~OSQLBackEndManager() {
52} 60}
53/** 61/**
54 * scan dirs 62 * scan dirs
55 */ 63 */
56OSQLBackEnd::ValueList OSQLBackEndManager::scan() { 64OSQLBackEnd::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 */
69OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { 77OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) {
70 OSQLBackEnd::ValueList list; 78 OSQLBackEnd::ValueList list;
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
8namespace Opie {
9namespace DB {
10
8class OSQLBackEndManager { 11class OSQLBackEndManager {
9public: 12public:
10 OSQLBackEndManager(const QStringList& path ); 13 OSQLBackEndManager(const QStringList& path );
11 ~OSQLBackEndManager(); 14 ~OSQLBackEndManager();
12 OSQLBackEnd::ValueList scan(); 15 OSQLBackEnd::ValueList scan();
13private: 16private:
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
5using namespace Opie::DB;
6
5OSQLDriver::OSQLDriver( QLibrary* lib ) 7OSQLDriver::OSQLDriver( QLibrary* lib )
6: QObject(), m_lib(lib) { 8: QObject(), m_lib(lib) {
7} 9}
8OSQLDriver::~OSQLDriver() { 10OSQLDriver::~OSQLDriver() {
9 delete m_lib; 11 delete m_lib;
10} 12}
11bool OSQLDriver::sync() { 13bool 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,33 +1,37 @@
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
9class QLibrary; 9class QLibrary;
10
11namespace Opie {
12namespace DB {
13
10class OSQLResult; 14class OSQLResult;
11class OSQLQuery; 15class OSQLQuery;
12class OSQLError; 16class 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 */
22class OSQLDriver : public QObject{ 26class OSQLDriver : public QObject{
23 Q_OBJECT 27 Q_OBJECT
24public: 28public:
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();
@@ -63,25 +67,28 @@ public:
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
80private: 84private:
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
3using namespace Opie::DB;
4
3OSQLError::OSQLError( const QString& driverText, 5OSQLError::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}
10OSQLError::~OSQLError() { 12OSQLError::~OSQLError() {
11} 13}
12QString OSQLError::driverText()const { 14QString OSQLError::driverText()const {
13 return m_drvText; 15 return m_drvText;
14} 16}
15QString OSQLError::databaseText()const { 17QString OSQLError::databaseText()const {
16 return m_drvDBText; 18 return m_drvDBText;
17} 19}
18int OSQLError::type()const { 20int OSQLError::type()const {
19 return m_type; 21 return m_type;
20} 22}
21int OSQLError::subNumber()const { 23int 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,30 +1,33 @@
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
8namespace Opie {
9namespace DB {
7/** 10/**
8 * OSQLError is the base class of all errors 11 * OSQLError is the base class of all errors
9 */ 12 */
10class OSQLError { 13class OSQLError {
11public: 14public:
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
@@ -35,25 +38,27 @@ public:
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;
50private: 53private:
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
@@ -19,135 +19,138 @@
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
43using namespace Opie::DB;
44using namespace Opie::DB::Private;
45
43namespace { 46namespace {
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
52OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) 55OSQLiteDriver::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
59OSQLiteDriver::~OSQLiteDriver() { 62OSQLiteDriver::~OSQLiteDriver() {
60 close(); 63 close();
61} 64}
62 65
63 66
64QString OSQLiteDriver::id()const { 67QString OSQLiteDriver::id()const {
65 return QString::fromLatin1("SQLite"); 68 return QString::fromLatin1("SQLite");
66} 69}
67 70
68void OSQLiteDriver::setUserName( const QString& ) {} 71void OSQLiteDriver::setUserName( const QString& ) {}
69 72
70 73
71void OSQLiteDriver::setPassword( const QString& ) {} 74void OSQLiteDriver::setPassword( const QString& ) {}
72 75
73 76
74void OSQLiteDriver::setUrl( const QString& url ) { 77void OSQLiteDriver::setUrl( const QString& url ) {
75 m_url = url; 78 m_url = url;
76} 79}
77 80
78 81
79void OSQLiteDriver::setOptions( const QStringList& ) { 82void 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 */
87bool OSQLiteDriver::open() { 90bool 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 */
109bool OSQLiteDriver::close() { 112bool 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 */
118OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 121OSQLResult 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
141OSQLTable::ValueList OSQLiteDriver::tables() const { 144OSQLTable::ValueList OSQLiteDriver::tables() const {
142 145
143} 146}
144 147
145 148
146OSQLError OSQLiteDriver::lastError() { 149OSQLError 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
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
10namespace Opie {
11namespace DB {
12namespace Private {
13
10class OSQLiteDriver : public OSQLDriver { 14class OSQLiteDriver : public OSQLDriver {
11 Q_OBJECT 15 Q_OBJECT
12public: 16public:
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;
25private: 29private:
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,69 +1,71 @@
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
8using namespace Opie::DB;
9
8OSQLManager::OSQLManager() { 10OSQLManager::OSQLManager() {
9} 11}
10OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { 12OSQLBackEnd::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 */
30OSQLDriver* OSQLManager::load( const QString& name ) { 32OSQLDriver* 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 */
41OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { 43OSQLDriver* 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 */
52OSQLDriver* OSQLManager::standard() { 54OSQLDriver* 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}
66void OSQLManager::registerPath( const QString& path ) { 68void OSQLManager::registerPath( const QString& path ) {
67 m_path << path; 69 m_path << path;
68} 70}
69bool OSQLManager::unregisterPath( const QString& path ) { 71bool OSQLManager::unregisterPath( const QString& path ) {
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,34 +1,36 @@
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
11namespace Opie {
12namespace 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 */
18class OSQLDriver; 20class OSQLDriver;
19class OSQLManager : public QObject { 21class OSQLManager : public QObject {
20 Q_OBJECT 22 Q_OBJECT
21public: 23public:
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 */
@@ -38,27 +40,31 @@ public:
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 );
58private: 60private:
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
4using namespace Opie::DB;
5
4OSQLQuery::OSQLQuery() { 6OSQLQuery::OSQLQuery() {
5} 7}
6OSQLQuery::~OSQLQuery() { 8OSQLQuery::~OSQLQuery() {
7} 9}
8 10
9OSQLRawQuery::OSQLRawQuery(const QString& query) 11OSQLRawQuery::OSQLRawQuery(const QString& query)
10 : OSQLQuery(), m_query( query ) { 12 : OSQLQuery(), m_query( query ) {
11 13
12} 14}
13OSQLRawQuery::~OSQLRawQuery() { 15OSQLRawQuery::~OSQLRawQuery() {
14} 16}
15QString OSQLRawQuery::query()const { 17QString 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,73 +1,79 @@
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
10namespace Opie {
11namespace DB {
12
10/** I'm not happy with them 13/** I'm not happy with them
11class OSQLQueryOrder { 14class OSQLQueryOrder {
12public: 15public:
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& );
23private: 26private:
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};
28class OSQLWhere { 31class OSQLWhere {
29public: 32public:
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;
37private: 40private:
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*/
44class OSQLQuery { 47class OSQLQuery {
45public: 48public:
46 OSQLQuery(); 49 OSQLQuery();
47 virtual ~OSQLQuery(); 50 virtual ~OSQLQuery();
48 51
49 virtual QString query()const = 0; 52 virtual QString query()const = 0;
53private:
54 class Private;
55 Private *d;
50}; 56};
51 57
52class OSQLRawQuery : public OSQLQuery { 58class OSQLRawQuery : public OSQLQuery {
53public: 59public:
54 OSQLRawQuery( const QString& query ); 60 OSQLRawQuery( const QString& query );
55 ~OSQLRawQuery(); 61 ~OSQLRawQuery();
56 QString query() const; 62 QString query() const;
57private: 63private:
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
64class OSQLSelectQuery : public OSQLQuery { 70class OSQLSelectQuery : public OSQLQuery {
65public: 71public:
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& );
@@ -98,25 +104,27 @@ 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;
103private: 109private:
104 QString m_table; 110 QString m_table;
105 OSQLWhere::ValueList m_where; 111 OSQLWhere::ValueList m_where;
106 112
107}; 113};
108class OSQLUpdateQuery : public OSQLQuery { 114class OSQLUpdateQuery : public OSQLQuery {
109public: 115public:
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,27 +1,29 @@
1 1
2#include "osqlresult.h" 2#include "osqlresult.h"
3 3
4using namespace Opie::DB;
5
4OSQLResultItem::OSQLResultItem( const TableString& string, 6OSQLResultItem::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}
10OSQLResultItem::~OSQLResultItem() { 12OSQLResultItem::~OSQLResultItem() {
11} 13}
12OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { 14OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) {
13 *this = item; 15 *this = item;
14} 16}
15OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { 17OSQLResultItem &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}
20OSQLResultItem::TableString OSQLResultItem::tableString()const{ 22OSQLResultItem::TableString OSQLResultItem::tableString()const{
21 return m_string; 23 return m_string;
22} 24}
23OSQLResultItem::TableInt OSQLResultItem::tableInt()const { 25OSQLResultItem::TableInt OSQLResultItem::tableInt()const {
24 return m_int; 26 return m_int;
25} 27}
26QString OSQLResultItem::data( const QString& columnName, bool *ok ) { 28QString OSQLResultItem::data( const QString& columnName, bool *ok ) {
27 TableString::Iterator it = m_string.find( columnName ); 29 TableString::Iterator it = m_string.find( columnName );
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,33 +1,37 @@
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
11namespace Opie {
12namespace DB {
13
10/** 14/**
11 * ResultItem represents one row of the resulting answer 15 * ResultItem represents one row of the resulting answer
12 */ 16 */
13class OSQLResultItem { 17class OSQLResultItem {
14public: 18public:
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& );
@@ -86,27 +90,31 @@ public:
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;
105private: 109private:
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,26 +1,28 @@
1#include "osqltable.h" 1#include "osqltable.h"
2 2
3using namespace Opie::DB;
4
3OSQLTableItem::OSQLTableItem() {} 5OSQLTableItem::OSQLTableItem() {}
4OSQLTableItem::OSQLTableItem( enum Type type, 6OSQLTableItem::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}
11OSQLTableItem::~OSQLTableItem() {} 13OSQLTableItem::~OSQLTableItem() {}
12OSQLTableItem::OSQLTableItem( const OSQLTableItem& item) { 14OSQLTableItem::OSQLTableItem( const OSQLTableItem& item) {
13 *this = item; 15 *this = item;
14} 16}
15OSQLTableItem &OSQLTableItem::operator=(const OSQLTableItem& other) { 17OSQLTableItem &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}
21QString OSQLTableItem::fieldName()const{ 23QString OSQLTableItem::fieldName()const{
22 return m_field; 24 return m_field;
23} 25}
24OSQLTableItem::Type OSQLTableItem::type()const { 26OSQLTableItem::Type OSQLTableItem::type()const {
25 return m_type; 27 return m_type;
26} 28}
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,31 +1,33 @@
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
8namespace Opie {
9namespace 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 */
12class OSQLTableItem { 14class OSQLTableItem {
13public: 15public:
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 /**
@@ -69,27 +71,32 @@ public:
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
90private: 92private:
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