Skip to content

Unable to handle SQL_VARIANT types #51

@david-garcia-garcia

Description

@david-garcia-garcia

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions