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

Unable to handle SQL_VARIANT types #51

Closed
david-garcia-garcia opened this issue May 21, 2015 · 4 comments
Closed

Unable to handle SQL_VARIANT types #51

david-garcia-garcia opened this issue May 21, 2015 · 4 comments

Comments

@david-garcia-garcia
Copy link

The PDO driver is chocking on SQL_VARIANT types, but this can contain themselves simple types such as char, intenger, etc...

Steps to reproduce:

  1. Create an UDF:

CREATE FUNCTION [dbo].[GREATEST](@OP1 sql_variant, @OP2 sql_variant) RETURNS sql_variant AS
BEGIN
DECLARE @Result sql_variant
SET @Result = CASE WHEN @OP1 >= @OP2 THEN @OP1 ELSE @OP2 END
RETURN @Result
END
GO

  1. Run this query through the PDO

SELECT dbo.GREATEST(5, 6)

  1. Theses are the errors you get:

Without Buffered Queries:

SQLSTATE[IMSSP]: Invalid type.

With Buffered Queries:

Fatal error: Unknown type in sqlsrv_buffered_query::sqlsrv_buffered_query

I can manage to get it to work if I use PDO::PARAM_INT on the column before the fetch, but there is no way that I can infer this informatino from the PDO metadata (getColumnMeta) that is reporting:

sql_srv_type = sql_variant
native_type = string

Possible solutions.....

  1. At least let me retrieve the data as a string by default, instead of Fatal crashing.
@stevebauman
Copy link

stevebauman commented Mar 6, 2017

This is still an issue today running IIS 10 / PHP 7.1.1 / using SQLSRV RC 4.1.3. Is there a fix in the works?

@Hadis-Knj
Copy link

@stevebauman PHP drivers rely on ODBC to handle SQL data types, and SQL_VARIANT is not supported in ODBC. We're looking into David's suggestion to see if SQL variants can be handled with string inferred type.

@stevebauman
Copy link

@Hadis-Fard Awesome! Thanks for the reply :).

@Hadis-Knj
Copy link

Hadis-Knj commented May 25, 2017

@stevebauman @david-garcia-garcia we added support for sql variants in 4.2.0-preview, you can get the driver from our PECL repositiry or GitHub releases page. Note that sqlvariant for output parameters is not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants