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
@@ -12,25 +12,25 @@ HEADERS = osqlbackend.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,15 +1,17 @@
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;
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,20 +1,23 @@
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
@@ -61,15 +64,20 @@ public:
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,17 +1,21 @@
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 );
@@ -35,24 +39,28 @@ namespace {
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() ) {
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,21 +1,25 @@
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 */
@@ -75,13 +79,16 @@ public:
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,14 +1,16 @@
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}
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,18 +1,21 @@
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 )
@@ -47,13 +50,15 @@ public:
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
@@ -31,24 +31,27 @@
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{
@@ -77,33 +80,33 @@ void OSQLiteDriver::setUrl( const QString& url ) {
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() {
@@ -117,25 +120,25 @@ bool OSQLiteDriver::close() {
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 {
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,19 +1,21 @@
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
@@ -22,36 +24,36 @@ OSQLBackEnd::ValueList OSQLManager::queryBackEnd() {
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 ) {
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,22 +1,24 @@
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 /**
@@ -50,15 +52,19 @@ public:
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,15 +1,17 @@
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 {
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,21 +1,24 @@
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;
@@ -38,24 +41,27 @@ 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*/
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
@@ -110,13 +116,15 @@ 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,15 +1,17 @@
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) {
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,21 +1,25 @@
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
@@ -98,15 +102,19 @@ public:
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,14 +1,16 @@
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}
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,19 +1,21 @@
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 };
@@ -81,15 +83,20 @@ public:
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