diff --git a/source/pdo_sqlsrv/pdo_util.cpp b/source/pdo_sqlsrv/pdo_util.cpp index 1021fd291..6db8a3638 100644 --- a/source/pdo_sqlsrv/pdo_util.cpp +++ b/source/pdo_sqlsrv/pdo_util.cpp @@ -417,6 +417,10 @@ pdo_error PDO_ERRORS[] = { PDO_SQLSRV_ERROR_CE_EMULATE_PREPARE_UNSUPPORTED, { IMSSP, (SQLCHAR*) "Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection.", -82, false } }, + { + SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED, + { IMSSP, (SQLCHAR*) "Stored Procedures do not support text, ntext or image as OUTPUT parameters.", -83, false } + }, { UINT_MAX, {} } }; diff --git a/source/shared/core_sqlsrv.h b/source/shared/core_sqlsrv.h index 16ca57110..bad4b5384 100644 --- a/source/shared/core_sqlsrv.h +++ b/source/shared/core_sqlsrv.h @@ -1689,6 +1689,7 @@ enum SQLSRV_ERROR_CODES { SQLSRV_ERROR_KEYSTORE_PATH_MISSING, SQLSRV_ERROR_KEYSTORE_KEY_MISSING, SQLSRV_ERROR_KEYSTORE_INVALID_VALUE, + SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED, // Driver specific error codes starts from here. SQLSRV_ERROR_DRIVER_SPECIFIC = 1000, diff --git a/source/shared/core_stmt.cpp b/source/shared/core_stmt.cpp index 7dafef7da..bf268d8bd 100644 --- a/source/shared/core_stmt.cpp +++ b/source/shared/core_stmt.cpp @@ -420,8 +420,15 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_ } } - // if it's an output parameter and the user asks for a certain type, we have to convert the zval to that type so - // when the buffer is filled, the type is correct + // If the user specifies a certain type for an output parameter, we have to convert the zval + // to that type so that when the buffer is filled, the type is correct. But first, + // should check if a LOB type is specified. + CHECK_CUSTOM_ERROR( direction != SQL_PARAM_INPUT && ( sql_type == SQL_LONGVARCHAR + || sql_type == SQL_WLONGVARCHAR || sql_type == SQL_LONGVARBINARY ), + stmt, SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED ){ + throw core::CoreException(); + } + if( direction == SQL_PARAM_OUTPUT ){ switch( php_out_type ) { case SQLSRV_PHPTYPE_INT: diff --git a/source/sqlsrv/util.cpp b/source/sqlsrv/util.cpp index b8dd765db..264139ea1 100644 --- a/source/sqlsrv/util.cpp +++ b/source/sqlsrv/util.cpp @@ -408,6 +408,11 @@ ss_error SS_ERRORS[] = { SQLSRV_ERROR_SPECIFIED_DRIVER_NOT_FOUND, { IMSSP, (SQLCHAR*) "The specified ODBC Driver is not found.", -107, false } }, + { + SQLSRV_ERROR_OUTPUT_PARAM_TYPES_NOT_SUPPORTED, + { IMSSP, (SQLCHAR*) "Stored Procedures do not support text, ntext or image as OUTPUT parameters.", -108, false } + }, + // terminate the list of errors/warnings { UINT_MAX, {} } }; diff --git a/test/functional/sqlsrv/srv_231_string_truncation_text.phpt b/test/functional/sqlsrv/srv_231_string_truncation_text.phpt new file mode 100644 index 000000000..2e2107c2a --- /dev/null +++ b/test/functional/sqlsrv/srv_231_string_truncation_text.phpt @@ -0,0 +1,134 @@ +--TEST-- +GitHub issue #231 - String truncation when binding text/ntext/image to check error messages +--ENV-- +PHPT_EXEC=true +--SKIPIF-- + +--FILE-- + + +--EXPECT-- + +Data Type: text binding as +Output parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. +InOut parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. + +Data Type: ntext binding as +Output parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. +InOut parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. + +Data Type: image binding as +Output parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters. +InOut parameter: Stored Procedures do not support text, ntext or image as OUTPUT parameters.