*/
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;
}
/*
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);
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 )
{
mdb->status = 1; /* failed */
}
}
- else
- {
- mdb->status = 1; /* failed */
- }
Dmsg0(500, "my_ingres_query finishing\n");
return mdb->status;
#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)
switch (ingvar->sqltype)
{
+ /* TODO: add date types (at least TSTMP,TSW TSWO) */
case IISQ_DTE_TYPE:
inglength = 25;
break;
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,
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 )
{
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)
{
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;i<ing_res->num_fields;++i)
- { printf("F%d:%s ",i,row->sqlvar[i].sqldata); }
- printf("\n");
- DEBE
-
}
}
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
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;
}
if ( user != NULL)
{
- DEBB(1)
- printf("Connection: with user/passwd\n");
- DEBE
strcpy(ingdbuser,user);
if ( passwd != NULL)
{ strcpy(ingdbpasw,passwd); }
}
else
{
- DEBB(1)
- printf("Connection: w/ user/passwd\n");
- DEBE
EXEC SQL CONNECT :ingdbname;
}
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)
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