}
/* Data at exec macro only valid for C char/binary data */
- if ((fSqlType == SQL_LONGVARBINARY || fSqlType == SQL_LONGVARCHAR) && pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET)
+ if (pcbValue && (*pcbValue == SQL_DATA_AT_EXEC ||
+ *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET))
stmt->parameters[ipar].data_at_exec = TRUE;
else
stmt->parameters[ipar].data_at_exec = FALSE;
+ /* Clear premature result */
+ if (stmt->status == STMT_PREMATURE)
+ SC_recycle_statement(stmt);
+
mylog("SQLBindParamater: ipar=%d, paramType=%d, fCType=%d, fSqlType=%d, cbColDef=%d, ibScale=%d, rgbValue=%d, *pcbValue = %d, data_at_exec = %d\n", ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, pcbValue ? *pcbValue : -777, stmt->parameters[ipar].data_at_exec);
return SQL_SUCCESS;
#include "qresult.h"
#include "convert.h"
#include "bind.h"
+#include "pgtypes.h"
#include "lobj.h"
extern GLOBAL_VALUES globals;
*/
if (stmt->prepare && stmt->status == STMT_PREMATURE)
{
- stmt->status = STMT_FINISHED;
- if (stmt->errormsg == NULL)
- {
- mylog("%s: premature statement but return SQL_SUCCESS\n", func);
- return SQL_SUCCESS;
- }
+ if (stmt->inaccurate_result)
+ SC_recycle_statement(stmt);
else
{
- SC_log_error(func, "", stmt);
- mylog("%s: premature statement so return SQL_ERROR\n", func);
- return SQL_ERROR;
+ stmt->status = STMT_FINISHED;
+ if (stmt->errormsg == NULL)
+ {
+ mylog("%s: premature statement but return SQL_SUCCESS\n", func);
+ return SQL_SUCCESS;
+ }
+ else
+ {
+ SC_log_error(func, "", stmt);
+ mylog("%s: premature statement so return SQL_ERROR\n", func);
+ return SQL_ERROR;
+ }
}
}
}
- /*
- * The bound parameters could have possibly changed since the last
- * execute of this statement? Therefore check for params and re-copy.
- */
- stmt->data_at_exec = -1;
- for (i = 0; i < stmt->parameters_allocated; i++)
+ /* Check if statement has any data-at-execute parameters when it is not in SC_pre_execute. */
+ if (!stmt->pre_executing)
{
- /* Check for data at execution parameters */
- if (stmt->parameters[i].data_at_exec == TRUE)
+
+ /*
+ * The bound parameters could have possibly changed since the last
+ * execute of this statement? Therefore check for params and re-copy.
+ */
+ stmt->data_at_exec = -1;
+ for (i = 0; i < stmt->parameters_allocated; i++)
{
- if (stmt->data_at_exec < 0)
- stmt->data_at_exec = 1;
- else
- stmt->data_at_exec++;
+ /* Check for data at execution parameters */
+ if (stmt->parameters[i].data_at_exec == TRUE)
+ {
+ if (stmt->data_at_exec < 0)
+ stmt->data_at_exec = 1;
+ else
+ stmt->data_at_exec++;
+ }
}
- }
- /* If there are some data at execution parameters, return need data */
+ /* If there are some data at execution parameters, return need data */
- /*
- * SQLParamData and SQLPutData will be used to send params and execute
- * the statement.
- */
- if (stmt->data_at_exec > 0)
- return SQL_NEED_DATA;
+ /*
+ * SQLParamData and SQLPutData will be used to send params and execute
+ * the statement.
+ */
+ if (stmt->data_at_exec > 0)
+ return SQL_NEED_DATA;
+
+ }
mylog("%s: copying statement params: trans_status=%d, len=%d, stmt='%s'\n", func, conn->transact_status, strlen(stmt->statement), stmt->statement);
}
else
- { /* for handling text fields and small
- * binaries */
+ { /* for handling fields */
if (cbValue == SQL_NTS)
{
}
else
{
- current_param->EXEC_buffer = malloc(cbValue + 1);
- if (!current_param->EXEC_buffer)
+ Int2 ctype = current_param->CType;
+ if (ctype == SQL_C_DEFAULT)
+ ctype = sqltype_to_default_ctype(current_param->SQLType);
+ if (ctype == SQL_C_CHAR || ctype == SQL_C_BINARY)
{
- stmt->errornumber = STMT_NO_MEMORY_ERROR;
- stmt->errormsg = "Out of memory in SQLPutData (2)";
- SC_log_error(func, "", stmt);
- return SQL_ERROR;
+ current_param->EXEC_buffer = malloc(cbValue + 1);
+ if (!current_param->EXEC_buffer)
+ {
+ stmt->errornumber = STMT_NO_MEMORY_ERROR;
+ stmt->errormsg = "Out of memory in SQLPutData (2)";
+ SC_log_error(func, "", stmt);
+ return SQL_ERROR;
+ }
+ memcpy(current_param->EXEC_buffer, rgbValue, cbValue);
+ current_param->EXEC_buffer[cbValue] = '\0';
+ }
+ else
+ {
+ Int4 used = ctype_length(ctype);
+ current_param->EXEC_buffer = malloc(used);
+ if (!current_param->EXEC_buffer)
+ {
+ stmt->errornumber = STMT_NO_MEMORY_ERROR;
+ stmt->errormsg = "Out of memory in SQLPutData (2)";
+ SC_log_error(func, "", stmt);
+ return SQL_ERROR;
+ }
+ memcpy(current_param->EXEC_buffer, rgbValue, used);
}
- memcpy(current_param->EXEC_buffer, rgbValue, cbValue);
- current_param->EXEC_buffer[cbValue] = '\0';
}
}
}
/* Clear Statement Options -- defaults will be set in AllocStmt */
memset(&rv->options, 0, sizeof(StatementOptions));
+
+ rv->pre_executing = FALSE;
+ rv->inaccurate_result = FALSE;
}
return rv;
}
QR_Destructor(self->result);
self->result = NULL;
}
+ self->inaccurate_result = FALSE;
/****************************************************************/
/* Reset only parameters that have anything to do with results */
void
SC_pre_execute(StatementClass *self)
{
-
mylog("SC_pre_execute: status = %d\n", self->status);
if (self->status == STMT_READY)
{
mylog(" preprocess: status = READY\n");
- SQLExecute(self);
+ if (self->statement_type == STMT_TYPE_SELECT)
+ {
+ char old_pre_executing = self->pre_executing;
+ self->pre_executing = TRUE;
+ self->inaccurate_result = FALSE;
+
+ SQLExecute(self);
+
+ self->pre_executing = old_pre_executing;
- if (self->status == STMT_FINISHED)
+ if (self->status == STMT_FINISHED)
+ {
+ mylog(" preprocess: after status = FINISHED, so set PREMATURE\n");
+ self->status = STMT_PREMATURE;
+ }
+ }
+ else
{
- mylog(" preprocess: after status = FINISHED, so set PREMATURE\n");
+ self->result = QR_Constructor();
+ QR_set_status(self->result, PGRES_TUPLES_OK);
+ self->inaccurate_result = TRUE;
self->status = STMT_PREMATURE;
}
}