DBI provides a connection manager that the thing looks up against when a db-specific call is made. Here is an example of closing the connection in rmysql:
s_object *
RS_MySQL_closeConnection(Con_Handle *conHandle)
{
S_EVALUATOR
RS_DBI_connection *con;
MYSQL *my_connection;
s_object *status;
con = RS_DBI_getConnection(conHandle);
.
.
.
my_connection = (MYSQL *) con->drvConnection;
mysql_close(my_connection);
…
}
and the same thing from rsqlite:
SEXP
RS_SQLite_closeConnection(Con_Handle conHandle)
{
RS_DBI_connection *con;
sqlite3 *db_connection;
SEXP status;
int rc;
con = RS_DBI_getConnection(conHandle);
db_connection = (sqlite3 *) con->drvConnection;
rc = sqlite3_close(db_connection); /* it also frees db_connection */
.
.
.
return status;
}
and here's RS_MySQL_exec to run a generic query.
/* Here is where we actually run the query */
state = mysql_query(my_connection, dyn_statement);
if(state) {
char errMsg[256];
free(dyn_statement);
(void) sprintf(errMsg, "could not run statement: %s",
mysql_error(my_connection));
RS_DBI_errorMessage(errMsg, RS_DBI_ERROR);
}
So it looks like: 1) new storage.h will need include configure options for whether to include rs-dbi.h, rs-mysql.h, and rs-sqlite.h, defaulting to all of the above. 2) MCMCstore will be templated for each storagetype. 3) the connection will be opened from R, when tables are created, then the connection id passed to the model-fitting c++ code. The model-fitting code will initialize an object of class MCMCstore. The MCMCstore class store() function will call appropriate db-specific code (sqlite_bind_double, whatever mysql bind syntax is, insert, exec, reset,… etc.).
No comments:
Post a Comment