Skip to content

Commit

Permalink
adjust sql_data_type and column_size for NULL parameters (#1311)
Browse files Browse the repository at this point in the history
Fix for #1310 - Co-authored-by: George Carrette <[email protected]>
  • Loading branch information
gjcarrette authored Oct 20, 2021
1 parent 608a080 commit 8de0978
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,16 +2148,17 @@ void sqlsrv_param::process_null_param(_Inout_ zval* param_z)
// Derive the param SQL type only if it is unknown
if (sql_data_type == SQL_UNKNOWN_TYPE) {
// Use the encoding to guess whether the sql_type is binary type or char type. For NULL cases,
// if the server type is a binary type, than the server expects the sql_type to be binary type
// if the server type is a binary type, then the server expects the sql_type to be binary type
// as well, otherwise an error stating "Implicit conversion not allowed.." is thrown by the
// server. For all other server types, setting the sql_type to sql_char works fine.
sql_data_type = (encoding == SQLSRV_ENCODING_BINARY) ? SQL_BINARY : SQL_CHAR;
// server. For all other server types, setting the sql_type to sql_varchar works fine.
// It must be varchar with column size 0 for ISNULL to work properly.
sql_data_type = (encoding == SQLSRV_ENCODING_BINARY) ? SQL_BINARY : SQL_VARCHAR;
}

c_data_type = (encoding == SQLSRV_ENCODING_BINARY) ? SQL_C_BINARY : SQL_C_CHAR;

if (column_size == SQLSRV_UNKNOWN_SIZE) {
column_size = 1;
column_size = (encoding == SQLSRV_ENCODING_BINARY) ? 1 : 0;
decimal_digits = 0;
}
buffer = NULL;
Expand Down

0 comments on commit 8de0978

Please sign in to comment.