* -----------------------------------------------------------------------
*/
-/* List of open databases */ /* SRE: needed for ingres? */
+/* List of open databases */
static BQUEUE db_list = {&db_list, &db_list};
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int mult_db_connections)
{
B_DB *mdb;
+ int next_session_id = 0;
if (!db_user) {
Jmsg(jcr, M_FATAL, 0, _("A user name for Ingres must be supplied.\n"));
V(mutex);
return mdb; /* already open */
}
+
+ if (mdb->session_id > next_session_id) {
+ next_session_id = mdb->session_id;
+ }
+ }
+ } else {
+ /*
+ * See what the next available session_id is.
+ * We first see what the highest session_id is used now.
+ */
+ foreach_dlist(mdb, db_list) {
+ if (mdb->session_id > next_session_id) {
+ next_session_id = mdb->session_id;
+ }
}
}
Dmsg0(100, "db_open first time\n");
mdb->db_socket = bstrdup(db_socket);
}
mdb->db_port = db_port;
+ mdb->session_id = ++next_session_id;
mdb->have_insert_id = TRUE;
mdb->errmsg = get_pool_memory(PM_EMSG); /* get error message buffer */
*mdb->errmsg = 0;
return true;
}
-/*
- * Check for errors in DBMS work
- */
-static int sql_check(B_DB *mdb)
-{
- int errorcode;
-
- if ((errorcode = INGcheck()) < 0) {
- /* TODO: fill mdb->errmsg */
- Mmsg(mdb->errmsg, "Something went wrong - still searching!\n");
- } else if (errorcode > 0) {
- /* just a warning, proceed */
- }
- return errorcode;
-}
-
/*
* Now actually open the database. This can generate errors,
* which are returned in the errmsg
port = NULL;
}
- mdb->db = INGconnectDB(mdb->db_name, mdb->db_user, mdb->db_password);
+ mdb->db = INGconnectDB(mdb->db_name, mdb->db_user, mdb->db_password, mdb->session_id);
Dmsg0(50, "Ingres real CONNECT done\n");
Dmsg3(50, "db_user=%s db_name=%s db_password=%s\n", mdb->db_user, mdb->db_name,
mdb->db_password==NULL?"(NULL)":mdb->db_password);
- if (sql_check(mdb)) {
+ if (!mdb->db) {
Mmsg2(&mdb->errmsg, _("Unable to connect to Ingres server.\n"
"Database=%s User=%s\n"
"It is probably not running or your password is incorrect.\n"),
*/
void my_ingres_close(B_DB *mdb)
{
- INGdisconnectDB(mdb->db);
- //SRE: error handling?
+ Dmsg0(500, "my_ingres_close closing database connection\n");
+ INGdisconnectDB(mdb->db);
+ //SRE: error handling?
}
INGRES_ROW my_ingres_fetch_row(B_DB *mdb)
/* TODO: differentiate between SELECTs and other queries */
- if ((cols = INGgetCols(new_query)) <= 0) {
+ if ((cols = INGgetCols(mdb->db, new_query)) <= 0) {
if (cols < 0 ) {
Dmsg0(500,"my_ingres_query: neg.columns: no DML stmt!\n");
}
{
return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0;
}
-short INGgetCols(const char *query)
+short INGgetCols(INGconn *conn, const char *query)
{
/* # line 57 "myingres.sc" */
+ int sess_id;
char *stmt;
-/* # line 59 "myingres.sc" */
+/* # line 60 "myingres.sc" */
short number = 1;
IISQLDA *sqlda;
memset(sqlda, 0, (IISQDA_HEAD_SIZE + (number * IISQDA_VAR_SIZE)));
sqlda->sqln = number;
stmt = bstrdup(query);
-/* # line 71 "myingres.sc" */ /* prepare */
+ /*
+ * Switch to the correct default session for this thread.
+ */
+ sess_id = conn->session_id;
+/* # line 76 "myingres.sc" */ /* set_sql */
+ {
+ IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id);
+ }
+/* # line 78 "myingres.sc" */ /* prepare */
{
IIsqInit(&sqlca);
IIsqPrepare(0,(char *)"s1",(char *)0,0,stmt);
}
-/* # line 72 "myingres.sc" */ /* host code */
+/* # line 79 "myingres.sc" */ /* host code */
if (INGcheck() < 0) {
number = -1;
goto bail_out;
}
-/* # line 77 "myingres.sc" */ /* describe */
+/* # line 84 "myingres.sc" */ /* describe */
{
IIsqInit(&sqlca);
IIsqDescribe(0,(char *)"s1",sqlda,0);
}
-/* # line 78 "myingres.sc" */ /* host code */
+/* # line 85 "myingres.sc" */ /* host code */
if (INGcheck() < 0) {
number = -1;
goto bail_out;
}
number = sqlda->sqld;
bail_out:
+ /*
+ * Switch to no default session for this thread.
+ */
+/* # line 96 "myingres.sc" */ /* set_sql */
+ {
+ IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97));
+ }
+/* # line 97 "myingres.sc" */ /* host code */
free(stmt);
free(sqlda);
return number;
}
static inline IISQLDA *INGgetDescriptor(short numCols, const char *query)
{
-/* # line 93 "myingres.sc" */
+/* # line 104 "myingres.sc" */
char *stmt;
-/* # line 95 "myingres.sc" */
+/* # line 106 "myingres.sc" */
int i;
IISQLDA *sqlda;
memset(sqlda, 0, (IISQDA_HEAD_SIZE + (numCols * IISQDA_VAR_SIZE)));
sqlda->sqln = numCols;
stmt = bstrdup(query);
-/* # line 107 "myingres.sc" */ /* prepare */
+/* # line 118 "myingres.sc" */ /* prepare */
{
IIsqInit(&sqlca);
IIsqPrepare(0,(char *)"s2",sqlda,0,stmt);
}
-/* # line 109 "myingres.sc" */ /* host code */
+/* # line 120 "myingres.sc" */ /* host code */
free(stmt);
for (i = 0; i < sqlda->sqld; ++i) {
/*
IISQLDA *desc;
int check = -1;
desc = ing_res->sqlda;
-/* # line 363 "myingres.sc" */ /* host code */
+/* # line 374 "myingres.sc" */ /* host code */
if ((check = INGcheck()) < 0) {
return check;
}
-/* # line 367 "myingres.sc" */ /* open */
+/* # line 378 "myingres.sc" */ /* open */
{
IIsqInit(&sqlca);
- IIcsOpen((char *)"c2",19318,7414);
+ IIcsOpen((char *)"c2",10631,20435);
IIwritio(0,(short *)0,1,32,0,(char *)"s2");
- IIcsQuery((char *)"c2",19318,7414);
+ IIcsQuery((char *)"c2",10631,20435);
}
-/* # line 368 "myingres.sc" */ /* host code */
+/* # line 379 "myingres.sc" */ /* host code */
if ((check = INGcheck()) < 0) {
return check;
}
/* for (linecount = 0; sqlca.sqlcode == 0; ++linecount) */
do {
-/* # line 374 "myingres.sc" */ /* fetch */
+/* # line 385 "myingres.sc" */ /* fetch */
{
IIsqInit(&sqlca);
- if (IIcsRetScroll((char *)"c2",19318,7414,-1,-1) != 0) {
+ if (IIcsRetScroll((char *)"c2",10631,20435,-1,-1) != 0) {
IIcsDaGet(0,desc);
IIcsERetrieve();
} /* IIcsRetrieve */
}
-/* # line 376 "myingres.sc" */ /* host code */
+/* # line 387 "myingres.sc" */ /* host code */
if ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) ) {
row = INGgetRowSpace(ing_res); /* alloc space for fetched row */
/*
++linecount;
}
} while ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) );
-/* # line 394 "myingres.sc" */ /* close */
+/* # line 405 "myingres.sc" */ /* close */
{
IIsqInit(&sqlca);
- IIcsClose((char *)"c2",19318,7414);
+ IIcsClose((char *)"c2",10631,20435);
}
-/* # line 396 "myingres.sc" */ /* host code */
+/* # line 407 "myingres.sc" */ /* host code */
ing_res->status = ING_COMMAND_OK;
ing_res->num_rows = linecount;
return linecount;
}
int INGexec(INGconn *conn, const char *query)
{
- int check;
-/* # line 477 "myingres.sc" */
+/* # line 487 "myingres.sc" */
+ int sess_id;
int rowcount;
char *stmt;
-/* # line 480 "myingres.sc" */
+/* # line 491 "myingres.sc" */
stmt = bstrdup(query);
rowcount = -1;
-/* # line 485 "myingres.sc" */ /* execute */
+ /*
+ * Switch to the correct default session for this thread.
+ */
+ sess_id = conn->session_id;
+/* # line 500 "myingres.sc" */ /* set_sql */
+ {
+ IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id);
+ }
+/* # line 501 "myingres.sc" */ /* execute */
{
IIsqInit(&sqlca);
IIsqExImmed(stmt);
IIsyncup((char *)0,0);
}
-/* # line 487 "myingres.sc" */ /* host code */
+/* # line 503 "myingres.sc" */ /* host code */
free(stmt);
- if ((check = INGcheck()) < 0) {
- return check;
+ if ((rowcount = INGcheck()) < 0) {
+ goto bail_out;
}
-/* # line 493 "myingres.sc" */ /* inquire_ingres */
+/* # line 509 "myingres.sc" */ /* inquire_ingres */
{
IILQisInqSqlio((short *)0,1,30,sizeof(rowcount),&rowcount,8);
}
-/* # line 494 "myingres.sc" */ /* host code */
- if ((check = INGcheck()) < 0) {
- return check;
+/* # line 510 "myingres.sc" */ /* host code */
+ if ((rowcount = INGcheck()) < 0) {
+ goto bail_out;
}
+bail_out:
+ /*
+ * Switch to no default session for this thread.
+ */
+/* # line 518 "myingres.sc" */ /* set_sql */
+ {
+ IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97));
+ }
+/* # line 519 "myingres.sc" */ /* host code */
return rowcount;
}
INGresult *INGquery(INGconn *conn, const char *query)
IISQLDA *desc = NULL;
INGresult *res = NULL;
int rows = -1;
- int cols = INGgetCols(query);
+ int cols = INGgetCols(conn, query);
+/* # line 531 "myingres.sc" */
+
+ int sess_id;
+/* # line 533 "myingres.sc" */
+
+ /*
+ * Switch to the correct default session for this thread.
+ */
+ sess_id = conn->session_id;
+/* # line 539 "myingres.sc" */ /* set_sql */
+ {
+ IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id);
+ }
+/* # line 541 "myingres.sc" */ /* host code */
desc = INGgetDescriptor(cols, query);
if (!desc) {
- return NULL;
+ goto bail_out;
}
res = INGgetINGresult(desc);
if (!res) {
- return NULL;
+ goto bail_out;
}
rows = INGfetchAll(query, res);
if (rows < 0) {
- INGfreeDescriptor(desc);
- INGfreeINGresult(res);
- return NULL;
+ INGfreeDescriptor(desc);
+ INGfreeINGresult(res);
+ res = NULL;
+ goto bail_out;
}
+bail_out:
+ /*
+ * Switch to no default session for this thread.
+ */
+/* # line 564 "myingres.sc" */ /* set_sql */
+ {
+ IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97));
+ }
+/* # line 565 "myingres.sc" */ /* host code */
return res;
}
void INGclear(INGresult *res)
INGfreeDescriptor(res->sqlda);
INGfreeINGresult(res);
}
-INGconn *INGconnectDB(char *dbname, char *user, char *passwd)
+INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id)
{
INGconn *dbconn;
if (dbname == NULL || strlen(dbname) == 0) {
}
dbconn = (INGconn *)malloc(sizeof(INGconn));
memset(dbconn, 0, sizeof(INGconn));
-/* # line 553 "myingres.sc" */
+/* # line 589 "myingres.sc" */
char ingdbname[24];
char ingdbuser[32];
- char ingdbpasw[32];
- char conn_name[32];
+ char ingdbpasswd[32];
int sess_id;
-/* # line 559 "myingres.sc" */
+/* # line 594 "myingres.sc" */
+ sess_id = session_id;
bstrncpy(ingdbname, dbname, sizeof(ingdbname));
if (user != NULL) {
bstrncpy(ingdbuser, user, sizeof(ingdbuser));
if (passwd != NULL) {
- bstrncpy(ingdbpasw, passwd, sizeof(ingdbpasw));
+ bstrncpy(ingdbpasswd, passwd, sizeof(ingdbpasswd));
} else {
- memset(ingdbpasw, 0, sizeof(ingdbpasw));
+ memset(ingdbpasswd, 0, sizeof(ingdbpasswd));
}
-/* # line 570 "myingres.sc" */ /* connect */
+/* # line 606 "myingres.sc" */ /* connect */
{
IIsqInit(&sqlca);
+ IILQsidSessID(sess_id);
IIsqUser(ingdbuser);
- IIsqConnect(0,ingdbname,(char *)"-dbms_password",ingdbpasw,(char *)0,
+ IIsqConnect(0,ingdbname,(char *)"-dbms_password",ingdbpasswd,(char *)0,
(char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0,
(char *)0, (char *)0, (char *)0, (char *)0);
}
-/* # line 574 "myingres.sc" */ /* host code */
+/* # line 611 "myingres.sc" */ /* host code */
} else {
-/* # line 575 "myingres.sc" */ /* connect */
+/* # line 612 "myingres.sc" */ /* connect */
{
IIsqInit(&sqlca);
+ IILQsidSessID(sess_id);
IIsqConnect(0,ingdbname,(char *)0, (char *)0, (char *)0, (char *)0,
(char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0,
(char *)0, (char *)0, (char *)0);
}
-/* # line 576 "myingres.sc" */ /* host code */
+/* # line 615 "myingres.sc" */ /* host code */
}
-/* # line 578 "myingres.sc" */ /* inquire_sql */
- {
- IILQisInqSqlio((short *)0,1,32,31,conn_name,13);
- }
-/* # line 579 "myingres.sc" */ /* inquire_sql */
- {
- IILQisInqSqlio((short *)0,1,30,sizeof(sess_id),&sess_id,11);
- }
-/* # line 581 "myingres.sc" */ /* host code */
+ if (INGcheck() < 0) {
+ return NULL;
+ }
bstrncpy(dbconn->dbname, ingdbname, sizeof(dbconn->dbname));
bstrncpy(dbconn->user, ingdbuser, sizeof(dbconn->user));
- bstrncpy(dbconn->password, ingdbpasw, sizeof(dbconn->password));
- bstrncpy(dbconn->connection_name, conn_name, sizeof(dbconn->connection_name));
+ bstrncpy(dbconn->password, ingdbpasswd, sizeof(dbconn->password));
dbconn->session_id = sess_id;
dbconn->msg = (char*)malloc(257);
memset(dbconn->msg, 0, 257);
+ /*
+ * Switch to no default session for this thread undo default settings from SQL CONNECT.
+ */
+/* # line 627 "myingres.sc" */ /* set_sql */
+ {
+ IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97));
+ }
+/* # line 629 "myingres.sc" */ /* host code */
return dbconn;
}
void INGdisconnectDB(INGconn *dbconn)
{
-/* # line 594 "myingres.sc" */
+/* # line 634 "myingres.sc" */
int sess_id;
-/* # line 596 "myingres.sc" */
+/* # line 636 "myingres.sc" */
sess_id = dbconn->session_id;
-/* # line 600 "myingres.sc" */ /* disconnect */
+/* # line 639 "myingres.sc" */ /* disconnect */
{
IIsqInit(&sqlca);
IILQsidSessID(sess_id);
IIsqDisconnect();
}
-/* # line 602 "myingres.sc" */ /* host code */
+/* # line 641 "myingres.sc" */ /* host code */
if (dbconn != NULL) {
free(dbconn->msg);
free(dbconn);
}
char *INGerrorMessage(const INGconn *conn)
{
-/* # line 610 "myingres.sc" */
+/* # line 649 "myingres.sc" */
char errbuf[256];
-/* # line 612 "myingres.sc" */
+/* # line 651 "myingres.sc" */
-/* # line 614 "myingres.sc" */ /* inquire_ingres */
+/* # line 653 "myingres.sc" */ /* inquire_ingres */
{
IILQisInqSqlio((short *)0,1,32,255,errbuf,63);
}
-/* # line 615 "myingres.sc" */ /* host code */
+/* # line 654 "myingres.sc" */ /* host code */
memcpy(conn->msg, &errbuf, 256);
return conn->msg;
}
int INGputCopyEnd(INGconn *conn, const char *errormsg);
int INGputCopyData(INGconn *conn, const char *buffer, int nbytes);
*/
-/* # line 629 "myingres.sc" */
+/* # line 668 "myingres.sc" */
#endif
return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0;
}
-short INGgetCols(const char *query)
+short INGgetCols(INGconn *conn, const char *query)
{
EXEC SQL BEGIN DECLARE SECTION;
+ int sess_id;
char *stmt;
EXEC SQL END DECLARE SECTION;
sqlda->sqln = number;
stmt = bstrdup(query);
+
+ /*
+ * Switch to the correct default session for this thread.
+ */
+ sess_id = conn->session_id;
+ EXEC SQL SET_SQL (SESSION = :sess_id);
EXEC SQL PREPARE s1 from :stmt;
if (INGcheck() < 0) {
number = sqlda->sqld;
bail_out:
+ /*
+ * Switch to no default session for this thread.
+ */
+ EXEC SQL SET_SQL (SESSION = NONE);
free(stmt);
free(sqlda);
return number;
int INGexec(INGconn *conn, const char *query)
{
- int check;
EXEC SQL BEGIN DECLARE SECTION;
+ int sess_id;
int rowcount;
char *stmt;
EXEC SQL END DECLARE SECTION;
stmt = bstrdup(query);
rowcount = -1;
+ /*
+ * Switch to the correct default session for this thread.
+ */
+ sess_id = conn->session_id;
+ EXEC SQL SET_SQL (SESSION = :sess_id);
EXEC SQL EXECUTE IMMEDIATE :stmt;
free(stmt);
- if ((check = INGcheck()) < 0) {
- return check;
+ if ((rowcount = INGcheck()) < 0) {
+ goto bail_out;
}
EXEC SQL INQUIRE_INGRES(:rowcount = ROWCOUNT);
- if ((check = INGcheck()) < 0) {
- return check;
+ if ((rowcount = INGcheck()) < 0) {
+ goto bail_out;
}
-
+
+bail_out:
+ /*
+ * Switch to no default session for this thread.
+ */
+ EXEC SQL SET_SQL (SESSION = NONE);
return rowcount;
}
IISQLDA *desc = NULL;
INGresult *res = NULL;
int rows = -1;
- int cols = INGgetCols(query);
+ int cols = INGgetCols(conn, query);
+ EXEC SQL BEGIN DECLARE SECTION;
+ int sess_id;
+ EXEC SQL END DECLARE SECTION;
+
+ /*
+ * Switch to the correct default session for this thread.
+ */
+ sess_id = conn->session_id;
+ EXEC SQL SET_SQL (SESSION = :sess_id);
desc = INGgetDescriptor(cols, query);
if (!desc) {
- return NULL;
+ goto bail_out;
}
res = INGgetINGresult(desc);
if (!res) {
- return NULL;
+ goto bail_out;
}
rows = INGfetchAll(query, res);
if (rows < 0) {
- INGfreeDescriptor(desc);
- INGfreeINGresult(res);
- return NULL;
+ INGfreeDescriptor(desc);
+ INGfreeINGresult(res);
+ res = NULL;
+ goto bail_out;
}
+bail_out:
+ /*
+ * Switch to no default session for this thread.
+ */
+ EXEC SQL SET_SQL (SESSION = NONE);
return res;
}
INGfreeINGresult(res);
}
-INGconn *INGconnectDB(char *dbname, char *user, char *passwd)
+INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id)
{
INGconn *dbconn;
EXEC SQL BEGIN DECLARE SECTION;
char ingdbname[24];
char ingdbuser[32];
- char ingdbpasw[32];
- char conn_name[32];
+ char ingdbpasswd[32];
int sess_id;
EXEC SQL END DECLARE SECTION;
+ sess_id = session_id;
bstrncpy(ingdbname, dbname, sizeof(ingdbname));
if (user != NULL) {
bstrncpy(ingdbuser, user, sizeof(ingdbuser));
if (passwd != NULL) {
- bstrncpy(ingdbpasw, passwd, sizeof(ingdbpasw));
+ bstrncpy(ingdbpasswd, passwd, sizeof(ingdbpasswd));
} else {
- memset(ingdbpasw, 0, sizeof(ingdbpasw));
+ memset(ingdbpasswd, 0, sizeof(ingdbpasswd));
}
EXEC SQL CONNECT
:ingdbname
- identified by :ingdbuser
- dbms_password = :ingdbpasw;
+ SESSION :sess_id
+ IDENTIFIED BY :ingdbuser
+ DBMS_PASSWORD = :ingdbpasswd;
} else {
- EXEC SQL CONNECT :ingdbname;
+ EXEC SQL CONNECT
+ :ingdbname
+ SESSION :sess_id;
}
-
- EXEC SQL INQUIRE_SQL(:conn_name = connection_name);
- EXEC SQL INQUIRE_SQL(:sess_id = session);
+ if (INGcheck() < 0) {
+ return NULL;
+ }
bstrncpy(dbconn->dbname, ingdbname, sizeof(dbconn->dbname));
bstrncpy(dbconn->user, ingdbuser, sizeof(dbconn->user));
- bstrncpy(dbconn->password, ingdbpasw, sizeof(dbconn->password));
- bstrncpy(dbconn->connection_name, conn_name, sizeof(dbconn->connection_name));
+ bstrncpy(dbconn->password, ingdbpasswd, sizeof(dbconn->password));
dbconn->session_id = sess_id;
dbconn->msg = (char*)malloc(257);
memset(dbconn->msg, 0, 257);
+ /*
+ * Switch to no default session for this thread undo default settings from SQL CONNECT.
+ */
+ EXEC SQL SET_SQL (SESSION = NONE);
+
return dbconn;
}
EXEC SQL END DECLARE SECTION;
sess_id = dbconn->session_id;
-
EXEC SQL DISCONNECT SESSION :sess_id;
if (dbconn != NULL) {