author | chicken <chicken> | 2004-03-01 15:58:07 (UTC) |
---|---|---|
committer | chicken <chicken> | 2004-03-01 15:58:07 (UTC) |
commit | 931c55406a043195712955c732a875e17899df90 (patch) (side-by-side diff) | |
tree | 8097c88ee3e96f8fb613ccca1ebf36bf73070dcc /libopie2/opiedb | |
parent | 87676b131aad1bfe979570a48107527db4040020 (diff) | |
download | opie-931c55406a043195712955c732a875e17899df90.zip opie-931c55406a043195712955c732a875e17899df90.tar.gz opie-931c55406a043195712955c732a875e17899df90.tar.bz2 |
fix includes
-rw-r--r-- | libopie2/opiedb/osqlbackendmanager.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiedb/osqlitedriver.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiedb/osqlmanager.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiedb/osqlresult.cpp | 1 |
4 files changed, 0 insertions, 5 deletions
diff --git a/libopie2/opiedb/osqlbackendmanager.cpp b/libopie2/opiedb/osqlbackendmanager.cpp index 0f261b9..95ed77b 100644 --- a/libopie2/opiedb/osqlbackendmanager.cpp +++ b/libopie2/opiedb/osqlbackendmanager.cpp @@ -1,99 +1,98 @@ #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/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp index b857534..6141504 100644 --- a/libopie2/opiedb/osqlitedriver.cpp +++ b/libopie2/opiedb/osqlitedriver.cpp @@ -1,189 +1,188 @@ /* This file is part of the Opie Project =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "osqlresult.h" #include "osqlquery.h" #include "osqlitedriver.h" #include <opie2/odebug.h> #include <stdlib.h> // fromLocal8Bit() does not work as expected. Thus it // is replaced by fromLatin1() (eilers) #define __BUGGY_LOCAL8BIT_ namespace { struct Query { OSQLError::ValueList errors; OSQLResultItem::ValueList items; OSQLiteDriver *driver; }; } OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) : OSQLDriver( lib ) { m_sqlite = 0l; } OSQLiteDriver::~OSQLiteDriver() { close(); } QString OSQLiteDriver::id()const { return QString::fromLatin1("SQLite"); } void OSQLiteDriver::setUserName( const QString& ) {} void OSQLiteDriver::setPassword( const QString& ) {} void OSQLiteDriver::setUrl( const QString& url ) { m_url = url; } void OSQLiteDriver::setOptions( const QStringList& ) { } /* * try to open a db specified via setUrl * and options */ bool OSQLiteDriver::open() { char *error; odebug << "OSQLiteDriver::open: about to open" << oendl; m_sqlite = sqlite_open(m_url.local8Bit(), 0, &error ); /* failed to open */ if (m_sqlite == 0l ) { // FIXME set the last error owarn << "OSQLiteDriver::open: " << error << oendl; free( error ); return false; } return true; } /* close the db * sqlite closes them without * telling failure or success */ bool OSQLiteDriver::close() { if (m_sqlite ) sqlite_close( m_sqlite ), m_sqlite=0l; return true; } /* Query */ OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { if ( !m_sqlite ) { // FIXME set error code OSQLResult result( OSQLResult::Failure ); return result; } Query query; query.driver = this; char *err; /* SQLITE_OK 0 if return code > 0 == failure */ if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { owarn << "OSQLiteDriver::query: Error while executing" << oendl; free(err ); // FixMe Errors } OSQLResult result(OSQLResult::Success, query.items, query.errors ); return result; } OSQLTable::ValueList OSQLiteDriver::tables() const { } OSQLError OSQLiteDriver::lastError() { OSQLError error; return error; }; /* handle a callback add the row to the global * OSQLResultItem */ int OSQLiteDriver::handleCallBack( int, char**, char** ) { return 0; } /* callback_handler add the values to the list*/ int OSQLiteDriver::call_back( void* voi, int argc, char** argv, char** columns) { Query* qu = (Query*)voi; //copy them over to a OSQLResultItem QMap<QString, QString> tableString; QMap<int, QString> tableInt; for (int i = 0; i < argc; i++ ) { #ifdef __BUGGY_LOCAL8BIT_ tableInt.insert( i, QString::fromLatin1( argv[i] ) ); tableString.insert( QString::fromLatin1( columns[i] ), QString::fromLatin1( argv[i] ) ); #else tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); tableString.insert( QString::fromLocal8Bit( columns[i] ), QString::fromLocal8Bit( argv[i] ) ); #endif } OSQLResultItem item( tableString, tableInt ); qu->items.append( item ); return ((Query*)voi)->driver->handleCallBack( argc, argv, columns ); } diff --git a/libopie2/opiedb/osqlmanager.cpp b/libopie2/opiedb/osqlmanager.cpp index b0fea04..766ebe1 100644 --- a/libopie2/opiedb/osqlmanager.cpp +++ b/libopie2/opiedb/osqlmanager.cpp @@ -1,83 +1,81 @@ #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/libopie2/opiedb/osqlresult.cpp b/libopie2/opiedb/osqlresult.cpp index 490fb45..42da356 100644 --- a/libopie2/opiedb/osqlresult.cpp +++ b/libopie2/opiedb/osqlresult.cpp @@ -1,127 +1,126 @@ -#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; } |