From: Marco van Wieringen Date: Fri, 2 Apr 2010 08:03:10 +0000 (+0200) Subject: Regenerated code for Ingres using esqlcc X-Git-Tag: Release-5.0.2~128 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=84809edd683452fc7a42e5f244649a084c4c1785;p=bacula%2Fbacula Regenerated code for Ingres using esqlcc --- diff --git a/bacula/src/cats/myingres.c b/bacula/src/cats/myingres.c index 313a90ad99..ea41efdc3f 100644 --- a/bacula/src/cats/myingres.c +++ b/bacula/src/cats/myingres.c @@ -6,7 +6,6 @@ #include extern IISQLCA sqlca; /* SQL Communications Area */ #include -/* # line 7 "myingres.sc" */ /* host code */ #include #include #include @@ -18,68 +17,87 @@ int INGcheck() { return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0; } -short INGgetCols(const char *stmt) +short INGgetCols(B_DB *mdb, const char *query) { -/* # line 23 "myingres.sc" */ + bool stmt_free = false; +/* # line 24 "myingres.sc" */ - char *stmtd; -/* # line 25 "myingres.sc" */ + char *stmt; +/* # line 26 "myingres.sc" */ short number = 1; IISQLDA *sqlda; sqlda = (IISQLDA *)malloc(IISQDA_HEAD_SIZE + (number * IISQDA_VAR_SIZE)); memset(sqlda, 0, (IISQDA_HEAD_SIZE + (number * IISQDA_VAR_SIZE))); sqlda->sqln = number; - stmtd = (char*)malloc(strlen(stmt)+1); - bstrncpy(stmtd,stmt,strlen(stmt)+1); -/* # line 38 "myingres.sc" */ /* prepare */ + /* + * See if we need to run this through the limit_filter. + */ + if (strstr(query, "LIMIT") != NULL) { + stmt = mdb->limit_filter->replace(query); + } else { + stmt = bstrdup(query); + stmt_free = true; + } +/* # line 46 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); - IIsqPrepare(0,(char *)"s1",(char *)0,0,stmtd); + IIsqPrepare(0,(char *)"s1",(char *)0,0,stmt); } -/* # line 39 "myingres.sc" */ /* host code */ +/* # line 47 "myingres.sc" */ /* host code */ if (INGcheck() < 0) { - free(stmtd); - free(sqlda); - return -1; + number = -1; + goto bail_out; } -/* # line 44 "myingres.sc" */ /* describe */ +/* # line 52 "myingres.sc" */ /* describe */ { IIsqInit(&sqlca); IIsqDescribe(0,(char *)"s1",sqlda,0); } -/* # line 45 "myingres.sc" */ /* host code */ +/* # line 53 "myingres.sc" */ /* host code */ if (INGcheck() < 0) { - free(stmtd); - free(sqlda); - return -1; + number = -1; + goto bail_out; } number = sqlda->sqld; - free(stmtd); +bail_out: + if (stmt_free) { + free(stmt); + } free(sqlda); return number; } -IISQLDA *INGgetDescriptor(short numCols, const char *stmt) +static inline IISQLDA *INGgetDescriptor(B_DB *mdb, short numCols, const char *query) { -/* # line 59 "myingres.sc" */ + bool stmt_free = false; +/* # line 71 "myingres.sc" */ - char *stmtd; -/* # line 61 "myingres.sc" */ + char *stmt; +/* # line 73 "myingres.sc" */ int i; IISQLDA *sqlda; sqlda = (IISQLDA *)malloc(IISQDA_HEAD_SIZE + (numCols * IISQDA_VAR_SIZE)); memset(sqlda, 0, (IISQDA_HEAD_SIZE + (numCols * IISQDA_VAR_SIZE))); sqlda->sqln = numCols; - stmtd = (char *)malloc(strlen(stmt)+1); - bstrncpy(stmtd,stmt,strlen(stmt)+1); -/* # line 74 "myingres.sc" */ /* prepare */ + /* + * See if we need to run this through the limit_filter. + */ + if (strstr(query, "LIMIT") != NULL) { + stmt = mdb->limit_filter->replace(query); + } else { + stmt = bstrdup(query); + stmt_free = true; + } +/* # line 93 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); - IIsqPrepare(0,(char *)"s2",sqlda,0,stmtd); + IIsqPrepare(0,(char *)"s2",sqlda,0,stmt); } -/* # line 76 "myingres.sc" */ /* host code */ - free(stmtd); +/* # line 95 "myingres.sc" */ /* host code */ + if (stmt_free) { + free(stmt); + } for (i = 0; i < sqlda->sqld; ++i) { /* * Negative type indicates nullable coulumns, so an indicator @@ -114,12 +132,12 @@ IISQLDA *INGgetDescriptor(short numCols, const char *stmt) } return sqlda; } -void INGfreeDescriptor(IISQLDA *sqlda) +static void INGfreeDescriptor(IISQLDA *sqlda) { + int i; if (!sqlda) { return; } - int i; for (i = 0; i < sqlda->sqld; ++i) { if (sqlda->sqlvar[i].sqldata) { free(sqlda->sqlvar[i].sqldata); @@ -131,7 +149,7 @@ void INGfreeDescriptor(IISQLDA *sqlda) free(sqlda); sqlda = NULL; } -int INGgetTypeSize(IISQLVAR *ingvar) +static inline int INGgetTypeSize(IISQLVAR *ingvar) { int inglength = 0; /* @@ -150,13 +168,13 @@ int INGgetTypeSize(IISQLVAR *ingvar) } return inglength; } -INGresult *INGgetINGresult(IISQLDA *sqlda) +static inline INGresult *INGgetINGresult(IISQLDA *sqlda) { + int i; + INGresult *result = NULL; if (!sqlda) { return NULL; } - int i; - INGresult *result = NULL; result = (INGresult *)malloc(sizeof(INGresult)); memset(result, 0, sizeof(INGresult)); result->sqlda = sqlda; @@ -179,37 +197,34 @@ INGresult *INGgetINGresult(IISQLDA *sqlda) } return result; } -void INGfreeINGresult(INGresult *ing_res) +static void INGfreeINGresult(INGresult *ing_res) { + int rows; + ING_ROW *rowtemp; if (!ing_res) { return; } - int rows; - ING_ROW *rowtemp; /* * Free all rows and fields, then res, not descriptor! + * + * Use of rows is a nasty workaround til I find the reason, + * why aggregates like max() don't work */ - if (ing_res != NULL) { - /* - * Use of rows is a nasty workaround til I find the reason, - * why aggregates like max() don't work - */ - rows = ing_res->num_rows; - 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; - } - if (ing_res->fields) { - free(ing_res->fields); - } + rows = ing_res->num_rows; + 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; + } + if (ing_res->fields) { + free(ing_res->fields); } free(ing_res); ing_res = NULL; } -ING_ROW *INGgetRowSpace(INGresult *ing_res) +static inline ING_ROW *INGgetRowSpace(INGresult *ing_res) { int i; unsigned short len; /* used for VARCHAR type length */ @@ -255,15 +270,14 @@ ING_ROW *INGgetRowSpace(INGresult *ing_res) vars[i].sqldata = (char *)malloc(20); memset(vars[i].sqldata, 0, 20); switch (sqlda->sqlvar[i].sqllen) { - // %d,%ld,%lld case 2: - bsnprintf(vars[i].sqldata, 20, "%hd",*(signed short*)sqlda->sqlvar[i].sqldata); + bsnprintf(vars[i].sqldata, 20, "%d",*(short*)sqlda->sqlvar[i].sqldata); break; case 4: - bsnprintf(vars[i].sqldata, 20, "%d",*(signed int*)sqlda->sqlvar[i].sqldata); + bsnprintf(vars[i].sqldata, 20, "%ld",*(int*)sqlda->sqlvar[i].sqldata); break; case 8: - bsnprintf(vars[i].sqldata, 20, "%ld",*(signed long*)sqlda->sqlvar[i].sqldata); + bsnprintf(vars[i].sqldata, 20, "%lld",*(long*)sqlda->sqlvar[i].sqldata); break; } break; @@ -284,7 +298,7 @@ ING_ROW *INGgetRowSpace(INGresult *ing_res) } return row; } -void INGfreeRowSpace(ING_ROW *row, IISQLDA *sqlda) +static inline void INGfreeRowSpace(ING_ROW *row, IISQLDA *sqlda) { int i; if (row == NULL || sqlda == NULL) { @@ -301,39 +315,39 @@ void INGfreeRowSpace(ING_ROW *row, IISQLDA *sqlda) free(row->sqlvar); free(row); } -int INGfetchAll(const char *stmt, INGresult *ing_res) +static inline int INGfetchAll(const char *query, INGresult *ing_res) { int linecount = 0; ING_ROW *row; IISQLDA *desc; int check = -1; desc = ing_res->sqlda; -/* # line 335 "myingres.sc" */ /* host code */ +/* # line 352 "myingres.sc" */ /* host code */ if ((check = INGcheck()) < 0) { return check; } -/* # line 339 "myingres.sc" */ /* open */ +/* # line 356 "myingres.sc" */ /* open */ { IIsqInit(&sqlca); - IIcsOpen((char *)"c2",10703,7614); + IIcsOpen((char *)"c2",9209,14491); IIwritio(0,(short *)0,1,32,0,(char *)"s2"); - IIcsQuery((char *)"c2",10703,7614); + IIcsQuery((char *)"c2",9209,14491); } -/* # line 340 "myingres.sc" */ /* host code */ +/* # line 357 "myingres.sc" */ /* host code */ if ((check = INGcheck()) < 0) { return check; } /* for (linecount = 0; sqlca.sqlcode == 0; ++linecount) */ do { -/* # line 346 "myingres.sc" */ /* fetch */ +/* # line 363 "myingres.sc" */ /* fetch */ { IIsqInit(&sqlca); - if (IIcsRetScroll((char *)"c2",10703,7614,-1,-1) != 0) { + if (IIcsRetScroll((char *)"c2",9209,14491,-1,-1) != 0) { IIcsDaGet(0,desc); IIcsERetrieve(); } /* IIcsRetrieve */ } -/* # line 348 "myingres.sc" */ /* host code */ +/* # line 365 "myingres.sc" */ /* host code */ if ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) ) { row = INGgetRowSpace(ing_res); /* alloc space for fetched row */ /* @@ -350,22 +364,25 @@ int INGfetchAll(const char *stmt, INGresult *ing_res) ++linecount; } } while ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) ); -/* # line 366 "myingres.sc" */ /* close */ +/* # line 383 "myingres.sc" */ /* close */ { IIsqInit(&sqlca); - IIcsClose((char *)"c2",10703,7614); + IIcsClose((char *)"c2",9209,14491); } -/* # line 368 "myingres.sc" */ /* host code */ +/* # line 385 "myingres.sc" */ /* host code */ ing_res->status = ING_COMMAND_OK; ing_res->num_rows = linecount; return linecount; } -ING_STATUS INGresultStatus(INGresult *res) +static inline ING_STATUS INGresultStatus(INGresult *res) { - if (res == NULL) {return ING_NO_RESULT;} - return res->status; + if (res == NULL) { + return ING_NO_RESULT; + } else { + return res->status; + } } -void INGrowSeek(INGresult *res, int row_number) +static void INGrowSeek(INGresult *res, int row_number) { ING_ROW *trow = NULL; if (res->act_row->row_number == row_number) { @@ -377,7 +394,7 @@ void INGrowSeek(INGresult *res, int row_number) if (row_number<0 || row_number>res->num_rows) { return; } - for (trow = res->first_row ; trow->row_number != row_number ; trow = trow->next ); + for (trow = res->first_row; trow->row_number != row_number; trow = trow->next) ; res->act_row = trow; /* * Note - can be null - if row_number not found, right? @@ -395,7 +412,7 @@ int INGgetisnull(INGresult *res, int row_number, int column_number) if (row_number != res->act_row->row_number) { INGrowSeek(res, row_number); } - return (*res->act_row->sqlvar[column_number].sqlind == -1) ? 1 : 0; + return (*res->act_row->sqlvar[column_number].sqlind == -1) 1 : 0; } int INGntuples(const INGresult *res) { @@ -417,40 +434,50 @@ short INGftype(const INGresult *res, int column_number) { return res->fields[column_number].type; } -int INGexec(INGconn *conn, const char *query) +int INGexec(B_DB *mdb, INGconn *conn, const char *query) { + bool stmt_free = false; int check; -/* # line 443 "myingres.sc" */ +/* # line 467 "myingres.sc" */ int rowcount; char *stmt; -/* # line 446 "myingres.sc" */ +/* # line 470 "myingres.sc" */ - stmt = (char *)malloc(strlen(query)+1); - bstrncpy(stmt,query,strlen(query)+1); + /* + * See if we need to run this through the limit_filter. + */ + if (strstr(query, "LIMIT") != NULL) { + stmt = mdb->limit_filter->replace(query); + } else { + stmt = bstrdup(query); + stmt_free = true; + } rowcount = -1; -/* # line 452 "myingres.sc" */ /* execute */ +/* # line 483 "myingres.sc" */ /* execute */ { IIsqInit(&sqlca); IIsqExImmed(stmt); IIsyncup((char *)0,0); } -/* # line 453 "myingres.sc" */ /* host code */ - free(stmt); +/* # line 485 "myingres.sc" */ /* host code */ + if (stmt_free) { + free(stmt); + } if ((check = INGcheck()) < 0) { return check; } -/* # line 458 "myingres.sc" */ /* inquire_ingres */ +/* # line 493 "myingres.sc" */ /* inquire_ingres */ { IILQisInqSqlio((short *)0,1,30,sizeof(rowcount),&rowcount,8); } -/* # line 459 "myingres.sc" */ /* host code */ +/* # line 494 "myingres.sc" */ /* host code */ if ((check = INGcheck()) < 0) { return check; } return rowcount; } -INGresult *INGquery(INGconn *conn, const char *query) +INGresult *INGquery(B_DB *mdb, INGconn *conn, const char *query) { /* * TODO: error handling @@ -458,7 +485,7 @@ INGresult *INGquery(INGconn *conn, const char *query) IISQLDA *desc = NULL; INGresult *res = NULL; int rows = -1; - int cols = INGgetCols(query); + int cols = INGgetCols(mdb, query); desc = INGgetDescriptor(cols, query); if (!desc) { return NULL; @@ -480,25 +507,25 @@ void INGclear(INGresult *res) if (res == NULL) { return; } - IISQLDA *desc = res->sqlda; INGfreeINGresult(res); - INGfreeDescriptor(desc); + INGfreeDescriptor(res->sqlda); } INGconn *INGconnectDB(char *dbname, char *user, char *passwd) { + INGconn *dbconn; if (dbname == NULL || strlen(dbname) == 0) { return NULL; } - INGconn *dbconn = (INGconn *)malloc(sizeof(INGconn)); + dbconn = (INGconn *)malloc(sizeof(INGconn)); memset(dbconn, 0, sizeof(INGconn)); -/* # line 513 "myingres.sc" */ +/* # line 550 "myingres.sc" */ char ingdbname[24]; char ingdbuser[32]; char ingdbpasw[32]; char conn_name[32]; int sess_id; -/* # line 519 "myingres.sc" */ +/* # line 556 "myingres.sc" */ bstrncpy(ingdbname, dbname, sizeof(ingdbname)); if (user != NULL) { @@ -508,7 +535,7 @@ INGconn *INGconnectDB(char *dbname, char *user, char *passwd) } else { memset(ingdbpasw, 0, sizeof(ingdbpasw)); } -/* # line 530 "myingres.sc" */ /* connect */ +/* # line 567 "myingres.sc" */ /* connect */ { IIsqInit(&sqlca); IIsqUser(ingdbuser); @@ -516,26 +543,26 @@ 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 534 "myingres.sc" */ /* host code */ +/* # line 571 "myingres.sc" */ /* host code */ } else { -/* # line 535 "myingres.sc" */ /* connect */ +/* # line 572 "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 536 "myingres.sc" */ /* host code */ +/* # line 573 "myingres.sc" */ /* host code */ } -/* # line 538 "myingres.sc" */ /* inquire_sql */ +/* # line 575 "myingres.sc" */ /* inquire_sql */ { IILQisInqSqlio((short *)0,1,32,31,conn_name,13); } -/* # line 539 "myingres.sc" */ /* inquire_sql */ +/* # line 576 "myingres.sc" */ /* inquire_sql */ { IILQisInqSqlio((short *)0,1,30,sizeof(sess_id),&sess_id,11); } -/* # line 541 "myingres.sc" */ /* host code */ +/* # line 578 "myingres.sc" */ /* host code */ bstrncpy(dbconn->dbname, ingdbname, sizeof(dbconn->dbname)); bstrncpy(dbconn->user, ingdbuser, sizeof(dbconn->user)); bstrncpy(dbconn->password, ingdbpasw, sizeof(dbconn->password)); @@ -550,12 +577,12 @@ void INGdisconnectDB(INGconn *dbconn) /* * TODO: check for any real use of dbconn: maybe whenn multithreaded? */ -/* # line 557 "myingres.sc" */ /* disconnect */ +/* # line 594 "myingres.sc" */ /* disconnect */ { IIsqInit(&sqlca); IIsqDisconnect(); } -/* # line 558 "myingres.sc" */ /* host code */ +/* # line 595 "myingres.sc" */ /* host code */ if (dbconn != NULL) { free(dbconn->msg); free(dbconn); @@ -563,17 +590,17 @@ void INGdisconnectDB(INGconn *dbconn) } char *INGerrorMessage(const INGconn *conn) { -/* # line 566 "myingres.sc" */ +/* # line 603 "myingres.sc" */ char errbuf[256]; -/* # line 568 "myingres.sc" */ +/* # line 605 "myingres.sc" */ -/* # line 570 "myingres.sc" */ /* inquire_ingres */ +/* # line 607 "myingres.sc" */ /* inquire_ingres */ { IILQisInqSqlio((short *)0,1,32,255,errbuf,63); } -/* # line 571 "myingres.sc" */ /* host code */ - memcpy(conn->msg,&errbuf,256); +/* # line 608 "myingres.sc" */ /* host code */ + memcpy(conn->msg, &errbuf, 256); return conn->msg; } char *INGcmdTuples(INGresult *res) @@ -584,5 +611,5 @@ char *INGcmdTuples(INGresult *res) int INGputCopyEnd(INGconn *conn, const char *errormsg); int INGputCopyData(INGconn *conn, const char *buffer, int nbytes); */ -/* # line 585 "myingres.sc" */ +/* # line 622 "myingres.sc" */ #endif diff --git a/bacula/src/cats/myingres.h b/bacula/src/cats/myingres.h index dc204c83ca..6fb6f4e45a 100644 --- a/bacula/src/cats/myingres.h +++ b/bacula/src/cats/myingres.h @@ -48,29 +48,20 @@ typedef struct ing_conn { char *msg; } INGconn; /* ---Prototypes--- */ -int INGcheck(); -ING_STATUS INGresultStatus(INGresult *res); -short INGgetCols(const char *stmt); -IISQLDA *INGgetDescriptor(short numCols, const char *stmt); -void INGfreeDescriptor(IISQLDA *sqlda); -int INGgetTypeSize(IISQLVAR *ingvar); -INGresult *INGgetINGresult(IISQLDA *sqlda); -void INGfreeINGresult(INGresult *ing_res); -ING_ROW *INGgetRowSpace(INGresult *ing_res); -void INGfreeRowSpace(ING_ROW *row, IISQLDA *sqlda); -int INGfetchAll(const char *stmt, INGresult *ing_res); -void INGrowSeek(INGresult *res, int row_number); -char *INGgetvalue(INGresult *res, int row_number, int column_number); -int INGgetisnull(INGresult *res, int row_number, int column_number); -int INGntuples(const INGresult *res); -int INGnfields(const INGresult *res); -char *INGfname(const INGresult *res, int column_number); -short INGftype(const INGresult *res, int column_number); -INGresult *INGexec(INGconn *db, const char *query); -void INGclear(INGresult *res); +int INGcheck(void); +short INGgetCols(B_DB *mdb, const char *stmt); +char *INGgetvalue(INGresult *res, int row_number, int column_number); +int INGgetisnull(INGresult *res, int row_number, int column_number); +int INGntuples(const INGresult *res); +int INGnfields(const INGresult *res); +char *INGfname(const INGresult *res, int column_number); +short INGftype(const INGresult *res, int column_number); +int INGexec(B_DB *mdb, INGconn *db, const char *query); +INGresult *INGquery(B_DB *mdb, INGconn *db, const char *query); +void INGclear(INGresult *res); 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" */ +void INGdisconnectDB(INGconn *dbconn); +char *INGerrorMessage(const INGconn *conn); +char *INGcmdTuples(INGresult *res); +/* # line 75 "myingres.sh" */ #endif /* _MYINGRES_SH */