summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2010-09-04 16:54:57 +0200
committerAndreas Baumann <abaumann@yahoo.com>2010-09-04 16:54:57 +0200
commit9a717577d06f00bb8a0c7338f7b687540b5e017d (patch)
treea81207d179392c440b700e86e5d400821e6bac45
parenta33fbbf643a52938063779a35167757a2426446e (diff)
downloadsqlitexx-9a717577d06f00bb8a0c7338f7b687540b5e017d.tar.gz
sqlitexx-9a717577d06f00bb8a0c7338f7b687540b5e017d.tar.bz2
some fixes for unsigned int parameters for prepared statements
-rw-r--r--include/sqlite3xx/connection.hpp1
-rw-r--r--include/sqlite3xx/prepared_statement.hpp2
-rw-r--r--src/connection.cpp7
-rw-r--r--src/prepared_statement.cpp20
-rw-r--r--tests/test9.cpp2
5 files changed, 31 insertions, 1 deletions
diff --git a/include/sqlite3xx/connection.hpp b/include/sqlite3xx/connection.hpp
index 0d95a7e..c7c1069 100644
--- a/include/sqlite3xx/connection.hpp
+++ b/include/sqlite3xx/connection.hpp
@@ -71,6 +71,7 @@ class SQLITEXX_LIBEXPORT connection {
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 unsigned 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 );
diff --git a/include/sqlite3xx/prepared_statement.hpp b/include/sqlite3xx/prepared_statement.hpp
index 4542941..336adaf 100644
--- a/include/sqlite3xx/prepared_statement.hpp
+++ b/include/sqlite3xx/prepared_statement.hpp
@@ -71,6 +71,7 @@ namespace prepare {
invocation( connection& c, transaction& t, const string& stmt );
invocation &setparam( const int& value, bool nonnull );
+ invocation &setparam( const unsigned 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 );
@@ -104,6 +105,7 @@ class SQLITEXX_LIBEXPORT prepared_stmt {
void reset( );
void setparam( const int pos, const int value );
+ void setparam( const int pos, const unsigned 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 );
diff --git a/src/connection.cpp b/src/connection.cpp
index 30ab00a..5db2e4d 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -154,6 +154,13 @@ void connection::prepare_setparam( const string& name, const int pos, const int
stmt->setparam( pos, value );
}
+void connection::prepare_setparam( const string& name, const int pos, const unsigned int value ) {
+ prepared_stmt* stmt = find_prepared( name );
+ if( _trace ) cout << "TRACE: prepared '" << name << "' param '" <<
+ pos << "'" << " value: " << value << endl;
+ stmt->setparam( pos, value );
+}
+
void connection::prepare_setparam( const string& name, const int pos, const char* value ) {
prepared_stmt* stmt = find_prepared( name );
if( _trace ) cout << "TRACE: prepared '" << name << "' param '" <<
diff --git a/src/prepared_statement.cpp b/src/prepared_statement.cpp
index fef5090..b8074b3 100644
--- a/src/prepared_statement.cpp
+++ b/src/prepared_statement.cpp
@@ -68,6 +68,13 @@ prepare::invocation& prepare::invocation::setparam( const int& value, bool nonnu
return *this;
}
+prepare::invocation& prepare::invocation::setparam( const unsigned int& value, bool nonnull ) {
+ SQLITEXX_UNUSED( nonnull );
+ _pos++;
+ _c.prepare_setparam( _stmt, _pos, value );
+ return *this;
+}
+
prepare::invocation& prepare::invocation::setparam( const char* value, bool nonnull ) {
SQLITEXX_UNUSED( nonnull );
_pos++;
@@ -163,6 +170,19 @@ void prepared_stmt::setparam( const int pos, const int v ) {
}
}
+void prepared_stmt::setparam( const int pos, const unsigned int v ) {
+ int rc;
+ assert( _stmt != NULL );
+ rc = sqlite3_bind_int( _stmt, pos, v );
+ if( rc != SQLITE_OK ) {
+ ostringstream s;
+ s << "sqlite3::prepared_stmt::setparam bind error: "
+ << sqlite3_errmsg( _db ) << " (rc: " << rc << ")";
+ string msg = s.str( );
+ throw sql_error( msg, _sql );
+ }
+}
+
void prepared_stmt::setparam( const int pos, const char* v ) {
int rc;
assert( _stmt != NULL );
diff --git a/tests/test9.cpp b/tests/test9.cpp
index 62e17dc..bbcddb6 100644
--- a/tests/test9.cpp
+++ b/tests/test9.cpp
@@ -52,7 +52,7 @@ static THREAD_FUNC_DECL produce( void *thread_data )
try {
connection c( "test9.db" );
- c.prepare( "ins", "insert into x values( ? )" )( "text", sqlite3xx::prepare::treat_direct );
+ c.prepare( "ins", "insert into x values( ? )" )( "integer", prepare::treat_direct );
for( int i = 0; i < NOF_PRODUCER_TRANSACTIONS; i++ ) {
work t( c, "ins" );