From: Kern Sibbald Date: Sat, 10 Apr 2010 10:17:33 +0000 (+0200) Subject: Revert "First attempt at making things multi-threaded and make it possible to" X-Git-Tag: Release-5.0.2~55 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8d2a602a4997d5031064adf1e2ec0a98e8556c03;p=bacula%2Fbacula Revert "First attempt at making things multi-threaded and make it possible to" This reverts commit 69820d0776da2818115d90a2a73b790885c16aa5. --- diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 5bbd4d7df4..20351bd04b 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -576,7 +576,6 @@ struct B_DB { char *db_address; /* host address */ char *db_socket; /* socket for local access */ int db_port; /* port of host address */ - int session_id; /* unique session id */ int have_insert_id; /* do have insert_id() */ bool connected; POOLMEM *errmsg; /* nicely edited error message */ diff --git a/bacula/src/cats/ingres.c b/bacula/src/cats/ingres.c index 1d307167a3..0dae5b060a 100755 --- a/bacula/src/cats/ingres.c +++ b/bacula/src/cats/ingres.c @@ -56,7 +56,7 @@ * ----------------------------------------------------------------------- */ -/* List of open databases */ +/* List of open databases */ /* SRE: needed for ingres? */ static BQUEUE db_list = {&db_list, &db_list}; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -80,7 +80,6 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char 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")); @@ -98,20 +97,6 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char 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"); @@ -129,7 +114,6 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char 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; @@ -178,6 +162,22 @@ static bool check_database_encoding(JCR *jcr, B_DB *mdb) 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 @@ -212,13 +212,13 @@ db_open_database(JCR *jcr, B_DB *mdb) port = NULL; } - mdb->db = INGconnectDB(mdb->db_name, mdb->db_user, mdb->db_password, mdb->session_id); + mdb->db = INGconnectDB(mdb->db_name, mdb->db_user, mdb->db_password); 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 (!mdb->db) { + if (sql_check(mdb)) { 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"), @@ -390,9 +390,8 @@ bool db_sql_query(B_DB *mdb, const char *query, DB_RESULT_HANDLER *result_handle */ void my_ingres_close(B_DB *mdb) { - Dmsg0(500, "my_ingres_close closing database connection\n"); - INGdisconnectDB(mdb->db); - //SRE: error handling? + INGdisconnectDB(mdb->db); + //SRE: error handling? } INGRES_ROW my_ingres_fetch_row(B_DB *mdb) @@ -553,7 +552,7 @@ int my_ingres_query(B_DB *mdb, const char *query) /* TODO: differentiate between SELECTs and other queries */ - if ((cols = INGgetCols(mdb->db, new_query)) <= 0) { + if ((cols = INGgetCols(new_query)) <= 0) { if (cols < 0 ) { Dmsg0(500,"my_ingres_query: neg.columns: no DML stmt!\n"); } diff --git a/bacula/src/cats/myingres.c b/bacula/src/cats/myingres.c index 7fe5a3977c..24b98ea4e1 100644 --- a/bacula/src/cats/myingres.c +++ b/bacula/src/cats/myingres.c @@ -54,13 +54,12 @@ int INGcheck() { return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0; } -short INGgetCols(INGconn *conn, const char *query) +short INGgetCols(const char *query) { /* # line 57 "myingres.sc" */ - int sess_id; char *stmt; -/* # line 60 "myingres.sc" */ +/* # line 59 "myingres.sc" */ short number = 1; IISQLDA *sqlda; @@ -68,54 +67,38 @@ short INGgetCols(INGconn *conn, const char *query) memset(sqlda, 0, (IISQDA_HEAD_SIZE + (number * IISQDA_VAR_SIZE))); sqlda->sqln = number; stmt = bstrdup(query); - /* - * 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 */ +/* # line 71 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); IIsqPrepare(0,(char *)"s1",(char *)0,0,stmt); } -/* # line 79 "myingres.sc" */ /* host code */ +/* # line 72 "myingres.sc" */ /* host code */ if (INGcheck() < 0) { number = -1; goto bail_out; } -/* # line 84 "myingres.sc" */ /* describe */ +/* # line 77 "myingres.sc" */ /* describe */ { IIsqInit(&sqlca); IIsqDescribe(0,(char *)"s1",sqlda,0); } -/* # line 85 "myingres.sc" */ /* host code */ +/* # line 78 "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 104 "myingres.sc" */ +/* # line 93 "myingres.sc" */ char *stmt; -/* # line 106 "myingres.sc" */ +/* # line 95 "myingres.sc" */ int i; IISQLDA *sqlda; @@ -123,12 +106,12 @@ static inline IISQLDA *INGgetDescriptor(short numCols, const char *query) memset(sqlda, 0, (IISQDA_HEAD_SIZE + (numCols * IISQDA_VAR_SIZE))); sqlda->sqln = numCols; stmt = bstrdup(query); -/* # line 118 "myingres.sc" */ /* prepare */ +/* # line 107 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); IIsqPrepare(0,(char *)"s2",sqlda,0,stmt); } -/* # line 120 "myingres.sc" */ /* host code */ +/* # line 109 "myingres.sc" */ /* host code */ free(stmt); for (i = 0; i < sqlda->sqld; ++i) { /* @@ -353,32 +336,32 @@ static inline int INGfetchAll(const char *query, INGresult *ing_res) IISQLDA *desc; int check = -1; desc = ing_res->sqlda; -/* # line 374 "myingres.sc" */ /* host code */ +/* # line 363 "myingres.sc" */ /* host code */ if ((check = INGcheck()) < 0) { return check; } -/* # line 378 "myingres.sc" */ /* open */ +/* # line 367 "myingres.sc" */ /* open */ { IIsqInit(&sqlca); - IIcsOpen((char *)"c2",10631,20435); + IIcsOpen((char *)"c2",19318,7414); IIwritio(0,(short *)0,1,32,0,(char *)"s2"); - IIcsQuery((char *)"c2",10631,20435); + IIcsQuery((char *)"c2",19318,7414); } -/* # line 379 "myingres.sc" */ /* host code */ +/* # line 368 "myingres.sc" */ /* host code */ if ((check = INGcheck()) < 0) { return check; } /* for (linecount = 0; sqlca.sqlcode == 0; ++linecount) */ do { -/* # line 385 "myingres.sc" */ /* fetch */ +/* # line 374 "myingres.sc" */ /* fetch */ { IIsqInit(&sqlca); - if (IIcsRetScroll((char *)"c2",10631,20435,-1,-1) != 0) { + if (IIcsRetScroll((char *)"c2",19318,7414,-1,-1) != 0) { IIcsDaGet(0,desc); IIcsERetrieve(); } /* IIcsRetrieve */ } -/* # line 387 "myingres.sc" */ /* host code */ +/* # line 376 "myingres.sc" */ /* host code */ if ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) ) { row = INGgetRowSpace(ing_res); /* alloc space for fetched row */ /* @@ -395,12 +378,12 @@ static inline int INGfetchAll(const char *query, INGresult *ing_res) ++linecount; } } while ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) ); -/* # line 405 "myingres.sc" */ /* close */ +/* # line 394 "myingres.sc" */ /* close */ { IIsqInit(&sqlca); - IIcsClose((char *)"c2",10631,20435); + IIcsClose((char *)"c2",19318,7414); } -/* # line 407 "myingres.sc" */ /* host code */ +/* # line 396 "myingres.sc" */ /* host code */ ing_res->status = ING_COMMAND_OK; ing_res->num_rows = linecount; return linecount; @@ -467,51 +450,34 @@ short INGftype(const INGresult *res, int column_number) } int INGexec(INGconn *conn, const char *query) { -/* # line 487 "myingres.sc" */ + int check; +/* # line 477 "myingres.sc" */ - int sess_id; int rowcount; char *stmt; -/* # line 491 "myingres.sc" */ +/* # line 480 "myingres.sc" */ stmt = bstrdup(query); rowcount = -1; - /* - * 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 */ +/* # line 485 "myingres.sc" */ /* execute */ { IIsqInit(&sqlca); IIsqExImmed(stmt); IIsyncup((char *)0,0); } -/* # line 503 "myingres.sc" */ /* host code */ +/* # line 487 "myingres.sc" */ /* host code */ free(stmt); - if ((rowcount = INGcheck()) < 0) { - goto bail_out; + if ((check = INGcheck()) < 0) { + return check; } -/* # line 509 "myingres.sc" */ /* inquire_ingres */ +/* # line 493 "myingres.sc" */ /* inquire_ingres */ { IILQisInqSqlio((short *)0,1,30,sizeof(rowcount),&rowcount,8); } -/* # line 510 "myingres.sc" */ /* host code */ - if ((rowcount = INGcheck()) < 0) { - goto bail_out; +/* # line 494 "myingres.sc" */ /* host code */ + if ((check = INGcheck()) < 0) { + return check; } -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) @@ -522,45 +488,21 @@ INGresult *INGquery(INGconn *conn, const char *query) IISQLDA *desc = NULL; INGresult *res = NULL; int rows = -1; - 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 */ + int cols = INGgetCols(query); desc = INGgetDescriptor(cols, query); if (!desc) { - goto bail_out; + return NULL; } res = INGgetINGresult(desc); if (!res) { - goto bail_out; + return NULL; } rows = INGfetchAll(query, res); if (rows < 0) { - INGfreeDescriptor(desc); - INGfreeINGresult(res); - res = NULL; - goto bail_out; + INGfreeDescriptor(desc); + INGfreeINGresult(res); + return NULL; } -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) @@ -571,7 +513,7 @@ void INGclear(INGresult *res) INGfreeDescriptor(res->sqlda); INGfreeINGresult(res); } -INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id) +INGconn *INGconnectDB(char *dbname, char *user, char *passwd) { INGconn *dbconn; if (dbname == NULL || strlen(dbname) == 0) { @@ -579,78 +521,75 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id) } dbconn = (INGconn *)malloc(sizeof(INGconn)); memset(dbconn, 0, sizeof(INGconn)); -/* # line 589 "myingres.sc" */ +/* # line 553 "myingres.sc" */ char ingdbname[24]; char ingdbuser[32]; - char ingdbpasswd[32]; + char ingdbpasw[32]; + char conn_name[32]; int sess_id; -/* # line 594 "myingres.sc" */ +/* # line 559 "myingres.sc" */ - sess_id = session_id; bstrncpy(ingdbname, dbname, sizeof(ingdbname)); if (user != NULL) { bstrncpy(ingdbuser, user, sizeof(ingdbuser)); if (passwd != NULL) { - bstrncpy(ingdbpasswd, passwd, sizeof(ingdbpasswd)); + bstrncpy(ingdbpasw, passwd, sizeof(ingdbpasw)); } else { - memset(ingdbpasswd, 0, sizeof(ingdbpasswd)); + memset(ingdbpasw, 0, sizeof(ingdbpasw)); } -/* # line 606 "myingres.sc" */ /* connect */ +/* # line 570 "myingres.sc" */ /* connect */ { IIsqInit(&sqlca); - IILQsidSessID(sess_id); IIsqUser(ingdbuser); - IIsqConnect(0,ingdbname,(char *)"-dbms_password",ingdbpasswd,(char *)0, + IIsqConnect(0,ingdbname,(char *)"-dbms_password",ingdbpasw,(char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0); } -/* # line 611 "myingres.sc" */ /* host code */ +/* # line 574 "myingres.sc" */ /* host code */ } else { -/* # line 612 "myingres.sc" */ /* connect */ +/* # line 575 "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 615 "myingres.sc" */ /* host code */ +/* # line 576 "myingres.sc" */ /* host code */ } - if (INGcheck() < 0) { - return NULL; - } +/* # 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 */ bstrncpy(dbconn->dbname, ingdbname, sizeof(dbconn->dbname)); bstrncpy(dbconn->user, ingdbuser, sizeof(dbconn->user)); - bstrncpy(dbconn->password, ingdbpasswd, sizeof(dbconn->password)); + bstrncpy(dbconn->password, ingdbpasw, sizeof(dbconn->password)); + bstrncpy(dbconn->connection_name, conn_name, sizeof(dbconn->connection_name)); 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 634 "myingres.sc" */ +/* # line 594 "myingres.sc" */ int sess_id; -/* # line 636 "myingres.sc" */ +/* # line 596 "myingres.sc" */ sess_id = dbconn->session_id; -/* # line 639 "myingres.sc" */ /* disconnect */ +/* # line 600 "myingres.sc" */ /* disconnect */ { IIsqInit(&sqlca); IILQsidSessID(sess_id); IIsqDisconnect(); } -/* # line 641 "myingres.sc" */ /* host code */ +/* # line 602 "myingres.sc" */ /* host code */ if (dbconn != NULL) { free(dbconn->msg); free(dbconn); @@ -658,16 +597,16 @@ void INGdisconnectDB(INGconn *dbconn) } char *INGerrorMessage(const INGconn *conn) { -/* # line 649 "myingres.sc" */ +/* # line 610 "myingres.sc" */ char errbuf[256]; -/* # line 651 "myingres.sc" */ +/* # line 612 "myingres.sc" */ -/* # line 653 "myingres.sc" */ /* inquire_ingres */ +/* # line 614 "myingres.sc" */ /* inquire_ingres */ { IILQisInqSqlio((short *)0,1,32,255,errbuf,63); } -/* # line 654 "myingres.sc" */ /* host code */ +/* # line 615 "myingres.sc" */ /* host code */ memcpy(conn->msg, &errbuf, 256); return conn->msg; } @@ -679,5 +618,5 @@ char *INGcmdTuples(INGresult *res) int INGputCopyEnd(INGconn *conn, const char *errormsg); int INGputCopyData(INGconn *conn, const char *buffer, int nbytes); */ -/* # line 668 "myingres.sc" */ +/* # line 629 "myingres.sc" */ #endif diff --git a/bacula/src/cats/myingres.h b/bacula/src/cats/myingres.h index dbe2309bcc..7f450651f1 100644 --- a/bacula/src/cats/myingres.h +++ b/bacula/src/cats/myingres.h @@ -65,12 +65,13 @@ typedef struct ing_conn { char dbname[24]; char user[32]; char password[32]; + char connection_name[32]; int session_id; char *msg; } INGconn; /* ---Prototypes--- */ int INGcheck(void); -short INGgetCols(INGconn *conn, const char *query); +short INGgetCols(const char *stmt); char *INGgetvalue(INGresult *res, int row_number, int column_number); bool INGgetisnull(INGresult *res, int row_number, int column_number); int INGntuples(const INGresult *res); @@ -80,7 +81,7 @@ short INGftype(const INGresult *res, int column_number); int INGexec(INGconn *db, const char *query); INGresult *INGquery(INGconn *db, const char *query); void INGclear(INGresult *res); -INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id); +INGconn *INGconnectDB(char *dbname, char *user, char *passwd); void INGdisconnectDB(INGconn *dbconn); char *INGerrorMessage(const INGconn *conn); char *INGcmdTuples(INGresult *res); diff --git a/bacula/src/cats/myingres.sc b/bacula/src/cats/myingres.sc index d21dfa40f3..cf1678dce0 100644 --- a/bacula/src/cats/myingres.sc +++ b/bacula/src/cats/myingres.sc @@ -52,10 +52,9 @@ int INGcheck() return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0; } -short INGgetCols(INGconn *conn, const char *query) +short INGgetCols(const char *query) { EXEC SQL BEGIN DECLARE SECTION; - int sess_id; char *stmt; EXEC SQL END DECLARE SECTION; @@ -68,12 +67,6 @@ short INGgetCols(INGconn *conn, const char *query) 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) { @@ -90,10 +83,6 @@ short INGgetCols(INGconn *conn, const char *query) 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; @@ -484,8 +473,8 @@ short INGftype(const INGresult *res, int column_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; @@ -493,29 +482,19 @@ int INGexec(INGconn *conn, const char *query) 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 ((rowcount = INGcheck()) < 0) { - goto bail_out; + if ((check = INGcheck()) < 0) { + return check; } EXEC SQL INQUIRE_INGRES(:rowcount = ROWCOUNT); - if ((rowcount = INGcheck()) < 0) { - goto bail_out; + if ((check = INGcheck()) < 0) { + return check; } - -bail_out: - /* - * Switch to no default session for this thread. - */ - EXEC SQL SET_SQL (SESSION = NONE); + return rowcount; } @@ -527,41 +506,26 @@ INGresult *INGquery(INGconn *conn, const char *query) IISQLDA *desc = NULL; INGresult *res = NULL; int rows = -1; - 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); + int cols = INGgetCols(query); desc = INGgetDescriptor(cols, query); if (!desc) { - goto bail_out; + return NULL; } res = INGgetINGresult(desc); if (!res) { - goto bail_out; + return NULL; } rows = INGfetchAll(query, res); if (rows < 0) { - INGfreeDescriptor(desc); - INGfreeINGresult(res); - res = NULL; - goto bail_out; + INGfreeDescriptor(desc); + INGfreeINGresult(res); + return NULL; } -bail_out: - /* - * Switch to no default session for this thread. - */ - EXEC SQL SET_SQL (SESSION = NONE); return res; } @@ -575,7 +539,7 @@ void INGclear(INGresult *res) INGfreeINGresult(res); } -INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id) +INGconn *INGconnectDB(char *dbname, char *user, char *passwd) { INGconn *dbconn; @@ -589,46 +553,39 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id) EXEC SQL BEGIN DECLARE SECTION; char ingdbname[24]; char ingdbuser[32]; - char ingdbpasswd[32]; + char ingdbpasw[32]; + char conn_name[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(ingdbpasswd, passwd, sizeof(ingdbpasswd)); + bstrncpy(ingdbpasw, passwd, sizeof(ingdbpasw)); } else { - memset(ingdbpasswd, 0, sizeof(ingdbpasswd)); + memset(ingdbpasw, 0, sizeof(ingdbpasw)); } EXEC SQL CONNECT :ingdbname - SESSION :sess_id - IDENTIFIED BY :ingdbuser - DBMS_PASSWORD = :ingdbpasswd; + identified by :ingdbuser + dbms_password = :ingdbpasw; } else { - EXEC SQL CONNECT - :ingdbname - SESSION :sess_id; + EXEC SQL CONNECT :ingdbname; } - if (INGcheck() < 0) { - return NULL; - } + + EXEC SQL INQUIRE_SQL(:conn_name = connection_name); + EXEC SQL INQUIRE_SQL(:sess_id = session); bstrncpy(dbconn->dbname, ingdbname, sizeof(dbconn->dbname)); bstrncpy(dbconn->user, ingdbuser, sizeof(dbconn->user)); - bstrncpy(dbconn->password, ingdbpasswd, sizeof(dbconn->password)); + bstrncpy(dbconn->password, ingdbpasw, sizeof(dbconn->password)); + bstrncpy(dbconn->connection_name, conn_name, sizeof(dbconn->connection_name)); 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; } @@ -639,6 +596,7 @@ void INGdisconnectDB(INGconn *dbconn) EXEC SQL END DECLARE SECTION; sess_id = dbconn->session_id; + EXEC SQL DISCONNECT SESSION :sess_id; if (dbconn != NULL) { diff --git a/bacula/src/cats/myingres.sh b/bacula/src/cats/myingres.sh index a41b87ca1a..88120e4d4d 100644 --- a/bacula/src/cats/myingres.sh +++ b/bacula/src/cats/myingres.sh @@ -76,6 +76,7 @@ typedef struct ing_conn { char dbname[24]; char user[32]; char password[32]; + char connection_name[32]; int session_id; char *msg; } INGconn; @@ -83,7 +84,7 @@ typedef struct ing_conn { /* ---Prototypes--- */ int INGcheck(void); -short INGgetCols(INGconn *conn, const char *query); +short INGgetCols(const char *stmt); char *INGgetvalue(INGresult *res, int row_number, int column_number); bool INGgetisnull(INGresult *res, int row_number, int column_number); int INGntuples(const INGresult *res); @@ -93,7 +94,7 @@ short INGftype(const INGresult *res, int column_number); int INGexec(INGconn *db, const char *query); INGresult *INGquery(INGconn *db, const char *query); void INGclear(INGresult *res); -INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id); +INGconn *INGconnectDB(char *dbname, char *user, char *passwd); void INGdisconnectDB(INGconn *dbconn); char *INGerrorMessage(const INGconn *conn); char *INGcmdTuples(INGresult *res);