if (result_handler != NULL) {
Dmsg0(500, "db_sql_query invoking handler\n");
- if ((mdb->result = sql_store_result(mdb)) != NULL) {
+ if (mdb->result != NULL) {
int num_fields = sql_num_fields(mdb);
Dmsg0(500, "db_sql_query sql_store_result suceeded\n");
int j;
INGRES_ROW row = NULL; // by default, return NULL
+ if (!mdb->result) {
+ return row;
+ }
+ if (mdb->result->num_rows <= 0) {
+ return row;
+ }
+
Dmsg0(500, "my_ingres_fetch_row start\n");
if (!mdb->row || mdb->row_size < mdb->num_fields) {
mdb->row_size = num_fields;
// now reset the row_number now that we have the space allocated
- mdb->row_number = 0;
+ mdb->row_number = 1;
}
// if still within the result set
- if (mdb->row_number < mdb->num_rows) {
+ if (mdb->row_number <= mdb->num_rows) {
Dmsg2(500, "my_ingres_fetch_row row number '%d' is acceptable (0..%d)\n", mdb->row_number, mdb->num_rows);
// get each value from this row
for (j = 0; j < mdb->num_fields; j++) {
#include "bacula.h"
/* # line 3 "myingres.sc" */
#ifdef HAVE_INGRES
-#include <eqpname.h>
-#include <eqdefcc.h>
+#include <eqdefc.h>
#include <eqsqlca.h>
-extern IISQLCA sqlca; /* SQL Communications Area */
+ extern IISQLCA sqlca; /* SQL Communications Area */
#include <eqsqlda.h>
+/* # line 7 "myingres.sc" */ /* host code */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
}
void INGfreeDescriptor(IISQLDA *sqlda)
{
+ if (!sqlda) {
+ return;
+ }
int i;
for (i = 0; i < sqlda->sqld; ++i) {
if (sqlda->sqlvar[i].sqldata) {
}
INGresult *INGgetINGresult(IISQLDA *sqlda)
{
+ if (!sqlda) {
+ return NULL;
+ }
int i;
INGresult *result = NULL;
result = (INGresult *)malloc(sizeof(INGresult));
}
void INGfreeINGresult(INGresult *ing_res)
{
+ if (!ing_res) {
+ return;
+ }
int rows;
ING_ROW *rowtemp;
/*
IISQLDA *desc;
int check = -1;
desc = ing_res->sqlda;
-/* # line 305 "myingres.sc" */ /* host code */
+/* # line 317 "myingres.sc" */ /* host code */
if ((check = INGcheck()) < 0) {
return check;
}
-/* # line 309 "myingres.sc" */ /* open */
+/* # line 321 "myingres.sc" */ /* open */
{
IIsqInit(&sqlca);
- IIcsOpen((char *)"c2",4824,17405);
+ IIcsOpen((char *)"c2",27229,4179);
IIwritio(0,(short *)0,1,32,0,(char *)"s2");
- IIcsQuery((char *)"c2",4824,17405);
+ IIcsQuery((char *)"c2",27229,4179);
}
-/* # line 310 "myingres.sc" */ /* host code */
+/* # line 322 "myingres.sc" */ /* host code */
if ((check = INGcheck()) < 0) {
return check;
}
/* for (linecount = 0; sqlca.sqlcode == 0; ++linecount) */
- while(sqlca.sqlcode == 0) {
-/* # line 316 "myingres.sc" */ /* fetch */
+ do {
+/* # line 328 "myingres.sc" */ /* fetch */
{
IIsqInit(&sqlca);
- if (IIcsRetScroll((char *)"c2",4824,17405,-1,-1) != 0) {
+ if (IIcsRetScroll((char *)"c2",27229,4179,-1,-1) != 0) {
IIcsDaGet(0,desc);
IIcsERetrieve();
} /* IIcsRetrieve */
}
-/* # line 317 "myingres.sc" */ /* host code */
- if ((check = INGcheck()) < 0) {
-/* # line 318 "myingres.sc" */ /* close */
- {
- IIsqInit(&sqlca);
- IIcsClose((char *)"c2",4824,17405);
- }
-/* # line 319 "myingres.sc" */ /* host code */
- return check;
- }
- if (sqlca.sqlcode == 0) {
+/* # line 330 "myingres.sc" */ /* host code */
+ if ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) ) {
row = INGgetRowSpace(ing_res); /* alloc space for fetched row */
/*
* Initialize list when encountered first time
}
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;
+ row->row_number = linecount;
}
- }
-/* # line 340 "myingres.sc" */ /* close */
+ } while ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) )
+/* # line 348 "myingres.sc" */ /* close */
{
IIsqInit(&sqlca);
- IIcsClose((char *)"c2",4824,17405);
+ IIcsClose((char *)"c2",27229,4179);
}
-/* # line 342 "myingres.sc" */ /* host code */
+/* # line 350 "myingres.sc" */ /* host code */
ing_res->status = ING_COMMAND_OK;
ing_res->num_rows = linecount;
return linecount;
}
void INGrowSeek(INGresult *res, int row_number)
{
- ING_ROW *trow;
+ ING_ROW *trow = NULL;
+ int i;
if (res->act_row->row_number == row_number) {
return;
}
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 , i=1 ; trow->row_number != row_number , i <= res->num_rows; trow = trow->next , ++i);
res->act_row = trow;
/*
* Note - can be null - if row_number not found, right?
int INGexec(INGconn *conn, const char *query)
{
int check;
-/* # line 417 "myingres.sc" */
+/* # line 426 "myingres.sc" */
int rowcount;
char *stmt;
-/* # line 420 "myingres.sc" */
+/* # line 429 "myingres.sc" */
stmt = (char *)malloc(strlen(query)+1);
bstrncpy(stmt,query,strlen(query)+1);
rowcount = -1;
-/* # line 426 "myingres.sc" */ /* execute */
+/* # line 435 "myingres.sc" */ /* execute */
{
IIsqInit(&sqlca);
IIsqExImmed(stmt);
IIsyncup((char *)0,0);
}
-/* # line 427 "myingres.sc" */ /* host code */
+/* # line 436 "myingres.sc" */ /* host code */
free(stmt);
if ((check = INGcheck()) < 0) {
return check;
}
-/* # line 432 "myingres.sc" */ /* inquire_ingres */
+/* # line 441 "myingres.sc" */ /* inquire_ingres */
{
IILQisInqSqlio((short *)0,1,30,sizeof(rowcount),&rowcount,8);
}
-/* # line 433 "myingres.sc" */ /* host code */
+/* # line 442 "myingres.sc" */ /* host code */
if ((check = INGcheck()) < 0) {
return check;
}
int rows = -1;
int cols = INGgetCols(query);
desc = INGgetDescriptor(cols, query);
+ if (!desc) {
+ return NULL;
+ }
res = INGgetINGresult(desc);
+ if (!res) {
+ return NULL;
+ }
rows = INGfetchAll(query, res);
if (rows < 0) {
INGfreeINGresult(res);
+ INGfreeDescriptor(desc);
return NULL;
}
return res;
}
INGconn *dbconn = (INGconn *)malloc(sizeof(INGconn));
memset(dbconn, 0, sizeof(INGconn));
-/* # line 480 "myingres.sc" */
+/* # line 496 "myingres.sc" */
char ingdbname[24];
char ingdbuser[32];
char ingdbpasw[32];
char conn_name[32];
int sess_id;
-/* # line 486 "myingres.sc" */
+/* # line 502 "myingres.sc" */
bstrncpy(ingdbname, dbname, sizeof(ingdbname));
if (user != NULL) {
} else {
memset(ingdbpasw, 0, sizeof(ingdbpasw));
}
-/* # line 497 "myingres.sc" */ /* connect */
+/* # line 513 "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 501 "myingres.sc" */ /* host code */
+/* # line 517 "myingres.sc" */ /* host code */
} else {
-/* # line 502 "myingres.sc" */ /* connect */
+/* # line 518 "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 503 "myingres.sc" */ /* host code */
+/* # line 519 "myingres.sc" */ /* host code */
}
-/* # line 505 "myingres.sc" */ /* inquire_sql */
+/* # line 521 "myingres.sc" */ /* inquire_sql */
{
IILQisInqSqlio((short *)0,1,32,31,conn_name,13);
}
-/* # line 506 "myingres.sc" */ /* inquire_sql */
+/* # line 522 "myingres.sc" */ /* inquire_sql */
{
IILQisInqSqlio((short *)0,1,30,sizeof(sess_id),&sess_id,11);
}
-/* # line 508 "myingres.sc" */ /* host code */
+/* # line 524 "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 524 "myingres.sc" */ /* disconnect */
+/* # line 540 "myingres.sc" */ /* disconnect */
{
IIsqInit(&sqlca);
IIsqDisconnect();
}
-/* # line 525 "myingres.sc" */ /* host code */
+/* # line 541 "myingres.sc" */ /* host code */
if (dbconn != NULL) {
free(dbconn->msg);
free(dbconn);
}
char *INGerrorMessage(const INGconn *conn)
{
-/* # line 533 "myingres.sc" */
+/* # line 549 "myingres.sc" */
char errbuf[256];
-/* # line 535 "myingres.sc" */
+/* # line 551 "myingres.sc" */
-/* # line 537 "myingres.sc" */ /* inquire_ingres */
+/* # line 553 "myingres.sc" */ /* inquire_ingres */
{
IILQisInqSqlio((short *)0,1,32,255,errbuf,63);
}
-/* # line 538 "myingres.sc" */ /* host code */
+/* # line 554 "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 552 "myingres.sc" */
+/* # line 568 "myingres.sc" */
#endif
void INGfreeDescriptor(IISQLDA *sqlda)
{
+ if (!sqlda) {
+ return;
+ }
+
int i;
for (i = 0; i < sqlda->sqld; ++i) {
INGresult *INGgetINGresult(IISQLDA *sqlda)
{
+ if (!sqlda) {
+ return NULL;
+ }
+
int i;
INGresult *result = NULL;
void INGfreeINGresult(INGresult *ing_res)
{
+ if (!ing_res) {
+ return;
+ }
+
int rows;
ING_ROW *rowtemp;
}
/* for (linecount = 0; sqlca.sqlcode == 0; ++linecount) */
- while(sqlca.sqlcode == 0) {
+ do {
EXEC SQL FETCH c2 USING DESCRIPTOR :desc;
- if ((check = INGcheck()) < 0) {
- EXEC SQL CLOSE c2;
- return check;
- }
- if (sqlca.sqlcode == 0) {
+ if ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) ) {
row = INGgetRowSpace(ing_res); /* alloc space for fetched 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;
+ row->row_number = linecount;
}
- }
+ } while ( (sqlca.sqlcode == 0) || (sqlca.sqlcode == -40202) )
EXEC SQL CLOSE c2;
void INGrowSeek(INGresult *res, int row_number)
{
- ING_ROW *trow;
+ ING_ROW *trow = NULL;
+ int i;
if (res->act_row->row_number == row_number) {
return;
}
return;
}
- for (trow = res->first_row; trow->row_number != row_number; trow = trow->next) ;
+ for (trow = res->first_row , i=1 ; trow->row_number != row_number , i <= res->num_rows; trow = trow->next , ++i);
res->act_row = trow;
/*
* Note - can be null - if row_number not found, right?
int cols = INGgetCols(query);
desc = INGgetDescriptor(cols, query);
+ if (!desc) {
+ return NULL;
+ }
res = INGgetINGresult(desc);
+ if (!res) {
+ return NULL;
+ }
rows = INGfetchAll(query, res);
if (rows < 0) {
INGfreeINGresult(res);
+ INGfreeDescriptor(desc);
return NULL;
}
return res;
"PurgedFiles TINYINT, "
"FileSetId INTEGER UNSIGNED, "
"JobFiles INTEGER UNSIGNED, "
- "JobStatus CHAR)"};
+ "JobStatus CHAR)",
+ /* Ingres */
+ "DECLARE GLOBAL TEMPORARY TABLE DelCandidates ("
+ "JobId INTEGER NOT NULL, "
+ "PurgedFiles SMALLINT, "
+ "FileSetId INTEGER, "
+ "JobFiles INTEGER, "
+ "JobStatus char(1))"
+ "ON COMMIT PERSERVE ROWS WITH NORECOVERY"
+};
/* ======= ua_restore.c */
"VolumeName TEXT,"
"StartFile INTEGER UNSIGNED,"
"VolSessionId INTEGER UNSIGNED,"
- "VolSessionTime INTEGER UNSIGNED)"};
+ "VolSessionTime INTEGER UNSIGNED)",
+ /* Ingres */
+ "DECLARE GLOBAL TEMPORARY TABLE temp ("
+ "JobId INTEGER NOT NULL,"
+ "JobTDate BIGINT,"
+ "ClientId INTEGER,"
+ "Level CHAR,"
+ "JobFiles INTEGER,"
+ "JobBytes BIGINT,"
+ "StartTime TEXT,"
+ "VolumeName TEXT,"
+ "StartFile INTEGER,"
+ "VolSessionId INTEGER,"
+ "VolSessionTime INTEGER)"
+ "ON COMMIT PRESERVE ROWS WITH NORECOVERY"
+ };
const char *uar_create_temp1[4] = {
/* Mysql */
/* SQLite3 */
"CREATE TEMPORARY TABLE temp1 ("
"JobId INTEGER UNSIGNED NOT NULL,"
- "JobTDate BIGINT UNSIGNED)"};
+ "JobTDate BIGINT UNSIGNED)",
+ /* Ingres */
+ "DECLARE GLOBAL TEMPORARY TABLE temp1 ("
+ "JobId INTEGER NOT NULL,"
+ "JobTDate BIGINT)"
+ "ON COMMIT PRESERVE ROWS WITH NORECOVERY"
+ };
/* Query to get all files in a directory -- no recursing
* Note, for PostgreSQL since it respects the "Single Value
/* SQLite3 */
"CREATE TEMPORARY TABLE basefile%lld ("
"Path TEXT,"
- "Name TEXT)"
+ "Name TEXT)",
+
+ /* Ingres */
+ "DECLARE GLOBAL TEMPORARY TABLE basefile%lld ("
+ "Path TEXT NOT NULL,"
+ "Name TEXT NOT NULL)"
+ "ON COMMIT PRESERVE ROWS WITH NORECOVERY"
};
/*
exit(1);
}
-/* simple handler for debug output of CRUD example*/
+/*
+ * simple handler for debug output of CRUD example
+ */
static int test_handler(void *ctx, int num_fields, char **row)
{
Dmsg2(200, " Values are %d, %s\n", str_to_int64(row[0]), row[1]);
return 0;
}
+/*
+ * string handler for debug output of simple SELECT tests
+ */
+static int string_handler(void *ctx, int num_fields, char **row)
+{
+ Dmsg1(200, " Value is >>%s<<\n", row[0]);
+ return 0;
+}
/* number of thread started */
Pmsg0(0, "\nsimple CRUD test...\n\n");
Dmsg0(200, "DB-Statement: CREATE TABLE t1 ( c1 integer, c2 varchar(29))\n");
- if (!db_sql_query(db, "CREATE TABLE t1 ( c1 integer, c2 varchar(29))", NULL, NULL))
- {
+ if (!db_sql_query(db, "CREATE TABLE t1 ( c1 integer, c2 varchar(29))", NULL, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n"));
}
Dmsg0(200, "DB-Statement: INSERT INTO t1 VALUES (1, 'foo')\n");
- if (!db_sql_query(db, "INSERT INTO t1 VALUES (1, 'foo')", NULL, NULL))
- {
+ if (!db_sql_query(db, "INSERT INTO t1 VALUES (1, 'foo')", NULL, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("INSERT-Stmt went wrong\n"));
}
- Dmsg0(200, "DB-Statement: SELECT * FROM t1 (should be 1, foo)\n");
- if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL))
- {
+ Dmsg0(200, "DB-Statement: SELECT c1,c2 FROM t1 (should be 1, foo)\n");
+ if (!db_sql_query(db, "SELECT c1,c2 FROM t1", test_handler, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
}
Dmsg0(200, "DB-Statement: UPDATE t1 SET c2='bar' WHERE c1=1\n");
- if (!db_sql_query(db, "UPDATE t1 SET c2='bar' WHERE c1=1", NULL, NULL))
- {
+ if (!db_sql_query(db, "UPDATE t1 SET c2='bar' WHERE c1=1", NULL, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("UPDATE-Stmt went wrong\n"));
}
Dmsg0(200, "DB-Statement: SELECT * FROM t1 (should be 1, bar)\n");
- if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL))
- {
+ if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
}
- Dmsg0(200, "DB-Statement: DELETE FROM t1 WHERE c2 LIKE '%r'\n");
- if (!db_sql_query(db, "DELETE FROM t1 WHERE c2 LIKE '%r'", NULL, NULL))
- {
+ Dmsg0(200, "DB-Statement: DELETE FROM t1 WHERE c2 LIKE '\%r'\n");
+ if (!db_sql_query(db, "DELETE FROM t1 WHERE c2 LIKE '%r'", NULL, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("DELETE-Stmt went wrong\n"));
}
Dmsg0(200, "DB-Statement: SELECT * FROM t1 (should be 0 rows)\n");
- if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL))
- {
+ if (!db_sql_query(db, "SELECT * FROM t1", test_handler, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
}
Dmsg0(200, "DB-Statement: DROP TABLE t1\n");
- if (!db_sql_query(db, "DROP TABLE t1", NULL, NULL))
- {
+ if (!db_sql_query(db, "DROP TABLE t1", NULL, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n"));
}
- /* datatypes test */
+ /*
+ * simple SELECT test without tables
+ */
+
+ Dmsg0(200, "DB-Statement: SELECT 'Test of simple SELECT!'\n");
+ if (!db_sql_query(db, "SELECT 'Test of simple SELECT!'", string_handler, NULL)) {
+ Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
+ }
+
+ Dmsg0(200, "DB-Statement: SELECT 'Test of simple SELECT!' as Text\n");
+ if (!db_sql_query(db, "SELECT 'Test of simple SELECT!' as Text", string_handler, NULL)) {
+ Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
+ }
+
+ Dmsg0(200, "DB-Statement: SELECT VARCHAR(LENGTH('Test of simple SELECT!'))\n");
+ if (!db_sql_query(db, "SELECT VARCHAR(LENGTH('Test of simple SELECT!'))", string_handler, NULL)) {
+ Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
+ }
+
+ Dmsg0(200, "DB-Statement: SELECT DBMSINFO('_version')\n");
+ if (!db_sql_query(db, "SELECT DBMSINFO('_version')", string_handler, NULL)) {
+ Emsg0(M_ERROR_TERM, 0, _("SELECT-Stmt went wrong\n"));
+ }
+
+ /*
+ * datatypes test
+ */
Pmsg0(0, "\ndatatypes test... (TODO)\n\n");
"c2 varchar(255),"
"c3 char(255)"
/* some more datatypes... "c4 ," */
- ")" , NULL, NULL))
- {
+ ")" , NULL, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("CREATE-Stmt went wrong\n"));
}
Dmsg0(200, "DB-Statement: DROP TABLE for datatypes\n");
- if (!db_sql_query(db, "DROP TABLE t2", NULL, NULL))
- {
+ if (!db_sql_query(db, "DROP TABLE t2", NULL, NULL)) {
Emsg0(M_ERROR_TERM, 0, _("DROP-Stmt went wrong\n"));
}