From 1dcc640c490a6619eeba19a6bdb93c4ac8d5a6fc Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 6 Sep 2010 10:53:02 +0200 Subject: more cleanup in exceptions, added a database_locked exception, now we must fix the code to throw this exception all the time and not do funny sleeps in the middle of the sqlitexx layer! --- src/except.cpp | 11 +++++++++-- src/prepared_statement.cpp | 19 ++++++++++++++----- src/result.cpp | 4 +--- 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/except.cpp b/src/except.cpp index 5ae357d..9a07334 100644 --- a/src/except.cpp +++ b/src/except.cpp @@ -44,11 +44,18 @@ sql_error::sql_error( const string &_what, const string &_q ) { } -sql_error::~sql_error( ) throw( ){ +sql_error::~sql_error( ) throw( ) +{ } -const string& sql_error::query( ) const throw( ) { +const string& sql_error::query( ) const throw( ) +{ return m_q; } +database_locked::database_locked( ) + : failure( "database locked" ) +{ +} + } /* namespace sqlite3xx */ diff --git a/src/prepared_statement.cpp b/src/prepared_statement.cpp index b8074b3..674fbec 100644 --- a/src/prepared_statement.cpp +++ b/src/prepared_statement.cpp @@ -122,11 +122,20 @@ prepared_stmt::prepared_stmt( sqlite3 *db, string __sql ) : #else rc = sqlite3_prepare( db, _sql.c_str( ), -1, &_stmt, &tail ); #endif - if( rc != SQLITE_OK ) { - ostringstream s; - s << "sqlite3::prepared_stmt::prepared_stmt error: " << sqlite3_errmsg( _db ); - string msg = s.str( ); - throw sql_error( msg, _sql ); + switch( rc ) { + case SQLITE_BUSY: + throw database_locked( ); + + case SQLITE_OK: + break; + + default: + { + ostringstream s; + s << "sqlite3::prepared_stmt::prepared_stmt error: " << sqlite3_errmsg( _db ); + string msg = s.str( ); + throw sql_error( msg, _sql ); + } } } diff --git a/src/result.cpp b/src/result.cpp index f855a0a..5f989a9 100644 --- a/src/result.cpp +++ b/src/result.cpp @@ -74,7 +74,6 @@ ostream& operator<<( ostream& o, const result::field& f ) { void result::Step( ) { int rc; -TRY_AGAIN_STEP: rc = sqlite3_step( _stmt ); switch( rc ) { case SQLITE_DONE: @@ -95,8 +94,7 @@ TRY_AGAIN_STEP: /* don't fail if the sqlite file is locked by another writer, try again later */ case SQLITE_BUSY: -// sqlitexx_port_sleep( 1 ); - goto TRY_AGAIN_STEP; + throw database_locked( ); default: { ostringstream s; -- cgit v1.2.3-54-g00ecf