From 376461fab491f370e3d80a933259cacbb252bdc1 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 7 Sep 2017 15:26:46 -0700 Subject: [PATCH] fix according to code review --- source/shared/core_sqlsrv.h | 9 +++++---- source/shared/core_stmt.cpp | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/shared/core_sqlsrv.h b/source/shared/core_sqlsrv.h index 58af8895..cb655909 100644 --- a/source/shared/core_sqlsrv.h +++ b/source/shared/core_sqlsrv.h @@ -172,6 +172,7 @@ const int SQL_SERVER_MAX_FIELD_SIZE = 8000; const int SQL_SERVER_MAX_PRECISION = 38; const int SQL_SERVER_MAX_TYPE_SIZE = 0; const int SQL_SERVER_MAX_PARAMS = 2100; +// increase the maximum message length to accommodate for the long error returned for operand type clash const int SQL_MAX_ERROR_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH * 4; // max size of a date time string when converting from a DateTime object to a string @@ -2196,14 +2197,14 @@ namespace core { } } - inline void SQLSetDescField(_Inout_ sqlsrv_stmt* stmt, _In_ SQLSMALLINT rec_num, _In_ SQLSMALLINT fld_id, _In_reads_bytes_opt_(str_len) SQLPOINTER value_ptr, _In_ SQLINTEGER str_len TSRMLS_DC) + inline void SQLSetDescField( _Inout_ sqlsrv_stmt* stmt, _In_ SQLSMALLINT rec_num, _In_ SQLSMALLINT fld_id, _In_reads_bytes_opt_( str_len ) SQLPOINTER value_ptr, _In_ SQLINTEGER str_len TSRMLS_DC ) { SQLRETURN r; SQLHDESC hIpd = NULL; - core::SQLGetStmtAttr(stmt, SQL_ATTR_IMP_PARAM_DESC, &hIpd, 0, 0); - r = ::SQLSetDescField(hIpd, rec_num, fld_id, value_ptr, str_len); + core::SQLGetStmtAttr( stmt, SQL_ATTR_IMP_PARAM_DESC, &hIpd, 0, 0 ); + r = ::SQLSetDescField( hIpd, rec_num, fld_id, value_ptr, str_len ); - CHECK_SQL_ERROR_OR_WARNING(r, stmt) { + CHECK_SQL_ERROR_OR_WARNING( r, stmt ) { throw CoreException(); } } diff --git a/source/shared/core_stmt.cpp b/source/shared/core_stmt.cpp index 26a61f43..79913e6a 100644 --- a/source/shared/core_stmt.cpp +++ b/source/shared/core_stmt.cpp @@ -559,6 +559,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_ // avoid this silent truncation, we set the column_size to be "MAX" size for // string types. This will guarantee that there is no silent truncation for // output parameters. + // if column encryption is enabled, do not set the length to unlimited since SQLDescribe paramter already derive the length for us if( direction == SQL_PARAM_OUTPUT && !stmt->conn->ce_option.enabled ) { switch( sql_type ) { @@ -2530,7 +2531,7 @@ void resize_output_buffer_if_necessary( _Inout_ sqlsrv_stmt* stmt, _Inout_ zval* SQLULEN field_size = column_size; // with AE on, when column_size is retrieved from SQLDescribeParam, column_size does not include the decimal place // include the decimal for output params by adding elem_size - if ( stmt->conn->ce_option.enabled && decimal_digits != 0 ) + if ( stmt->conn->ce_option.enabled && decimal_digits > 0 ) { field_size += elem_size; }