summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libsql/DESIGN19
-rw-r--r--libsql/TODO9
-rw-r--r--libsql/libopiesql.pro27
-rw-r--r--libsql/osqlbackend.cpp73
-rw-r--r--libsql/osqlbackend.h75
-rw-r--r--libsql/osqlbackendmanager.cpp99
-rw-r--r--libsql/osqldriver.cpp13
-rw-r--r--libsql/osqldriver.h87
-rw-r--r--libsql/osqlerror.cpp23
-rw-r--r--libsql/osqlerror.h59
-rw-r--r--libsql/osqlitedriver.h34
-rw-r--r--libsql/osqlmanager.cpp83
-rw-r--r--libsql/osqlmanager.h62
-rw-r--r--libsql/osqlquery.cpp17
-rw-r--r--libsql/osqlquery.h122
-rw-r--r--libsql/osqlresult.cpp127
-rw-r--r--libsql/osqlresult.h112
-rw-r--r--libsql/osqltable.cpp46
-rw-r--r--libsql/osqltable.h95
-rw-r--r--libsql/test/main.cpp29
-rw-r--r--libsql/test/spaltenweise.cpp41
-rw-r--r--libsql/test/spaltenweise.pro9
-rw-r--r--libsql/test/test.osql4
-rw-r--r--libsql/test/test.pro9
-rw-r--r--libsql/test/test2.osql5
-rw-r--r--libsql/test/zeilenweise.cpp84
-rw-r--r--libsql/test/zeilenweise.pro9
27 files changed, 1372 insertions, 0 deletions
diff --git a/libsql/DESIGN b/libsql/DESIGN
new file mode 100644
index 0000000..a6c7217
--- a/dev/null
+++ b/libsql/DESIGN
@@ -0,0 +1,19 @@
1Design of OpieSQL
2
3My intention for OpieSQL was to write
4a simple c++ interface which would allow
5easy use of common database functions on
6different backends
7
8How does these goals reflect the current Implementation
9
10-through OSQLManager + OSQLBackEnd I'll be able to change
11the default db driver and be able to add new
12driver implementations
13
14-OSQLQuery, RawQuery, SelectQuery allows a flexible and
15OO way of fast querying databases
16
17-much more ;)
18
19
diff --git a/libsql/TODO b/libsql/TODO
new file mode 100644
index 0000000..ca04ac6
--- a/dev/null
+++ b/libsql/TODO
@@ -0,0 +1,9 @@
1* something like Capabilities of a Driver
2 - ROWID
3 - How to declare INTEGER PRIMARY KEY
4 - Abstract from implementation of some dbs
5 - provides( Type::What )
6
7 * OSQLDriver DriverVersion - DatabaseVersion
8 * Better OSQLQueries
9 - more than OSQLRawQuery \ No newline at end of file
diff --git a/libsql/libopiesql.pro b/libsql/libopiesql.pro
new file mode 100644
index 0000000..cc20ace
--- a/dev/null
+++ b/libsql/libopiesql.pro
@@ -0,0 +1,27 @@
1TEMPLATE = lib
2CONFIG += qte warn_on release
3 HEADERS = osqlbackend.h \
4 osqldriver.h \
5 osqlerror.h \
6 osqlmanager.h \
7 osqlquery.h \
8 osqlresult.h \
9 osqltable.h \
10 osqlbackendmanager.h \
11 osqlitedriver.h
12 SOURCES = osqlbackend.cpp \
13 osqldriver.cpp \
14 osqlerror.cpp \
15 osqlmanager.cpp \
16 osqlquery.cpp \
17 osqlresult.cpp \
18 osqltable.cpp \
19 osqlbackendmanager.cpp \
20 osqlitedriver.cpp
21
22 TARGET = opiesql
23INCLUDEPATH += $(OPIEDIR)/include
24DESTDIR = $(QTDIR)/lib$(PROJMAK)
25LIBS += -lsqlite
26#VERSION = 1.0.0
27
diff --git a/libsql/osqlbackend.cpp b/libsql/osqlbackend.cpp
new file mode 100644
index 0000000..d6c39a9
--- a/dev/null
+++ b/libsql/osqlbackend.cpp
@@ -0,0 +1,73 @@
1
2#include "osqlbackend.h"
3
4
5OSQLBackEnd::OSQLBackEnd( const QString& name,
6 const QString& vendor,
7 const QString& license,
8 const QCString& lib )
9 : m_name( name), m_vendor( vendor), m_license( license ), m_lib( lib )
10{
11 m_default = false;
12 m_pref = -1;
13}
14OSQLBackEnd::OSQLBackEnd( const OSQLBackEnd& back ) {
15 (*this) = back;
16}
17OSQLBackEnd::~OSQLBackEnd() {
18}
19bool OSQLBackEnd::operator==( const OSQLBackEnd& other ) {
20 if ( m_pref != other.m_pref ) return false;
21 if ( m_default != other.m_default ) return false;
22 if ( m_name != other.m_name ) return false;
23 if ( m_vendor != other.m_vendor ) return false;
24 if ( m_license != other.m_license ) return false;
25 if ( m_lib != other.m_lib ) return false;
26
27 return true;
28}
29OSQLBackEnd &OSQLBackEnd::operator=(const OSQLBackEnd& back ) {
30 m_name = back.m_name;
31 m_vendor = back.m_vendor;
32 m_license = back.m_license;
33 m_lib = back.m_lib;
34 m_pref = back.m_pref;
35 m_default = back.m_default;
36 return *this;
37}
38QString OSQLBackEnd::name() const {
39 return m_name;
40}
41QString OSQLBackEnd::vendor() const {
42 return m_vendor;
43}
44QString OSQLBackEnd::license() const {
45 return m_license;
46}
47QCString OSQLBackEnd::library() const {
48 return m_lib;
49}
50bool OSQLBackEnd::isDefault()const {
51 return m_default;
52}
53int OSQLBackEnd::preference()const {
54 return m_pref;
55}
56void OSQLBackEnd::setName( const QString& name ) {
57 m_name = name;
58}
59void OSQLBackEnd::setVendor( const QString& vendor ) {
60 m_vendor = vendor;
61}
62void OSQLBackEnd::setLicense( const QString & license ) {
63 m_license = license;
64}
65void OSQLBackEnd::setLibrary( const QCString& lib ) {
66 m_lib = lib;
67}
68void OSQLBackEnd::setDefault( bool def) {
69 m_default = def;
70}
71void OSQLBackEnd::setPreference( int pref ) {
72 m_pref = pref;
73}
diff --git a/libsql/osqlbackend.h b/libsql/osqlbackend.h
new file mode 100644
index 0000000..ad879a4
--- a/dev/null
+++ b/libsql/osqlbackend.h
@@ -0,0 +1,75 @@
1
2#ifndef OSQL_BACKEND_H
3#define OSQL_BACKEND_H
4
5#include <qcstring.h>
6#include <qstring.h>
7#include <qvaluelist.h>
8
9/**
10 * OSQLBackEnd represents an available backend
11 * to the Opie Database Service
12 * It's used to easily extend OSQL services by
13 * 3rd party plugins.
14 * It's used to show
15 */
16class OSQLBackEnd /*: public QShared */ {
17public:
18 typedef QValueList<OSQLBackEnd> ValueList;
19 /**
20 * A basic c'tor
21 * @param name the user visible name of the service
22 * @param vendor the vendor of the service
23 * @param license the license of the service
24 * @param library what is the name of lib if builtin it's builtin
25 */
26 OSQLBackEnd( const QString& name = QString::null,
27 const QString& vendor = QString::null,
28 const QString& license = QString::null,
29 const QCString& library = QCString() );
30 OSQLBackEnd( const OSQLBackEnd& );
31 OSQLBackEnd &operator=( const OSQLBackEnd& );
32 bool operator==(const OSQLBackEnd& );
33
34 ~OSQLBackEnd();
35
36 /** @return the name */
37 QString name()const;
38
39 /** @return the vendor */
40 QString vendor()const;
41
42 /** @return the license */
43 QString license()const;
44
45 /** @return the name of the library */
46 QCString library() const;
47
48 bool isDefault()const;
49 int preference()const;
50
51 /** @param name the name to set */
52 void setName( const QString& name );
53
54 /** @param vendor the vendor to set */
55 void setVendor( const QString& vendor );
56
57 /** @param license the license applied */
58 void setLicense( const QString& license );
59
60 /** @param the lib to set */
61 void setLibrary( const QCString& lib );
62
63 void setDefault( bool );
64 void setPreference( int );
65
66private:
67 QString m_name;
68 QString m_vendor;
69 QString m_license;
70 QCString m_lib;
71 bool m_default :1;
72 int m_pref;
73};
74
75#endif
diff --git a/libsql/osqlbackendmanager.cpp b/libsql/osqlbackendmanager.cpp
new file mode 100644
index 0000000..0f261b9
--- a/dev/null
+++ b/libsql/osqlbackendmanager.cpp
@@ -0,0 +1,99 @@
1#include <qdir.h>
2#include <qfile.h>
3#include <qmap.h>
4
5#include "osqlbackendmanager.h"
6
7namespace {
8 class Config {
9 typedef QMap<QString, QString> List;
10 public:
11 Config( const QString& fileName );
12 /**
13 * Quite simple layout in nature
14 * BeginFile
15 * Key = Value
16 */
17 bool load();
18 QString value( const QString& key );
19 private:
20 List m_list;
21 QString m_fileName;
22 };
23 Config::Config( const QString& fileName )
24 : m_fileName( fileName ) {
25 }
26
27 bool Config::load() {
28 if (!QFile::exists( m_fileName ) )
29 return false;
30 QFile file( m_fileName );
31 if (!file.open(IO_ReadOnly ) )
32 return false;
33 QStringList list = QStringList::split( '\n', file.readAll() );
34 QStringList::Iterator it;
35 QString line;
36 for (it = list.begin(); it != list.end(); ++it ) {
37 line = (*it).stripWhiteSpace();
38 qWarning("Anonymous::Config:" + line );
39 QStringList test = QStringList::split(' ', line );
40 m_list.insert( test[0], test[2] );
41 }
42 return true;
43 }
44 QString Config::value( const QString& key ) {
45 return m_list[key];
46 }
47};
48OSQLBackEndManager::OSQLBackEndManager( const QStringList& path )
49 :m_path( path )
50{
51}
52OSQLBackEndManager::~OSQLBackEndManager() {
53}
54/**
55 * scan dirs
56 */
57OSQLBackEnd::ValueList OSQLBackEndManager::scan() {
58 OSQLBackEnd::ValueList list;
59 if (!m_path.isEmpty() ) {
60 QStringList::Iterator it;
61 for ( it = m_path.begin(); it != m_path.end(); ++it ) {
62 list += scanDir( (*it) );
63 }
64 }
65 return list;
66}
67/**
68 * scan a specified dir for *.osql
69 */
70OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) {
71 OSQLBackEnd::ValueList list;
72 QDir dir( dirName );
73 if (dir.exists() ) {
74 QStringList files = dir.entryList( "*.osql" );
75 QStringList::Iterator it;
76 for ( it = files.begin(); it != files.end(); ++it ) {
77 list.append( file2backend( (*it) ) );
78 }
79 }
80 return list;
81}
82
83/**
84 * read a config file and convert it to a OSQLBackEnd
85 */
86OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) {
87 OSQLBackEnd end;
88 qWarning("fileName: " + file );
89 Config cfg( file );
90 if (cfg.load() ) {
91 end.setName( cfg.value( "Name") );
92 end.setVendor( cfg.value("Vendor") );
93 end.setLicense( cfg.value("License") );
94 end.setLibrary( cfg.value("Library").local8Bit() );
95 end.setDefault( cfg.value("Default").toInt() );
96 end.setPreference( cfg.value("Preference").toInt() );
97 }
98 return end;
99}
diff --git a/libsql/osqldriver.cpp b/libsql/osqldriver.cpp
new file mode 100644
index 0000000..258c116
--- a/dev/null
+++ b/libsql/osqldriver.cpp
@@ -0,0 +1,13 @@
1#include <qpe/qlibrary.h>
2
3#include "osqldriver.h"
4
5OSQLDriver::OSQLDriver( QLibrary* lib )
6: QObject(), m_lib(lib) {
7}
8OSQLDriver::~OSQLDriver() {
9 delete m_lib;
10}
11bool OSQLDriver::sync() {
12 return true;
13}
diff --git a/libsql/osqldriver.h b/libsql/osqldriver.h
new file mode 100644
index 0000000..68d8ee6
--- a/dev/null
+++ b/libsql/osqldriver.h
@@ -0,0 +1,87 @@
1#ifndef OSQL_DRIVER_H
2#define OSQL_DRIVER_H
3
4#include <qobject.h>
5#include <qstring.h>
6
7#include "osqltable.h"
8
9class QLibrary;
10class OSQLResult;
11class OSQLQuery;
12class OSQLError;
13
14/**
15 * A OSQLDriver implements the communication with
16 * a database.
17 * After you queried and loaded a driver you can
18 * set some informations and finally try to open
19 * the database
20 *
21 */
22class OSQLDriver : public QObject{
23 Q_OBJECT
24public:
25 enum Capabilities { RowID=0 };
26 /**
27 * OSQLDriver constructor. It takes the QLibrary
28 * as parent.
29 *
30 */
31 OSQLDriver( QLibrary* lib=0 );
32
33 virtual ~OSQLDriver();
34 /**
35 * Id returns the identifier of the OSQLDriver
36 */
37 virtual QString id()const = 0;
38
39 /**
40 * set the UserName to the database
41 */
42 virtual void setUserName( const QString& ) = 0;
43
44 /**
45 * set the PassWord to the database
46 */
47 virtual void setPassword( const QString& )= 0;
48
49 /**
50 * set the Url
51 */
52 virtual void setUrl( const QString& ) = 0;
53
54 /**
55 * setOptions
56 */
57 virtual void setOptions( const QStringList& ) = 0;
58
59 /**
60 * tries to open a connection to the database
61 */
62 virtual bool open() = 0;
63 virtual bool close() = 0;
64
65 virtual OSQLError lastError() = 0;
66
67 /**
68 * Query the Database with a OSQLQuery
69 * OSQLResult holds the result
70 */
71 virtual OSQLResult query( OSQLQuery* ) = 0;
72
73 /**
74 * Get a list of tables
75 */
76 virtual OSQLTable::ValueList tables() const = 0l;
77 virtual bool sync();
78
79
80private:
81 QLibrary* m_lib;
82 class OSQLDriverPrivate;
83 OSQLDriverPrivate *d;
84
85};
86
87#endif
diff --git a/libsql/osqlerror.cpp b/libsql/osqlerror.cpp
new file mode 100644
index 0000000..3890a50
--- a/dev/null
+++ b/libsql/osqlerror.cpp
@@ -0,0 +1,23 @@
1#include "osqlerror.h"
2
3OSQLError::OSQLError( const QString& driverText,
4 const QString& driverDatabaseText,
5 int type, int subType )
6 : m_drvText( driverText ), m_drvDBText( driverDatabaseText ),
7 m_type( type ), m_number( subType )
8{
9}
10OSQLError::~OSQLError() {
11}
12QString OSQLError::driverText()const {
13 return m_drvText;
14}
15QString OSQLError::databaseText()const {
16 return m_drvDBText;
17}
18int OSQLError::type()const {
19 return m_type;
20}
21int OSQLError::subNumber()const {
22 return m_number;
23}
diff --git a/libsql/osqlerror.h b/libsql/osqlerror.h
new file mode 100644
index 0000000..35a4368
--- a/dev/null
+++ b/libsql/osqlerror.h
@@ -0,0 +1,59 @@
1#ifndef OSQL_ERROR_H
2#define OSQL_ERROR_H
3
4#include <qstring.h>
5#include <qvaluelist.h>
6
7/**
8 * OSQLError is the base class of all errors
9 */
10class OSQLError {
11public:
12 typedef QValueList<OSQLError> ValueList;
13 enum Type { None = 0, // NoError
14 Internal, // Internal Error in OSQL
15 Unknown, // Unknown Error
16 Transaction, // Transaction Error
17 Statement, // Wrong Statement
18 Connection, // Connection Error( lost )
19 Driver // Driver Specefic error
20 };
21 enum DriverError {
22 DriverInternal=0, // internal DriverError
23 Permission, // Permission Problem
24 Abort, // Abort of the SQL
25 Busy, // Busy Error
26 Locked, // Locked
27 NoMem, // No Memory
28 ReadOnly, // Database is read only
29 Interrupt, // Interrupt
30 IOErr, // IO Error
31 Corrupt, // Database Corruption
32 NotFound, // Table not Found
33 Full, // Full
34 CantOpen, // Can not open Table/Database
35 Protocol, // internal protocol error
36 Schema, // schema changed
37 TooBig, // Data too big
38 Mismatch, // Type mismatch
39 Misuse // misuse
40 };
41 OSQLError( const QString& driverText = QString::null,
42 const QString& driverDatabaseText = QString::null,
43 int type = None, int subNumber = -1 );
44 ~OSQLError();
45
46 QString driverText()const;
47 QString databaseText()const;
48 int type()const;
49 int subNumber()const;
50private:
51 QString m_drvText;
52 QString m_drvDBText;
53 int m_type;
54 int m_number;
55 class OSQLErrorPrivate;
56 OSQLErrorPrivate* d;
57};
58
59#endif
diff --git a/libsql/osqlitedriver.h b/libsql/osqlitedriver.h
new file mode 100644
index 0000000..6984539
--- a/dev/null
+++ b/libsql/osqlitedriver.h
@@ -0,0 +1,34 @@
1#ifndef OSQL_LITE_DRIVER_H
2#define OSQL_LITE_DRIVER_H
3
4#include <sqlite.h>
5
6#include "osqldriver.h"
7#include "osqlerror.h"
8#include "osqlresult.h"
9
10class OSQLiteDriver : public OSQLDriver {
11 Q_OBJECT
12public:
13 OSQLiteDriver( QLibrary *lib = 0l );
14 ~OSQLiteDriver();
15 QString id()const;
16 void setUserName( const QString& );
17 void setPassword( const QString& );
18 void setUrl( const QString& url );
19 void setOptions( const QStringList& );
20 bool open();
21 bool close();
22 OSQLError lastError();
23 OSQLResult query( OSQLQuery* );
24 OSQLTable::ValueList tables()const;
25private:
26 OSQLError m_lastE;
27 OSQLResult m_result;
28 OSQLResultItem m_items;
29 int handleCallBack( int, char**, char** );
30 static int call_back( void*, int, char**, char** );
31 QString m_url;
32 sqlite *m_sqlite;
33};
34#endif
diff --git a/libsql/osqlmanager.cpp b/libsql/osqlmanager.cpp
new file mode 100644
index 0000000..b0fea04
--- a/dev/null
+++ b/libsql/osqlmanager.cpp
@@ -0,0 +1,83 @@
1
2#include <stdlib.h>
3
4#include "osqlbackend.h"
5#include "osqldriver.h"
6#include "osqlmanager.h"
7#include "osqlbackendmanager.h"
8#include "osqlitedriver.h"
9
10OSQLManager::OSQLManager() {
11}
12OSQLBackEnd::ValueList OSQLManager::queryBackEnd() {
13 m_list.clear();
14 QString opie = QString::fromLatin1( getenv("OPIEDIR") );
15 QString qpe = QString::fromLatin1( getenv("QPEDIR") );
16
17 if ( !m_path.contains(opie) && !opie.isEmpty() )
18 m_path << opie;
19 if ( !m_path.contains(qpe) && !qpe.isEmpty() )
20 m_path << qpe;
21
22 OSQLBackEndManager mng( m_path );
23 m_list = mng.scan();
24 m_list += builtIn();
25
26 return m_list;
27}
28/*
29 * loading dso's is currently not enabled due problems with QLibrary
30 * beeing in libqpe and not libqte
31 */
32OSQLDriver* OSQLManager::load( const QString& name ) {
33 OSQLDriver* driver = 0l;
34
35 if ( name == "SQLite" ) {
36 driver = new OSQLiteDriver();
37 }
38 return driver;
39}
40/*
41 * same as above
42 */
43OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) {
44 OSQLDriver *driver = 0l;
45 if ( end.library() == "builtin" &&
46 end.name() == "SQLite" )
47 driver = new OSQLiteDriver();
48
49 return driver;
50}
51/*
52 * let's find the a default with the highes preference
53 */
54OSQLDriver* OSQLManager::standard() {
55 OSQLDriver* driver =0l;
56 if ( m_list.isEmpty() ) queryBackEnd();
57 OSQLBackEnd::ValueList::Iterator it;
58 OSQLBackEnd back;
59 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
60 if ( (*it).isDefault() &&
61 back.preference() < (*it).preference() ) {
62 back = (*it);
63 }
64 }
65 driver = load( back );
66 return driver;
67}
68void OSQLManager::registerPath( const QString& path ) {
69 m_path << path;
70}
71bool OSQLManager::unregisterPath( const QString& path ) {
72 m_path.remove( path );
73 return true;
74}
75OSQLBackEnd::ValueList OSQLManager::builtIn()const {
76 OSQLBackEnd::ValueList list;
77 // create the OSQLiteBackend
78 OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" );
79 back.setDefault( true );
80 back.setPreference( 50 );
81 list.append( back );
82 return list;
83}
diff --git a/libsql/osqlmanager.h b/libsql/osqlmanager.h
new file mode 100644
index 0000000..b3d8d69
--- a/dev/null
+++ b/libsql/osqlmanager.h
@@ -0,0 +1,62 @@
1
2#ifndef OSQL_MANAGER_H
3#define OSQL_MANAGER_H
4
5#include <qobject.h>
6
7#include "osqlbackend.h"
8
9/**
10 * OSQLManager is responsible for loading
11 * and unloading, querying different OSQL
12 * services
13 * Load a OSQLDriver and delete it yourself
14 *
15 */
16class OSQLDriver;
17class OSQLManager : public QObject {
18 Q_OBJECT
19public:
20 /**
21 * Empty c'tor
22 */
23 OSQLManager();
24
25 /**
26 * Query the Manager for different backends
27 */
28 OSQLBackEnd::ValueList queryBackEnd();
29
30 /**
31 * Load a backend with it's name from param name
32 */
33 OSQLDriver* load( const QString& name );
34
35 /**
36 * Load a OSQLDevice from const reference of OSQLBackEnd
37 */
38 OSQLDriver* load( const OSQLBackEnd& );
39
40 /**
41 * loads the Opie standard backend
42 */
43 OSQLDriver *standard();
44
45 /**
46 * register path to the search path list
47 * When querying for services we scan all the
48 * registered path for backends
49 */
50 void registerPath( const QString& path );
51
52 /**
53 * unregisterPath from the search path list
54 */
55 bool unregisterPath( const QString& path );
56private:
57 OSQLBackEnd::ValueList builtIn()const;
58 OSQLBackEnd::ValueList m_list;
59 QStringList m_path;
60};
61
62#endif
diff --git a/libsql/osqlquery.cpp b/libsql/osqlquery.cpp
new file mode 100644
index 0000000..ecd53f2
--- a/dev/null
+++ b/libsql/osqlquery.cpp
@@ -0,0 +1,17 @@
1
2#include "osqlquery.h"
3
4OSQLQuery::OSQLQuery() {
5}
6OSQLQuery::~OSQLQuery() {
7}
8
9OSQLRawQuery::OSQLRawQuery(const QString& query)
10 : OSQLQuery(), m_query( query ) {
11
12}
13OSQLRawQuery::~OSQLRawQuery() {
14}
15QString OSQLRawQuery::query()const {
16 return m_query;
17}
diff --git a/libsql/osqlquery.h b/libsql/osqlquery.h
new file mode 100644
index 0000000..63c26b0
--- a/dev/null
+++ b/libsql/osqlquery.h
@@ -0,0 +1,122 @@
1
2#ifndef OSQL_QUERY_H
3#define OSQL_QUERY_H
4
5#include <qmap.h>
6#include <qvaluelist.h>
7#include <qstring.h>
8
9
10/** I'm not happy with them
11class OSQLQueryOrder {
12public:
13 typedef QValueList<OSQLQueryOrder> ValueList;
14 OSQLQueryOrder(const QString& table = QString::null );
15 OSQLQueryOrder( const OSQLQueryOrder& );
16 ~OSQLQueryOrder();
17 void setOrderFields( const QStringList& list );
18 void setValue( const QString& fieldName, const QString& Value );
19 void setValues( const QMap<QString, QString>& );
20 QMap<QString, QString> orders() const;
21 QString orderStatement()const;
22 OSQLQueryOrder &operator=(const OSQLQueryOrder& );
23private:
24 QMap<QString, QString> m_fields;
25 class OSQLQueryOrderPrivate;
26 OSQLQueryOrderPrivate* d;
27};
28class OSQLWhere {
29public:
30 typedef QValueList<OSQLWhere> ValueList;
31 enum Vergleiche { Equal = 0, Like, Greater, GreaterEqual,
32 Smaller, SmallerEqual };
33 OSQLWhere(const QString& table = QString::null );
34 ~OSQLWhere();
35 void setExpression(const QString& key, enum Vergleiche, const QString& );
36 QString statement()const;
37private:
38 int m_vergleich;
39 const QString& m_left;
40 const QString& m_right;
41
42};
43*/
44class OSQLQuery {
45public:
46 OSQLQuery();
47 virtual ~OSQLQuery();
48
49 virtual QString query()const = 0;
50};
51
52class OSQLRawQuery : public OSQLQuery {
53public:
54 OSQLRawQuery( const QString& query );
55 ~OSQLRawQuery();
56 QString query() const;
57private:
58 class OSQLRawQueryPrivate;
59 OSQLRawQueryPrivate* d;
60 QString m_query;
61
62};
63/* I'm not happy with them again
64class OSQLSelectQuery : public OSQLQuery {
65public:
66 OSQLSelectQuery();
67 ~OSQLSelectQuery();
68 void setTables( const QStringList& allTablesToQuery );
69 void setValues( const QString& table, const QStringList& columns );
70 void setOrder( const OSQLSelectQuery& );
71 void setOrderList( const OSQLQueryOrder::ValueList& );
72 void setWhereList( const OSQLWhere& );
73 void setWhereList( const OSQLWhere::ValueList& );
74 QString query()const;
75private:
76 QStringList m_tables;
77 QMap<QString, QStringList> m_values;
78 OSQLQueryOrder::ValueList m_order;
79 OSQLWhere::ValueList m_where;
80 class OSQLSelectQueryPrivate;
81 OSQLSelectQueryPrivate* d;
82};
83class OSQLInsertQuery : public OSQLQuery {
84public:
85 OSQLInsertQuery(const QString& table);
86 ~OSQLInsertQuery();
87 void setInserFields( const QStringList& );
88 void setValue( const QString& field, const QString& value );
89 void setValues(const QMap<QString, QString>& );
90 QString query()const;
91private:
92 QString m_table;
93 QStringList m_fields;
94 QMap<QString, QString> m_values;
95};
96class OSQLDeleteQuery : public OSQLQuery {
97public:
98 OSQLDeleteQuery(const QString& table);
99 ~OSQLDeleteQuery();
100 void setWhere( const OSQLWhere& );
101 void setWheres( const OSQLWhere::ValueList& );
102 QString query()const;
103private:
104 QString m_table;
105 OSQLWhere::ValueList m_where;
106
107};
108class OSQLUpdateQuery : public OSQLQuery {
109public:
110 OSQLUpdateQuery( const QString& table );
111 ~OSQLUpdateQuery();
112 void setWhere( const OSQLWhere& );
113 void setWheres( const OSQLWhere::ValueList& );
114 */
115 /* replaces all previous set Values */
116 /*
117 void setValue( const QString& field, const QString& value );
118 void setValue( const QMap<QString, QString> &fields );
119 QString query() const;
120};
121*/
122#endif
diff --git a/libsql/osqlresult.cpp b/libsql/osqlresult.cpp
new file mode 100644
index 0000000..490fb45
--- a/dev/null
+++ b/libsql/osqlresult.cpp
@@ -0,0 +1,127 @@
1
2#include "osqlquery.h"
3#include "osqlresult.h"
4
5OSQLResultItem::OSQLResultItem( const TableString& string,
6 const TableInt& Int)
7 : m_string( string ), m_int( Int )
8{
9
10}
11OSQLResultItem::~OSQLResultItem() {
12}
13OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) {
14 *this = item;
15}
16OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) {
17 m_string = other.m_string;
18 m_int = other.m_int;
19 return *this;
20}
21OSQLResultItem::TableString OSQLResultItem::tableString()const{
22 return m_string;
23}
24OSQLResultItem::TableInt OSQLResultItem::tableInt()const {
25 return m_int;
26}
27QString OSQLResultItem::data( const QString& columnName, bool *ok ) {
28 TableString::Iterator it = m_string.find( columnName );
29
30 /* if found */
31 if ( it != m_string.end() ) {
32 if ( ok ) *ok = true;
33 return it.data();
34 }else{
35 if ( ok ) *ok = false;
36 return QString::null;
37 }
38
39}
40QString OSQLResultItem::data( int column, bool *ok ) {
41 TableInt::Iterator it = m_int.find( column );
42
43 /* if found */
44 if ( it != m_int.end() ) {
45 if ( ok ) *ok = true;
46 return it.data();
47 }else{
48 if ( ok ) *ok = false;
49 return QString::null;
50 }
51}
52/*
53 * DateFormat is 'YYYY-MM-DD'
54 */
55QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) {
56 QDate date = QDate::currentDate();
57 QString str = data( column, ok );
58 if (!str.isEmpty() ) {
59 ;// convert
60 }
61 return date;
62}
63QDate OSQLResultItem::dataToDate( int column, bool *ok ) {
64 QDate date = QDate::currentDate();
65 QString str = data( column, ok );
66 if (!str.isEmpty() ) {
67 ;// convert
68 }
69 return date;
70
71}
72QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) {
73 QDateTime time = QDateTime::currentDateTime();
74 return time;
75}
76QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) {
77 QDateTime time = QDateTime::currentDateTime();
78 return time;
79}
80
81OSQLResult::OSQLResult( enum State state,
82 const OSQLResultItem::ValueList& list,
83 const OSQLError::ValueList& error )
84 : m_state( state ), m_list( list ), m_error( error )
85{
86
87}
88OSQLResult::~OSQLResult() {
89
90}
91OSQLResult::State OSQLResult::state()const {
92 return m_state;
93}
94void OSQLResult::setState( OSQLResult::State state ) {
95 m_state = state;
96}
97OSQLError::ValueList OSQLResult::errors()const {
98 return m_error;
99}
100void OSQLResult::setErrors( const OSQLError::ValueList& err ) {
101 m_error = err;
102}
103OSQLResultItem::ValueList OSQLResult::results()const {
104 return m_list;
105}
106void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) {
107 m_list = result;
108}
109OSQLResultItem OSQLResult::first() {
110 it = m_list.begin();
111 return (*it);
112}
113OSQLResultItem OSQLResult::next(){
114 ++it;
115 return (*it);
116}
117bool OSQLResult::atEnd(){
118 if ( it == m_list.end() )
119 return true;
120
121 return false;
122}
123OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const {
124 OSQLResultItem::ValueList::ConstIterator it;
125 it = m_list.begin();
126 return it;
127}
diff --git a/libsql/osqlresult.h b/libsql/osqlresult.h
new file mode 100644
index 0000000..9c9efa2
--- a/dev/null
+++ b/libsql/osqlresult.h
@@ -0,0 +1,112 @@
1#ifndef OSQL_RESULT_H
2#define OSQL_RESULT_H
3
4#include <qdatetime.h>
5#include <qmap.h>
6#include <qvaluelist.h>
7
8
9#include "osqlerror.h"
10/**
11 * ResultItem represents one row of the resulting answer
12 */
13class OSQLResultItem {
14public:
15 typedef QValueList<OSQLResultItem> ValueList;
16 /**
17 * TableString is used to establish the relations
18 * between the column name and the real item
19 */
20 typedef QMap<QString, QString> TableString;
21
22 /**
23 * TableInt is used to establish a relation between a
24 * position of a column and the row value
25 */
26 typedef QMap<int, QString> TableInt;
27
28 /**
29 * Default c'tor. It has a TableString and a TableInt
30 */
31 OSQLResultItem(const TableString& = TableString(),
32 const TableInt& = TableInt() );
33 OSQLResultItem( const OSQLResultItem& );
34 ~OSQLResultItem();
35 OSQLResultItem &operator=( const OSQLResultItem& );
36 /**
37 * returns the TableString
38 */
39 TableString tableString()const;
40
41 /**
42 * returns the TableInt
43 */
44 TableInt tableInt() const;
45
46 /**
47 * retrieves the Data from columnName
48 *
49 */
50 QString data( const QString& columnName, bool *ok = 0);
51
52 /**
53 * QString for column number
54 */
55 QString data(int columnNumber, bool *ok = 0);
56
57 /**
58 * Date conversion from columnName
59 */
60 QDate dataToDate( const QString& columnName, bool *ok = 0 );
61
62 /**
63 * Date conversion from column-number
64 */
65 QDate dataToDate( int columnNumber, bool *ok = 0 );
66
67 QDateTime dataToDateTime( const QString& columName, bool *ok = 0 );
68 QDateTime dataToDateTime( int columnNumber, bool *ok = 0 );
69private:
70 TableString m_string;
71 TableInt m_int;
72};
73
74/**
75 * the OSQLResult
76 * either a SQL statement failed or succeeded
77 */
78class OSQLResult {
79public:
80 /** The State of a Result */
81 enum State{ Success = 0, Failure,Undefined };
82
83 /**
84 * default c'tor
85 * @param state The State of the Result
86 * @param r ResultItems
87 * @prarm errors the Errors a OSQLResult created
88 */
89 OSQLResult( enum State state = Undefined,
90 const OSQLResultItem::ValueList& r= OSQLResultItem::ValueList(),
91 const OSQLError::ValueList& errors = OSQLError::ValueList() );
92 ~OSQLResult();
93 State state()const;
94 OSQLError::ValueList errors()const;
95 OSQLResultItem::ValueList results()const;
96
97 void setState( enum State state );
98 void setErrors( const OSQLError::ValueList& error );
99 void setResults( const OSQLResultItem::ValueList& result );
100
101 OSQLResultItem first();
102 OSQLResultItem next();
103 bool atEnd();
104 OSQLResultItem::ValueList::ConstIterator iterator()const;
105private:
106 enum State m_state;
107 OSQLResultItem::ValueList m_list;
108 OSQLError::ValueList m_error;
109 OSQLResultItem::ValueList::Iterator it;
110};
111
112#endif
diff --git a/libsql/osqltable.cpp b/libsql/osqltable.cpp
new file mode 100644
index 0000000..cde40f4
--- a/dev/null
+++ b/libsql/osqltable.cpp
@@ -0,0 +1,46 @@
1#include "osqltable.h"
2
3OSQLTableItem::OSQLTableItem() {}
4OSQLTableItem::OSQLTableItem( enum Type type,
5 const QString& field,
6 const QVariant& var)
7 : m_type( type ), m_field( field ), m_var( var )
8{
9
10}
11OSQLTableItem::~OSQLTableItem() {}
12OSQLTableItem::OSQLTableItem( const OSQLTableItem& item) {
13 *this = item;
14}
15OSQLTableItem &OSQLTableItem::operator=(const OSQLTableItem& other) {
16 m_var = other.m_var;
17 m_field = other.m_field;
18 m_type = other.m_type;
19 return *this;
20}
21QString OSQLTableItem::fieldName()const{
22 return m_field;
23}
24OSQLTableItem::Type OSQLTableItem::type()const {
25 return m_type;
26}
27QVariant OSQLTableItem::more()const {
28 return m_var;
29}
30
31OSQLTable::OSQLTable( const QString& tableName )
32 : m_table( tableName )
33{
34
35}
36OSQLTable::~OSQLTable() {
37}
38void OSQLTable::setColumns( const OSQLTableItem::ValueList& list) {
39 m_list = list;
40}
41OSQLTableItem::ValueList OSQLTable::columns()const {
42 return m_list;
43}
44QString OSQLTable::tableName()const {
45 return m_table;
46}
diff --git a/libsql/osqltable.h b/libsql/osqltable.h
new file mode 100644
index 0000000..87f7e74
--- a/dev/null
+++ b/libsql/osqltable.h
@@ -0,0 +1,95 @@
1#ifndef OSQL_TABLE_H
2#define OSQL_TABLE_H
3
4#include <qstring.h>
5#include <qvaluelist.h>
6#include <qvariant.h>
7
8/**
9 * OSQLTableItem saves one column of a complete
10 * table
11 */
12class OSQLTableItem {
13public:
14 typedef QValueList<OSQLTableItem> ValueList;
15 /**
16 * Type kinds ( to be extended )
17 */
18 enum Type { Undefined=-1, Integer=0, BigInteger =1,
19 Float = 2, VarChar = 4 };
20 /**
21 * A constructor
22 * @param type the Type of the Column
23 * @param fieldName the Name of the Column
24 * @param var a Variant
25 */
26 OSQLTableItem();
27 OSQLTableItem( enum Type type,
28 const QString& fieldName,
29 const QVariant& var= QVariant() );
30
31 /**
32 * copy c'tor
33 */
34 OSQLTableItem( const OSQLTableItem& );
35
36 /**
37 * d'tor
38 */
39 ~OSQLTableItem();
40
41 OSQLTableItem& operator=( const OSQLTableItem& );
42
43 /**
44 * the fieldName
45 */
46 QString fieldName() const;
47
48 /**
49 * the field Type
50 */
51 Type type() const;
52 QVariant more() const;
53private:
54 class OSQLTableItemPrivate;
55 OSQLTableItemPrivate* d;
56 Type m_type;
57 QString m_field;
58 QVariant m_var;
59};
60
61/**
62 * A OSQLTable consists of OSQLTableItems
63 */
64class OSQLTable {
65public:
66 typedef QValueList<OSQLTable> ValueList;
67
68 /**
69 * @param tableName the Name of the Table
70 */
71 OSQLTable(const QString& tableName);
72
73 /**
74 * d'tor
75 */
76 ~OSQLTable();
77
78 /**
79 * setColumns sets the Columns of the Table
80 */
81 void setColumns( const OSQLTableItem::ValueList& );
82
83 /**
84 * returns all columns of the table
85 */
86 OSQLTableItem::ValueList columns() const;
87
88 QString tableName()const;
89
90private:
91 QString m_table;
92 OSQLTableItem::ValueList m_list;
93};
94
95#endif
diff --git a/libsql/test/main.cpp b/libsql/test/main.cpp
new file mode 100644
index 0000000..9b35ff3
--- a/dev/null
+++ b/libsql/test/main.cpp
@@ -0,0 +1,29 @@
1#include <qdir.h>
2
3#include <qpe/qpeapplication.h>
4#include "../osqlmanager.h"
5#include "../osqlquery.h"
6#include "../osqldriver.h"
7#include "../osqlresult.h"
8
9int main( int argc, char* argv[] ) {
10
11QPEApplication app( argc, argv );
12OSQLManager man;
13man.registerPath( QDir::currentDirPath() );
14OSQLBackEnd::ValueList list = man.queryBackEnd();
15
16OSQLDriver *driver = man.standard();
17 qWarning("testmain" + driver->id() );
18 driver->setUrl("/home/ich/test2vhgytry");
19 if ( driver->open() ) {
20 qWarning("could open");
21 }else
22 qWarning("wasn't able to open");
23 OSQLRawQuery raw("select * from t2" );
24 OSQLResult res = driver->query( &raw );
25
26 OSQLRawQuery raw2( "insert into t2 VALUES(ROWID,'Meine Mutter') ");
27 res = driver->query(&raw2);
28
29};
diff --git a/libsql/test/spaltenweise.cpp b/libsql/test/spaltenweise.cpp
new file mode 100644
index 0000000..8790cdd
--- a/dev/null
+++ b/libsql/test/spaltenweise.cpp
@@ -0,0 +1,41 @@
1#include <qdir.h>
2
3#include <qpe/qpeapplication.h>
4#include "../osqlmanager.h"
5#include "../osqlquery.h"
6#include "../osqldriver.h"
7#include "../osqlresult.h"
8
9int main( int argc, char* argv[] ) {
10
11 QPEApplication app( argc, argv );
12 OSQLManager man;
13 man.registerPath( QDir::currentDirPath() );
14 OSQLBackEnd::ValueList list = man.queryBackEnd();
15
16 OSQLDriver *driver = man.standard();
17 qWarning("testmain" + driver->id() );
18 driver->setUrl("/home/ich/spaltenweise");
19 if ( driver->open() ) {
20 qWarning("could open");
21 }else
22 qWarning("wasn't able to open");
23 OSQLRawQuery *raw = new OSQLRawQuery("create table todolist("
24 "uid,categories,completed,"
25 "progress,summary,HasDate,"
26 "DateDay,DateMonth,DateYear,"
27 "priority,description)" );
28
29 OSQLResult res = driver->query( raw );
30 delete raw;
31 for (int i = 0; i< 10000; i++ ) {
32 int uid = i;
33 OSQLRawQuery raw("insert into todolist VALUES("+
34 QString::number(uid)+ ",'-122324;-12132',1,100,"+
35 "'Summary234-"+QString::number(uid)+"',1,5,8,2002,1,"+
36 "'Description\n12344')");
37 OSQLResult res = driver->query( &raw );
38
39 }
40 return 0;
41};
diff --git a/libsql/test/spaltenweise.pro b/libsql/test/spaltenweise.pro
new file mode 100644
index 0000000..5b881c0
--- a/dev/null
+++ b/libsql/test/spaltenweise.pro
@@ -0,0 +1,9 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS =
4 SOURCES = spaltenweise.cpp
5INCLUDEPATH += $(OPIEDIR)/include
6 DEPENDPATH+= $(OPIEDIR)/include
7LIBS += -lqpe -lopiesql
8 TARGET = spaltenweise
9
diff --git a/libsql/test/test.osql b/libsql/test/test.osql
new file mode 100644
index 0000000..340e4f2
--- a/dev/null
+++ b/libsql/test/test.osql
@@ -0,0 +1,4 @@
1Name = Test1
2Vendor = Zecke
3License = ZPL
4Preference = 15
diff --git a/libsql/test/test.pro b/libsql/test/test.pro
new file mode 100644
index 0000000..188c367
--- a/dev/null
+++ b/libsql/test/test.pro
@@ -0,0 +1,9 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS =
4 SOURCES = main.cpp
5INCLUDEPATH += $(OPIEDIR)/include
6 DEPENDPATH+= $(OPIEDIR)/include
7LIBS += -lqpe -lopiesql
8 TARGET = sqltest
9
diff --git a/libsql/test/test2.osql b/libsql/test/test2.osql
new file mode 100644
index 0000000..952c99b
--- a/dev/null
+++ b/libsql/test/test2.osql
@@ -0,0 +1,5 @@
1Name = Test2
2Vendor = Schaf
3License = SPL
4Preference = 15
5Default = 0
diff --git a/libsql/test/zeilenweise.cpp b/libsql/test/zeilenweise.cpp
new file mode 100644
index 0000000..e538c9f
--- a/dev/null
+++ b/libsql/test/zeilenweise.cpp
@@ -0,0 +1,84 @@
1#include <qdir.h>
2
3#include <qpe/qpeapplication.h>
4#include "../osqlmanager.h"
5#include "../osqlquery.h"
6#include "../osqldriver.h"
7#include "../osqlresult.h"
8
9int main( int argc, char* argv[] ) {
10
11QPEApplication app( argc, argv );
12OSQLManager man;
13man.registerPath( QDir::currentDirPath() );
14OSQLBackEnd::ValueList list = man.queryBackEnd();
15
16OSQLDriver *driver = man.standard();
17 qWarning("testmain" + driver->id() );
18 driver->setUrl("/home/ich/zeilenweise");
19 if ( driver->open() ) {
20 qWarning("could open");
21 }else
22 qWarning("wasn't able to open");
23 OSQLRawQuery raw2("BEGIN TRANSACTION");
24 OSQLRawQuery *raw = new OSQLRawQuery("create table todolist(uid,key,value)");
25 OSQLResult res = driver->query( &raw2 );
26 res = driver->query( raw );
27 delete raw;
28 for (int i = 0; i< 10000; i++ ) {
29 int uid = i;
30 OSQLRawQuery *raw;
31 raw = new OSQLRawQuery("insert into todolist VALUES("+QString::number(uid)+",'Categories',"+"'-122324;-12132')");
32 OSQLResult res = driver->query(raw );
33 delete raw;
34
35 raw = new OSQLRawQuery("insert into todolist VALUES("+QString::number(uid) +
36 ",'Completed',1)" );
37 res = driver->query(raw );
38 delete raw;
39
40 raw = new OSQLRawQuery("insert into todolist VALUES("+
41 QString::number(uid)+",'Progress',100)" );
42 res = driver->query( raw );
43 delete raw;
44
45 raw = new OSQLRawQuery("insert into todolist VALUES("+
46 QString::number(uid)+",'Summary',"+
47 "'Summary234-"+ QString::number(uid) + "')");
48 res = driver->query( raw );
49 delete raw;
50
51 raw = new OSQLRawQuery("insert into todolist VALUES("+
52 QString::number(uid)+",'HasDate',1)");
53 res = driver->query( raw );
54 delete raw;
55
56 raw = new OSQLRawQuery("insert into todolist VALUES("+
57 QString::number(uid)+",'DateDay',5)");
58 res = driver->query( raw );
59 delete raw;
60
61 raw = new OSQLRawQuery("insert into todolist VALUES("+
62 QString::number(uid)+",'DateMonth',8)");
63 res = driver->query( raw );
64 delete raw;
65
66 raw = new OSQLRawQuery("insert into todolist VALUES("+
67 QString::number(uid)+",'DateYear',2002)");
68 res = driver->query( raw );
69 delete raw;
70
71 raw = new OSQLRawQuery("insert into todolist VALUES("+
72 QString::number(uid)+",'Priority',1)");
73 res = driver->query( raw );
74 delete raw;
75
76 raw = new OSQLRawQuery("insert into todolist VALUES("+
77 QString::number(uid)+",'Description','" +
78 QString::number(uid) + "Description\n12344')");
79 res = driver->query( raw );
80 delete raw;
81 }
82 OSQLRawQuery raw3("COMMIT");
83 res = driver->query(&raw3 );
84};
diff --git a/libsql/test/zeilenweise.pro b/libsql/test/zeilenweise.pro
new file mode 100644
index 0000000..516b7c0
--- a/dev/null
+++ b/libsql/test/zeilenweise.pro
@@ -0,0 +1,9 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on release
3 HEADERS =
4 SOURCES = zeilenweise.cpp
5INCLUDEPATH += $(OPIEDIR)/include
6 DEPENDPATH+= $(OPIEDIR)/include
7LIBS += -lqpe -lopiesql
8 TARGET = zeilenweise
9