33
33
#include "qresult.h"
34
34
#include "convert.h"
35
35
#include "bind.h"
36
+ #include "pgtypes.h"
36
37
#include "lobj.h"
37
38
38
39
extern GLOBAL_VALUES globals ;
@@ -222,17 +223,22 @@ SQLExecute(
222
223
*/
223
224
if (stmt -> prepare && stmt -> status == STMT_PREMATURE )
224
225
{
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 );
231
228
else
232
229
{
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
+ }
236
242
}
237
243
}
238
244
@@ -283,30 +289,36 @@ SQLExecute(
283
289
}
284
290
285
291
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 )
292
294
{
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 ++ )
295
302
{
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
+ }
300
311
}
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 */
303
313
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
+ }
310
322
311
323
312
324
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(
777
789
778
790
}
779
791
else
780
- { /* for handling text fields and small
781
- * binaries */
792
+ { /* for handling fields */
782
793
783
794
if (cbValue == SQL_NTS )
784
795
{
@@ -793,16 +804,35 @@ SQLPutData(
793
804
}
794
805
else
795
806
{
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 )
798
811
{
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 );
803
835
}
804
- memcpy (current_param -> EXEC_buffer , rgbValue , cbValue );
805
- current_param -> EXEC_buffer [cbValue ] = '\0' ;
806
836
}
807
837
}
808
838
}
0 commit comments