From c30f2d6100f278d354c0fcf5cbdf18bf8f35f864 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 12 Oct 2017 11:33:45 -0700 Subject: [PATCH] change encoding to SYSTEM when converting int to string for inout and output param --- source/shared/core_sqlsrv.h | 2 +- source/shared/core_stmt.cpp | 6 ++++-- test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt | 12 ++++++------ test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt | 8 ++++---- test/functional/sqlsrv/MsHelper.inc | 1 + test/functional/sqlsrv/sqlsrv_bigint_outparam.phpt | 12 ++++++------ test/functional/sqlsrv/sqlsrv_bool_outparam.phpt | 8 ++++---- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/source/shared/core_sqlsrv.h b/source/shared/core_sqlsrv.h index 5e50564d..16ca5711 100644 --- a/source/shared/core_sqlsrv.h +++ b/source/shared/core_sqlsrv.h @@ -1433,7 +1433,7 @@ typedef sqlsrv_stmt* (*driver_stmt_factory)( sqlsrv_conn* conn, SQLHANDLE h, err sqlsrv_stmt* core_sqlsrv_create_stmt( _Inout_ sqlsrv_conn* conn, _In_ driver_stmt_factory stmt_factory, _In_opt_ HashTable* options_ht, _In_opt_ const stmt_option valid_stmt_opts[], _In_ error_callback const err, _In_opt_ void* driver TSRMLS_DC ); void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_num, _In_ SQLSMALLINT direction, _Inout_ zval* param_z, - _In_ SQLSRV_PHPTYPE php_out_type, _In_ SQLSRV_ENCODING encoding, _Inout_ SQLSMALLINT sql_type, _Inout_ SQLULEN column_size, + _In_ SQLSRV_PHPTYPE php_out_type, _Inout_ SQLSRV_ENCODING encoding, _Inout_ SQLSMALLINT sql_type, _Inout_ SQLULEN column_size, _Inout_ SQLSMALLINT decimal_digits TSRMLS_DC ); SQLRETURN core_sqlsrv_execute( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC, _In_reads_bytes_(sql_len) const char* sql = NULL, _In_ int sql_len = 0 ); field_meta_data* core_sqlsrv_field_metadata( _Inout_ sqlsrv_stmt* stmt, _In_ SQLSMALLINT colno TSRMLS_DC ); diff --git a/source/shared/core_stmt.cpp b/source/shared/core_stmt.cpp index 84f36b4e..f0823aa8 100644 --- a/source/shared/core_stmt.cpp +++ b/source/shared/core_stmt.cpp @@ -342,7 +342,7 @@ sqlsrv_stmt* core_sqlsrv_create_stmt( _Inout_ sqlsrv_conn* conn, _In_ driver_stm // The sql type is given as a hint if the driver provides it. void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_num, _In_ SQLSMALLINT direction, _Inout_ zval* param_z, - _In_ SQLSRV_PHPTYPE php_out_type, _In_ SQLSRV_ENCODING encoding, _Inout_ SQLSMALLINT sql_type, _Inout_ SQLULEN column_size, + _In_ SQLSRV_PHPTYPE php_out_type, _Inout_ SQLSRV_ENCODING encoding, _Inout_ SQLSMALLINT sql_type, _Inout_ SQLULEN column_size, _Inout_ SQLSMALLINT decimal_digits TSRMLS_DC ) { SQLSMALLINT c_type; @@ -373,7 +373,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_ } bool zval_was_null = ( Z_TYPE_P( param_z ) == IS_NULL ); bool zval_was_bool = ( Z_TYPE_P( param_z ) == IS_TRUE || Z_TYPE_P( param_z ) == IS_FALSE ); - bool zval_was_long = ( Z_TYPE_P( param_z ) == IS_LONG && php_out_type == SQLSRV_PHPTYPE_INT ); + bool zval_was_long = ( Z_TYPE_P( param_z ) == IS_LONG && php_out_type == SQLSRV_PHPTYPE_INT && (sql_type == SQL_BIGINT || sql_type == SQL_UNKNOWN_TYPE )); // if the user asks for for a specific type for input and output, make sure the data type we send matches the data we // type we expect back, since we can only send and receive the same type. Anything can be converted to a string, so // we always let that match if they want a string back. @@ -386,6 +386,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_ } if( zval_was_long ){ convert_to_string( param_z ); + encoding = SQLSRV_ENCODING_SYSTEM; match = Z_TYPE_P( param_z ) == IS_STRING; } else { @@ -424,6 +425,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_ case SQLSRV_PHPTYPE_INT: if( zval_was_long ){ convert_to_string( param_z ); + encoding = SQLSRV_ENCODING_SYSTEM; } else { convert_to_long( param_z ); diff --git a/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt b/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt index 5b47022f..740291f7 100644 --- a/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt +++ b/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt @@ -69,14 +69,14 @@ unset($stmt); unset($conn); ?> --EXPECT-- -Large bigint output: +Large bigint output: string(18) "922337203685479936" -Large bigint inout: +Large bigint inout: string(18) "922337203685479936" -Small bigint output: -int(922337203) - -Small bigint inout: +Small bigint output: +int(922337203) + +Small bigint inout: int(922337203) diff --git a/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt b/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt index b2eb8781..b1df6b9d 100644 --- a/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt +++ b/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt @@ -69,14 +69,14 @@ unset($stmt); unset($conn); ?> --EXPECT-- -True bool output: +True bool output: int(1) -True bool inout: +True bool inout: int(1) -True bool output: +True bool output: int(0) -True bool inout: +True bool inout: int(0) diff --git a/test/functional/sqlsrv/MsHelper.inc b/test/functional/sqlsrv/MsHelper.inc index c6fa7173..7cf5f3f8 100644 --- a/test/functional/sqlsrv/MsHelper.inc +++ b/test/functional/sqlsrv/MsHelper.inc @@ -328,6 +328,7 @@ function connect($options = array(), $disableCE = false) */ function createTable($conn, $tbname, $columnMetaArr) { + require_once("MsCommon.inc"); dropTable($conn, $tbname); $colDef = ""; foreach ($columnMetaArr as $meta) { diff --git a/test/functional/sqlsrv/sqlsrv_bigint_outparam.phpt b/test/functional/sqlsrv/sqlsrv_bigint_outparam.phpt index e0073a1f..fd2023a2 100644 --- a/test/functional/sqlsrv/sqlsrv_bigint_outparam.phpt +++ b/test/functional/sqlsrv/sqlsrv_bigint_outparam.phpt @@ -66,14 +66,14 @@ sqlsrv_close($conn); ?> --EXPECT-- -Large bigint output: +Large bigint output: string(18) "922337203685479936" -Large bigint inout: +Large bigint inout: string(18) "922337203685479936" -Small bigint output: -int(922337203) - -Small bigint inout: +Small bigint output: +int(922337203) + +Small bigint inout: int(922337203) diff --git a/test/functional/sqlsrv/sqlsrv_bool_outparam.phpt b/test/functional/sqlsrv/sqlsrv_bool_outparam.phpt index 99668467..a07aa91c 100644 --- a/test/functional/sqlsrv/sqlsrv_bool_outparam.phpt +++ b/test/functional/sqlsrv/sqlsrv_bool_outparam.phpt @@ -66,14 +66,14 @@ sqlsrv_close($conn); ?> --EXPECT-- -True bool output: +True bool output: bool(true) -True bool inout: +True bool inout: bool(true) -False bool output: +False bool output: bool(false) -False bool inout: +False bool inout: bool(false)