From: Kern Sibbald Date: Fri, 6 Nov 2009 20:56:18 +0000 (+0100) Subject: Tweak myingres.c so it build only when HAVE_INGRES X-Git-Tag: Release-5.0.0~98 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=80c5a1082b9e65197f43e7ca1c63bc2dd6208d43;p=bacula%2Fbacula Tweak myingres.c so it build only when HAVE_INGRES --- diff --git a/bacula/src/cats/myingres.c b/bacula/src/cats/myingres.c index 289f5d74b2..fcfa3fa515 100644 --- a/bacula/src/cats/myingres.c +++ b/bacula/src/cats/myingres.c @@ -1,3 +1,8 @@ +#include "bacula.h" +#include "cats.h" + +#ifdef HAVE_INGRES + # include "/opt/Ingres/IngresII/ingres/files/eqdefc.h" # include "/opt/Ingres/IngresII/ingres/files/eqsqlca.h" extern IISQLCA sqlca; /* SQL Communications Area */ @@ -13,18 +18,18 @@ int INGcheck() { char errbuf[256]; - if (sqlca.sqlcode < 0) - { -/* # line 23 "myingres.sc" */ /* inquire_ingres */ + if (sqlca.sqlcode < 0) + { +/* # line 23 "myingres.sc" */ /* inquire_ingres */ { IILQisInqSqlio((short *)0,1,32,255,errbuf,63); } -/* # line 24 "myingres.sc" */ /* host code */ - printf("Ingres-DBMS-Fehler: %s\n", errbuf); - return sqlca.sqlcode; +/* # line 24 "myingres.sc" */ /* host code */ + printf("Ingres-DBMS-Fehler: %s\n", errbuf); + return sqlca.sqlcode; } - else - return 0; + else + return 0; } short INGgetCols(const char *stmt) { @@ -32,21 +37,21 @@ short INGgetCols(const char *stmt) IISQLDA *sqlda; sqlda = (IISQLDA *)calloc(1,IISQDA_HEAD_SIZE + (number * IISQDA_VAR_SIZE)); if (sqlda == (IISQLDA *)0) - { printf("Failure allocating %d SQLDA elements\n",number); } + { printf("Failure allocating %d SQLDA elements\n",number); } sqlda->sqln = number; char stmt_buffer[2000]; strcpy(stmt_buffer,stmt); -/* # line 46 "myingres.sc" */ /* prepare */ +/* # line 46 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); IIsqPrepare(0,(char *)"s1",(char *)0,0,stmt_buffer); } -/* # line 47 "myingres.sc" */ /* describe */ +/* # line 47 "myingres.sc" */ /* describe */ { IIsqInit(&sqlca); IIsqDescribe(0,(char *)"s1",sqlda,0); } -/* # line 49 "myingres.sc" */ /* host code */ +/* # line 49 "myingres.sc" */ /* host code */ number = sqlda->sqld; free(sqlda); return number; @@ -56,26 +61,26 @@ IISQLDA *INGgetDescriptor(short numCols, const char *stmt) IISQLDA *sqlda; sqlda = (IISQLDA *)calloc(1,IISQDA_HEAD_SIZE + (numCols * IISQDA_VAR_SIZE)); if (sqlda == (IISQLDA *)0) - { printf("Failure allocating %d SQLDA elements\n",numCols); } + { printf("Failure allocating %d SQLDA elements\n",numCols); } sqlda->sqln = numCols; char stmt_buffer[2000]; strcpy(stmt_buffer,stmt); -/* # line 69 "myingres.sc" */ /* prepare */ +/* # line 69 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); IIsqPrepare(0,(char *)"s2",sqlda,0,stmt_buffer); } -/* # line 71 "myingres.sc" */ /* host code */ +/* # line 71 "myingres.sc" */ /* host code */ int i; for (i=0;isqld;++i) { - sqlda->sqlvar[i].sqldata = - (char *)malloc(sqlda->sqlvar[i].sqllen); - if (sqlda->sqlvar[i].sqldata == (char *)0) - { printf("Failure allocating %d bytes for SQLVAR data\n",sqlda->sqlvar[i].sqllen); } - sqlda->sqlvar[i].sqlind = (short *)malloc(sizeof(short)); - if (sqlda->sqlvar[i].sqlind == (short *)0) - { printf("Failure allocating sqlind\n"); } + sqlda->sqlvar[i].sqldata = + (char *)malloc(sqlda->sqlvar[i].sqllen); + if (sqlda->sqlvar[i].sqldata == (char *)0) + { printf("Failure allocating %d bytes for SQLVAR data\n",sqlda->sqlvar[i].sqllen); } + sqlda->sqlvar[i].sqlind = (short *)malloc(sizeof(short)); + if (sqlda->sqlvar[i].sqlind == (short *)0) + { printf("Failure allocating sqlind\n"); } } return sqlda; } @@ -84,8 +89,8 @@ void INGfreeDescriptor(IISQLDA *sqlda) int i; for ( i = 0 ; i < sqlda->sqld ; ++i ) { - free(sqlda->sqlvar[i].sqldata); - free(sqlda->sqlvar[i].sqlind); + free(sqlda->sqlvar[i].sqldata); + free(sqlda->sqlvar[i].sqlind); } free(sqlda); sqlda = NULL; @@ -93,48 +98,48 @@ void INGfreeDescriptor(IISQLDA *sqlda) int INGgetTypeSize(IISQLVAR *ingvar) { int inglength = 0; - switch (ingvar->sqltype) + switch (ingvar->sqltype) { - case IISQ_DTE_TYPE: - inglength = 25; - break; - case IISQ_MNY_TYPE: - inglength = 8; - break; - default: - inglength = ingvar->sqllen; + case IISQ_DTE_TYPE: + inglength = 25; + break; + case IISQ_MNY_TYPE: + inglength = 8; + break; + default: + inglength = ingvar->sqllen; } - return inglength; + return inglength; } INGresult *INGgetINGresult(IISQLDA *sqlda) { INGresult *result = NULL; result = (INGresult *)calloc(1, sizeof(INGresult)); if (result == (INGresult *)0) - { printf("Failure allocating INGresult\n"); } - result->sqlda = sqlda; - result->num_fields = sqlda->sqld; - result->num_rows = 0; - result->first_row = NULL; - result->status = ING_EMPTY_RESULT; - result->act_row = NULL; + { printf("Failure allocating INGresult\n"); } + result->sqlda = sqlda; + result->num_fields = sqlda->sqld; + result->num_rows = 0; + result->first_row = NULL; + result->status = ING_EMPTY_RESULT; + result->act_row = NULL; strcpy(result->numrowstring,""); result->fields = (INGRES_FIELD *)calloc(1, sizeof(INGRES_FIELD) * result->num_fields); if (result->fields == (INGRES_FIELD *)0) - { printf("Failure allocating %d INGRES_FIELD elements\n",result->num_fields); } + { printf("Failure allocating %d INGRES_FIELD elements\n",result->num_fields); } DEBB(2) - printf("INGgetINGresult, before loop over %d fields\n", result->num_fields); + printf("INGgetINGresult, before loop over %d fields\n", result->num_fields); DEBE int i; for (i=0;inum_fields;++i) { - memset(result->fields[i].name,'\0',34); - strncpy(result->fields[i].name, - sqlda->sqlvar[i].sqlname.sqlnamec, - sqlda->sqlvar[i].sqlname.sqlnamel); - result->fields[i].max_length = INGgetTypeSize(&sqlda->sqlvar[i]); - result->fields[i].type = abs(sqlda->sqlvar[i].sqltype); - result->fields[i].flags = (abs(sqlda->sqlvar[i].sqltype)<0) ? 1 : 0; + memset(result->fields[i].name,'\0',34); + strncpy(result->fields[i].name, + sqlda->sqlvar[i].sqlname.sqlnamec, + sqlda->sqlvar[i].sqlname.sqlnamel); + result->fields[i].max_length = INGgetTypeSize(&sqlda->sqlvar[i]); + result->fields[i].type = abs(sqlda->sqlvar[i].sqltype); + result->fields[i].flags = (abs(sqlda->sqlvar[i].sqltype)<0) ? 1 : 0; } return result; } @@ -143,20 +148,20 @@ void INGfreeINGresult(INGresult *ing_res) /* TODO: 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, - why aggregates like max() don't work - */ - int rows = ing_res->num_rows; - ING_ROW *rowtemp; - ing_res->act_row = ing_res->first_row; - while (ing_res->act_row != NULL && rows > 0) - { - rowtemp = ing_res->act_row->next; - INGfreeRowSpace(ing_res->act_row, ing_res->sqlda); - ing_res->act_row = rowtemp; - --rows; - } - free(ing_res->fields); + /* use of rows is a nasty workaround til I find the reason, + why aggregates like max() don't work + */ + int rows = ing_res->num_rows; + ING_ROW *rowtemp; + ing_res->act_row = ing_res->first_row; + while (ing_res->act_row != NULL && rows > 0) + { + rowtemp = ing_res->act_row->next; + INGfreeRowSpace(ing_res->act_row, ing_res->sqlda); + ing_res->act_row = rowtemp; + --rows; + } + free(ing_res->fields); } free(ing_res); ing_res = NULL; @@ -168,53 +173,53 @@ ING_ROW *INGgetRowSpace(INGresult *ing_res) IISQLVAR *vars = NULL; row = (ING_ROW *)calloc(1,sizeof(ING_ROW)); if (row == (ING_ROW *)0) - { printf("Failure allocating ING_ROW\n"); } + { printf("Failure allocating ING_ROW\n"); } vars = (IISQLVAR *)calloc(1,sizeof(IISQLVAR) * sqlda->sqld); if (vars == (IISQLVAR *)0) - { printf("Failure allocating %d SQLVAR elements\n",sqlda->sqld); } + { printf("Failure allocating %d SQLVAR elements\n",sqlda->sqld); } row->sqlvar = vars; row->next = NULL; int i; unsigned short len; /* used for VARCHAR type length */ for (i=0;isqld;++i) { - /* make strings out of the data, then the space and assign - (why string? at least it seems that way, looking into the sources) - */ - switch (abs(ing_res->fields[i].type)) - { - case IISQ_VCH_TYPE: - len = ((ING_VARCHAR *)sqlda->sqlvar[i].sqldata)->len; - DEBB(2) - printf("length of varchar: %d\n", len); - DEBE - vars[i].sqldata = (char *)malloc(len+1); - if (vars[i].sqldata == (char *)0) - { printf("Failure allocating %d bytes for SQLVAR data\n",len+1); } - memcpy(vars[i].sqldata,sqlda->sqlvar[i].sqldata+2,len); - vars[i].sqldata[len] = '\0'; - break; - case IISQ_CHA_TYPE: - vars[i].sqldata = (char *)malloc(ing_res->fields[i].max_length+1); - if (vars[i].sqldata == (char *)0) - { printf("Failure allocating %d bytes for SQLVAR data\n",ing_res->fields[i].max_length); } - memcpy(vars[i].sqldata,sqlda->sqlvar[i].sqldata,sqlda->sqlvar[i].sqllen); - vars[i].sqldata[ing_res->fields[i].max_length] = '\0'; - break; - case IISQ_INT_TYPE: - vars[i].sqldata = (char *)malloc(20); - memset(vars[i].sqldata,'\0',20); - sprintf(vars[i].sqldata,"%d",*(int*)sqlda->sqlvar[i].sqldata); - break; - } - vars[i].sqlind = (short *)malloc(sizeof(short)); - if (sqlda->sqlvar[i].sqlind == (short *)0) - { printf("Failure allocating sqlind\n"); } - memcpy(vars[i].sqlind,sqlda->sqlvar[i].sqlind,sizeof(short)); - DEBB(2) - printf("INGgetRowSpace, Field %d, type %d, length %d, name %s\n", - i, sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqllen, ing_res->fields[i].name); - DEBE + /* make strings out of the data, then the space and assign + (why string? at least it seems that way, looking into the sources) + */ + switch (abs(ing_res->fields[i].type)) + { + case IISQ_VCH_TYPE: + len = ((ING_VARCHAR *)sqlda->sqlvar[i].sqldata)->len; + DEBB(2) + printf("length of varchar: %d\n", len); + DEBE + vars[i].sqldata = (char *)malloc(len+1); + if (vars[i].sqldata == (char *)0) + { printf("Failure allocating %d bytes for SQLVAR data\n",len+1); } + memcpy(vars[i].sqldata,sqlda->sqlvar[i].sqldata+2,len); + vars[i].sqldata[len] = '\0'; + break; + case IISQ_CHA_TYPE: + vars[i].sqldata = (char *)malloc(ing_res->fields[i].max_length+1); + if (vars[i].sqldata == (char *)0) + { printf("Failure allocating %d bytes for SQLVAR data\n",ing_res->fields[i].max_length); } + memcpy(vars[i].sqldata,sqlda->sqlvar[i].sqldata,sqlda->sqlvar[i].sqllen); + vars[i].sqldata[ing_res->fields[i].max_length] = '\0'; + break; + case IISQ_INT_TYPE: + vars[i].sqldata = (char *)malloc(20); + memset(vars[i].sqldata,'\0',20); + sprintf(vars[i].sqldata,"%d",*(int*)sqlda->sqlvar[i].sqldata); + break; + } + vars[i].sqlind = (short *)malloc(sizeof(short)); + if (sqlda->sqlvar[i].sqlind == (short *)0) + { printf("Failure allocating sqlind\n"); } + memcpy(vars[i].sqlind,sqlda->sqlvar[i].sqlind,sizeof(short)); + DEBB(2) + printf("INGgetRowSpace, Field %d, type %d, length %d, name %s\n", + i, sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqllen, ing_res->fields[i].name); + DEBE } return row; } @@ -223,13 +228,13 @@ void INGfreeRowSpace(ING_ROW *row, IISQLDA *sqlda) int i; if (row == NULL || sqlda == NULL) { - printf("INGfreeRowSpace: one argument is NULL!\n"); - return; + printf("INGfreeRowSpace: one argument is NULL!\n"); + return; } for ( i = 0 ; i < sqlda->sqld ; ++i ) { - free(row->sqlvar[i].sqldata); - free(row->sqlvar[i].sqlind); + free(row->sqlvar[i].sqldata); + free(row->sqlvar[i].sqlind); } free(row->sqlvar); free(row); @@ -242,21 +247,21 @@ int INGfetchAll(const char *stmt, INGresult *ing_res) char stmt_buffer[2000]; strcpy(stmt_buffer,stmt); desc = ing_res->sqlda; -/* # line 275 "myingres.sc" */ /* host code */ +/* # line 275 "myingres.sc" */ /* host code */ INGcheck(); -/* # line 277 "myingres.sc" */ /* open */ +/* # line 277 "myingres.sc" */ /* open */ { IIsqInit(&sqlca); IIcsOpen((char *)"c2",19215,16475); IIwritio(0,(short *)0,1,32,0,(char *)"s2"); IIcsQuery((char *)"c2",19215,16475); } -/* # line 278 "myingres.sc" */ /* host code */ +/* # line 278 "myingres.sc" */ /* host code */ INGcheck(); /* for (linecount=0;sqlca.sqlcode==0;++linecount) */ while(sqlca.sqlcode==0) { -/* # line 283 "myingres.sc" */ /* fetch */ +/* # line 283 "myingres.sc" */ /* fetch */ { IIsqInit(&sqlca); if (IIcsRetScroll((char *)"c2",19215,16475,-1,-1) != 0) { @@ -264,37 +269,37 @@ int INGfetchAll(const char *stmt, INGresult *ing_res) IIcsERetrieve(); } /* IIcsRetrieve */ } -/* # line 284 "myingres.sc" */ /* host code */ - INGcheck(); - if (sqlca.sqlcode == 0) - { - row = INGgetRowSpace(ing_res); /* alloc space for fetched row */ - /* initialize list when encountered first time */ - if (ing_res->first_row == 0) - { - ing_res->first_row = row; /* head of the list */ - ing_res->first_row->next = NULL; - ing_res->act_row = ing_res->first_row; - } - ing_res->act_row->next = row; /* append row to old act_row */ - 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 - } +/* # line 284 "myingres.sc" */ /* host code */ + INGcheck(); + if (sqlca.sqlcode == 0) + { + row = INGgetRowSpace(ing_res); /* alloc space for fetched row */ + /* initialize list when encountered first time */ + if (ing_res->first_row == 0) + { + ing_res->first_row = row; /* head of the list */ + ing_res->first_row->next = NULL; + ing_res->act_row = ing_res->first_row; + } + ing_res->act_row->next = row; /* append row to old act_row */ + 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 + } } -/* # line 313 "myingres.sc" */ /* close */ +/* # line 313 "myingres.sc" */ /* close */ { IIsqInit(&sqlca); IIcsClose((char *)"c2",19215,16475); } -/* # line 315 "myingres.sc" */ /* host code */ +/* # line 315 "myingres.sc" */ /* host code */ ing_res->status = ING_COMMAND_OK; ing_res->num_rows = linecount; return linecount; @@ -318,13 +323,13 @@ void INGrowSeek(INGresult *res, int row_number) char *INGgetvalue(INGresult *res, int row_number, int column_number) { if (row_number != res->act_row->row_number) - { INGrowSeek(res, row_number); } + { INGrowSeek(res, row_number); } return res->act_row->sqlvar[column_number].sqldata; } int INGgetisnull(INGresult *res, int row_number, int column_number) { if (row_number != res->act_row->row_number) - { INGrowSeek(res, row_number); } + { INGrowSeek(res, row_number); } return (short)*res->act_row->sqlvar[column_number].sqlind; } int INGntuples(const INGresult *res) @@ -338,9 +343,9 @@ int INGnfields(const INGresult *res) char *INGfname(const INGresult *res, int column_number) { if ( (column_number > res->num_fields) || (column_number < 0) ) - { return NULL; } + { return NULL; } else - { return res->fields[column_number].name; } + { return res->fields[column_number].name; } } short INGftype(const INGresult *res, int column_number) { @@ -356,31 +361,31 @@ INGresult *INGexec(INGconn *conn, const char *query) strncpy(stmt,query,strlen(query)); stmt[strlen(query)]='\0'; DEBB(1) - printf("INGexec: query is >>%s<<\n",stmt); + printf("INGexec: query is >>%s<<\n",stmt); DEBE if ((cols = INGgetCols(query)) == 0) { - DEBB(1) - printf("INGexec: non-select\n"); - DEBE - /* non-select statement - TODO: EXECUTE IMMEDIATE */ -/* # line 400 "myingres.sc" */ /* execute */ + DEBB(1) + printf("INGexec: non-select\n"); + DEBE + /* non-select statement - TODO: EXECUTE IMMEDIATE */ +/* # line 400 "myingres.sc" */ /* execute */ { IIsqInit(&sqlca); IIsqExImmed(stmt); IIsyncup((char *)0,0); } -/* # line 401 "myingres.sc" */ /* host code */ +/* # line 401 "myingres.sc" */ /* host code */ } else { - DEBB(1) - printf("INGexec: select\n"); - DEBE - /* select statement */ - desc = INGgetDescriptor(cols, query); - res = INGgetINGresult(desc); - INGfetchAll(query, res); + DEBB(1) + printf("INGexec: select\n"); + DEBE + /* select statement */ + desc = INGgetDescriptor(cols, query); + res = INGgetINGresult(desc); + INGfetchAll(query, res); } return res; } @@ -394,10 +399,10 @@ void INGclear(INGresult *res) INGconn *INGconnectDB(char *dbname, char *user, char *passwd) { if (dbname == NULL || strlen(dbname) == 0) - { return NULL; } + { return NULL; } INGconn *dbconn = (INGconn *)calloc(1,sizeof(INGconn)); if (dbconn == (INGconn *)0) - { printf("Failure allocating INGconn\n"); } + { printf("Failure allocating INGconn\n"); } char ingdbname[24]; char ingdbuser[32]; char ingdbpasw[32]; @@ -406,15 +411,15 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd) strcpy(ingdbname,dbname); if ( user != NULL) { - DEBB(1) - printf("Connection: with user/passwd\n"); - DEBE + DEBB(1) + printf("Connection: with user/passwd\n"); + DEBE strcpy(ingdbuser,user); - if ( passwd != NULL) - { strcpy(ingdbpasw,passwd); } - else - { strcpy(ingdbpasw, ""); } -/* # line 452 "myingres.sc" */ /* connect */ + if ( passwd != NULL) + { strcpy(ingdbpasw,passwd); } + else + { strcpy(ingdbpasw, ""); } +/* # line 452 "myingres.sc" */ /* connect */ { IIsqInit(&sqlca); IIsqUser(ingdbuser); @@ -422,63 +427,63 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd) (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0); } -/* # line 456 "myingres.sc" */ /* host code */ +/* # line 456 "myingres.sc" */ /* host code */ } else { - DEBB(1) - printf("Connection: w/ user/passwd\n"); - DEBE -/* # line 462 "myingres.sc" */ /* connect */ + DEBB(1) + printf("Connection: w/ user/passwd\n"); + DEBE +/* # line 462 "myingres.sc" */ /* connect */ { IIsqInit(&sqlca); 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 463 "myingres.sc" */ /* host code */ +/* # line 463 "myingres.sc" */ /* host code */ } -/* # line 465 "myingres.sc" */ /* inquire_sql */ +/* # line 465 "myingres.sc" */ /* inquire_sql */ { IILQisInqSqlio((short *)0,1,32,31,conn_name,13); } -/* # line 466 "myingres.sc" */ /* inquire_sql */ +/* # line 466 "myingres.sc" */ /* inquire_sql */ { IILQisInqSqlio((short *)0,1,30,sizeof(sess_id),&sess_id,11); } -/* # line 468 "myingres.sc" */ /* host code */ +/* # line 468 "myingres.sc" */ /* host code */ strcpy(dbconn->dbname,ingdbname); strcpy(dbconn->user,ingdbuser); 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 - ); + 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 return dbconn; } void INGdisconnectDB(INGconn *dbconn) { /* TODO: use of dbconn */ -/* # line 490 "myingres.sc" */ /* disconnect */ +/* # line 490 "myingres.sc" */ /* disconnect */ { IIsqInit(&sqlca); IIsqDisconnect(); } -/* # line 491 "myingres.sc" */ /* host code */ +/* # line 491 "myingres.sc" */ /* host code */ free(dbconn); } char *INGerrorMessage(const INGconn *conn) { return NULL; } -char *INGcmdTuples(INGresult *res) +char *INGcmdTuples(INGresult *res) { return res->numrowstring; } @@ -487,3 +492,5 @@ char *INGerrorMessage(const INGconn *conn); int INGputCopyEnd(INGconn *conn, const char *errormsg); int INGputCopyData(INGconn *conn, const char *buffer, int nbytes); */ + +#endif