summaryrefslogtreecommitdiff
authorzecke <zecke>2002-08-27 20:17:50 (UTC)
committer zecke <zecke>2002-08-27 20:17:50 (UTC)
commit86352e32f449ecf00de254674b7dcac72bc34a14 (patch) (side-by-side diff)
treeb5803b69ca00dceea1e2a76a5eee390f0748f27e
parent1398b50ffc193bc9ab69ebe198aeda847c39516e (diff)
downloadopie-86352e32f449ecf00de254674b7dcac72bc34a14.zip
opie-86352e32f449ecf00de254674b7dcac72bc34a14.tar.gz
opie-86352e32f449ecf00de254674b7dcac72bc34a14.tar.bz2
Initial check in of the light wrapper library
around normal SQL The first driver implementation is a SQLite version
Diffstat (more/less context) (show 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 @@
+Design of OpieSQL
+
+My intention for OpieSQL was to write
+a simple c++ interface which would allow
+easy use of common database functions on
+different backends
+
+How does these goals reflect the current Implementation
+
+-through OSQLManager + OSQLBackEnd I'll be able to change
+the default db driver and be able to add new
+driver implementations
+
+-OSQLQuery, RawQuery, SelectQuery allows a flexible and
+OO way of fast querying databases
+
+-much more ;)
+
+
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 @@
+* something like Capabilities of a Driver
+ - ROWID
+ - How to declare INTEGER PRIMARY KEY
+ - Abstract from implementation of some dbs
+ - provides( Type::What )
+
+ * OSQLDriver DriverVersion - DatabaseVersion
+ * Better OSQLQueries
+ - 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 @@
+TEMPLATE = lib
+CONFIG += qte warn_on release
+HEADERS = osqlbackend.h \
+ osqldriver.h \
+ osqlerror.h \
+ osqlmanager.h \
+ osqlquery.h \
+ osqlresult.h \
+ osqltable.h \
+ osqlbackendmanager.h \
+ osqlitedriver.h
+SOURCES = osqlbackend.cpp \
+ osqldriver.cpp \
+ osqlerror.cpp \
+ osqlmanager.cpp \
+ osqlquery.cpp \
+ osqlresult.cpp \
+ osqltable.cpp \
+ osqlbackendmanager.cpp \
+ osqlitedriver.cpp
+
+TARGET = opiesql
+INCLUDEPATH += $(OPIEDIR)/include
+DESTDIR = $(QTDIR)/lib$(PROJMAK)
+LIBS += -lsqlite
+#VERSION = 1.0.0
+
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 @@
+
+#include "osqlbackend.h"
+
+
+OSQLBackEnd::OSQLBackEnd( const QString& name,
+ const QString& vendor,
+ const QString& license,
+ const QCString& lib )
+ : m_name( name), m_vendor( vendor), m_license( license ), m_lib( lib )
+{
+ m_default = false;
+ m_pref = -1;
+}
+OSQLBackEnd::OSQLBackEnd( const OSQLBackEnd& back ) {
+ (*this) = back;
+}
+OSQLBackEnd::~OSQLBackEnd() {
+}
+bool OSQLBackEnd::operator==( const OSQLBackEnd& other ) {
+ if ( m_pref != other.m_pref ) return false;
+ if ( m_default != other.m_default ) return false;
+ if ( m_name != other.m_name ) return false;
+ if ( m_vendor != other.m_vendor ) return false;
+ if ( m_license != other.m_license ) return false;
+ if ( m_lib != other.m_lib ) return false;
+
+ return true;
+}
+OSQLBackEnd &OSQLBackEnd::operator=(const OSQLBackEnd& back ) {
+ m_name = back.m_name;
+ m_vendor = back.m_vendor;
+ m_license = back.m_license;
+ m_lib = back.m_lib;
+ m_pref = back.m_pref;
+ m_default = back.m_default;
+ return *this;
+}
+QString OSQLBackEnd::name() const {
+ return m_name;
+}
+QString OSQLBackEnd::vendor() const {
+ return m_vendor;
+}
+QString OSQLBackEnd::license() const {
+ return m_license;
+}
+QCString OSQLBackEnd::library() const {
+ return m_lib;
+}
+bool OSQLBackEnd::isDefault()const {
+ return m_default;
+}
+int OSQLBackEnd::preference()const {
+ return m_pref;
+}
+void OSQLBackEnd::setName( const QString& name ) {
+ m_name = name;
+}
+void OSQLBackEnd::setVendor( const QString& vendor ) {
+ m_vendor = vendor;
+}
+void OSQLBackEnd::setLicense( const QString & license ) {
+ m_license = license;
+}
+void OSQLBackEnd::setLibrary( const QCString& lib ) {
+ m_lib = lib;
+}
+void OSQLBackEnd::setDefault( bool def) {
+ m_default = def;
+}
+void OSQLBackEnd::setPreference( int pref ) {
+ m_pref = pref;
+}
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 @@
+
+#ifndef OSQL_BACKEND_H
+#define OSQL_BACKEND_H
+
+#include <qcstring.h>
+#include <qstring.h>
+#include <qvaluelist.h>
+
+/**
+ * OSQLBackEnd represents an available backend
+ * to the Opie Database Service
+ * It's used to easily extend OSQL services by
+ * 3rd party plugins.
+ * It's used to show
+ */
+class OSQLBackEnd /*: public QShared */ {
+public:
+ typedef QValueList<OSQLBackEnd> ValueList;
+ /**
+ * A basic c'tor
+ * @param name the user visible name of the service
+ * @param vendor the vendor of the service
+ * @param license the license of the service
+ * @param library what is the name of lib if builtin it's builtin
+ */
+ OSQLBackEnd( const QString& name = QString::null,
+ const QString& vendor = QString::null,
+ const QString& license = QString::null,
+ const QCString& library = QCString() );
+ OSQLBackEnd( const OSQLBackEnd& );
+ OSQLBackEnd &operator=( const OSQLBackEnd& );
+ bool operator==(const OSQLBackEnd& );
+
+ ~OSQLBackEnd();
+
+ /** @return the name */
+ QString name()const;
+
+ /** @return the vendor */
+ QString vendor()const;
+
+ /** @return the license */
+ QString license()const;
+
+ /** @return the name of the library */
+ QCString library() const;
+
+ bool isDefault()const;
+ int preference()const;
+
+ /** @param name the name to set */
+ void setName( const QString& name );
+
+ /** @param vendor the vendor to set */
+ void setVendor( const QString& vendor );
+
+ /** @param license the license applied */
+ void setLicense( const QString& license );
+
+ /** @param the lib to set */
+ void setLibrary( const QCString& lib );
+
+ void setDefault( bool );
+ void setPreference( int );
+
+private:
+ QString m_name;
+ QString m_vendor;
+ QString m_license;
+ QCString m_lib;
+ bool m_default :1;
+ int m_pref;
+};
+
+#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 @@
+#include <qdir.h>
+#include <qfile.h>
+#include <qmap.h>
+
+#include "osqlbackendmanager.h"
+
+namespace {
+ class Config {
+ typedef QMap<QString, QString> List;
+ public:
+ Config( const QString& fileName );
+ /**
+ * Quite simple layout in nature
+ * BeginFile
+ * Key = Value
+ */
+ bool load();
+ QString value( const QString& key );
+ private:
+ List m_list;
+ QString m_fileName;
+ };
+ Config::Config( const QString& fileName )
+ : m_fileName( fileName ) {
+ }
+
+ bool Config::load() {
+ if (!QFile::exists( m_fileName ) )
+ return false;
+ QFile file( m_fileName );
+ if (!file.open(IO_ReadOnly ) )
+ return false;
+ QStringList list = QStringList::split( '\n', file.readAll() );
+ QStringList::Iterator it;
+ QString line;
+ for (it = list.begin(); it != list.end(); ++it ) {
+ line = (*it).stripWhiteSpace();
+ qWarning("Anonymous::Config:" + line );
+ QStringList test = QStringList::split(' ', line );
+ m_list.insert( test[0], test[2] );
+ }
+ return true;
+ }
+ QString Config::value( const QString& key ) {
+ return m_list[key];
+ }
+};
+OSQLBackEndManager::OSQLBackEndManager( const QStringList& path )
+ :m_path( path )
+{
+}
+OSQLBackEndManager::~OSQLBackEndManager() {
+}
+/**
+ * scan dirs
+ */
+OSQLBackEnd::ValueList OSQLBackEndManager::scan() {
+ OSQLBackEnd::ValueList list;
+ if (!m_path.isEmpty() ) {
+ QStringList::Iterator it;
+ for ( it = m_path.begin(); it != m_path.end(); ++it ) {
+ list += scanDir( (*it) );
+ }
+ }
+ return list;
+}
+/**
+ * scan a specified dir for *.osql
+ */
+OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) {
+ OSQLBackEnd::ValueList list;
+ QDir dir( dirName );
+ if (dir.exists() ) {
+ QStringList files = dir.entryList( "*.osql" );
+ QStringList::Iterator it;
+ for ( it = files.begin(); it != files.end(); ++it ) {
+ list.append( file2backend( (*it) ) );
+ }
+ }
+ return list;
+}
+
+/**
+ * read a config file and convert it to a OSQLBackEnd
+ */
+OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) {
+ OSQLBackEnd end;
+ qWarning("fileName: " + file );
+ Config cfg( file );
+ if (cfg.load() ) {
+ end.setName( cfg.value( "Name") );
+ end.setVendor( cfg.value("Vendor") );
+ end.setLicense( cfg.value("License") );
+ end.setLibrary( cfg.value("Library").local8Bit() );
+ end.setDefault( cfg.value("Default").toInt() );
+ end.setPreference( cfg.value("Preference").toInt() );
+ }
+ return end;
+}
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 @@
+#include <qpe/qlibrary.h>
+
+#include "osqldriver.h"
+
+OSQLDriver::OSQLDriver( QLibrary* lib )
+: QObject(), m_lib(lib) {
+}
+OSQLDriver::~OSQLDriver() {
+ delete m_lib;
+}
+bool OSQLDriver::sync() {
+ return true;
+}
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 @@
+#ifndef OSQL_DRIVER_H
+#define OSQL_DRIVER_H
+
+#include <qobject.h>
+#include <qstring.h>
+
+#include "osqltable.h"
+
+class QLibrary;
+class OSQLResult;
+class OSQLQuery;
+class OSQLError;
+
+/**
+ * A OSQLDriver implements the communication with
+ * a database.
+ * After you queried and loaded a driver you can
+ * set some informations and finally try to open
+ * the database
+ *
+ */
+class OSQLDriver : public QObject{
+ Q_OBJECT
+public:
+ enum Capabilities { RowID=0 };
+ /**
+ * OSQLDriver constructor. It takes the QLibrary
+ * as parent.
+ *
+ */
+ OSQLDriver( QLibrary* lib=0 );
+
+ virtual ~OSQLDriver();
+ /**
+ * Id returns the identifier of the OSQLDriver
+ */
+ virtual QString id()const = 0;
+
+ /**
+ * set the UserName to the database
+ */
+ virtual void setUserName( const QString& ) = 0;
+
+ /**
+ * set the PassWord to the database
+ */
+ virtual void setPassword( const QString& )= 0;
+
+ /**
+ * set the Url
+ */
+ virtual void setUrl( const QString& ) = 0;
+
+ /**
+ * setOptions
+ */
+ virtual void setOptions( const QStringList& ) = 0;
+
+ /**
+ * tries to open a connection to the database
+ */
+ virtual bool open() = 0;
+ virtual bool close() = 0;
+
+ virtual OSQLError lastError() = 0;
+
+ /**
+ * Query the Database with a OSQLQuery
+ * OSQLResult holds the result
+ */
+ virtual OSQLResult query( OSQLQuery* ) = 0;
+
+ /**
+ * Get a list of tables
+ */
+ virtual OSQLTable::ValueList tables() const = 0l;
+ virtual bool sync();
+
+
+private:
+ QLibrary* m_lib;
+ class OSQLDriverPrivate;
+ OSQLDriverPrivate *d;
+
+};
+
+#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 @@
+#include "osqlerror.h"
+
+OSQLError::OSQLError( const QString& driverText,
+ const QString& driverDatabaseText,
+ int type, int subType )
+ : m_drvText( driverText ), m_drvDBText( driverDatabaseText ),
+ m_type( type ), m_number( subType )
+{
+}
+OSQLError::~OSQLError() {
+}
+QString OSQLError::driverText()const {
+ return m_drvText;
+}
+QString OSQLError::databaseText()const {
+ return m_drvDBText;
+}
+int OSQLError::type()const {
+ return m_type;
+}
+int OSQLError::subNumber()const {
+ return m_number;
+}
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 @@
+#ifndef OSQL_ERROR_H
+#define OSQL_ERROR_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+
+/**
+ * OSQLError is the base class of all errors
+ */
+class OSQLError {
+public:
+ typedef QValueList<OSQLError> ValueList;
+ enum Type { None = 0, // NoError
+ Internal, // Internal Error in OSQL
+ Unknown, // Unknown Error
+ Transaction, // Transaction Error
+ Statement, // Wrong Statement
+ Connection, // Connection Error( lost )
+ Driver // Driver Specefic error
+ };
+ enum DriverError {
+ DriverInternal=0, // internal DriverError
+ Permission, // Permission Problem
+ Abort, // Abort of the SQL
+ Busy, // Busy Error
+ Locked, // Locked
+ NoMem, // No Memory
+ ReadOnly, // Database is read only
+ Interrupt, // Interrupt
+ IOErr, // IO Error
+ Corrupt, // Database Corruption
+ NotFound, // Table not Found
+ Full, // Full
+ CantOpen, // Can not open Table/Database
+ Protocol, // internal protocol error
+ Schema, // schema changed
+ TooBig, // Data too big
+ Mismatch, // Type mismatch
+ Misuse // misuse
+ };
+ OSQLError( const QString& driverText = QString::null,
+ const QString& driverDatabaseText = QString::null,
+ int type = None, int subNumber = -1 );
+ ~OSQLError();
+
+ QString driverText()const;
+ QString databaseText()const;
+ int type()const;
+ int subNumber()const;
+private:
+ QString m_drvText;
+ QString m_drvDBText;
+ int m_type;
+ int m_number;
+ class OSQLErrorPrivate;
+ OSQLErrorPrivate* d;
+};
+
+#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 @@
+#ifndef OSQL_LITE_DRIVER_H
+#define OSQL_LITE_DRIVER_H
+
+#include <sqlite.h>
+
+#include "osqldriver.h"
+#include "osqlerror.h"
+#include "osqlresult.h"
+
+class OSQLiteDriver : public OSQLDriver {
+ Q_OBJECT
+public:
+ OSQLiteDriver( QLibrary *lib = 0l );
+ ~OSQLiteDriver();
+ QString id()const;
+ void setUserName( const QString& );
+ void setPassword( const QString& );
+ void setUrl( const QString& url );
+ void setOptions( const QStringList& );
+ bool open();
+ bool close();
+ OSQLError lastError();
+ OSQLResult query( OSQLQuery* );
+ OSQLTable::ValueList tables()const;
+private:
+ OSQLError m_lastE;
+ OSQLResult m_result;
+ OSQLResultItem m_items;
+ int handleCallBack( int, char**, char** );
+ static int call_back( void*, int, char**, char** );
+ QString m_url;
+ sqlite *m_sqlite;
+};
+#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 @@
+
+#include <stdlib.h>
+
+#include "osqlbackend.h"
+#include "osqldriver.h"
+#include "osqlmanager.h"
+#include "osqlbackendmanager.h"
+#include "osqlitedriver.h"
+
+OSQLManager::OSQLManager() {
+}
+OSQLBackEnd::ValueList OSQLManager::queryBackEnd() {
+ m_list.clear();
+ QString opie = QString::fromLatin1( getenv("OPIEDIR") );
+ QString qpe = QString::fromLatin1( getenv("QPEDIR") );
+
+ if ( !m_path.contains(opie) && !opie.isEmpty() )
+ m_path << opie;
+ if ( !m_path.contains(qpe) && !qpe.isEmpty() )
+ m_path << qpe;
+
+ OSQLBackEndManager mng( m_path );
+ m_list = mng.scan();
+ m_list += builtIn();
+
+ return m_list;
+}
+/*
+ * loading dso's is currently not enabled due problems with QLibrary
+ * beeing in libqpe and not libqte
+ */
+OSQLDriver* OSQLManager::load( const QString& name ) {
+ OSQLDriver* driver = 0l;
+
+ if ( name == "SQLite" ) {
+ driver = new OSQLiteDriver();
+ }
+ return driver;
+}
+/*
+ * same as above
+ */
+OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) {
+ OSQLDriver *driver = 0l;
+ if ( end.library() == "builtin" &&
+ end.name() == "SQLite" )
+ driver = new OSQLiteDriver();
+
+ return driver;
+}
+/*
+ * let's find the a default with the highes preference
+ */
+OSQLDriver* OSQLManager::standard() {
+ OSQLDriver* driver =0l;
+ if ( m_list.isEmpty() ) queryBackEnd();
+ OSQLBackEnd::ValueList::Iterator it;
+ OSQLBackEnd back;
+ for ( it = m_list.begin(); it != m_list.end(); ++it ) {
+ if ( (*it).isDefault() &&
+ back.preference() < (*it).preference() ) {
+ back = (*it);
+ }
+ }
+ driver = load( back );
+ return driver;
+}
+void OSQLManager::registerPath( const QString& path ) {
+ m_path << path;
+}
+bool OSQLManager::unregisterPath( const QString& path ) {
+ m_path.remove( path );
+ return true;
+}
+OSQLBackEnd::ValueList OSQLManager::builtIn()const {
+ OSQLBackEnd::ValueList list;
+ // create the OSQLiteBackend
+ OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" );
+ back.setDefault( true );
+ back.setPreference( 50 );
+ list.append( back );
+ return list;
+}
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 @@
+
+#ifndef OSQL_MANAGER_H
+#define OSQL_MANAGER_H
+
+#include <qobject.h>
+
+#include "osqlbackend.h"
+
+/**
+ * OSQLManager is responsible for loading
+ * and unloading, querying different OSQL
+ * services
+ * Load a OSQLDriver and delete it yourself
+ *
+ */
+class OSQLDriver;
+class OSQLManager : public QObject {
+ Q_OBJECT
+public:
+ /**
+ * Empty c'tor
+ */
+ OSQLManager();
+
+ /**
+ * Query the Manager for different backends
+ */
+ OSQLBackEnd::ValueList queryBackEnd();
+
+ /**
+ * Load a backend with it's name from param name
+ */
+ OSQLDriver* load( const QString& name );
+
+ /**
+ * Load a OSQLDevice from const reference of OSQLBackEnd
+ */
+ OSQLDriver* load( const OSQLBackEnd& );
+
+ /**
+ * loads the Opie standard backend
+ */
+ OSQLDriver *standard();
+
+ /**
+ * register path to the search path list
+ * When querying for services we scan all the
+ * registered path for backends
+ */
+ void registerPath( const QString& path );
+
+ /**
+ * unregisterPath from the search path list
+ */
+ bool unregisterPath( const QString& path );
+private:
+ OSQLBackEnd::ValueList builtIn()const;
+ OSQLBackEnd::ValueList m_list;
+ QStringList m_path;
+};
+
+#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 @@
+
+#include "osqlquery.h"
+
+OSQLQuery::OSQLQuery() {
+}
+OSQLQuery::~OSQLQuery() {
+}
+
+OSQLRawQuery::OSQLRawQuery(const QString& query)
+ : OSQLQuery(), m_query( query ) {
+
+}
+OSQLRawQuery::~OSQLRawQuery() {
+}
+QString OSQLRawQuery::query()const {
+ return m_query;
+}
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 @@
+
+#ifndef OSQL_QUERY_H
+#define OSQL_QUERY_H
+
+#include <qmap.h>
+#include <qvaluelist.h>
+#include <qstring.h>
+
+
+/** I'm not happy with them
+class OSQLQueryOrder {
+public:
+ typedef QValueList<OSQLQueryOrder> ValueList;
+ OSQLQueryOrder(const QString& table = QString::null );
+ OSQLQueryOrder( const OSQLQueryOrder& );
+ ~OSQLQueryOrder();
+ void setOrderFields( const QStringList& list );
+ void setValue( const QString& fieldName, const QString& Value );
+ void setValues( const QMap<QString, QString>& );
+ QMap<QString, QString> orders() const;
+ QString orderStatement()const;
+ OSQLQueryOrder &operator=(const OSQLQueryOrder& );
+private:
+ QMap<QString, QString> m_fields;
+ class OSQLQueryOrderPrivate;
+ OSQLQueryOrderPrivate* d;
+};
+class OSQLWhere {
+public:
+ typedef QValueList<OSQLWhere> ValueList;
+ enum Vergleiche { Equal = 0, Like, Greater, GreaterEqual,
+ Smaller, SmallerEqual };
+ OSQLWhere(const QString& table = QString::null );
+ ~OSQLWhere();
+ void setExpression(const QString& key, enum Vergleiche, const QString& );
+ QString statement()const;
+private:
+ int m_vergleich;
+ const QString& m_left;
+ const QString& m_right;
+
+};
+*/
+class OSQLQuery {
+public:
+ OSQLQuery();
+ virtual ~OSQLQuery();
+
+ virtual QString query()const = 0;
+};
+
+class OSQLRawQuery : public OSQLQuery {
+public:
+ OSQLRawQuery( const QString& query );
+ ~OSQLRawQuery();
+ QString query() const;
+private:
+ class OSQLRawQueryPrivate;
+ OSQLRawQueryPrivate* d;
+ QString m_query;
+
+};
+/* I'm not happy with them again
+class OSQLSelectQuery : public OSQLQuery {
+public:
+ OSQLSelectQuery();
+ ~OSQLSelectQuery();
+ void setTables( const QStringList& allTablesToQuery );
+ void setValues( const QString& table, const QStringList& columns );
+ void setOrder( const OSQLSelectQuery& );
+ void setOrderList( const OSQLQueryOrder::ValueList& );
+ void setWhereList( const OSQLWhere& );
+ void setWhereList( const OSQLWhere::ValueList& );
+ QString query()const;
+private:
+ QStringList m_tables;
+ QMap<QString, QStringList> m_values;
+ OSQLQueryOrder::ValueList m_order;
+ OSQLWhere::ValueList m_where;
+ class OSQLSelectQueryPrivate;
+ OSQLSelectQueryPrivate* d;
+};
+class OSQLInsertQuery : public OSQLQuery {
+public:
+ OSQLInsertQuery(const QString& table);
+ ~OSQLInsertQuery();
+ void setInserFields( const QStringList& );
+ void setValue( const QString& field, const QString& value );
+ void setValues(const QMap<QString, QString>& );
+ QString query()const;
+private:
+ QString m_table;
+ QStringList m_fields;
+ QMap<QString, QString> m_values;
+};
+class OSQLDeleteQuery : public OSQLQuery {
+public:
+ OSQLDeleteQuery(const QString& table);
+ ~OSQLDeleteQuery();
+ void setWhere( const OSQLWhere& );
+ void setWheres( const OSQLWhere::ValueList& );
+ QString query()const;
+private:
+ QString m_table;
+ OSQLWhere::ValueList m_where;
+
+};
+class OSQLUpdateQuery : public OSQLQuery {
+public:
+ OSQLUpdateQuery( const QString& table );
+ ~OSQLUpdateQuery();
+ void setWhere( const OSQLWhere& );
+ void setWheres( const OSQLWhere::ValueList& );
+ */
+ /* replaces all previous set Values */
+ /*
+ void setValue( const QString& field, const QString& value );
+ void setValue( const QMap<QString, QString> &fields );
+ QString query() const;
+};
+*/
+#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 @@
+
+#include "osqlquery.h"
+#include "osqlresult.h"
+
+OSQLResultItem::OSQLResultItem( const TableString& string,
+ const TableInt& Int)
+ : m_string( string ), m_int( Int )
+{
+
+}
+OSQLResultItem::~OSQLResultItem() {
+}
+OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) {
+ *this = item;
+}
+OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) {
+ m_string = other.m_string;
+ m_int = other.m_int;
+ return *this;
+}
+OSQLResultItem::TableString OSQLResultItem::tableString()const{
+ return m_string;
+}
+OSQLResultItem::TableInt OSQLResultItem::tableInt()const {
+ return m_int;
+}
+QString OSQLResultItem::data( const QString& columnName, bool *ok ) {
+ TableString::Iterator it = m_string.find( columnName );
+
+ /* if found */
+ if ( it != m_string.end() ) {
+ if ( ok ) *ok = true;
+ return it.data();
+ }else{
+ if ( ok ) *ok = false;
+ return QString::null;
+ }
+
+}
+QString OSQLResultItem::data( int column, bool *ok ) {
+ TableInt::Iterator it = m_int.find( column );
+
+ /* if found */
+ if ( it != m_int.end() ) {
+ if ( ok ) *ok = true;
+ return it.data();
+ }else{
+ if ( ok ) *ok = false;
+ return QString::null;
+ }
+}
+/*
+ * DateFormat is 'YYYY-MM-DD'
+ */
+QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) {
+ QDate date = QDate::currentDate();
+ QString str = data( column, ok );
+ if (!str.isEmpty() ) {
+ ;// convert
+ }
+ return date;
+}
+QDate OSQLResultItem::dataToDate( int column, bool *ok ) {
+ QDate date = QDate::currentDate();
+ QString str = data( column, ok );
+ if (!str.isEmpty() ) {
+ ;// convert
+ }
+ return date;
+
+}
+QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) {
+ QDateTime time = QDateTime::currentDateTime();
+ return time;
+}
+QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) {
+ QDateTime time = QDateTime::currentDateTime();
+ return time;
+}
+
+OSQLResult::OSQLResult( enum State state,
+ const OSQLResultItem::ValueList& list,
+ const OSQLError::ValueList& error )
+ : m_state( state ), m_list( list ), m_error( error )
+{
+
+}
+OSQLResult::~OSQLResult() {
+
+}
+OSQLResult::State OSQLResult::state()const {
+ return m_state;
+}
+void OSQLResult::setState( OSQLResult::State state ) {
+ m_state = state;
+}
+OSQLError::ValueList OSQLResult::errors()const {
+ return m_error;
+}
+void OSQLResult::setErrors( const OSQLError::ValueList& err ) {
+ m_error = err;
+}
+OSQLResultItem::ValueList OSQLResult::results()const {
+ return m_list;
+}
+void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) {
+ m_list = result;
+}
+OSQLResultItem OSQLResult::first() {
+ it = m_list.begin();
+ return (*it);
+}
+OSQLResultItem OSQLResult::next(){
+ ++it;
+ return (*it);
+}
+bool OSQLResult::atEnd(){
+ if ( it == m_list.end() )
+ return true;
+
+ return false;
+}
+OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const {
+ OSQLResultItem::ValueList::ConstIterator it;
+ it = m_list.begin();
+ return it;
+}
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 @@
+#ifndef OSQL_RESULT_H
+#define OSQL_RESULT_H
+
+#include <qdatetime.h>
+#include <qmap.h>
+#include <qvaluelist.h>
+
+
+#include "osqlerror.h"
+/**
+ * ResultItem represents one row of the resulting answer
+ */
+class OSQLResultItem {
+public:
+ typedef QValueList<OSQLResultItem> ValueList;
+ /**
+ * TableString is used to establish the relations
+ * between the column name and the real item
+ */
+ typedef QMap<QString, QString> TableString;
+
+ /**
+ * TableInt is used to establish a relation between a
+ * position of a column and the row value
+ */
+ typedef QMap<int, QString> TableInt;
+
+ /**
+ * Default c'tor. It has a TableString and a TableInt
+ */
+ OSQLResultItem(const TableString& = TableString(),
+ const TableInt& = TableInt() );
+ OSQLResultItem( const OSQLResultItem& );
+ ~OSQLResultItem();
+ OSQLResultItem &operator=( const OSQLResultItem& );
+ /**
+ * returns the TableString
+ */
+ TableString tableString()const;
+
+ /**
+ * returns the TableInt
+ */
+ TableInt tableInt() const;
+
+ /**
+ * retrieves the Data from columnName
+ *
+ */
+ QString data( const QString& columnName, bool *ok = 0);
+
+ /**
+ * QString for column number
+ */
+ QString data(int columnNumber, bool *ok = 0);
+
+ /**
+ * Date conversion from columnName
+ */
+ QDate dataToDate( const QString& columnName, bool *ok = 0 );
+
+ /**
+ * Date conversion from column-number
+ */
+ QDate dataToDate( int columnNumber, bool *ok = 0 );
+
+ QDateTime dataToDateTime( const QString& columName, bool *ok = 0 );
+ QDateTime dataToDateTime( int columnNumber, bool *ok = 0 );
+private:
+ TableString m_string;
+ TableInt m_int;
+};
+
+/**
+ * the OSQLResult
+ * either a SQL statement failed or succeeded
+ */
+class OSQLResult {
+public:
+ /** The State of a Result */
+ enum State{ Success = 0, Failure,Undefined };
+
+ /**
+ * default c'tor
+ * @param state The State of the Result
+ * @param r ResultItems
+ * @prarm errors the Errors a OSQLResult created
+ */
+ OSQLResult( enum State state = Undefined,
+ const OSQLResultItem::ValueList& r= OSQLResultItem::ValueList(),
+ const OSQLError::ValueList& errors = OSQLError::ValueList() );
+ ~OSQLResult();
+ State state()const;
+ OSQLError::ValueList errors()const;
+ OSQLResultItem::ValueList results()const;
+
+ void setState( enum State state );
+ void setErrors( const OSQLError::ValueList& error );
+ void setResults( const OSQLResultItem::ValueList& result );
+
+ OSQLResultItem first();
+ OSQLResultItem next();
+ bool atEnd();
+ OSQLResultItem::ValueList::ConstIterator iterator()const;
+private:
+ enum State m_state;
+ OSQLResultItem::ValueList m_list;
+ OSQLError::ValueList m_error;
+ OSQLResultItem::ValueList::Iterator it;
+};
+
+#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 @@
+#include "osqltable.h"
+
+OSQLTableItem::OSQLTableItem() {}
+OSQLTableItem::OSQLTableItem( enum Type type,
+ const QString& field,
+ const QVariant& var)
+ : m_type( type ), m_field( field ), m_var( var )
+{
+
+}
+OSQLTableItem::~OSQLTableItem() {}
+OSQLTableItem::OSQLTableItem( const OSQLTableItem& item) {
+ *this = item;
+}
+OSQLTableItem &OSQLTableItem::operator=(const OSQLTableItem& other) {
+ m_var = other.m_var;
+ m_field = other.m_field;
+ m_type = other.m_type;
+ return *this;
+}
+QString OSQLTableItem::fieldName()const{
+ return m_field;
+}
+OSQLTableItem::Type OSQLTableItem::type()const {
+ return m_type;
+}
+QVariant OSQLTableItem::more()const {
+ return m_var;
+}
+
+OSQLTable::OSQLTable( const QString& tableName )
+ : m_table( tableName )
+{
+
+}
+OSQLTable::~OSQLTable() {
+}
+void OSQLTable::setColumns( const OSQLTableItem::ValueList& list) {
+ m_list = list;
+}
+OSQLTableItem::ValueList OSQLTable::columns()const {
+ return m_list;
+}
+QString OSQLTable::tableName()const {
+ return m_table;
+}
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 @@
+#ifndef OSQL_TABLE_H
+#define OSQL_TABLE_H
+
+#include <qstring.h>
+#include <qvaluelist.h>
+#include <qvariant.h>
+
+/**
+ * OSQLTableItem saves one column of a complete
+ * table
+ */
+class OSQLTableItem {
+public:
+ typedef QValueList<OSQLTableItem> ValueList;
+ /**
+ * Type kinds ( to be extended )
+ */
+ enum Type { Undefined=-1, Integer=0, BigInteger =1,
+ Float = 2, VarChar = 4 };
+ /**
+ * A constructor
+ * @param type the Type of the Column
+ * @param fieldName the Name of the Column
+ * @param var a Variant
+ */
+ OSQLTableItem();
+ OSQLTableItem( enum Type type,
+ const QString& fieldName,
+ const QVariant& var= QVariant() );
+
+ /**
+ * copy c'tor
+ */
+ OSQLTableItem( const OSQLTableItem& );
+
+ /**
+ * d'tor
+ */
+ ~OSQLTableItem();
+
+ OSQLTableItem& operator=( const OSQLTableItem& );
+
+ /**
+ * the fieldName
+ */
+ QString fieldName() const;
+
+ /**
+ * the field Type
+ */
+ Type type() const;
+ QVariant more() const;
+private:
+ class OSQLTableItemPrivate;
+ OSQLTableItemPrivate* d;
+ Type m_type;
+ QString m_field;
+ QVariant m_var;
+};
+
+/**
+ * A OSQLTable consists of OSQLTableItems
+ */
+class OSQLTable {
+public:
+ typedef QValueList<OSQLTable> ValueList;
+
+ /**
+ * @param tableName the Name of the Table
+ */
+ OSQLTable(const QString& tableName);
+
+ /**
+ * d'tor
+ */
+ ~OSQLTable();
+
+ /**
+ * setColumns sets the Columns of the Table
+ */
+ void setColumns( const OSQLTableItem::ValueList& );
+
+ /**
+ * returns all columns of the table
+ */
+ OSQLTableItem::ValueList columns() const;
+
+ QString tableName()const;
+
+private:
+ QString m_table;
+ OSQLTableItem::ValueList m_list;
+};
+
+#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 @@
+#include <qdir.h>
+
+#include <qpe/qpeapplication.h>
+#include "../osqlmanager.h"
+#include "../osqlquery.h"
+#include "../osqldriver.h"
+#include "../osqlresult.h"
+
+int main( int argc, char* argv[] ) {
+
+QPEApplication app( argc, argv );
+OSQLManager man;
+man.registerPath( QDir::currentDirPath() );
+OSQLBackEnd::ValueList list = man.queryBackEnd();
+
+OSQLDriver *driver = man.standard();
+ qWarning("testmain" + driver->id() );
+ driver->setUrl("/home/ich/test2vhgytry");
+ if ( driver->open() ) {
+ qWarning("could open");
+ }else
+ qWarning("wasn't able to open");
+ OSQLRawQuery raw("select * from t2" );
+ OSQLResult res = driver->query( &raw );
+
+ OSQLRawQuery raw2( "insert into t2 VALUES(ROWID,'Meine Mutter') ");
+ res = driver->query(&raw2);
+
+};
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 @@
+#include <qdir.h>
+
+#include <qpe/qpeapplication.h>
+#include "../osqlmanager.h"
+#include "../osqlquery.h"
+#include "../osqldriver.h"
+#include "../osqlresult.h"
+
+int main( int argc, char* argv[] ) {
+
+ QPEApplication app( argc, argv );
+ OSQLManager man;
+ man.registerPath( QDir::currentDirPath() );
+ OSQLBackEnd::ValueList list = man.queryBackEnd();
+
+ OSQLDriver *driver = man.standard();
+ qWarning("testmain" + driver->id() );
+ driver->setUrl("/home/ich/spaltenweise");
+ if ( driver->open() ) {
+ qWarning("could open");
+ }else
+ qWarning("wasn't able to open");
+ OSQLRawQuery *raw = new OSQLRawQuery("create table todolist("
+ "uid,categories,completed,"
+ "progress,summary,HasDate,"
+ "DateDay,DateMonth,DateYear,"
+ "priority,description)" );
+
+ OSQLResult res = driver->query( raw );
+ delete raw;
+ for (int i = 0; i< 10000; i++ ) {
+ int uid = i;
+ OSQLRawQuery raw("insert into todolist VALUES("+
+ QString::number(uid)+ ",'-122324;-12132',1,100,"+
+ "'Summary234-"+QString::number(uid)+"',1,5,8,2002,1,"+
+ "'Description\n12344')");
+ OSQLResult res = driver->query( &raw );
+
+ }
+ return 0;
+};
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 @@
+TEMPLATE = app
+CONFIG = qt warn_on release
+HEADERS =
+SOURCES = spaltenweise.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lqpe -lopiesql
+TARGET = spaltenweise
+
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 @@
+Name = Test1
+Vendor = Zecke
+License = ZPL
+Preference = 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 @@
+TEMPLATE = app
+CONFIG = qt warn_on release
+HEADERS =
+SOURCES = main.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lqpe -lopiesql
+TARGET = sqltest
+
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 @@
+Name = Test2
+Vendor = Schaf
+License = SPL
+Preference = 15
+Default = 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 @@
+#include <qdir.h>
+
+#include <qpe/qpeapplication.h>
+#include "../osqlmanager.h"
+#include "../osqlquery.h"
+#include "../osqldriver.h"
+#include "../osqlresult.h"
+
+int main( int argc, char* argv[] ) {
+
+QPEApplication app( argc, argv );
+OSQLManager man;
+man.registerPath( QDir::currentDirPath() );
+OSQLBackEnd::ValueList list = man.queryBackEnd();
+
+OSQLDriver *driver = man.standard();
+ qWarning("testmain" + driver->id() );
+ driver->setUrl("/home/ich/zeilenweise");
+ if ( driver->open() ) {
+ qWarning("could open");
+ }else
+ qWarning("wasn't able to open");
+ OSQLRawQuery raw2("BEGIN TRANSACTION");
+ OSQLRawQuery *raw = new OSQLRawQuery("create table todolist(uid,key,value)");
+ OSQLResult res = driver->query( &raw2 );
+ res = driver->query( raw );
+ delete raw;
+ for (int i = 0; i< 10000; i++ ) {
+ int uid = i;
+ OSQLRawQuery *raw;
+ raw = new OSQLRawQuery("insert into todolist VALUES("+QString::number(uid)+",'Categories',"+"'-122324;-12132')");
+ OSQLResult res = driver->query(raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+QString::number(uid) +
+ ",'Completed',1)" );
+ res = driver->query(raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'Progress',100)" );
+ res = driver->query( raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'Summary',"+
+ "'Summary234-"+ QString::number(uid) + "')");
+ res = driver->query( raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'HasDate',1)");
+ res = driver->query( raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'DateDay',5)");
+ res = driver->query( raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'DateMonth',8)");
+ res = driver->query( raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'DateYear',2002)");
+ res = driver->query( raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'Priority',1)");
+ res = driver->query( raw );
+ delete raw;
+
+ raw = new OSQLRawQuery("insert into todolist VALUES("+
+ QString::number(uid)+",'Description','" +
+ QString::number(uid) + "Description\n12344')");
+ res = driver->query( raw );
+ delete raw;
+ }
+ OSQLRawQuery raw3("COMMIT");
+ res = driver->query(&raw3 );
+};
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 @@
+TEMPLATE = app
+CONFIG = qt warn_on release
+HEADERS =
+SOURCES = zeilenweise.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lqpe -lopiesql
+TARGET = zeilenweise
+