Reset type after bind param (#1452)

* Reset type after bind param

Keep the same behavior as 5.9
Issue #1448

* Add unit test, skip for decimal format

* Add unit test, skip for decimal format

* Update unit test
This commit is contained in:
Sicong 2023-05-12 10:54:27 -07:00
parent f6f76d4ac1
commit b1df4089cb
2 changed files with 37 additions and 0 deletions

View file

@ -2508,6 +2508,9 @@ void sqlsrv_param::bind_param(_Inout_ sqlsrv_stmt* stmt)
}
core::SQLBindParameter(stmt, param_pos + 1, direction, c_data_type, sql_data_type, column_size, decimal_digits, buffer, buffer_length, &strlen_or_indptr);
if (!stmt->conn->ce_option.enabled && !stmt->format_decimals) {
sql_data_type = SQL_UNKNOWN_TYPE;
}
}
void sqlsrv_param::init_data_from_zval(_Inout_ sqlsrv_stmt* stmt)

View file

@ -0,0 +1,34 @@
--TEST--
Test for Github Issue 1448
--DESCRIPTION--
Prepare and execute with int, then execute with string caused "Invalid character value for cast specification" error.
Repro script provided by thsmrtone1
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require_once( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
var_dump( sqlsrv_errors() );
die( "sqlsrv_connect failed." );
}
sqlsrv_query($conn, "CREATE TABLE test1448 (testCol nvarchar(50) NULL)");
$v0 = 1000;
$stmt = sqlsrv_prepare($conn, 'INSERT INTO [test1448] (testCol) VALUES (?);', [&$v0]);
sqlsrv_execute($stmt);
$v0 = 'abcd';
sqlsrv_execute($stmt);
$error = sqlsrv_errors(SQLSRV_ERR_ERRORS);
var_dump($error);
dropTable($conn, "test1448");
sqlsrv_close($conn);
?>
--EXPECT--
NULL