Skip to content

Commit

Permalink
Reset type after bind param (#1452)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
absci authored May 12, 2023
1 parent 3cd248f commit d79a62a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions test/functional/sqlsrv/sqlsrv_github_1448.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d79a62a

Please sign in to comment.