-
Notifications
You must be signed in to change notification settings - Fork 374
Description
PHP Driver version or file name
php-sqlsrv-5.8.0
SQL Server version
Microsoft SQL Server 2017 (RTM-CU21) (KB4557397) - 14.0.3335.7
Microsoft SQL Server 2016 (SP2-CU14) (KB4564903) - 13.0.5830.85
Client operating system
CentOS Linux release 7.6.1810 (Core)
Linux 3.10.0-957.12.1.el7.x86_64 #1 SMP Mon Apr 29 14:59:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
PHP version
PHP 7.4.3
Microsoft ODBC Driver version
Name : msodbcsql17
Version : 17.7.1.1
Build Date : Fri 15 Jan 2021 02:56:50 PM EST
Table schema
None required to run the test.
Problem description
The Microsoft SQL Server ISNULL function seems to badly handle a NULL value transmitted to it
using SQLBindParameter with a data type of SQL_CHAR and length of 1. Because the only
purpose of PDO_SQLSRV is to interact with the Microsoft flagship relational database product
I am asking for a work-around to be implemented so that a NULL is transmitted
using SQLBindParameter with data type of SQL_VARCHAR and length of 0. This work
around has been proven with the SQLRelay open source file src/connections/odbc.cpp starting at
about line 2407 where there is extensive commentary about this issue.
This work around would speed up the full retirement of the PDO_DBLIB freetds driver at the company where I work. In order to continue using Microsoft SQL Server I can supply a patch to PDO_SQLSRV if such a patch would be accepted in principal rather than rejected as not needed due to the possibility of fixing Microsoft SQL Server instead.
Expected behavior and actual behavior
select cast(ISNULL(:K, -1) as int) as K
is expected to return -1 when K is NULL. Instead it gives
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting the varchar value ='*' to data type int.
Repro code or steps to reproduce
Run the attached php file with environment variables set to the database server, user credentials and database used for testing. Also attached is a stdout and an odbc trace.
env DB_SERVER=localhost DB_NAME=master DB_USER=user1 DB_PASS=pass1 php infnext-1870-sqlsrv-null-bug.php
Using the php file from this zip. The zip also contains a stdout and an odbc trace log.