summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <Andreas.Baumann@eurospider.com>2010-09-06 15:16:38 +0200
committerAndreas Baumann <Andreas.Baumann@eurospider.com>2010-09-06 15:16:38 +0200
commitf6c143f4c4e4f0a8118596909114e34dfc496b92 (patch)
tree1a372ef0090360cf80c8d3168ba8e4e619c6b349
parent23979669900d75bccefb5b4a825882d329a2bd9d (diff)
downloadsqlitexx-f6c143f4c4e4f0a8118596909114e34dfc496b92.tar.gz
sqlitexx-f6c143f4c4e4f0a8118596909114e34dfc496b92.tar.bz2
fixed test9, works now
-rw-r--r--include/sqlite3xx/except.hpp5
-rw-r--r--src/except.cpp5
-rw-r--r--src/prepared_statement.cpp4
-rw-r--r--src/result.cpp2
-rw-r--r--tests/test9.cpp30
5 files changed, 31 insertions, 15 deletions
diff --git a/include/sqlite3xx/except.hpp b/include/sqlite3xx/except.hpp
index 742f17c..e19232e 100644
--- a/include/sqlite3xx/except.hpp
+++ b/include/sqlite3xx/except.hpp
@@ -44,7 +44,7 @@ class SQLITEXX_LIBEXPORT failure : public sqlitexx_exception, public runtime_err
virtual exception &base( ) throw( ) { return *this; }
public:
- explicit failure( const string &s );
+ explicit failure( const string &m );
};
class SQLITEXX_LIBEXPORT sql_error : public failure
@@ -54,7 +54,7 @@ class SQLITEXX_LIBEXPORT sql_error : public failure
public:
sql_error( );
explicit sql_error( const string& _q );
- explicit sql_error( const string& _m, const string& _q );
+ explicit sql_error( const string& _what, const string& _q );
virtual ~sql_error( ) throw( );
const string& msg( ) const throw( );
@@ -65,6 +65,7 @@ class SQLITEXX_LIBEXPORT database_locked : public failure
{
public:
database_locked( );
+ explicit database_locked( const string &_what );
};
} // namespace sqlite3xx
diff --git a/src/except.cpp b/src/except.cpp
index 9a07334..6b34c69 100644
--- a/src/except.cpp
+++ b/src/except.cpp
@@ -58,4 +58,9 @@ database_locked::database_locked( )
{
}
+database_locked::database_locked( const string &_what )
+ : failure( _what )
+{
+}
+
} /* namespace sqlite3xx */
diff --git a/src/prepared_statement.cpp b/src/prepared_statement.cpp
index a63a75c..b2308bd 100644
--- a/src/prepared_statement.cpp
+++ b/src/prepared_statement.cpp
@@ -127,7 +127,7 @@ prepared_stmt::prepared_stmt( sqlite3 *db, string __sql ) :
break;
case SQLITE_BUSY:
- throw database_locked( );
+ throw database_locked( "locked in prepared statement" );
default:
{
@@ -163,7 +163,7 @@ void prepared_stmt::reset( ) {
break;
case SQLITE_BUSY:
- throw database_locked( );
+ throw database_locked( "database locked in reset" );
default:
{
diff --git a/src/result.cpp b/src/result.cpp
index 5f989a9..6edd2e7 100644
--- a/src/result.cpp
+++ b/src/result.cpp
@@ -94,7 +94,7 @@ void result::Step( ) {
/* don't fail if the sqlite file is locked by another writer, try again later */
case SQLITE_BUSY:
- throw database_locked( );
+ throw database_locked( "database locked in step" );
default: {
ostringstream s;
diff --git a/tests/test9.cpp b/tests/test9.cpp
index 5252524..07c1348 100644
--- a/tests/test9.cpp
+++ b/tests/test9.cpp
@@ -45,7 +45,7 @@ const int NOF_CONSUMER_OPS = 100;
static MUTEX_TYPE cout_mutex;
static bool verbose = false;
-static bool tracing = true;
+static bool tracing = false;
static THREAD_FUNC_DECL produce( void *thread_data )
{
@@ -54,7 +54,12 @@ static THREAD_FUNC_DECL produce( void *thread_data )
try {
connection c( "test9.db" );
if( tracing ) c.trace( true );
- c.prepare( "ins", "insert into x values( ? )" )( "integer", prepare::treat_direct );
+PRODUCER_PREPARE_AGAIN:
+ try {
+ c.prepare( "ins", "insert into x values( ? )" )( "integer", prepare::treat_direct );
+ } catch( const database_locked& e ) {
+ goto PRODUCER_PREPARE_AGAIN;
+ }
for( int i = 0; i < NOF_PRODUCER_TRANSACTIONS; i++ ) {
work t( c, "ins" );
@@ -68,18 +73,18 @@ PRODUCER_INS_AGAIN:
try {
result r = t.prepared( "ins" )( no * 100000 + i * 1000 + j ).exec( );
assert( r.affected_rows( ) == 1 );
- } catch( database_locked& e ) {
+ t.commit( );
+ } catch( const database_locked& e ) {
goto PRODUCER_INS_AGAIN;
}
}
- t.commit( );
if( verbose ) {
MUTEX_LOCK( cout_mutex );
cout << "producer " << no << " transaction " << i << " terminated" << endl;
MUTEX_UNLOCK( cout_mutex );
}
}
- } catch( sql_error& e ) {
+ } catch( const sql_error& e ) {
cerr << "producer error, " << e.what( ) << ": " << e.query( ) << endl;
}
@@ -92,7 +97,12 @@ static THREAD_FUNC_DECL consume( void *thread_data )
try {
connection c( "test9.db" );
- c.prepare( "sel", "select * from x" );
+CONSUMER_PREPARE_AGAIN:
+ try {
+ c.prepare( "sel", "select * from x" );
+ } catch( const database_locked &e ) {
+ goto CONSUMER_PREPARE_AGAIN;
+ }
if( tracing ) c.trace( true );
for( int i = 0; i < NOF_CONSUMER_TRANSACTIONS; i++ ) {
@@ -116,18 +126,18 @@ CONSUMER_SELECT_AGAIN:
cout << "consumer " << no << " transaction " << i << " got " << nof_rows << " rows." << endl;
MUTEX_UNLOCK( cout_mutex );
}
- } catch( database_locked& e ) {
+ t.commit( );
+ } catch( const database_locked& e ) {
goto CONSUMER_SELECT_AGAIN;
}
}
- t.commit( );
if( verbose ) {
MUTEX_LOCK( cout_mutex );
cout << "consumer " << no << " transaction " << i << " terminated" << endl;
MUTEX_UNLOCK( cout_mutex );
}
}
- } catch( sql_error& e ) {
+ } catch( const sql_error& e ) {
cerr << "consumer error, " << e.what( ) << ": " << e.query( ) << endl;
}
@@ -171,7 +181,7 @@ int main( ) {
MUTEX_CLEANUP( cout_mutex );
- } catch( sql_error& e ) {
+ } catch( const sql_error& e ) {
cerr << e.what( ) << ": " << e.query( ) << endl;
}
}