Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid precision error #1497

Merged
merged 8 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading