summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.in1
-rw-r--r--krecipes/src/backends/SQLite/Makefile.am6
-rw-r--r--krecipes/src/backends/SQLite/libqsqlite/Makefile.am17
-rw-r--r--krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.cpp171
-rw-r--r--krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.h59
-rw-r--r--krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.cpp197
-rw-r--r--krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.h142
-rw-r--r--krecipes/src/backends/SQLite/literecipedb.h14
-rw-r--r--krecipes/src/backends/SQLite/qsql_sqlite.cpp470
-rw-r--r--krecipes/src/backends/SQLite/qsql_sqlite.h54
10 files changed, 11 insertions, 1120 deletions
diff --git a/configure.in b/configure.in
index 1c6962b..115274e 100644
--- a/configure.in
+++ b/configure.in
@@ -196,7 +196,6 @@ AC_CONFIG_FILES([ krecipes/src/backends/Makefile ])
AC_CONFIG_FILES([ krecipes/src/backends/MySQL/Makefile ])
AC_CONFIG_FILES([ krecipes/src/backends/PostgreSQL/Makefile ])
AC_CONFIG_FILES([ krecipes/src/backends/SQLite/Makefile ])
-AC_CONFIG_FILES([ krecipes/src/backends/SQLite/libqsqlite/Makefile ])
AC_CONFIG_FILES([ krecipes/src/datablocks/Makefile ])
AC_CONFIG_FILES([ krecipes/src/dialogs/Makefile ])
AC_CONFIG_FILES([ krecipes/src/exporters/Makefile ])
diff --git a/krecipes/src/backends/SQLite/Makefile.am b/krecipes/src/backends/SQLite/Makefile.am
index c29f5d3..49648f6 100644
--- a/krecipes/src/backends/SQLite/Makefile.am
+++ b/krecipes/src/backends/SQLite/Makefile.am
@@ -6,14 +6,10 @@
# set the include path for X, qt and KDE
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../.. $(all_includes)
-SUBDIRS = libqsqlite
-
# Instructions for building the convenience library
noinst_LTLIBRARIES=libkrecsqlite.la
-libkrecsqlite_la_SOURCES=literecipedb.cpp qsql_sqlite.cpp
+libkrecsqlite_la_SOURCES=literecipedb.cpp
libkrecsqlite_la_METASOURCES=AUTO
-libkrecsqlite_la_LIBADD=libqsqlite/libkrecqsqlite.la
-
#the library search path.
libkrecsqlite_la_LDFLAGS = $(KDE_RPATH) $(all_libraries)
diff --git a/krecipes/src/backends/SQLite/libqsqlite/Makefile.am b/krecipes/src/backends/SQLite/libqsqlite/Makefile.am
deleted file mode 100644
index b368a5a..0000000
--- a/krecipes/src/backends/SQLite/libqsqlite/Makefile.am
+++ /dev/null
@@ -1,17 +0,0 @@
-## Makefile.am for krecipes
-
-# this is the program that gets installed. it's name is used for all
-# of the other Makefile.am variables
-
-# set the include path for X, qt and KDE
-INCLUDES = $(all_includes)
-
-#building the library
-
-noinst_LTLIBRARIES=libkrecqsqlite.la
-libkrecqsqlite_la_SOURCES=krecqsqlitedb.cpp krecqsqliteresult.cpp
-libkrecqsqlite_la_METASOURCES=AUTO
-
-#the library search path.
-libkrecqsqlite_la_LDFLAGS = $(KDE_RPATH) $(all_libraries)
-
diff --git a/krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.cpp b/krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.cpp
deleted file mode 100644
index 777dedb..0000000
--- a/krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/***************************************************************************
-* *
-* Copyright (C) 2003 *
-* by Unai Garro (ugarro@users.sourceforge.net) *
-* Martin Imobersteg <imm@gmx.ch> *
-* and opie project *
-* *
-* *
-* This code was originally developed by the opie project, on which *
-* Martin Imobersteg based his work. *
-* This file is adds a small extension, necessary to perform some minimum *
-* SQL actions *
-* *
-* (this project is different from that in qsqlite.sf.net) *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-***************************************************************************/
-
-
-#include "krecqsqlitedb.h"
-#include "krecqsqliteresult.h"
-
-#include <ntqvaluelist.h>
-
-#include <kdebug.h>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if HAVE_SQLITE
-#include <sqlite.h>
-#elif HAVE_SQLITE3
-#include <sqlite3.h>
-#endif
-#include <stdlib.h>
-
-TQSQLiteDB::TQSQLiteDB( TQObject *, const char * )
-{}
-
-bool TQSQLiteDB::open( const TQString &dbname )
-{
- char * errmsg = 0;
-
-#if HAVE_SQLITE
-
- m_db = sqlite_open( dbname.latin1(), 0, &errmsg );
-#elif HAVE_SQLITE3
-
- int res = sqlite3_open( dbname.latin1(), &m_db );
-
- if ( res != SQLITE_OK )
- return false;
-#endif
-
- if ( m_db == 0L ) {
-#if HAVE_SQLITE
- sqlite_freemem( errmsg );
-#elif HAVE_SQLITE3
- sqlite3_free( errmsg );
-#endif
- return false;
- }
-
- int func_res;
- #if HAVE_SQLITE
- func_res = sqlite_create_function(m_db,"lastInsertID",0,&lastInsertID,m_db );
- #elif HAVE_SQLITE3
- func_res = sqlite3_create_function(m_db,"lastInsertID",0,SQLITE_ANY,m_db,
- &lastInsertID, 0, 0 );
- #endif
-
- return func_res == 0;
-}
-
-void TQSQLiteDB::close()
-{
- if ( m_db ) {
-#if HAVE_SQLITE
- sqlite_close( m_db );
-#elif HAVE_SQLITE3
-
- sqlite3_close( m_db );
-#endif
-
- m_db = 0L;
- }
-}
-
-TQSQLiteResult TQSQLiteDB::executeQuery( const TQString &query, int *lastID )
-{
- TQSQLiteResult res;
- if ( !m_db ) {
- return res;
- }
-
- char *errmsg = 0;
-#if HAVE_SQLITE
-
- if ( sqlite_exec( m_db, query.latin1(), &call_back, &res, &errmsg ) > 0 )
-#elif HAVE_SQLITE3
-
- if ( sqlite3_exec( m_db, query.latin1(), &call_back, &res, &errmsg ) > 0 )
-#endif
-
- {
- kdDebug() << "SQLite error: " << errmsg << endl <<
- "\t (Query: " << query << ")" << endl;
- res.setError( errmsg );
- res.setStatus( TQSQLiteResult::Failure );
-#if HAVE_SQLITE
- sqlite_freemem( errmsg );
-#elif HAVE_SQLITE3
- sqlite3_free( errmsg );
-#endif
- }
-
- if ( lastID ) {
-#if HAVE_SQLITE
- * lastID = sqlite_last_insert_rowid( m_db );
-#elif HAVE_SQLITE3
-
- *lastID = sqlite3_last_insert_rowid( m_db );
-#endif
-
- }
-
- res.setStatus( TQSQLiteResult::Success );
-
- return res;
-}
-
-int TQSQLiteDB::call_back( void* result, int argc, char** argv, char** columns )
-{
- TQSQLiteResult * res = ( TQSQLiteResult* ) result;
-
- TQMap<TQString, TQCString> tableString;
- TQMap<int, TQCString> tableInt;
-
- for ( int i = 0; i < argc; i++ ) {
- tableInt.insert( i, argv[ i ] );
- tableString.insert( columns[ i ],
- argv[ i ] );
- }
-
- TQSQLiteResultRow row( tableString, tableInt );
- res->addRow( row );
-
- return 0;
-}
-
-#if HAVE_SQLITE
-void TQSQLiteDB::lastInsertID(sqlite_func *context,int argc,const char**)
-{
- Q_ASSERT( argc==0 );
-
- void *db = sqlite_user_data(context);
- sqlite_set_result_int(context, sqlite_last_insert_rowid( (sqlite*)db ) );
-}
-#elif HAVE_SQLITE3
-void TQSQLiteDB::lastInsertID( sqlite3_context *context, int argc, sqlite3_value ** )
-{
- Q_ASSERT( argc==0 );
-
- void *db = sqlite3_user_data(context);
- sqlite3_result_int(context, sqlite3_last_insert_rowid( (sqlite3*)db ) );
-}
-#endif
-
diff --git a/krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.h b/krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.h
deleted file mode 100644
index bff1967..0000000
--- a/krecipes/src/backends/SQLite/libqsqlite/krecqsqlitedb.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/***************************************************************************
-* *
-* Copyright (C) 2003 *
-* by Unai Garro (ugarro@users.sourceforge.net) *
-* Martin Imobersteg <imm@gmx.ch> *
-* and opie project *
-* *
-* *
-* This code was originally developed by the opie project, on which *
-* Martin Imobersteg based his work. *
-* This file is adds a small extension, necessary to perform some minimum *
-* SQL actions *
-* *
-* (this project is different from that in qsqlite.sf.net) *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-***************************************************************************/
-
-#ifndef TQSQLITEDB_H
-#define TQSQLITEDB_H
-
-#include <ntqvaluelist.h>
-#include <ntqstringlist.h>
-#include <ntqobject.h>
-
-#include "config.h"
-#if HAVE_SQLITE
-#include <sqlite.h>
-#elif HAVE_SQLITE3
-#include <sqlite3.h>
-#endif
-
-#include "krecqsqliteresult.h"
-
-
-class TQSQLiteDB
-{
-public:
- TQSQLiteDB( TQObject *parent = 0, const char *name = 0 );
- bool open( const TQString &dbname );
- void close();
- TQSQLiteResult executeQuery( const TQString &query, int *lastID = 0 );
- int size(); //Returns the number of rows returned
-
-private:
- static int call_back( void* res, int argc, char** argv, char** columns );
-
- #if HAVE_SQLITE
- static void lastInsertID(sqlite_func*,int,const char**);
- sqlite *m_db;
- #elif HAVE_SQLITE3
- static void lastInsertID(sqlite3_context *context, int argc, sqlite3_value **argv);
- sqlite3 *m_db;
- #endif
-};
-
-#endif
diff --git a/krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.cpp b/krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.cpp
deleted file mode 100644
index 9a4f682..0000000
--- a/krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/***************************************************************************
-* *
-* Copyright (C) 2003 *
-* by Unai Garro (ugarro@users.sourceforge.net) *
-* Martin Imobersteg <imm@gmx.ch> *
-* and opie project *
-* *
-* *
-* This code was originally developed by the opie project, on which *
-* Martin Imobersteg based his work. *
-* This file is adds a small extension, necessary to perform some minimum *
-* SQL actions *
-* *
-* (this project is different from that in qsqlite.sf.net) *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-***************************************************************************/
-
-#include "krecqsqliteresult.h"
-
-TQSQLiteResultRow::TQSQLiteResultRow( const TableString& string, const TableInt& Int )
- : m_string( string ), m_int( Int )
-{}
-
-TQSQLiteResultRow::~TQSQLiteResultRow()
-{}
-
-TQSQLiteResultRow::TQSQLiteResultRow( const TQSQLiteResultRow& item )
-{
- *this = item;
-}
-
-TQSQLiteResultRow &TQSQLiteResultRow::operator=( const TQSQLiteResultRow& other )
-{
- m_string = other.m_string;
- m_int = other.m_int;
- return *this;
-}
-
-TQSQLiteResultRow::TableString TQSQLiteResultRow::tableString() const
-{
- return m_string;
-}
-
-TQSQLiteResultRow::TableInt TQSQLiteResultRow::tableInt() const
-{
- return m_int;
-}
-
-TQCString TQSQLiteResultRow::data( const TQString& 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 TQCString(0);
- }
-
-}
-
-TQCString TQSQLiteResultRow::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 TQCString(0);
- }
-}
-
-/*
- * DateFormat is 'YYYY-MM-DD'
- */
-TQDate TQSQLiteResultRow::dataToDate( const TQString& column, bool *ok )
-{
- TQDate date = TQDate::currentDate();
- TQString str = data( column, ok );
- if ( !str.isEmpty() ) {
- ; // convert
- }
- return date;
-}
-
-TQDate TQSQLiteResultRow::dataToDate( int column, bool *ok )
-{
- TQDate date = TQDate::currentDate();
- TQString str = data( column, ok );
- if ( !str.isEmpty() ) {
- ; // convert
- }
- return date;
-}
-
-TQDateTime TQSQLiteResultRow::dataToDateTime( const TQString& column )
-{
- TQDateTime time = TQDateTime::currentDateTime();
- return time;
-}
-
-TQDateTime TQSQLiteResultRow::dataToDateTime( int column )
-{
- TQDateTime time = TQDateTime::currentDateTime();
- return time;
-}
-
-TQSQLiteResult::TQSQLiteResult( enum Status status,
- const TQSQLiteResult::Columns& list,
- const TQString &error )
- : m_status( status ), m_list( list ), m_error( error )
-{}
-
-TQSQLiteResult::~TQSQLiteResult()
-{}
-
-TQSQLiteResult::Status TQSQLiteResult::getStatus() const
-{
- return m_status;
-}
-
-void TQSQLiteResult::setStatus( TQSQLiteResult::Status status )
-{
- m_status = status;
-}
-
-TQSQLiteResult::Columns TQSQLiteResult::getResults() const
-{
- return m_list;
-}
-
-void TQSQLiteResult::setResults( const TQSQLiteResult::Columns& result )
-{
- m_list = result;
-}
-
-void TQSQLiteResult::addRow( TQSQLiteResultRow row )
-{
- m_list.append( row );
-}
-
-TQString TQSQLiteResult::getError() const
-{
- return m_error;
-}
-
-void TQSQLiteResult::setError( const TQString &error )
-{
- m_error = error;
-}
-
-TQSQLiteResultRow TQSQLiteResult::first()
-{
- it = m_list.begin();
- return ( *it );
-}
-
-TQSQLiteResultRow TQSQLiteResult::next()
-{
- ++it;
- return ( *it );
-}
-
-bool TQSQLiteResult::atEnd()
-{
- if ( it == m_list.end() ) {
- return true;
- }
-
- return false;
-}
-
-TQSQLiteResult::Columns::ConstIterator TQSQLiteResult::iterator() const
-{
- TQSQLiteResult::Columns::ConstIterator it;
- it = m_list.begin();
- return it;
-}
-
-int TQSQLiteResult::size() const
-{
- return ( m_list.size() );
-}
diff --git a/krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.h b/krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.h
deleted file mode 100644
index 8311925..0000000
--- a/krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/***************************************************************************
-* *
-* Copyright (C) 2003 *
-* by Unai Garro (ugarro@users.sourceforge.net) *
-* Martin Imobersteg <imm@gmx.ch> *
-* and opie project *
-* *
-* *
-* This code was originally developed by the opie project, on which *
-* Martin Imobersteg based his work. *
-* This file is adds a small extension, necessary to perform some minimum *
-* SQL actions *
-* *
-* (this project is different from that in qsqlite.sf.net) *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-***************************************************************************/
-
-#ifndef TQSQLITERESULT_H
-#define TQSQLITERESULT_H
-
-#include <ntqdatetime.h>
-#include <ntqmap.h>
-#include <ntqvaluelist.h>
-
-/**
- * ResultRow represents one row of the resulting answer
- */
-class TQSQLiteResultRow
-{
-public:
- /**
- * TableString is used to establish the relations
- * between the column name and the real item
- */
- typedef TQMap<TQString, TQCString> TableString;
-
- /**
- * TableInt is used to establish a relation between a
- * position of a column and the row value
- */
- typedef TQMap<int, TQCString> TableInt;
-
- /**
- * Default c'tor. It has a TableString and a TableInt
- */
- TQSQLiteResultRow( const TableString& = TableString(),
- const TableInt& = TableInt() );
- TQSQLiteResultRow( const TQSQLiteResultRow& );
- ~TQSQLiteResultRow();
- TQSQLiteResultRow &operator=( const TQSQLiteResultRow& );
-
- /**
- * returns the TableString
- */
- TableString tableString() const;
-
- /**
- * returns the TableInt
- */
- TableInt tableInt() const;
-
- /**
- * retrieves the Data from columnName
- *
- */
- TQCString data( const TQString& columnName, bool *ok = 0 );
-
- /**
- * TQString for column number
- */
- TQCString data( int columnNumber, bool *ok = 0 );
-
- /**
- * Date conversion from columnName
- */
- TQDate dataToDate( const TQString& columnName, bool *ok = 0 );
-
- /**
- * Date conversion from column-number
- */
- TQDate dataToDate( int columnNumber, bool *ok = 0 );
-
- TQDateTime dataToDateTime( const TQString& columName );
- TQDateTime dataToDateTime( int columnNumber );
-
-private:
- TableString m_string;
- TableInt m_int;
-};
-
-/**
- * the TQSQLiteResult
- * either a SQL statusment failed or succeeded
- */
-class TQSQLiteResult
-{
-
-public:
- typedef TQValueList<TQSQLiteResultRow> Columns;
-
- /** The Status of a Result */
- enum Status{ Success = 0, Failure, Undefined };
-
- /**
- * default c'tor
- * @param status The Status of the Result
- * @param r ResultItems
- * @param error Error Message
- */
- TQSQLiteResult( enum Status status = Undefined,
- const Columns &r = Columns(),
- const TQString &error = 0L );
- ~TQSQLiteResult();
-
- Status getStatus() const;
- Columns getResults() const;
- TQString getError() const;
-
- void setStatus( enum Status status );
- void setResults( const Columns &result );
- void setError( const TQString &error );
-
- void addRow( TQSQLiteResultRow row );
-
- TQSQLiteResultRow first();
- TQSQLiteResultRow next();
- bool atEnd();
-
- Columns::ConstIterator iterator() const;
- int size() const;
-
-private:
- enum Status m_status;
- Columns m_list;
- TQString m_error;
- Columns::Iterator it;
-};
-
-#endif
diff --git a/krecipes/src/backends/SQLite/literecipedb.h b/krecipes/src/backends/SQLite/literecipedb.h
index e0d8e76..0f00214 100644
--- a/krecipes/src/backends/SQLite/literecipedb.h
+++ b/krecipes/src/backends/SQLite/literecipedb.h
@@ -17,9 +17,15 @@
#include <ntqstring.h>
-#include "qsql_sqlite.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
-#define SQLITE_DRIVER "KRESQLITE"
+#ifdef HAVE_SQLITE3
+#define SQLITE_DRIVER "TQSQLITE3"
+#elif HAVE_SQLITE
+#define SQLITE_DRIVER "TQSQLITE"
+#endif
class LiteRecipeDB : public TQSqlRecipeDB
{
@@ -39,9 +45,9 @@ public:
virtual void givePermissions(const TQString&, const TQString&, const TQString&, const TQString&){} //no permissions in this backend
protected:
- virtual TQSqlDriver *qsqlDriver() const
+ virtual TQString qsqlDriverPlugin() const
{
- return new KreSQLiteDriver();
+ return SQLITE_DRIVER;
}
virtual TQString escapeAndEncode( const TQString &s ) const;
diff --git a/krecipes/src/backends/SQLite/qsql_sqlite.cpp b/krecipes/src/backends/SQLite/qsql_sqlite.cpp
deleted file mode 100644
index 9d65eac..0000000
--- a/krecipes/src/backends/SQLite/qsql_sqlite.cpp
+++ /dev/null
@@ -1,470 +0,0 @@
-/***************************************************************************
-* Copyright (C) 2005 by *
-* Jason Kivlighn (jkivlighn@gmail.com) *
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-***************************************************************************/
-
-#include "qsql_sqlite.h"
-
-#include <ntqdatetime.h>
-#include <ntqregexp.h>
-#include <ntqfile.h>
-
-#include <ntqptrvector.h>
-#include <unistd.h>
-
-#include <kdebug.h>
-
-#include "libqsqlite/krecqsqlitedb.h"
-#include "libqsqlite/krecqsqliteresult.h"
-
-#define TQSQLITE_DRIVER_NAME "KRE_QSQLITE"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if HAVE_SQLITE3
-#include <sqlite3.h>
-#define sqlite_free sqlite3_free
-#elif HAVE_SQLITE
-#include <sqlite.h>
-#endif
-
-class KreSQLiteResult : public TQSqlResult
-{
-public:
- KreSQLiteResult( const KreSQLiteDriver *d ): TQSqlResult( d )
- {
- db = d->db;
- }
- ~KreSQLiteResult() {}
-protected:
- TQVariant data( int );
- bool reset ( const TQString& );
- bool fetch( int );
- bool fetchFirst();
- bool fetchNext();
- bool fetchLast();
- bool isNull( int );
- TQSqlRecord record();
- int size();
- int numRowsAffected();
-
-private:
- TQSQLiteResult result;
- TQSQLiteResultRow row;
-
- TQSQLiteDB *db;
-};
-
-
-TQVariant KreSQLiteResult::data( int field )
-{
- if ( !isSelect() ) {
- //tqWarning( "KreSQLiteResult::data: column %d out of range", field );
- tqWarning( "KreSQLiteResult::data: not a select statement" );
- return TQVariant();
- }
-
- return TQVariant(row.data(field));
-}
-
-bool KreSQLiteResult::fetch( int i )
-{
-kdDebug()<<"fetch_i"<<endl;
- if ( isForwardOnly() ) { // fake a forward seek
- if ( at() < i ) {
- int x = i - at();
- while ( --x && fetchNext() );
- return fetchNext();
- } else {
- return false;
- }
- }
- if ( at() == i )
- return true;
-
- row = result.first();
- for ( int j = 0; j < i; ++j ) {
- if ( result.atEnd() )
- return false;
-
- row = result.next();
- }
-
- setAt( i );
- return true;
-}
-
-bool KreSQLiteResult::fetchNext()
-{
- row = result.next();
-
- if ( result.atEnd() )
- return false;
-
- setAt( at() + 1 );
- return true;
-}
-
-bool KreSQLiteResult::fetchFirst()
-{
- row = result.first();
-
- if ( result.atEnd() )
- return false;
-
- setAt(0);
- return true;
-}
-
-bool KreSQLiteResult::fetchLast()
-{kdDebug()<<"fetchlast"<<endl;
- if ( isForwardOnly() ) { // fake this since MySQL can't seek on forward only queries
- bool success = fetchNext(); // did we move at all?
- while ( fetchNext() );
- return success;
- }
- int numRows = size();
- if ( !numRows )
- return false;
- return fetch( numRows - 1 );
-}
-
-bool KreSQLiteResult::isNull( int i )
-{
- return false;
-}
-
-TQSqlRecord KreSQLiteResult::record()
-{kdDebug()<<"record"<<endl;
- return TQSqlRecord();
-}
-
-int KreSQLiteResult::size()
-{
-//kdDebug()<<"size: "<<result.size()<<endl;
- return result.size();
-}
-
-int KreSQLiteResult::numRowsAffected()
-{kdDebug()<<"numrowsaffected"<<endl;
- return 1;/*sqlite3_changes(db)*/
-}
-
-/*
- Execute \a query.
-*/
-bool KreSQLiteResult::reset(const TQString& query)
-{
- // this is where we build a query.
- if (!driver())
- return false;
- if (!driver()-> isOpen() || driver()->isOpenError())
- return false;
-
- //cleanup
- setAt( -1 );
-
- setSelect(true);
-
-
- result = db->executeQuery( query );
- int res = result.getStatus();
-
- if (res != SQLITE_OK ) {
- setLastError(TQSqlError("Unable to execute statement", result.getError(), TQSqlError::Statement, res));
- }
-
- setActive(true);
- return true;
-}
-
-/////////////////////////////////////////////////////////
-
-KreSQLiteDriver::KreSQLiteDriver(TQObject * parent, const char * name)
- : TQSqlDriver(parent, name ? name : TQSQLITE_DRIVER_NAME)
-{
-}
-
-KreSQLiteDriver::KreSQLiteDriver(TQSQLiteDB *connection, TQObject *parent, const char *name)
- : TQSqlDriver(parent, name ? name : TQSQLITE_DRIVER_NAME)
-{
- db = connection;
- setOpen(true);
- setOpenError(false);
-}
-
-
-KreSQLiteDriver::~KreSQLiteDriver()
-{
-}
-
-bool KreSQLiteDriver::hasFeature(DriverFeature f) const
-{
- switch (f) {
- case QuerySize:
- case Transactions:
- return true;
- // case BLOB:
- default:
- return false;
- }
-}
-
-/*
- SQLite dbs have no user name, passwords, hosts or ports.
- just file names.
-*/
-bool KreSQLiteDriver::open(const TQString & file, const TQString &, const TQString &, const TQString &, int)
-{
- if (isOpen())
- close();
-
- if (file.isEmpty())
- return false;
-
- db = new TQSQLiteDB;
- if ( !db->open(TQFile::encodeName(file)) ) {
- setLastError(TQSqlError("Error to open database", 0, TQSqlError::Connection));
- setOpenError(true);
- setOpen(false);
- return false;
- }
-
- setOpen(true);
- setOpenError(false);
- return true;
-}
-
-void KreSQLiteDriver::close()
-{
- if (isOpen()) {
- db->close();
- delete db; db = 0;
- setOpen(false);
- setOpenError(false);
- }
-}
-
-bool KreSQLiteDriver::ping()
-{
- if ( !isOpen() ) {
- return FALSE;
- }
-
- // FIXME
- // Implement ping if available
- return TRUE;
-}
-
-TQSqlQuery KreSQLiteDriver::createQuery() const
-{
- return TQSqlQuery(new KreSQLiteResult(this));
-}
-
-bool KreSQLiteDriver::beginTransaction()
-{
- if (!isOpen() || isOpenError())
- return false;
-
- TQSQLiteResult result = db->executeQuery( "BEGIN" );
- int status = result.getStatus();
- if (status == TQSQLiteResult::Success)
- return true;
-
- setLastError(TQSqlError("Unable to begin transaction", result.getError(), TQSqlError::Transaction, status));
- return false;
-}
-
-bool KreSQLiteDriver::commitTransaction()
-{
- if (!isOpen() || isOpenError())
- return false;
-
- TQSQLiteResult result = db->executeQuery( "COMMIT" );
- int status = result.getStatus();
- if (status == TQSQLiteResult::Success)
- return true;
-
- setLastError(TQSqlError("Unable to commit transaction", result.getError(), TQSqlError::Transaction, status));
- return false;
-}
-
-bool KreSQLiteDriver::rollbackTransaction()
-{
- if (!isOpen() || isOpenError())
- return false;
-
- TQSQLiteResult result = db->executeQuery( "ROLLBACK" );
- int status = result.getStatus();
- if (status == SQLITE_OK)
- return true;
-
- setLastError(TQSqlError("Unable to rollback transaction", result.getError(), TQSqlError::Transaction, status));
- return false;
-}
-
-TQStringList KreSQLiteDriver::tables(const TQString &typeName) const
-{
- TQStringList res;
- if (!isOpen())
- return res;
-
- int type = typeName.toInt();
-
- TQSqlQuery q = createQuery();
- q.setForwardOnly(true);
- #if (TQT_VERSION-0 >= 0x030000)
- if ((type & (int)TQSql::Tables) && (type & (int)TQSql::Views))
- q.exec("SELECT name FROM sqlite_master WHERE type='table' OR type='view'");
- else if (typeName.isEmpty() || (type & (int)TQSql::Tables))
- q.exec("SELECT name FROM sqlite_master WHERE type='table'");
- else if (type & (int)TQSql::Views)
- q.exec("SELECT name FROM sqlite_master WHERE type='view'");
- #else
- q.exec("SELECT name FROM sqlite_master WHERE type='table' OR type='view'");
- #endif
-
- if (q.isActive()) {
- while(q.next()) {
- res.append(q.value(0).toString());
- }
- }
-
- #if (TQT_VERSION-0 >= 0x030000)
- if (type & (int)TQSql::SystemTables) {
- // there are no internal tables beside this one:
- res.append("sqlite_master");
- }
- #endif
-
- return res;
-}
-
-TQSqlIndex KreSQLiteDriver::primaryIndex(const TQString &tblname) const
-{
- TQSqlRecordInfo rec(recordInfo(tblname)); // expensive :(
-
- if (!isOpen())
- return TQSqlIndex();
-
- TQSqlQuery q = createQuery();
- q.setForwardOnly(true);
- // finrst find a UNIQUE INDEX
- q.exec("PRAGMA index_list('" + tblname + "');");
- TQString indexname;
- while(q.next()) {
- if (q.value(2).toInt()==1) {
- indexname = q.value(1).toString();
- break;
- }
- }
- if (indexname.isEmpty())
- return TQSqlIndex();
-
- q.exec("PRAGMA index_info('" + indexname + "');");
-
- TQSqlIndex index(tblname, indexname);
- while(q.next()) {
- TQString name = q.value(2).toString();
- TQSqlVariant::Type type = TQSqlVariant::Invalid;
- if (rec.contains(name))
- type = rec.find(name).type();
- index.append(TQSqlField(name, type));
- }
- return index;
-}
-
-#if 0
-TQSqlRecordInfo KreSQLiteDriver::recordInfo(const TQString &tbl) const
-{
- if (!isOpen())
- return TQSqlRecordInfo();
-
- TQSqlQuery q = createQuery();
- q.setForwardOnly(true);
- q.exec("SELECT * FROM " + tbl + " LIMIT 1");
-return TQSqlRecordInfo();
-// return recordInfo(q);
-}
-
-TQSqlRecord KreSQLiteDriver::record(const TQString &tblname) const
-{
- if (!isOpen())
- return TQSqlRecord();
-
- return recordInfo(tblname).toRecord();
-}
-
-TQSqlRecord KreSQLiteDriver::record(const TQSqlQuery& query) const
-{
- if (query.isActive() && query.driver() == this) {
- KreSQLiteResult* result = (KreSQLiteResult*)query.result();
- return result->rInf.toRecord();
- }
- return TQSqlRecord();
-}
-
-TQSqlRecordInfo KreSQLiteDriver::recordInfo(const TQSqlQuery& query) const
-{
- if (query.isActive() && query.driver() == this) {
- KreSQLiteResult* result = (KreSQLiteResult*)query.result();
- return result->rInf;
- }
- return TQSqlRecordInfo();
-}
-
-//this would be used below in formatValue()
-static TQString escape( const TQString &s )
-{
- TQString s_escaped = s;
-
- if ( !s_escaped.isEmpty() ) { //###: sqlite_mprintf() seems to fill an empty string with garbage
- // Escape using SQLite's function
-#if HAVE_SQLITE
- char * escaped = sqlite_mprintf( "%q", s.latin1() ); // Escape the string(allocates memory)
-#elif HAVE_SQLITE3
- char * escaped = sqlite3_mprintf( "%q", s.latin1() ); // Escape the string(allocates memory)
-#endif
- s_escaped = escaped;
-#if HAVE_SQLITE
- sqlite_freemem( escaped ); // free allocated memory
-#elif HAVE_SQLITE3
- sqlite3_free( escaped ); // free allocated memory
-#endif
- }
-
- return ( s_escaped );
-}
-
-
-// Everything is considered a string given the implementation of this driver (we don't have field info). This would ruin a TQByteArray (for the photo).
-TQString KreSQLiteDriver::formatValue( const TQSqlField* field, bool trimStrings ) const
-{
- TQString r;
- if ( field->isNull() ) {
- r = nullText();
- } else {
- switch( field->type() ) {
- case TQVariant::String:
- case TQVariant::CString: {
- // Escape '\' characters
- r = TQSqlDriver::formatValue( field );
- //r = escape(r);
- //kdDebug()<<"escaping sqlite string: "<<r<<endl;
- break;
- }
- default:
- r = TQSqlDriver::formatValue( field, trimStrings );
- }
- }
- return r;
-}
-#endif
-
diff --git a/krecipes/src/backends/SQLite/qsql_sqlite.h b/krecipes/src/backends/SQLite/qsql_sqlite.h
deleted file mode 100644
index 526caa0..0000000
--- a/krecipes/src/backends/SQLite/qsql_sqlite.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/***************************************************************************
-* Copyright (C) 2005 by *
-* Jason Kivlighn (jkivlighn@gmail.com) *
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-***************************************************************************/
-
-#ifndef TQSQL_SQLITE_H
-#define TQSQL_SQLITE_H
-
-#include <ntqsqldriver.h>
-#include <ntqsqlresult.h>
-#include <ntqsqlrecord.h>
-#include <ntqsqlindex.h>
-
-typedef TQVariant TQSqlVariant;
-
-class TQSQLiteDB;
-
-class KreSQLiteDriver : public TQSqlDriver
-{
-public:
- KreSQLiteDriver(TQObject * parent = 0, const char * name = 0);
- KreSQLiteDriver(TQSQLiteDB *connection, TQObject *parent = 0, const char *name = 0);
- ~KreSQLiteDriver();
-
- bool hasFeature( DriverFeature ) const;
- bool open( const TQString&,
- const TQString&,
- const TQString&,
- const TQString&,
- int );
- void close();
- bool ping();
- TQSqlQuery createQuery() const;
-
- bool beginTransaction();
- bool commitTransaction();
- bool rollbackTransaction();
- TQStringList tables(const TQString &typeName) const;
- TQSqlIndex primaryIndex(const TQString &tblname) const;
- //TQSqlRecordInfo recordInfo(const TQString &tbl) const;
- //TQSqlRecord record(const TQString &tblname) const;
- //TQString formatValue( const TQSqlField* field, bool trimStrings ) const;
-
-private:
- friend class KreSQLiteResult;
-
- TQSQLiteDB *db;
-};
-#endif