RE: accessing SQLite from root/cint

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 12 May 2005 10:21:13 -0500


Hi Fred,

The call back function that you pass back to SQL lite have to be compiled they can not be interpreted (at least not directly).

If you really want to an interpreted call back you should compiled a small real callback function look like (or any other variant):  

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

   gROOT->ProcessLine(Form("actual_callback(0x%x,%d,0x%x,0x%x);",

       NotUsed,argc,argv,azColName));
}

and actual_callback can now be an interpreted function but you are passing the address of compiled_callback to sqllite.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Fred L Youhanaie
Sent: Sunday, May 08, 2005 7:41 PM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] accessing SQLite from root/cint

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 Thu May 12 2005 - 17:21:08 MEST

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