diff options
author | Andreas Baumann <Andreas.Baumann@eurospider.com> | 2010-09-06 10:53:02 +0200 |
---|---|---|
committer | Andreas Baumann <Andreas.Baumann@eurospider.com> | 2010-09-06 10:53:02 +0200 |
commit | 1dcc640c490a6619eeba19a6bdb93c4ac8d5a6fc (patch) | |
tree | fa6db7059152ef1f34ed925b39c92d068812cb75 /src | |
parent | 73a0556dca6ff98da2a77a34e75c5eec5969cd87 (diff) | |
download | sqlitexx-1dcc640c490a6619eeba19a6bdb93c4ac8d5a6fc.tar.gz sqlitexx-1dcc640c490a6619eeba19a6bdb93c4ac8d5a6fc.tar.bz2 |
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!
Diffstat (limited to 'src')
-rw-r--r-- | src/except.cpp | 11 | ||||
-rw-r--r-- | src/prepared_statement.cpp | 19 | ||||
-rw-r--r-- | src/result.cpp | 4 |
3 files changed, 24 insertions, 10 deletions
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; |