summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2010-02-13 09:56:58 +0100
committerAndreas Baumann <abaumann@yahoo.com>2010-02-13 09:56:58 +0100
commit68354c7d41085d1f976a5b1d7ee542479a85f621 (patch)
treeaec761c793093e4a2e4ce18d78b3b531bcb12a42 /include
downloadsqlitexx-68354c7d41085d1f976a5b1d7ee542479a85f621.tar.gz
sqlitexx-68354c7d41085d1f976a5b1d7ee542479a85f621.tar.bz2
imported trunk from sourceforge SVN
Diffstat (limited to 'include')
-rw-r--r--include/GNUmakefile20
-rw-r--r--include/sqlite3xx/connection.hpp87
-rw-r--r--include/sqlite3xx/except.hpp51
-rwxr-xr-xinclude/sqlite3xx/port/dllexport.h39
-rw-r--r--include/sqlite3xx/port/iterator.hpp52
-rw-r--r--include/sqlite3xx/port/stdint.h68
-rw-r--r--include/sqlite3xx/port/sys.h30
-rw-r--r--include/sqlite3xx/prepared_statement.hpp117
-rw-r--r--include/sqlite3xx/result.hpp287
-rw-r--r--include/sqlite3xx/sqlite3xx28
-rw-r--r--include/sqlite3xx/transaction.hpp68
11 files changed, 847 insertions, 0 deletions
diff --git a/include/GNUmakefile b/include/GNUmakefile
new file mode 100644
index 0000000..6612882
--- /dev/null
+++ b/include/GNUmakefile
@@ -0,0 +1,20 @@
+TOPDIR = ..
+
+-include $(TOPDIR)/makefiles/gmake/sub.mk
+
+local_all:
+
+local_clean:
+ -@rm -f sqlite3xx/*.bak
+ -@rm -f sqlite3xx/*~
+
+local_install:
+ $(INSTALL) -d -m 755 $(includedir)/sqlite3xx
+ $(INSTALL) -m 644 sqlite3xx/*.hpp $(includedir)/sqlite3xx
+ $(INSTALL) -m 644 sqlite3xx/sqlite3xx $(includedir)/sqlite3xx
+ $(INSTALL) -d -m 755 $(includedir)/sqlite3xx/port
+ $(INSTALL) -m 644 sqlite3xx/port/*.hpp $(includedir)/sqlite3xx/port
+ $(INSTALL) -m 644 sqlite3xx/port/*.h $(includedir)/sqlite3xx/port
+
+local_uninstall:
+ -@rm -rf $(includedir)/sqlite3xx
diff --git a/include/sqlite3xx/connection.hpp b/include/sqlite3xx/connection.hpp
new file mode 100644
index 0000000..ab1fa70
--- /dev/null
+++ b/include/sqlite3xx/connection.hpp
@@ -0,0 +1,87 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef SQLITE3XX_CONNECTION_H
+#define SQLITE3XX_CONNECTION_H
+
+#include "prepared_statement.hpp"
+#include "result.hpp"
+
+#include "sqlite3.h"
+
+#include <map>
+#include <iostream>
+
+#include <sqlite3xx/port/stdint.h> /* for uintmax_t */
+
+#include "port/dllexport.h"
+
+using namespace std;
+
+namespace sqlite3xx {
+
+class prepared_stmt;
+class result;
+
+class SQLITEXX_LIBEXPORT connection {
+ private:
+ typedef map<string, prepared_stmt *> PSMap;
+
+ unsigned int _internal_tno;
+ string _filename;
+ sqlite3 *db;
+ PSMap prepared_stmts;
+ bool _trace;
+
+ SQLITEXX_PRIVATE prepared_stmt* find_prepared( const string& name );
+
+ public:
+ connection( );
+ connection( string filename );
+ connection( const connection& c );
+ ~connection( );
+
+ void trace( bool __trace );
+
+ result exec( string sql );
+ result prepared_exec( const string& name );
+
+ prepare::declaration prepare( const string& name, string sql );
+ void prepare_param_declare( const string& stmt, const string& sqltype, prepare::param_treatment& treatment );
+ void prepared_reset( const string& name );
+ void prepare_setparam( const string& name, const int pos, const int value );
+ void prepare_setparam( const string& name, const int pos, const char* value );
+ void prepare_setparam( const string& name, const int pos, const double value );
+ void prepare_setparam( const string& name, const int pos, const long value );
+ void prepare_setparam( const string& name, const int pos, const uintmax_t value );
+
+ void unprepare( string name );
+
+ SQLITEXX_LIBEXPORT friend ostream& operator<<( ostream& o, const connection& c );
+
+ const char *dbname( ) { return _filename.c_str( ); };
+};
+
+}
+
+#endif /* SQLITE3XX_CONNECTION_H */
diff --git a/include/sqlite3xx/except.hpp b/include/sqlite3xx/except.hpp
new file mode 100644
index 0000000..2577e85
--- /dev/null
+++ b/include/sqlite3xx/except.hpp
@@ -0,0 +1,51 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef SQLITE3XX_EXCEPT_H
+#define SQLITE3XX_EXCEPT_H
+
+#include <stdexcept>
+
+#include "port/dllexport.h"
+
+using namespace std;
+
+namespace sqlite3xx {
+
+class SQLITEXX_LIBEXPORT sql_error : runtime_error {
+ string _m;
+ string _q;
+
+ public:
+ sql_error( );
+ explicit sql_error( string& q );
+ explicit sql_error( string& __m, string& q );
+ virtual ~sql_error( ) throw( );
+
+ const string& msg( ) const throw( );
+ const string& query( ) const throw( );
+};
+
+}
+
+#endif /* SQLITE3XX_EXCEPT_H */
diff --git a/include/sqlite3xx/port/dllexport.h b/include/sqlite3xx/port/dllexport.h
new file mode 100755
index 0000000..ae3bb13
--- /dev/null
+++ b/include/sqlite3xx/port/dllexport.h
@@ -0,0 +1,39 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __PORT_DLLEXPORT_H
+#define __PORT_DLLEXPORT_H
+
+#ifdef _WIN32
+#ifdef BUILD_SHARED
+#define SQLITEXX_LIBEXPORT __declspec( dllexport )
+#define SQLITEXX_PRIVATE __declspec( )
+#else
+#define SQLITEXX_LIBEXPORT
+#define SQLITEXX_PRIVATE
+#endif
+#else
+#define SQLITEXX_LIBEXPORT
+#define SQLITEXX_PRIVATE
+#endif
+
+#endif /* ifndef __PORT_DLLEXPORT_H */
diff --git a/include/sqlite3xx/port/iterator.hpp b/include/sqlite3xx/port/iterator.hpp
new file mode 100644
index 0000000..2bb083a
--- /dev/null
+++ b/include/sqlite3xx/port/iterator.hpp
@@ -0,0 +1,52 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef SQLITE3XX_ITERATOR_H
+#define SQLITE3XX_ITERATOR_H
+
+#include "sqlite3xx/port/sys.h"
+
+#ifdef SQLITE3XX_BROKEN_ITERATOR
+
+#include <iterator>
+
+namespace sqlite3xxstd {
+
+template<typename Cat,
+ typename T,
+ typename Dist,
+ typename Ptr=T*,
+ typename Ref=T&> struct iterator {
+
+ typedef Cat iterator_category;
+ typedef T value_type;
+ typedef Dist difference_type;
+ typedef Ptr pointer;
+ typedef Ref reference;
+};
+
+} /* namespace sqlite3xxstd */
+
+#endif /* SQLITE3XX_BROKEN_ITERATOR */
+
+#endif /* SQLITE3XX_ITERATOR_H */
diff --git a/include/sqlite3xx/port/stdint.h b/include/sqlite3xx/port/stdint.h
new file mode 100644
index 0000000..cd360b9
--- /dev/null
+++ b/include/sqlite3xx/port/stdint.h
@@ -0,0 +1,68 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __SQLITE3_PORT_STDINT_H
+#define __SQLITE3_PORT_STDINT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "sqlite3xx/port/sys.h"
+
+/* for uintptr_t and snprintf placeholder PRIdPTR (FIXME:
+ * needs a lot of improvement!)
+ */
+#if defined SUNOS
+
+#if OS_MAJOR_VERSION == 5
+
+#if OS_MINOR_VERSION == 8
+#include <sys/int_types.h>
+/* FIXME: this may depend on 32/64-bit version of Solaris 8! */
+#define PRIdPTR "d"
+typedef unsigned long long uint64_t;
+#else
+#include <inttypes.h>
+#include <stdint.h>
+#endif /* OS_MINOR_VERSION == 8 */
+#else
+#include <inttypes.h>
+#include <stdint.h>
+#endif /* OS_MAJOR_VERSION == 5 */
+#else
+
+#if !defined _WIN32
+#include <inttypes.h>
+#include <stdint.h>
+#else
+#include <windows.h>
+#define uintmax_t __int64
+#endif /* !defined _WIN32 */
+
+#endif /* defined SUNOS */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ifndef __SQLITE3_PORT_STDINT_H */
diff --git a/include/sqlite3xx/port/sys.h b/include/sqlite3xx/port/sys.h
new file mode 100644
index 0000000..3d2fd66
--- /dev/null
+++ b/include/sqlite3xx/port/sys.h
@@ -0,0 +1,30 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef SQLITE3XX_SYS_H
+#define SQLITE3XX_SYS_H
+
+/* TODO: check out platforms defining a proper iterator declataion template */
+#define SQLITE3XX_BROKEN_ITERATOR
+
+#endif /* ifndef SQLITE3XX_SYS_H */
diff --git a/include/sqlite3xx/prepared_statement.hpp b/include/sqlite3xx/prepared_statement.hpp
new file mode 100644
index 0000000..4542941
--- /dev/null
+++ b/include/sqlite3xx/prepared_statement.hpp
@@ -0,0 +1,117 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef SQLITE3XX_PREPARED_STATEMENT_H
+#define SQLITE3XX_PREPARED_STATEMENT_H
+
+#include <vector>
+#include <string>
+
+#include <sqlite3xx/port/stdint.h> /* for uintmax_t */
+
+#include "port/dllexport.h"
+
+#include "sqlite3.h"
+
+using namespace std;
+
+namespace sqlite3xx {
+
+class connection;
+class transaction;
+class result;
+
+namespace prepare {
+
+ enum param_treatment {
+ treat_direct
+ };
+
+ /* class to add () parameters to a prepare statement */
+ class SQLITEXX_LIBEXPORT declaration {
+ private:
+ connection& _c;
+ const string& _stmt;
+
+ public:
+ declaration( connection &c, const string& stmt );
+
+ const declaration& operator( )( const string& sql_type,
+ param_treatment treat ) const;
+ };
+
+ class SQLITEXX_LIBEXPORT invocation {
+ private:
+ connection& _c;
+ transaction& _t;
+ const string& _stmt;
+ int _pos;
+
+ public:
+ invocation( connection& c, transaction& t, const string& stmt );
+
+ invocation &setparam( const int& value, bool nonnull );
+ invocation &setparam( const char* value, bool nonnull );
+ invocation &setparam( const string& value, bool nonnull );
+ invocation &setparam( const double& value, bool nonnull );
+ invocation &setparam( const long& value, bool nonnull );
+ invocation &setparam( const uintmax_t& value, bool nonnull );
+
+ result exec( ) const;
+
+ template<typename T>
+ invocation &operator( )( const T &v, bool nonnull = true ) {
+ return setparam( v, nonnull );
+ }
+ };
+}
+
+class SQLITEXX_LIBEXPORT prepared_stmt {
+
+ private:
+ typedef pair<string,prepare::param_treatment> param;
+
+ sqlite3_stmt *_stmt;
+ string _sql;
+ vector<param> parameters;
+ sqlite3 *_db;
+
+ public:
+ prepared_stmt( sqlite3 *db, string __sql );
+ ~prepared_stmt( );
+ string sql( );
+ void addparam( const string& sqltype, prepare::param_treatment& treatment );
+
+ void reset( );
+ void setparam( const int pos, const int value );
+ void setparam( const int pos, const char* value );
+ void setparam( const int pos, const double value );
+ void setparam( const int pos, const long value );
+ void setparam( const int pos, const uintmax_t value );
+
+ sqlite3_stmt* getStmt( ) const;
+};
+
+} /* namespace sqlite3xx */
+
+#endif /* SQLITE3XX_PREPARED_STATEMENT_H */
diff --git a/include/sqlite3xx/result.hpp b/include/sqlite3xx/result.hpp
new file mode 100644
index 0000000..77d1938
--- /dev/null
+++ b/include/sqlite3xx/result.hpp
@@ -0,0 +1,287 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef SQLITE3XX_RESULT_H
+#define SQLITE3XX_RESULT_H
+
+#include "sqlite3.h"
+
+#include <iostream>
+#include <map>
+#include <vector>
+#include <stdexcept>
+#include <sstream>
+
+#include "port/iterator.hpp"
+#include "port/dllexport.h"
+
+using namespace std;
+
+namespace sqlite3xx {
+
+class SQLITEXX_LIBEXPORT result {
+ public:
+ class field;
+ class const_iterator;
+
+ typedef unsigned long size_type;
+ typedef signed long difference_type;
+
+ class SQLITEXX_LIBEXPORT tuple {
+ public:
+ typedef unsigned int size_type;
+
+ private:
+ const result *_r;
+ result::size_type _i;
+
+ public:
+ tuple( const result *r, size_type i ) :
+ _r( r ), _i( i ) { }
+ ~tuple( ) { }
+
+ size_type size( ) const {
+ return _r->columns( );
+ }
+
+ field operator[]( size_type i ) const {
+ return field( *this, i );
+ }
+ field operator[]( int i ) const {
+ return operator[]( (size_type)i );
+ }
+ field operator[]( string s ) const {
+ return field( *this, _r->column_number( s ) );
+ }
+
+ int column_type( size_type i ) const {
+ return _r->column_type( i );
+ }
+
+ int GetValueInt( size_type i ) const {
+ return _r->GetValueInt( i );
+ }
+
+ const unsigned char* GetValueText( size_type i ) const {
+ return _r->GetValueText( i );
+ }
+
+ double GetValueDouble( size_type i ) const {
+ return _r->GetValueDouble( i );
+ }
+
+ size_type rownumber( ) const throw( ) {
+ return _i;
+ }
+
+ protected:
+ tuple( );
+ };
+
+ class SQLITEXX_LIBEXPORT field {
+ private:
+ tuple _t;
+ tuple::size_type _c;
+
+ SQLITEXX_PRIVATE string type_to_str( const int type ) const {
+ switch( type ) {
+ case SQLITE_INTEGER: return "SQLITE_INTEGER";
+ case SQLITE_FLOAT: return "SQLITE_FLOAT";
+ case SQLITE_BLOB: return "SQLITE_BLOB";
+ case SQLITE_NULL: return "SQLITE_NULL";
+ case SQLITE3_TEXT: return "SQLITE_TEXT";
+ default: return "<unknown type>";
+ }
+ }
+
+ public:
+ field( const tuple& t, tuple::size_type c ) :
+ _t( t ), _c( c ) { }
+
+ SQLITEXX_LIBEXPORT friend ostream& operator<<( ostream& o, const field& f );
+
+ void GetValueOfType( int type, int& obj ) const {
+ if( type == SQLITE_INTEGER ) {
+ obj = _t.GetValueInt( _c );
+ } else if( type == SQLITE_NULL ) {
+ obj = 0;
+ } else {
+ ostringstream oss;
+ oss << "Invalid type conversion requested for integer type, type is "
+ << type_to_str( type ) << "(" << type << ")";
+ throw invalid_argument( oss.str( ) );
+ }
+ }
+
+ void GetValueOfType( int type, string& obj ) const {
+ if( type == SQLITE3_TEXT ) {
+ obj = string( (const char *)_t.GetValueText( _c ) );
+ } else if( type == SQLITE_NULL ) {
+ obj = string( );
+ } else {
+ ostringstream oss;
+ oss << "Invalid type conversion requested for string type, type is "
+ << type_to_str( type ) << "(" << type << ")";
+ throw invalid_argument( oss.str( ) );
+ }
+ }
+
+ void GetValueOfType( int type, double& obj ) const {
+ if( type == SQLITE_FLOAT ) {
+ obj = _t.GetValueDouble( _c );
+ } else if( type == SQLITE_NULL ) {
+ obj = 0.0;
+ } else {
+ ostringstream oss;
+ oss << "Invalid type conversion requested for double type, type is "
+ << type_to_str( type ) << "(" << type << ")";
+ throw invalid_argument( oss.str( ) );
+ }
+ }
+
+ template<typename T> bool to( T& obj ) const {
+ int type = _t.column_type( _c );
+ GetValueOfType( type, obj );
+ return true;
+ }
+ };
+
+ typedef sqlite3xxstd::iterator< std::random_access_iterator_tag,
+ const tuple,
+ result::difference_type,
+ const_iterator,
+ tuple>
+ const_iterator_base;
+
+ class SQLITEXX_LIBEXPORT const_iterator :
+ public const_iterator_base,
+ public tuple {
+
+ public:
+ typedef const tuple *pointer;
+
+ const_iterator( ) throw( ) : tuple( 0, 0 ) { }
+ const_iterator( const tuple& t ) throw( )
+ : tuple( t ) { }
+
+ pointer operator->( ) const { return this; }
+ const_iterator operator++( int incr );
+ bool operator<( const const_iterator& i ) const;
+
+ private:
+ int dummy;
+ friend class result;
+ SQLITEXX_PRIVATE const_iterator( const result* r, size_type i ) throw( ) :
+ tuple( r, i ) {
+ };
+ };
+
+ private:
+ sqlite3_stmt* _stmt;
+ size_type _row; /* the currently visible row from the cache */
+ size_type _crow; /* the row of the sqlite step cursor */
+ typedef map<string, size_type> ColMap;
+ ColMap _colmap;
+ typedef vector<int> ColType;
+ ColType _coltype;
+
+ enum Status {
+ st_nascent, /* created, we must call step */
+ st_nodata, /* a command without result data */
+ st_lastrow, /* a query, on the last row */
+ st_hasdata, /* a query, we must clean up in the end */
+ st_nomoredata /* a query, with no data left */
+ };
+
+ class CachedValue {
+ public:
+ int type;
+ union {
+ int i;
+ double d;
+ unsigned char *s;
+ } value;
+
+ public:
+ CachedValue( ) { type = 0; };
+ CachedValue( const CachedValue& v );
+ ~CachedValue( );
+ CachedValue& operator= ( const CachedValue& v );
+ };
+
+ typedef vector<CachedValue> ValueCache;
+ ValueCache _cache;
+
+ Status _status;
+
+ public:
+ result( sqlite3_stmt* stmt );
+ result( const result& r );
+ ~result( );
+ result& operator= ( const result& r );
+
+ size_type affected_rows( ) const;
+ size_type size( ) const;
+ size_type columns( ) const;
+
+ const tuple operator[]( size_type i ) throw( );
+
+ size_type column_number( string name ) const;
+ int column_type( size_type i ) const;
+ int column_type( string name ) const {
+ return column_type( column_number( name ) );
+ }
+
+ int GetValueInt( size_type i ) const {
+ return _cache[i].value.i;
+ }
+
+ const unsigned char* GetValueText( size_type i ) const {
+ return _cache[i].value.s;
+ }
+
+ double GetValueDouble( size_type i ) const {
+ return _cache[i].value.d;
+ }
+
+ const_iterator begin( ) const throw( ) {
+ return const_iterator( this, 0 );
+ }
+
+ /* as size( ) is not reliable, we can't create the correct
+ * tuple with the correct index here
+ */
+ const_iterator end( ) const throw( ) {
+ return const_iterator( this, size( ) );
+ }
+
+ private:
+ SQLITEXX_PRIVATE void Step( );
+ SQLITEXX_PRIVATE void BufferData( );
+ SQLITEXX_PRIVATE void FillColNameMap( );
+ SQLITEXX_PRIVATE void FillColTypeMap( );
+};
+
+}
+
+#endif /* SQLITE3XX_RESULT_H */
diff --git a/include/sqlite3xx/sqlite3xx b/include/sqlite3xx/sqlite3xx
new file mode 100644
index 0000000..4f5b65d
--- /dev/null
+++ b/include/sqlite3xx/sqlite3xx
@@ -0,0 +1,28 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "except.hpp"
+#include "connection.hpp"
+#include "prepared_statement.hpp"
+#include "transaction.hpp"
+#include "result.hpp"
diff --git a/include/sqlite3xx/transaction.hpp b/include/sqlite3xx/transaction.hpp
new file mode 100644
index 0000000..767555f
--- /dev/null
+++ b/include/sqlite3xx/transaction.hpp
@@ -0,0 +1,68 @@
+/*
+ * sqlite3xx - sqlite3 C++ layer, following the ideas of libpqxx
+ * Copyright (C) 2009 Andreas Baumann
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions of
+ * the GNU Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef SQLITE3XX_TRANSACTION_H
+#define SQLITE3XX_TRANSACTION_H
+
+#include "sqlite3xx/connection.hpp"
+#include "sqlite3xx/result.hpp"
+#include "sqlite3xx/prepared_statement.hpp"
+#include "sqlite3.h"
+
+#include "port/dllexport.h"
+
+namespace sqlite3xx {
+
+class SQLITEXX_LIBEXPORT transaction {
+ private:
+ enum Status {
+ st_nascent,
+ st_active,
+ st_aborted,
+ st_committed
+ };
+
+ private:
+ connection& _c;
+ string _name;
+ Status _status;
+
+ protected:
+ void Begin( );
+
+ public:
+ transaction( connection &c, string name = 0 );
+ ~transaction( );
+
+ void commit( );
+ void abort( );
+
+ result exec( string sql );
+ prepare::invocation prepared( const string& name );
+};
+
+typedef transaction work;
+
+}
+
+#endif /* SQLITE3XX_TRANSACTION_H */