From cb8934aed103efcadccd6c6e3464a85676979968 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Thu, 10 Feb 2011 19:48:21 +0000 Subject: [PATCH] implement sqlite3 busy handler, should remove 'database is locked' errors git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2004 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- modules/gsqlite3backend/ssqlite3.cc | 19 ++++++++----------- modules/gsqlite3backend/ssqlite3.hh | 1 + 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/gsqlite3backend/ssqlite3.cc b/modules/gsqlite3backend/ssqlite3.cc index 7d2de7dd6..a575fc62c 100644 --- a/modules/gsqlite3backend/ssqlite3.cc +++ b/modules/gsqlite3backend/ssqlite3.cc @@ -26,6 +26,8 @@ SSQLite3::SSQLite3( const std::string & database ) if ( sqlite3_open( database.c_str(), &m_pDB)!=SQLITE_OK ) throw sPerrorException( "Could not connect to the SQLite database '" + database + "'" ); + + sqlite3_busy_handler(m_pDB, busyHandler, 0); } @@ -68,6 +70,11 @@ int SSQLite3::doQuery( const std::string & query ) return 0; } +int SSQLite3::busyHandler(void*, int) +{ + usleep(1000); + return 1; +} // Returns a row from the result set. bool SSQLite3::getRow( row_t & row ) @@ -78,17 +85,7 @@ bool SSQLite3::getRow( row_t & row ) row.clear(); - do - { - rc = sqlite3_step( m_pStmt ); - - if ( rc == SQLITE_BUSY ) - Utility::usleep( 250 ); // FIXME: Should this be increased, decreased, or is it Just Right? :) - else - break; - - } while ( true ); - + rc = sqlite3_step( m_pStmt ); if ( rc == SQLITE_ROW ) { diff --git a/modules/gsqlite3backend/ssqlite3.hh b/modules/gsqlite3backend/ssqlite3.hh index 9d15dab3f..26bab13af 100644 --- a/modules/gsqlite3backend/ssqlite3.hh +++ b/modules/gsqlite3backend/ssqlite3.hh @@ -19,6 +19,7 @@ private: //! Pointer to the SQLite virtual machine executing a query. sqlite3_stmt *m_pStmt; + static int busyHandler(void*, int); protected: public: //! Constructor. -- 2.50.0