3333#include "qresult.h"
3434#include "convert.h"
3535#include "bind.h"
36+ #include "pgtypes.h"
3637#include "lobj.h"
3738
3839extern GLOBAL_VALUES globals ;
@@ -222,17 +223,22 @@ SQLExecute(
222223 */
223224 if (stmt -> prepare && stmt -> status == STMT_PREMATURE )
224225 {
225- stmt -> status = STMT_FINISHED ;
226- if (stmt -> errormsg == NULL )
227- {
228- mylog ("%s: premature statement but return SQL_SUCCESS\n" , func );
229- return SQL_SUCCESS ;
230- }
226+ if (stmt -> inaccurate_result )
227+ SC_recycle_statement (stmt );
231228 else
232229 {
233- SC_log_error (func , "" , stmt );
234- mylog ("%s: premature statement so return SQL_ERROR\n" , func );
235- return SQL_ERROR ;
230+ stmt -> status = STMT_FINISHED ;
231+ if (stmt -> errormsg == NULL )
232+ {
233+ mylog ("%s: premature statement but return SQL_SUCCESS\n" , func );
234+ return SQL_SUCCESS ;
235+ }
236+ else
237+ {
238+ SC_log_error (func , "" , stmt );
239+ mylog ("%s: premature statement so return SQL_ERROR\n" , func );
240+ return SQL_ERROR ;
241+ }
236242 }
237243 }
238244
@@ -283,30 +289,36 @@ SQLExecute(
283289 }
284290
285291
286- /*
287- * The bound parameters could have possibly changed since the last
288- * execute of this statement? Therefore check for params and re-copy.
289- */
290- stmt -> data_at_exec = -1 ;
291- for (i = 0 ; i < stmt -> parameters_allocated ; i ++ )
292+ /* Check if statement has any data-at-execute parameters when it is not in SC_pre_execute. */
293+ if (!stmt -> pre_executing )
292294 {
293- /* Check for data at execution parameters */
294- if (stmt -> parameters [i ].data_at_exec == TRUE)
295+
296+ /*
297+ * The bound parameters could have possibly changed since the last
298+ * execute of this statement? Therefore check for params and re-copy.
299+ */
300+ stmt -> data_at_exec = -1 ;
301+ for (i = 0 ; i < stmt -> parameters_allocated ; i ++ )
295302 {
296- if (stmt -> data_at_exec < 0 )
297- stmt -> data_at_exec = 1 ;
298- else
299- stmt -> data_at_exec ++ ;
303+ /* Check for data at execution parameters */
304+ if (stmt -> parameters [i ].data_at_exec == TRUE)
305+ {
306+ if (stmt -> data_at_exec < 0 )
307+ stmt -> data_at_exec = 1 ;
308+ else
309+ stmt -> data_at_exec ++ ;
310+ }
300311 }
301- }
302- /* If there are some data at execution parameters, return need data */
312+ /* If there are some data at execution parameters, return need data */
303313
304- /*
305- * SQLParamData and SQLPutData will be used to send params and execute
306- * the statement.
307- */
308- if (stmt -> data_at_exec > 0 )
309- return SQL_NEED_DATA ;
314+ /*
315+ * SQLParamData and SQLPutData will be used to send params and execute
316+ * the statement.
317+ */
318+ if (stmt -> data_at_exec > 0 )
319+ return SQL_NEED_DATA ;
320+
321+ }
310322
311323
312324 mylog ("%s: copying statement params: trans_status=%d, len=%d, stmt='%s'\n" , func , conn -> transact_status , strlen (stmt -> statement ), stmt -> statement );
@@ -777,8 +789,7 @@ SQLPutData(
777789
778790 }
779791 else
780- { /* for handling text fields and small
781- * binaries */
792+ { /* for handling fields */
782793
783794 if (cbValue == SQL_NTS )
784795 {
@@ -793,16 +804,35 @@ SQLPutData(
793804 }
794805 else
795806 {
796- current_param -> EXEC_buffer = malloc (cbValue + 1 );
797- if (!current_param -> EXEC_buffer )
807+ Int2 ctype = current_param -> CType ;
808+ if (ctype == SQL_C_DEFAULT )
809+ ctype = sqltype_to_default_ctype (current_param -> SQLType );
810+ if (ctype == SQL_C_CHAR || ctype == SQL_C_BINARY )
798811 {
799- stmt -> errornumber = STMT_NO_MEMORY_ERROR ;
800- stmt -> errormsg = "Out of memory in SQLPutData (2)" ;
801- SC_log_error (func , "" , stmt );
802- return SQL_ERROR ;
812+ current_param -> EXEC_buffer = malloc (cbValue + 1 );
813+ if (!current_param -> EXEC_buffer )
814+ {
815+ stmt -> errornumber = STMT_NO_MEMORY_ERROR ;
816+ stmt -> errormsg = "Out of memory in SQLPutData (2)" ;
817+ SC_log_error (func , "" , stmt );
818+ return SQL_ERROR ;
819+ }
820+ memcpy (current_param -> EXEC_buffer , rgbValue , cbValue );
821+ current_param -> EXEC_buffer [cbValue ] = '\0' ;
822+ }
823+ else
824+ {
825+ Int4 used = ctype_length (ctype );
826+ current_param -> EXEC_buffer = malloc (used );
827+ if (!current_param -> EXEC_buffer )
828+ {
829+ stmt -> errornumber = STMT_NO_MEMORY_ERROR ;
830+ stmt -> errormsg = "Out of memory in SQLPutData (2)" ;
831+ SC_log_error (func , "" , stmt );
832+ return SQL_ERROR ;
833+ }
834+ memcpy (current_param -> EXEC_buffer , rgbValue , used );
803835 }
804- memcpy (current_param -> EXEC_buffer , rgbValue , cbValue );
805- current_param -> EXEC_buffer [cbValue ] = '\0' ;
806836 }
807837 }
808838 }
0 commit comments