accessing SQLite from root/cint

From: Fred L Youhanaie <fly_at_anydata.co.uk>
Date: Mon, 09 May 2005 01:40:51 +0100

Hi,

I'm trying to use the SQLite API from root directly using the mechanism mentioned at: http://root.cern.ch/root/roottalk/roottalk05/0277.html, but getting segfaults from cint when sqlite3_exec is called with a callback function, an example code is included at the end. I do not get segfault when the 'callback' is replaced with 'NULL' when calling sqlite3_exec.

The same code (minus cint extern feature) works OK when compiled with g++ or ACLiC.

I am using the prebuilt binaries for Linux FC2, 4.03.02 and 4.04.02.

Many thanks and regards
f.



#include <stdio.h>

extern "/opt/sqlite-3.2.1/lib/libsqlite3.so" {
#pragma preprocessor on
#include <sqlite3.h>
#pragma preprocessor off

};

static int callback(void *NotUsed, int argc, char **argv, char **azColName) {

         printf("callback: %d %d\n", (int)NotUsed, argc);
         for (int i=0; i<argc; i++) {
                 printf("\t%s=%s\n", azColName[i], argv[i]);
         }
         return 0;

}

int prog_root()
{

         sqlite3 *db;
         char *zErrMsg = 0;
         int rc;
         rc = sqlite3_open("test1.db", &db);
         fprintf(stderr, "sqlite3_open: rc=%d.\n", rc);
         if (rc) {
                 fprintf(stderr, "Can't open database: %s\n", 
sqlite3_errmsg(db));
                 return(1);
         }
         rc = sqlite3_exec(db, "SELECT * FROM tab1", callback, 0, &zErrMsg);
         fprintf(stderr, "sqlite3_exec: rc=%d.\n", rc);
         if (rc) {
                 fprintf(stderr, "SQL error: %s\n", zErrMsg);
         }
         rc = sqlite3_close(db);
         fprintf(stderr, "sqlite3_close: rc=%d.\n", rc);
         return(rc);

}
Received on Mon May 09 2005 - 02:41:15 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET