]> granicus.if.org Git - pdns/commitdiff
implement sqlite3 busy handler, should remove 'database is locked' errors
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 10 Feb 2011 19:48:21 +0000 (19:48 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 10 Feb 2011 19:48:21 +0000 (19:48 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2004 d19b8d6e-7fed-0310-83ef-9ca221ded41b

modules/gsqlite3backend/ssqlite3.cc
modules/gsqlite3backend/ssqlite3.hh

index 7d2de7dd6f0f1c7145113a745958cf789893185d..a575fc62c54d16b0fa017628e6d65b53bd47d3df 100644 (file)
@@ -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 )
   {
index 9d15dab3fff7a0c19a53d6fdde237ef30ff3a31b..26bab13af093e3165f9762faa8dd739076cb7300 100644 (file)
@@ -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.