Skip to content

Commit

Permalink
Fix invalid precision error (#1497)
Browse files Browse the repository at this point in the history
* Set preview for beta release (#1430)

* Fix invalid percision error

* add a end of file for added test

* fix the test case

* remove sql type reset logic

---------

Co-authored-by: Sicong <[email protected]>
  • Loading branch information
MichaelSun90 and absci authored Jan 22, 2024
1 parent 41ac126 commit 09c53ef
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
4 changes: 1 addition & 3 deletions source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
} else {
SQLSRV_ASSERT(false, "sqlsrv_params_container::insert_param - Invalid parameter direction.");
}

stmt->params_container.insert_param(param_num, new_param);
param_ptr = new_param;
new_param.transferred();
Expand Down Expand Up @@ -2508,9 +2509,6 @@ 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
HY104 Invalid precision value when reusing prepared statement
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);

require_once('MsCommon.inc');

$conn = connect(array('CharacterSet'=>'UTF-8'));
if (!$conn) {
fatalError("Failed to connect");
}

$tableName = 'php_test_table';
$column = array(new AE\ColumnMeta("VARCHAR(8000)", "TestColumn", "NULL"));

$stmt = AE\createTable($conn, $tableName, $column);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}

$query = "INSERT INTO $tableName (TestColumn) VALUES (?)";
$parameterValue = "Test value.";
$parameterReference[0] = [ & $parameterValue, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARCHAR('8000') ];
$queryHandle = sqlsrv_prepare($conn, $query, $parameterReference);

$r1 = sqlsrv_execute($queryHandle);
if ($r1 === false) {
print_r(sqlsrv_errors(SQLSRV_ERR_ALL));
}

$r2 = sqlsrv_execute($queryHandle);
if ($r2 === false) {
print_r(sqlsrv_errors(SQLSRV_ERR_ALL));
}

dropTable($conn, $tableName);
sqlsrv_close($conn);

echo "Done\n";

?>
--EXPECT--
Done
34 changes: 0 additions & 34 deletions test/functional/sqlsrv/sqlsrv_github_1448.phpt

This file was deleted.

0 comments on commit 09c53ef

Please sign in to comment.