[Pdns-users] Two bugs found in SQLite module (Affecting SLAVES etc)

Darron Broad darron at kewl.org
Fri Jun 4 20:10:28 UTC 2004


Hi

I have found and fixed two bugs in the SQLite module (pdns-2.9.16).

If you are having problems setting up slaves using the SQLite backend,
the patches below should help you.

For your pleasure...

darron
----------------------------------------------------------------------------

Bug 1:

A command never gets finalised and the consequence is that inserts/updates
are never actually performed in the back end.

Fix 1:

I have changed the code to use sqlite_exec which performs an operation
in one command when no result sets are returned.

Bug 2:

GetRow never clears the row vector, consequently the vector continues to
grow each time getROw is called. GetRow appears to work when only one
row is returned in a result set, but when more than one row is returned,
things go horribly wrong.

Fix 2:

The row vector is cleared before returning a new row.

Other bugs:

SQLite error codes aren't inspected at any depth, it's unknown what
side affects this may cause. In my patch for ssqlite.cc/.hh I am using
the same error checking method as in the original.

Patches:

Find below two patches, one for ssqlite.hh and another for ssqlite.cc.

ssqlite.hh
==========

37,41c37
<   int doCommand( const std::string & query )
<   {
<     return doQuery(query);
<   }
< 
---
>   int doCommand( const std::string & query );

ssqlite.cc
==========

--- ssqlite.cc.orig	Fri Jun  4 20:56:22 2004
+++ ssqlite.cc	Fri Jun  4 20:56:55 2004
@@ -9,6 +9,10 @@
 #include "ssqlite.hh"
 #include <iostream>
 
+extern "C" {
+#include <unistd.h>
+};
+
 #ifdef WIN32

 # include <io.h>

 # define access _access

@@ -82,6 +86,40 @@
 }
 
 
+// Performs a command.
+int SSQLite::doCommand( const std::string & query )
+{   
+  int rc;
+  
+  // Execute the query.
+  char *pError = NULL;
+  do
+  {
+    rc= sqlite_exec( m_pDB, query.c_str(), NULL, NULL, &pError );
+
+    if ( rc == SQLITE_BUSY )
+      Utility::usleep( 250 ); // FIXME: Should this be increased, decreased, or is it Just Right? :)
+    else
+      break;
+
+  } while ( true );
+ 
+  if ( rc != SQLITE_OK )
+  {
+    std::string report( "Unable to exec SQLite statement" );
+
+    if( pError ) 
+    {
+      report += string( ": " ) + pError;
+      sqlite_freemem( pError );
+    }
+
+    sPerrorException( report );
+  }
+  return 0;
+}
+
+
 // Returns a row from the result set.
 bool SSQLite::getRow( row_t & row )
 {
@@ -89,6 +127,8 @@
   int  rc;
   const char **ppData;
   const char **ppColumnNames;
+
+  row.clear();  // This is important
 
   do
   {

--

 // /
{:)==={ Darron Broad <darron at kewl.org>
 \\ \



More information about the Pdns-users mailing list