Skip to content

Commit d79a62a

Browse files
authored
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
1 parent 3cd248f commit d79a62a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

source/shared/core_stmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,9 @@ void sqlsrv_param::bind_param(_Inout_ sqlsrv_stmt* stmt)
25082508
}
25092509

25102510
core::SQLBindParameter(stmt, param_pos + 1, direction, c_data_type, sql_data_type, column_size, decimal_digits, buffer, buffer_length, &strlen_or_indptr);
2511+
if (!stmt->conn->ce_option.enabled && !stmt->format_decimals) {
2512+
sql_data_type = SQL_UNKNOWN_TYPE;
2513+
}
25112514
}
25122515

25132516
void sqlsrv_param::init_data_from_zval(_Inout_ sqlsrv_stmt* stmt)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Test for Github Issue 1448
3+
--DESCRIPTION--
4+
Prepare and execute with int, then execute with string caused "Invalid character value for cast specification" error.
5+
Repro script provided by thsmrtone1
6+
--FILE--
7+
<?php
8+
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
9+
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
10+
11+
require_once( 'MsCommon.inc' );
12+
$conn = Connect();
13+
if( !$conn ) {
14+
var_dump( sqlsrv_errors() );
15+
die( "sqlsrv_connect failed." );
16+
}
17+
18+
sqlsrv_query($conn, "CREATE TABLE test1448 (testCol nvarchar(50) NULL)");
19+
20+
$v0 = 1000;
21+
$stmt = sqlsrv_prepare($conn, 'INSERT INTO [test1448] (testCol) VALUES (?);', [&$v0]);
22+
sqlsrv_execute($stmt);
23+
24+
$v0 = 'abcd';
25+
sqlsrv_execute($stmt);
26+
27+
$error = sqlsrv_errors(SQLSRV_ERR_ERRORS);
28+
var_dump($error);
29+
30+
dropTable($conn, "test1448");
31+
sqlsrv_close($conn);
32+
?>
33+
--EXPECT--
34+
NULL

0 commit comments

Comments
 (0)