Skip to content

Commit

Permalink
change encoding to SYSTEM when converting int to string for inout and…
Browse files Browse the repository at this point in the history
… output param
  • Loading branch information
yukiwongky committed Oct 12, 2017
1 parent a0e8862 commit c30f2d6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion source/shared/core_sqlsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 4 additions & 2 deletions source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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 );
Expand Down
10 changes: 5 additions & 5 deletions test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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 output:
int(922337203)

Small bigint inout:
Small bigint inout:
int(922337203)
8 changes: 4 additions & 4 deletions test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions test/functional/sqlsrv/MsHelper.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions test/functional/sqlsrv/sqlsrv_bigint_outparam.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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 output:
int(922337203)

Small bigint inout:
Small bigint inout:
int(922337203)
8 changes: 4 additions & 4 deletions test/functional/sqlsrv/sqlsrv_bool_outparam.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c30f2d6

Please sign in to comment.