From 523dd41c6be641fd35b96d9e0c21c95a55ddcb2f Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Sat, 20 Feb 2010 21:09:31 +0100 Subject: [PATCH] Added patch from Stefan Reddig -- fixed date types, errmsg Conflicts: bacula/src/cats/myingres.c bacula/src/cats/myingres.h bacula/src/cats/myingres.sc --- bacula/src/cats/ingres.c | 25 +++++--- bacula/src/cats/myingres.c | 19 +++--- bacula/src/cats/myingres.h | 12 +++- bacula/src/cats/myingres.sc | 117 +++++++++++++++--------------------- bacula/src/cats/myingres.sh | 3 +- 5 files changed, 89 insertions(+), 87 deletions(-) diff --git a/bacula/src/cats/ingres.c b/bacula/src/cats/ingres.c index 2d2f5a3ee5..8fe1de45b5 100755 --- a/bacula/src/cats/ingres.c +++ b/bacula/src/cats/ingres.c @@ -166,7 +166,17 @@ static bool check_database_encoding(JCR *jcr, B_DB *mdb) */ static int sql_check(B_DB *mdb) { - return INGcheck(); + 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; } /* @@ -515,8 +525,12 @@ int my_ingres_query(B_DB *mdb, const char *query) if (mdb->status == ING_COMMAND_OK) { Dmsg1(500, "we have a result\n", query); - if ((cols = INGgetCols(query)) == 0) + if ((cols = INGgetCols(query)) <= 0) { + if (cols < 0 ) + { + Dmsg0(500,"my_ingres_query: neg.columns: no DML stmt!\n"); + } Dmsg0(500,"my_ingres_query (non SELECT) starting...\n"); /* non SELECT */ mdb->num_rows = INGexec(mdb->db, query); @@ -531,9 +545,10 @@ int my_ingres_query(B_DB *mdb, const char *query) mdb->status = 0; } } - else if ( cols > 0) + else { /* SELECT */ + Dmsg0(500,"my_ingres_query (SELECT) starting...\n"); mdb->result = INGquery(mdb->db, query); if ( mdb->result != NULL ) { @@ -554,10 +569,6 @@ int my_ingres_query(B_DB *mdb, const char *query) mdb->status = 1; /* failed */ } } - else - { - mdb->status = 1; /* failed */ - } Dmsg0(500, "my_ingres_query finishing\n"); return mdb->status; diff --git a/bacula/src/cats/myingres.c b/bacula/src/cats/myingres.c index 4ed2fdae40..5e3a9c7e19 100644 --- a/bacula/src/cats/myingres.c +++ b/bacula/src/cats/myingres.c @@ -100,14 +100,15 @@ int INGgetTypeSize(IISQLVAR *ingvar) int inglength = 0; switch (ingvar->sqltype) { - case IISQ_DTE_TYPE: - inglength = 25; - break; - case IISQ_MNY_TYPE: - inglength = 8; - break; - default: - inglength = ingvar->sqllen; + /* TODO: add date types (at least TSTMP,TSW TSWO) */ + case IISQ_DTE_TYPE: + inglength = 25; + break; + case IISQ_MNY_TYPE: + inglength = 8; + break; + default: + inglength = ingvar->sqllen; } return inglength; } @@ -145,7 +146,7 @@ INGresult *INGgetINGresult(IISQLDA *sqlda) } void INGfreeINGresult(INGresult *ing_res) { - /* TODO: free all rows and fields, then res, not descriptor! */ + /* free all rows and fields, then res, not descriptor! */ if( ing_res != NULL ) { /* use of rows is a nasty workaround til I find the reason, diff --git a/bacula/src/cats/myingres.h b/bacula/src/cats/myingres.h index 7a8575e414..e2b8871be5 100644 --- a/bacula/src/cats/myingres.h +++ b/bacula/src/cats/myingres.h @@ -1,7 +1,15 @@ +<<<<<<< HEAD:bacula/src/cats/myingres.h # include "/opt/Ingres/IngresII/ingres/files/eqdefc.h" #ifndef _MYINGRES_SH #define _MYINGRES_SH # include "/opt/Ingres/IngresII/ingres/files/eqsqlda.h" +======= +#ifndef _MYINGRES_SH +#define _MYINGRES_SH +#include +#include +/* # line 6 "myingres.sh" */ /* host code */ +>>>>>>> 289e3c7... Added patch from Stefan Reddig -- fixed date types, errmsg:bacula/src/cats/myingres.h /* ---typedefs--- */ typedef struct ing_field { char name[34]; @@ -42,7 +50,8 @@ typedef struct ing_conn { char user[32]; char password[32]; char connection_name[32]; - int session_id; + int session_id; + char *msg; } INGconn; /* ---Prototypes--- */ int INGcheck(); @@ -69,4 +78,5 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd); void INGdisconnectDB(INGconn *dbconn); char *INGerrorMessage(const INGconn *conn); char *INGcmdTuples(INGresult *res); +/* # line 85 "myingres.sh" */ #endif /* _MYINGRES_SH */ diff --git a/bacula/src/cats/myingres.sc b/bacula/src/cats/myingres.sc index 89a25623f3..471b37bf84 100644 --- a/bacula/src/cats/myingres.sc +++ b/bacula/src/cats/myingres.sc @@ -7,25 +7,10 @@ EXEC SQL INCLUDE SQLDA; #include "myingres.h" -#define INGRES_DEBUG 0 -#define DEBB(x) if (INGRES_DEBUG >= x) { -#define DEBE } - /* ---Implementations--- */ int INGcheck() { - EXEC SQL BEGIN DECLARE SECTION; - char errbuf[256]; - EXEC SQL END DECLARE SECTION; - - if (sqlca.sqlcode < 0) - { - EXEC SQL INQUIRE_INGRES(:errbuf = ERRORTEXT); - printf("Ingres-DBMS-Fehler: %s\n", errbuf); - return sqlca.sqlcode; - } - else - return 0; + return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0; } short INGgetCols(const char *stmt) @@ -101,6 +86,7 @@ int INGgetTypeSize(IISQLVAR *ingvar) switch (ingvar->sqltype) { + /* TODO: add date types (at least TSTMP,TSW TSWO) */ case IISQ_DTE_TYPE: inglength = 25; break; @@ -155,7 +141,7 @@ INGresult *INGgetINGresult(IISQLDA *sqlda) void INGfreeINGresult(INGresult *ing_res) { - /* TODO: free all rows and fields, then res, not descriptor! */ + /* free all rows and fields, then res, not descriptor! */ if( ing_res != NULL ) { /* use of rows is a nasty workaround til I find the reason, @@ -243,11 +229,7 @@ ING_ROW *INGgetRowSpace(INGresult *ing_res) void INGfreeRowSpace(ING_ROW *row, IISQLDA *sqlda) { int i; - if (row == NULL || sqlda == NULL) - { - printf("INGfreeRowSpace: one argument is NULL!\n"); - return; - } + if (row == NULL || sqlda == NULL) { return; } for ( i = 0 ; i < sqlda->sqld ; ++i ) { @@ -263,25 +245,21 @@ int INGfetchAll(const char *stmt, INGresult *ing_res) int linecount = 0; ING_ROW *row; IISQLDA *desc; + int check = -1; - EXEC SQL BEGIN DECLARE SECTION; - char stmt_buffer[2000]; - EXEC SQL END DECLARE SECTION; - - strcpy(stmt_buffer,stmt); desc = ing_res->sqlda; EXEC SQL DECLARE c2 CURSOR FOR s2; - INGcheck(); + if ((check = INGcheck()) < 0) { return check; } EXEC SQL OPEN c2; - INGcheck(); + if ((check = INGcheck()) < 0) { return check; } /* for (linecount=0;sqlca.sqlcode==0;++linecount) */ while(sqlca.sqlcode==0) { EXEC SQL FETCH c2 USING DESCRIPTOR :desc; - INGcheck(); + if ((check = INGcheck()) < 0) { return check;} if (sqlca.sqlcode == 0) { @@ -298,15 +276,6 @@ int INGfetchAll(const char *stmt, INGresult *ing_res) ing_res->act_row = row; /* set row as act_row */ row->row_number = linecount; ++linecount; - - DEBB(2) - int i; - printf("Row %d ", linecount); - for (i=0;inum_fields;++i) - { printf("F%d:%s ",i,row->sqlvar[i].sqldata); } - printf("\n"); - DEBE - } } @@ -374,19 +343,29 @@ short INGftype(const INGresult *res, int column_number) return res->fields[column_number].type; } -INGresult *INGexec(INGconn *conn, const char *query) +int INGexec(INGconn *conn, const char *query) { - /* TODO: error handling -> res->status? */ - IISQLDA *desc = NULL; - INGresult *res = NULL; - int cols = -1; - + int check; EXEC SQL BEGIN DECLARE SECTION; - char stmt[2000]; + int rowcount; + char *stmt; EXEC SQL END DECLARE SECTION; - strncpy(stmt,query,strlen(query)); - stmt[strlen(query)]='\0'; + + stmt = (char *)malloc(strlen(query)+1); + strncpy(stmt,query,strlen(query)+1); + rowcount = -1; + + EXEC SQL EXECUTE IMMEDIATE :stmt; + free(stmt); + if ((check = INGcheck()) < 0) { return check; } + + EXEC SQL INQUIRE_INGRES(:rowcount = ROWCOUNT); + if ((check = INGcheck()) < 0) { return check; } + + return rowcount; +} +INGresult *INGquery(INGconn *conn, const char *query) DEBB(1) printf("INGexec: query is >>%s<<\n",stmt); DEBE @@ -408,6 +387,12 @@ INGresult *INGexec(INGconn *conn, const char *query) desc = INGgetDescriptor(cols, query); res = INGgetINGresult(desc); INGfetchAll(query, res); +======= + if (rows < 0) + { + INGfreeINGresult(res); + return NULL; +>>>>>>> 289e3c7... Added patch from Stefan Reddig -- fixed date types, errmsg:bacula/src/cats/myingres.sc } return res; } @@ -441,9 +426,6 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd) if ( user != NULL) { - DEBB(1) - printf("Connection: with user/passwd\n"); - DEBE strcpy(ingdbuser,user); if ( passwd != NULL) { strcpy(ingdbpasw,passwd); } @@ -456,9 +438,6 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd) } else { - DEBB(1) - printf("Connection: w/ user/passwd\n"); - DEBE EXEC SQL CONNECT :ingdbname; } @@ -470,30 +449,30 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd) strcpy(dbconn->password,ingdbpasw); strcpy(dbconn->connection_name,conn_name); dbconn->session_id = sess_id; - - DEBB(1) - printf("Connected to '%s' with user/passwd %s/%s, sessID/name %i/%s\n", - dbconn->dbname, - dbconn->user, - dbconn->password, - dbconn->session_id, - dbconn->connection_name - ); - DEBE + dbconn->msg = (char*)malloc(257); + memset(dbconn->msg,0,257); return dbconn; } void INGdisconnectDB(INGconn *dbconn) { - /* TODO: use of dbconn */ + /* TODO: check for any real use of dbconn: maybe whenn multithreaded? */ EXEC SQL DISCONNECT; - free(dbconn); + if (dbconn != NULL) { + free(dbconn->msg); + free(dbconn); + } } char *INGerrorMessage(const INGconn *conn) { - return NULL; + EXEC SQL BEGIN DECLARE SECTION; + char errbuf[256]; + EXEC SQL END DECLARE SECTION; + EXEC SQL INQUIRE_INGRES(:errbuf = ERRORTEXT); + memcpy(conn->msg,&errbuf,256); + return conn->msg; } char *INGcmdTuples(INGresult *res) @@ -501,9 +480,9 @@ char *INGcmdTuples(INGresult *res) return res->numrowstring; } - /* TODO? -char *INGerrorMessage(const INGconn *conn); int INGputCopyEnd(INGconn *conn, const char *errormsg); int INGputCopyData(INGconn *conn, const char *buffer, int nbytes); */ + +#endif diff --git a/bacula/src/cats/myingres.sh b/bacula/src/cats/myingres.sh index 2b81c6e457..641ee9ea5c 100644 --- a/bacula/src/cats/myingres.sh +++ b/bacula/src/cats/myingres.sh @@ -50,7 +50,8 @@ typedef struct ing_conn { char user[32]; char password[32]; char connection_name[32]; - int session_id; + int session_id; + char *msg; } INGconn; -- 2.39.5