Minor fixes to compile on unix for v6-40-0002
This commit is contained in:
parent
a75f2d21a8
commit
550de5db2c
|
@ -372,8 +372,10 @@ RETCODE SQL_API SQLCancel(
|
||||||
static char *func="SQLCancel";
|
static char *func="SQLCancel";
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
RETCODE result;
|
RETCODE result;
|
||||||
|
#ifdef WIN32
|
||||||
HMODULE hmodule;
|
HMODULE hmodule;
|
||||||
FARPROC addr;
|
FARPROC addr;
|
||||||
|
#endif
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog( "%s: entering...\n", func);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
portion of the registry. You may have to manually add this key.
|
portion of the registry. You may have to manually add this key.
|
||||||
This logfile is intended for development use, not for an end user!
|
This logfile is intended for development use, not for an end user!
|
||||||
*/
|
*/
|
||||||
// #define MY_LOG
|
#define MY_LOG
|
||||||
|
|
||||||
|
|
||||||
/* Uncomment Q_LOG to compile in the qlog() statements (Communications log, i.e. CommLog).
|
/* Uncomment Q_LOG to compile in the qlog() statements (Communications log, i.e. CommLog).
|
||||||
|
|
|
@ -36,6 +36,12 @@
|
||||||
|
|
||||||
extern GLOBAL_VALUES globals;
|
extern GLOBAL_VALUES globals;
|
||||||
|
|
||||||
|
RETCODE set_statement_option(ConnectionClass *conn,
|
||||||
|
StatementClass *stmt,
|
||||||
|
UWORD fOption,
|
||||||
|
UDWORD vParam);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RETCODE set_statement_option(ConnectionClass *conn,
|
RETCODE set_statement_option(ConnectionClass *conn,
|
||||||
StatementClass *stmt,
|
StatementClass *stmt,
|
||||||
|
|
|
@ -77,7 +77,7 @@ QR_inc_base(QResultClass *self, int base_inc)
|
||||||
/************************************/
|
/************************************/
|
||||||
|
|
||||||
QResultClass *
|
QResultClass *
|
||||||
QR_Constructor()
|
QR_Constructor(void)
|
||||||
{
|
{
|
||||||
QResultClass *rv;
|
QResultClass *rv;
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ struct QResultClass_ {
|
||||||
#define QR_get_status(self) (self->status)
|
#define QR_get_status(self) (self->status)
|
||||||
|
|
||||||
// Core Functions
|
// Core Functions
|
||||||
QResultClass *QR_Constructor();
|
QResultClass *QR_Constructor(void);
|
||||||
void QR_Destructor(QResultClass *self);
|
void QR_Destructor(QResultClass *self);
|
||||||
char QR_read_tuple(QResultClass *self, char binary);
|
char QR_read_tuple(QResultClass *self, char binary);
|
||||||
int QR_next_tuple(QResultClass *self);
|
int QR_next_tuple(QResultClass *self);
|
||||||
|
|
|
@ -740,139 +740,6 @@ mylog("SQLGetData: enter, stmt=%u\n", stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RETCODE
|
|
||||||
SC_fetch(StatementClass *stmt)
|
|
||||||
{
|
|
||||||
static char *func = "SC_fetch";
|
|
||||||
QResultClass *res = stmt->result;
|
|
||||||
int retval, result;
|
|
||||||
Int2 num_cols, lf;
|
|
||||||
Oid type;
|
|
||||||
char *value;
|
|
||||||
ColumnInfoClass *ci;
|
|
||||||
// TupleField *tupleField;
|
|
||||||
|
|
||||||
stmt->last_fetch_count = 0;
|
|
||||||
ci = QR_get_fields(res); /* the column info */
|
|
||||||
|
|
||||||
mylog("manual_result = %d, use_declarefetch = %d\n", stmt->manual_result, globals.use_declarefetch);
|
|
||||||
|
|
||||||
if ( stmt->manual_result || ! globals.use_declarefetch) {
|
|
||||||
|
|
||||||
if (stmt->currTuple >= QR_get_num_tuples(res) -1 ||
|
|
||||||
(stmt->options.maxRows > 0 && stmt->currTuple == stmt->options.maxRows - 1)) {
|
|
||||||
|
|
||||||
/* if at the end of the tuples, return "no data found"
|
|
||||||
and set the cursor past the end of the result set
|
|
||||||
*/
|
|
||||||
stmt->currTuple = QR_get_num_tuples(res);
|
|
||||||
return SQL_NO_DATA_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
mylog("**** SQLFetch: manual_result\n");
|
|
||||||
(stmt->currTuple)++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
// read from the cache or the physical next tuple
|
|
||||||
retval = QR_next_tuple(res);
|
|
||||||
if (retval < 0) {
|
|
||||||
mylog("**** SQLFetch: end_tuples\n");
|
|
||||||
return SQL_NO_DATA_FOUND;
|
|
||||||
}
|
|
||||||
else if (retval > 0)
|
|
||||||
(stmt->currTuple)++; // all is well
|
|
||||||
|
|
||||||
else {
|
|
||||||
mylog("SQLFetch: error\n");
|
|
||||||
stmt->errornumber = STMT_EXEC_ERROR;
|
|
||||||
stmt->errormsg = "Error fetching next row";
|
|
||||||
SC_log_error(func, "", stmt);
|
|
||||||
return SQL_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
num_cols = QR_NumResultCols(res);
|
|
||||||
|
|
||||||
result = SQL_SUCCESS;
|
|
||||||
stmt->last_fetch_count = 1;
|
|
||||||
|
|
||||||
for (lf=0; lf < num_cols; lf++) {
|
|
||||||
|
|
||||||
mylog("fetch: cols=%d, lf=%d, stmt = %u, stmt->bindings = %u, buffer[] = %u\n", num_cols, lf, stmt, stmt->bindings, stmt->bindings[lf].buffer);
|
|
||||||
|
|
||||||
/* reset for SQLGetData */
|
|
||||||
stmt->bindings[lf].data_left = -1;
|
|
||||||
|
|
||||||
if (stmt->bindings[lf].buffer != NULL) {
|
|
||||||
// this column has a binding
|
|
||||||
|
|
||||||
// type = QR_get_field_type(res, lf);
|
|
||||||
type = CI_get_oid(ci, lf); /* speed things up */
|
|
||||||
|
|
||||||
mylog("type = %d\n", type);
|
|
||||||
|
|
||||||
if (stmt->manual_result) {
|
|
||||||
value = QR_get_value_manual(res, stmt->currTuple, lf);
|
|
||||||
mylog("manual_result\n");
|
|
||||||
}
|
|
||||||
else if (globals.use_declarefetch)
|
|
||||||
value = QR_get_value_backend(res, lf);
|
|
||||||
else {
|
|
||||||
value = QR_get_value_backend_row(res, stmt->currTuple, lf);
|
|
||||||
}
|
|
||||||
|
|
||||||
mylog("value = '%s'\n", (value==NULL)?"<NULL>":value);
|
|
||||||
|
|
||||||
retval = copy_and_convert_field_bindinfo(stmt, type, value, lf);
|
|
||||||
|
|
||||||
mylog("copy_and_convert: retval = %d\n", retval);
|
|
||||||
|
|
||||||
switch(retval) {
|
|
||||||
case COPY_OK:
|
|
||||||
break; /* OK, do next bound column */
|
|
||||||
|
|
||||||
case COPY_UNSUPPORTED_TYPE:
|
|
||||||
stmt->errormsg = "Received an unsupported type from Postgres.";
|
|
||||||
stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
|
|
||||||
SC_log_error(func, "", stmt);
|
|
||||||
result = SQL_ERROR;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COPY_UNSUPPORTED_CONVERSION:
|
|
||||||
stmt->errormsg = "Couldn't handle the necessary data type conversion.";
|
|
||||||
stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
|
|
||||||
SC_log_error(func, "", stmt);
|
|
||||||
result = SQL_ERROR;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COPY_RESULT_TRUNCATED:
|
|
||||||
stmt->errornumber = STMT_TRUNCATED;
|
|
||||||
stmt->errormsg = "The buffer was too small for the result.";
|
|
||||||
result = SQL_SUCCESS_WITH_INFO;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COPY_GENERAL_ERROR: /* error msg already filled in */
|
|
||||||
SC_log_error(func, "", stmt);
|
|
||||||
result = SQL_ERROR;
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* This would not be meaningful in SQLFetch. */
|
|
||||||
case COPY_NO_DATA_FOUND:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
stmt->errormsg = "Unrecognized return value from copy_and_convert_field.";
|
|
||||||
stmt->errornumber = STMT_INTERNAL_ERROR;
|
|
||||||
SC_log_error(func, "", stmt);
|
|
||||||
result = SQL_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Returns data for bound columns in the current row ("hstmt->iCursor"),
|
// Returns data for bound columns in the current row ("hstmt->iCursor"),
|
||||||
|
|
|
@ -566,6 +566,142 @@ char rv;
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RETCODE
|
||||||
|
SC_fetch(StatementClass *self)
|
||||||
|
{
|
||||||
|
static char *func = "SC_fetch";
|
||||||
|
QResultClass *res = self->result;
|
||||||
|
int retval, result;
|
||||||
|
Int2 num_cols, lf;
|
||||||
|
Oid type;
|
||||||
|
char *value;
|
||||||
|
ColumnInfoClass *ci;
|
||||||
|
// TupleField *tupleField;
|
||||||
|
|
||||||
|
self->last_fetch_count = 0;
|
||||||
|
ci = QR_get_fields(res); /* the column info */
|
||||||
|
|
||||||
|
mylog("manual_result = %d, use_declarefetch = %d\n", self->manual_result, globals.use_declarefetch);
|
||||||
|
|
||||||
|
if ( self->manual_result || ! globals.use_declarefetch) {
|
||||||
|
|
||||||
|
if (self->currTuple >= QR_get_num_tuples(res) -1 ||
|
||||||
|
(self->options.maxRows > 0 && self->currTuple == self->options.maxRows - 1)) {
|
||||||
|
|
||||||
|
/* if at the end of the tuples, return "no data found"
|
||||||
|
and set the cursor past the end of the result set
|
||||||
|
*/
|
||||||
|
self->currTuple = QR_get_num_tuples(res);
|
||||||
|
return SQL_NO_DATA_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
mylog("**** SQLFetch: manual_result\n");
|
||||||
|
(self->currTuple)++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
// read from the cache or the physical next tuple
|
||||||
|
retval = QR_next_tuple(res);
|
||||||
|
if (retval < 0) {
|
||||||
|
mylog("**** SQLFetch: end_tuples\n");
|
||||||
|
return SQL_NO_DATA_FOUND;
|
||||||
|
}
|
||||||
|
else if (retval > 0)
|
||||||
|
(self->currTuple)++; // all is well
|
||||||
|
|
||||||
|
else {
|
||||||
|
mylog("SQLFetch: error\n");
|
||||||
|
self->errornumber = STMT_EXEC_ERROR;
|
||||||
|
self->errormsg = "Error fetching next row";
|
||||||
|
SC_log_error(func, "", self);
|
||||||
|
return SQL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
num_cols = QR_NumResultCols(res);
|
||||||
|
|
||||||
|
result = SQL_SUCCESS;
|
||||||
|
self->last_fetch_count = 1;
|
||||||
|
|
||||||
|
for (lf=0; lf < num_cols; lf++) {
|
||||||
|
|
||||||
|
mylog("fetch: cols=%d, lf=%d, self = %u, self->bindings = %u, buffer[] = %u\n", num_cols, lf, self, self->bindings, self->bindings[lf].buffer);
|
||||||
|
|
||||||
|
/* reset for SQLGetData */
|
||||||
|
self->bindings[lf].data_left = -1;
|
||||||
|
|
||||||
|
if (self->bindings[lf].buffer != NULL) {
|
||||||
|
// this column has a binding
|
||||||
|
|
||||||
|
// type = QR_get_field_type(res, lf);
|
||||||
|
type = CI_get_oid(ci, lf); /* speed things up */
|
||||||
|
|
||||||
|
mylog("type = %d\n", type);
|
||||||
|
|
||||||
|
if (self->manual_result) {
|
||||||
|
value = QR_get_value_manual(res, self->currTuple, lf);
|
||||||
|
mylog("manual_result\n");
|
||||||
|
}
|
||||||
|
else if (globals.use_declarefetch)
|
||||||
|
value = QR_get_value_backend(res, lf);
|
||||||
|
else {
|
||||||
|
value = QR_get_value_backend_row(res, self->currTuple, lf);
|
||||||
|
}
|
||||||
|
|
||||||
|
mylog("value = '%s'\n", (value==NULL)?"<NULL>":value);
|
||||||
|
|
||||||
|
retval = copy_and_convert_field_bindinfo(self, type, value, lf);
|
||||||
|
|
||||||
|
mylog("copy_and_convert: retval = %d\n", retval);
|
||||||
|
|
||||||
|
switch(retval) {
|
||||||
|
case COPY_OK:
|
||||||
|
break; /* OK, do next bound column */
|
||||||
|
|
||||||
|
case COPY_UNSUPPORTED_TYPE:
|
||||||
|
self->errormsg = "Received an unsupported type from Postgres.";
|
||||||
|
self->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
|
||||||
|
SC_log_error(func, "", self);
|
||||||
|
result = SQL_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case COPY_UNSUPPORTED_CONVERSION:
|
||||||
|
self->errormsg = "Couldn't handle the necessary data type conversion.";
|
||||||
|
self->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
|
||||||
|
SC_log_error(func, "", self);
|
||||||
|
result = SQL_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case COPY_RESULT_TRUNCATED:
|
||||||
|
self->errornumber = STMT_TRUNCATED;
|
||||||
|
self->errormsg = "The buffer was too small for the result.";
|
||||||
|
result = SQL_SUCCESS_WITH_INFO;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case COPY_GENERAL_ERROR: /* error msg already filled in */
|
||||||
|
SC_log_error(func, "", self);
|
||||||
|
result = SQL_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* This would not be meaningful in SQLFetch. */
|
||||||
|
case COPY_NO_DATA_FOUND:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
self->errormsg = "Unrecognized return value from copy_and_convert_field.";
|
||||||
|
self->errornumber = STMT_INTERNAL_ERROR;
|
||||||
|
SC_log_error(func, "", self);
|
||||||
|
result = SQL_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
RETCODE SC_execute(StatementClass *self)
|
RETCODE SC_execute(StatementClass *self)
|
||||||
{
|
{
|
||||||
static char *func="SC_execute";
|
static char *func="SC_execute";
|
||||||
|
|
|
@ -202,7 +202,8 @@ char SC_recycle_statement(StatementClass *self);
|
||||||
void SC_clear_error(StatementClass *self);
|
void SC_clear_error(StatementClass *self);
|
||||||
char SC_get_error(StatementClass *self, int *number, char **message);
|
char SC_get_error(StatementClass *self, int *number, char **message);
|
||||||
char *SC_create_errormsg(StatementClass *self);
|
char *SC_create_errormsg(StatementClass *self);
|
||||||
RETCODE SC_execute(StatementClass *stmt);
|
RETCODE SC_execute(StatementClass *self);
|
||||||
|
RETCODE SC_fetch(StatementClass *self);
|
||||||
void SC_free_params(StatementClass *self, char option);
|
void SC_free_params(StatementClass *self, char option);
|
||||||
void SC_log_error(char *func, char *desc, StatementClass *self);
|
void SC_log_error(char *func, char *desc, StatementClass *self);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue