*
* Stefan Reddig, June 2009
*/
+/* The following is necessary so that we do not include
+ * the dummy external definition of DB.
+ */
+#define __SQL_C /* indicate that this is sql.c */
#include "bacula.h"
-/* # line 37 "myingres.sc" */
+#include "cats.h"
+/* # line 43 "myingres.sc" */
#ifdef HAVE_INGRES
#include <eqpname.h>
#include <eqdefcc.h>
{
return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0;
}
-short INGgetCols(const char *query)
+short INGgetCols(B_DB *mdb, const char *query)
{
-/* # line 57 "myingres.sc" */
+ bool stmt_free = false;
+/* # line 64 "myingres.sc" */
char *stmt;
-/* # line 59 "myingres.sc" */
+/* # line 66 "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;
- stmt = bstrdup(query);
-/* # line 71 "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 86 "myingres.sc" */ /* prepare */
{
IIsqInit(&sqlca);
IIsqPrepare(0,(char *)"s1",(char *)0,0,stmt);
}
-/* # line 72 "myingres.sc" */ /* host code */
+/* # line 87 "myingres.sc" */ /* host code */
if (INGcheck() < 0) {
number = -1;
goto bail_out;
}
-/* # line 77 "myingres.sc" */ /* describe */
+/* # line 92 "myingres.sc" */ /* describe */
{
IIsqInit(&sqlca);
IIsqDescribe(0,(char *)"s1",sqlda,0);
}
-/* # line 78 "myingres.sc" */ /* host code */
+/* # line 93 "myingres.sc" */ /* host code */
if (INGcheck() < 0) {
number = -1;
goto bail_out;
}
number = sqlda->sqld;
bail_out:
- free(stmt);
+ if (stmt_free) {
+ free(stmt);
+ }
free(sqlda);
return number;
}
-static inline IISQLDA *INGgetDescriptor(short numCols, const char *query)
+static inline IISQLDA *INGgetDescriptor(B_DB *mdb, short numCols, const char *query)
{
-/* # line 93 "myingres.sc" */
+ bool stmt_free = false;
+/* # line 111 "myingres.sc" */
char *stmt;
-/* # line 95 "myingres.sc" */
+/* # line 113 "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;
- stmt = bstrdup(query);
-/* # line 107 "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 133 "myingres.sc" */ /* prepare */
{
IIsqInit(&sqlca);
IIsqPrepare(0,(char *)"s2",sqlda,0,stmt);
}
-/* # line 109 "myingres.sc" */ /* host code */
- free(stmt);
+/* # line 135 "myingres.sc" */ /* host code */
+ if (stmt_free) {
+ free(stmt);
+ }
for (i = 0; i < sqlda->sqld; ++i) {
/*
* Negative type indicates nullable coulumns, so an indicator
IISQLDA *desc;
int check = -1;
desc = ing_res->sqlda;
-/* # line 363 "myingres.sc" */ /* host code */
+/* # line 392 "myingres.sc" */ /* host code */
if ((check = INGcheck()) < 0) {
return check;
}
-/* # line 367 "myingres.sc" */ /* open */
+/* # line 396 "myingres.sc" */ /* open */
{
IIsqInit(&sqlca);
- IIcsOpen((char *)"c2",10560,29663);
+ IIcsOpen((char *)"c2",4150,23546);
IIwritio(0,(short *)0,1,32,0,(char *)"s2");
- IIcsQuery((char *)"c2",10560,29663);
+ IIcsQuery((char *)"c2",4150,23546);
}
-/* # line 368 "myingres.sc" */ /* host code */
+/* # line 397 "myingres.sc" */ /* host code */
if ((check = INGcheck()) < 0) {
return check;
}
/* for (linecount = 0; sqlca.sqlcode == 0; ++linecount) */
do {
-/* # line 374 "myingres.sc" */ /* fetch */
+/* # line 403 "myingres.sc" */ /* fetch */
{
IIsqInit(&sqlca);
- if (IIcsRetScroll((char *)"c2",10560,29663,-1,-1) != 0) {
+ if (IIcsRetScroll((char *)"c2",4150,23546,-1,-1) != 0) {
IIcsDaGet(0,desc);
IIcsERetrieve();
} /* IIcsRetrieve */
}
-/* # line 376 "myingres.sc" */ /* host code */
+/* # line 405 "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 423 "myingres.sc" */ /* close */
{
IIsqInit(&sqlca);
- IIcsClose((char *)"c2",10560,29663);
+ IIcsClose((char *)"c2",4150,23546);
}
-/* # line 396 "myingres.sc" */ /* host code */
+/* # line 425 "myingres.sc" */ /* host code */
ing_res->status = ING_COMMAND_OK;
ing_res->num_rows = linecount;
return linecount;
{
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 477 "myingres.sc" */
+/* # line 507 "myingres.sc" */
int rowcount;
char *stmt;
-/* # line 480 "myingres.sc" */
+/* # line 510 "myingres.sc" */
- stmt = bstrdup(query);
+ /*
+ * 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 485 "myingres.sc" */ /* execute */
+/* # line 523 "myingres.sc" */ /* execute */
{
IIsqInit(&sqlca);
IIsqExImmed(stmt);
IIsyncup((char *)0,0);
}
-/* # line 487 "myingres.sc" */ /* host code */
- free(stmt);
+/* # line 525 "myingres.sc" */ /* host code */
+ if (stmt_free) {
+ free(stmt);
+ }
if ((check = INGcheck()) < 0) {
return check;
}
-/* # line 493 "myingres.sc" */ /* inquire_ingres */
+/* # line 533 "myingres.sc" */ /* inquire_ingres */
{
IILQisInqSqlio((short *)0,1,30,sizeof(rowcount),&rowcount,8);
}
-/* # line 494 "myingres.sc" */ /* host code */
+/* # line 534 "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
IISQLDA *desc = NULL;
INGresult *res = NULL;
int rows = -1;
- int cols = INGgetCols(query);
- desc = INGgetDescriptor(cols, query);
+ int cols = INGgetCols(mdb, query);
+ desc = INGgetDescriptor(mdb, cols, query);
if (!desc) {
return NULL;
}
+
res = INGgetINGresult(desc);
if (!res) {
return NULL;
}
+
rows = INGfetchAll(query, res);
+
if (rows < 0) {
INGfreeDescriptor(desc);
INGfreeINGresult(res);
return NULL;
}
+
return res;
}
void INGclear(INGresult *res)
}
dbconn = (INGconn *)malloc(sizeof(INGconn));
memset(dbconn, 0, sizeof(INGconn));
-/* # line 553 "myingres.sc" */
+/* # line 590 "myingres.sc" */
char ingdbname[24];
char ingdbuser[32];
char ingdbpasw[32];
char conn_name[32];
int sess_id;
-/* # line 559 "myingres.sc" */
+/* # line 596 "myingres.sc" */
bstrncpy(ingdbname, dbname, sizeof(ingdbname));
if (user != NULL) {
} else {
memset(ingdbpasw, 0, sizeof(ingdbpasw));
}
-/* # line 570 "myingres.sc" */ /* connect */
+/* # line 607 "myingres.sc" */ /* connect */
{
IIsqInit(&sqlca);
IIsqUser(ingdbuser);
(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);
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 613 "myingres.sc" */ /* host code */
}
-/* # line 578 "myingres.sc" */ /* inquire_sql */
+/* # line 615 "myingres.sc" */ /* inquire_sql */
{
IILQisInqSqlio((short *)0,1,32,31,conn_name,13);
}
-/* # line 579 "myingres.sc" */ /* inquire_sql */
+/* # line 616 "myingres.sc" */ /* inquire_sql */
{
IILQisInqSqlio((short *)0,1,30,sizeof(sess_id),&sess_id,11);
}
-/* # line 581 "myingres.sc" */ /* host code */
+/* # line 618 "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));
/*
* TODO: check for any real use of dbconn: maybe whenn multithreaded?
*/
-/* # line 597 "myingres.sc" */ /* disconnect */
+/* # line 634 "myingres.sc" */ /* disconnect */
{
IIsqInit(&sqlca);
IIsqDisconnect();
}
-/* # line 598 "myingres.sc" */ /* host code */
+/* # line 635 "myingres.sc" */ /* host code */
if (dbconn != NULL) {
free(dbconn->msg);
free(dbconn);
}
char *INGerrorMessage(const INGconn *conn)
{
-/* # line 606 "myingres.sc" */
+/* # line 643 "myingres.sc" */
char errbuf[256];
-/* # line 608 "myingres.sc" */
+/* # line 645 "myingres.sc" */
-/* # line 610 "myingres.sc" */ /* inquire_ingres */
+/* # line 647 "myingres.sc" */ /* inquire_ingres */
{
IILQisInqSqlio((short *)0,1,32,255,errbuf,63);
}
-/* # line 611 "myingres.sc" */ /* host code */
+/* # line 648 "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 625 "myingres.sc" */
+/* # line 662 "myingres.sc" */
#endif
* Stefan Reddig, June 2009
*/
+/* The following is necessary so that we do not include
+ * the dummy external definition of DB.
+ */
+#define __SQL_C /* indicate that this is sql.c */
+
#include "bacula.h"
+#include "cats.h"
#ifdef HAVE_INGRES
EXEC SQL INCLUDE SQLCA;
return (sqlca.sqlcode < 0) ? sqlca.sqlcode : 0;
}
-short INGgetCols(const char *query)
+short INGgetCols(B_DB *mdb, const char *query)
{
+ bool stmt_free = false;
EXEC SQL BEGIN DECLARE SECTION;
char *stmt;
EXEC SQL END DECLARE SECTION;
sqlda->sqln = number;
- stmt = bstrdup(query);
+ /*
+ * 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;
+ }
EXEC SQL PREPARE s1 from :stmt;
if (INGcheck() < 0) {
number = sqlda->sqld;
bail_out:
- free(stmt);
+ if (stmt_free) {
+ free(stmt);
+ }
free(sqlda);
return number;
}
-static inline IISQLDA *INGgetDescriptor(short numCols, const char *query)
+static inline IISQLDA *INGgetDescriptor(B_DB *mdb, short numCols, const char *query)
{
+ bool stmt_free = false;
EXEC SQL BEGIN DECLARE SECTION;
char *stmt;
EXEC SQL END DECLARE SECTION;
sqlda->sqln = numCols;
- stmt = bstrdup(query);
+ /*
+ * 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;
+ }
EXEC SQL PREPARE s2 INTO :sqlda FROM :stmt;
- free(stmt);
+ if (stmt_free) {
+ free(stmt);
+ }
for (i = 0; i < sqlda->sqld; ++i) {
/*
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;
EXEC SQL BEGIN DECLARE SECTION;
int rowcount;
char *stmt;
EXEC SQL END DECLARE SECTION;
- stmt = bstrdup(query);
+ /*
+ * 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;
EXEC SQL EXECUTE IMMEDIATE :stmt;
- free(stmt);
+ if (stmt_free) {
+ free(stmt);
+ }
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
IISQLDA *desc = NULL;
INGresult *res = NULL;
int rows = -1;
- int cols = INGgetCols(query);
+ int cols = INGgetCols(mdb, query);
- desc = INGgetDescriptor(cols, query);
+ desc = INGgetDescriptor(mdb, cols, query);
if (!desc) {
return NULL;
}