summaryrefslogtreecommitdiff
path: root/tests/sqlite
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-12-06 18:26:28 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-12-06 18:26:28 +0100
commit03e26d2afeba8d7db58106decf195da924b9bd95 (patch)
tree7f1a8c7ab5c8f7cb180191abdbfe5ab7d7117012 /tests/sqlite
parent352bae73923d7ec6c20a51f639c5eccef80afcad (diff)
downloadcrawler-03e26d2afeba8d7db58106decf195da924b9bd95.tar.gz
crawler-03e26d2afeba8d7db58106decf195da924b9bd95.tar.bz2
added some sqlite3xx tests
Diffstat (limited to 'tests/sqlite')
-rw-r--r--tests/sqlite/GNUmakefile30
-rw-r--r--tests/sqlite/test1.cpp46
-rw-r--r--tests/sqlite/test2.cpp42
3 files changed, 118 insertions, 0 deletions
diff --git a/tests/sqlite/GNUmakefile b/tests/sqlite/GNUmakefile
new file mode 100644
index 0000000..7aa1d44
--- /dev/null
+++ b/tests/sqlite/GNUmakefile
@@ -0,0 +1,30 @@
+TOPDIR = ../..
+
+SUBDIRS =
+
+INCLUDE_DIRS = -I. -I$(TOPDIR) -I/usr/include/sqlite3xx
+
+LDFLAGS_DIR = \
+ -L/usr/lib
+
+LIBS_DIR = \
+ -lsqlite3xx -lsqlite3
+
+CPP_BINS = \
+ test1$(EXE) \
+ test2$(EXE)
+
+OBJS =
+
+-include $(TOPDIR)/makefiles/sub.mk
+
+local_all:
+
+local_clean:
+
+local_distclean:
+
+local_test: $(CPP_BINS)
+ @echo "libpqxx simple test.."
+ ./test1
+ \ No newline at end of file
diff --git a/tests/sqlite/test1.cpp b/tests/sqlite/test1.cpp
new file mode 100644
index 0000000..d0f64ee
--- /dev/null
+++ b/tests/sqlite/test1.cpp
@@ -0,0 +1,46 @@
+#include <iostream>
+#include <sstream>
+#include <stdio.h>
+
+#include "sqlite3xx"
+
+using namespace sqlite3xx;
+using namespace std;
+
+int main( ) {
+ try {
+ // connection c( "dbname=test" );
+ connection c( "test1.db" );
+
+ //c.trace( stdout );
+
+ cout << "Connected to database." << endl;
+ // << "Backend protocol version: " << c.server_version( ) << endl
+ // << "Protocol version: " << c.protocol_version( ) << endl
+ // << "Server PID: " << c.backendpid( ) << endl
+ // << "Prepared Statements: " << c.supports( c.cap_prepared_statements ) << endl;
+
+ work t( c, "test_transaction" );
+
+ t.exec( "create table test( a integer, b integer)" );
+ for( unsigned int i = 0; i < 1000; i++ ) {
+ ostringstream sql;
+ sql << "insert into test values( '" << i << "', '" << i << "' )";
+ t.exec( sql.str( ) );
+ }
+
+ result r( t.exec( "select * from test" ) );
+ cout << "a\tb" << endl;
+ for( result::size_type i = 0; i < r.size( ); i++ ) {
+ cout << r[i]["a"] << "\t" << r[i]["b"] << endl;
+ }
+
+ t.exec( "drop table test" );
+
+ t.commit( );
+ } catch( sql_error& e ) {
+ cerr << e.msg( ) << ": " << e.query( ) << endl;
+ }
+
+ return 0;
+}
diff --git a/tests/sqlite/test2.cpp b/tests/sqlite/test2.cpp
new file mode 100644
index 0000000..fc3a79e
--- /dev/null
+++ b/tests/sqlite/test2.cpp
@@ -0,0 +1,42 @@
+#include <iostream>
+#include <sstream>
+#include <stdio.h>
+
+#include "sqlite3xx"
+
+using namespace sqlite3xx;
+using namespace std;
+
+int main( ) {
+ try {
+ //connection c( "dbname=test" );
+ connection c( "test2.db" );
+
+ //c.trace( stdout );
+
+ work t( c, "test_transaction" );
+
+ t.exec( "create table test( a integer, b integer)" );
+ for( int i = 0; i < 1000; i++ ) {
+ c.prepare( "insertTestStmt",
+ "insert into test(a,b) values($1,$2)" )
+ ( "integer", prepare::treat_direct )
+ ( "integer", prepare::treat_direct );
+ t.prepared( "insertTestStmt" )(i)(i).exec( );
+ }
+
+ result r( t.exec( "select * from test" ) );
+ cout << "a\tb" << endl;
+ for( result::size_type i = 0; i < r.size( ); i++ ) {
+ cout << r[i]["a"] << "\t" << r[i]["b"] << endl;
+ }
+
+ t.exec( "drop table test" );
+
+ t.commit( );
+ } catch( sql_error& e ) {
+ cerr << e.msg( ) << ": " << e.query( ) << endl;
+ }
+
+ return 0;
+}