diff options
Diffstat (limited to 'src/interfaces/odbc/bind.c')
-rw-r--r-- | src/interfaces/odbc/bind.c | 114 |
1 files changed, 54 insertions, 60 deletions
diff --git a/src/interfaces/odbc/bind.c b/src/interfaces/odbc/bind.c index c01f61ab7fd..945d23d64d6 100644 --- a/src/interfaces/odbc/bind.c +++ b/src/interfaces/odbc/bind.c @@ -1,17 +1,17 @@ -
-/* Module: bind.c
- *
- * Description: This module contains routines related to binding
- * columns and parameters.
- *
- * Classes: BindInfoClass, ParameterInfoClass
- *
- * API functions: SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
- * SQLParamOptions(NI)
- *
- * Comments: See "notice.txt" for copyright and license information.
- *
- */
+ +/* Module: bind.c + * + * Description: This module contains routines related to binding + * columns and parameters. + * + * Classes: BindInfoClass, ParameterInfoClass + * + * API functions: SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams, + * SQLParamOptions(NI) + * + * Comments: See "notice.txt" for copyright and license information. + * + */ #include "bind.h" #include "environ.h" #include "statement.h" @@ -19,8 +19,8 @@ #include "pgtypes.h" #include <stdlib.h> #include <malloc.h> -#include <sql.h>
-#include <sqlext.h>
+#include <sql.h> +#include <sqlext.h> // Bind parameters on a statement handle @@ -77,10 +77,11 @@ StatementClass *stmt = (StatementClass *) hstmt; stmt->parameters[i].CType = 0; stmt->parameters[i].SQLType = 0; stmt->parameters[i].precision = 0; - stmt->parameters[i].scale = 0;
- stmt->parameters[i].data_at_exec = FALSE;
- stmt->parameters[i].EXEC_used = NULL;
- stmt->parameters[i].EXEC_buffer = NULL;
+ stmt->parameters[i].scale = 0; + stmt->parameters[i].data_at_exec = FALSE; + stmt->parameters[i].lobj_oid = 0; + stmt->parameters[i].EXEC_used = NULL; + stmt->parameters[i].EXEC_buffer = NULL; } } @@ -94,26 +95,28 @@ StatementClass *stmt = (StatementClass *) hstmt; stmt->parameters[ipar].CType = fCType; stmt->parameters[ipar].SQLType = fSqlType; stmt->parameters[ipar].precision = cbColDef; - stmt->parameters[ipar].scale = ibScale;
-
- /* If rebinding a parameter that had data-at-exec stuff in it,
- then free that stuff
- */
- if (stmt->parameters[ipar].EXEC_used) {
- free(stmt->parameters[ipar].EXEC_used);
- stmt->parameters[ipar].EXEC_used = NULL;
- }
-
- if (stmt->parameters[ipar].EXEC_buffer) {
- free(stmt->parameters[ipar].EXEC_buffer);
- stmt->parameters[ipar].EXEC_buffer = NULL;
- }
-
- if (pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET)
- stmt->parameters[ipar].data_at_exec = TRUE;
- else
- stmt->parameters[ipar].data_at_exec = FALSE;
-
+ stmt->parameters[ipar].scale = ibScale; + + /* If rebinding a parameter that had data-at-exec stuff in it, + then free that stuff + */ + if (stmt->parameters[ipar].EXEC_used) { + free(stmt->parameters[ipar].EXEC_used); + stmt->parameters[ipar].EXEC_used = NULL; + } + + if (stmt->parameters[ipar].EXEC_buffer) { + free(stmt->parameters[ipar].EXEC_buffer); + stmt->parameters[ipar].EXEC_buffer = NULL; + } + + if (pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET) + stmt->parameters[ipar].data_at_exec = TRUE; + else + stmt->parameters[ipar].data_at_exec = FALSE; + + mylog("SQLBindParamater: ipar = %d, *pcbValue = %d, data_at_exec = %d\n", + ipar, pcbValue ? *pcbValue: -777, stmt->parameters[ipar].data_at_exec); return SQL_SUCCESS; } @@ -188,6 +191,8 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol); stmt->bindings[icol].buffer = rgbValue; stmt->bindings[icol].used = pcbValue; stmt->bindings[icol].returntype = fCType; + + mylog(" bound buffer[%d] = %u\n", icol, stmt->bindings[icol].buffer); } return SQL_SUCCESS; @@ -228,7 +233,7 @@ StatementClass *stmt = (StatementClass *) hstmt; *pibScale = stmt->parameters[ipar].scale; if(pfNullable) - *pfNullable = pgtype_nullable(stmt->parameters[ipar].paramType); + *pfNullable = pgtype_nullable(stmt, stmt->parameters[ipar].paramType); return SQL_SUCCESS; } @@ -247,37 +252,25 @@ RETCODE SQL_API SQLParamOptions( // - - - - - - - - - -// Returns the number of parameter markers. +// Returns the number of parameters in an SQL statement RETCODE SQL_API SQLNumParams( HSTMT hstmt, SWORD FAR *pcpar) { StatementClass *stmt = (StatementClass *) hstmt; -unsigned int i; - // I guess this is the number of actual parameter markers - // in the statement, not the number of parameters that are bound. - // why does this have to be driver-specific? if(!stmt) return SQL_INVALID_HANDLE; - if(!stmt->statement) { - // no statement has been allocated - *pcpar = 0; - stmt->errormsg = "SQLNumParams called with no statement ready."; - stmt->errornumber = STMT_SEQUENCE_ERROR; - return SQL_ERROR; - } else { - *pcpar = 0; - for(i=0; i < strlen(stmt->statement); i++) { - if(stmt->statement[i] == '?') - (*pcpar)++; - } + // If the statement does not have parameters, it should just return 0. - return SQL_SUCCESS; + if (pcpar) { + *pcpar = stmt->parameters_allocated; } + + return SQL_SUCCESS; } /******************************************************************** @@ -309,7 +302,7 @@ extend_bindings(StatementClass *stmt, int num_columns) BindInfoClass *new_bindings; int i; - mylog("in extend_bindings\n"); +mylog("in extend_bindings: stmt=%u, bindings_allocated=%d, num_columns=%d\n", stmt, stmt->bindings_allocated, num_columns); /* if we have too few, allocate room for more, and copy the old */ /* entries into the new structure */ @@ -325,6 +318,7 @@ int i; } stmt->bindings = new_bindings; // null indicates error + stmt->bindings_allocated = num_columns; } else { /* if we have too many, make sure the extra ones are emptied out */ |