Addressed various issues with PHP 7.4 beta1 (#1015)

This commit is contained in:
Jenny Tam 2019-07-29 08:02:50 -07:00 committed by GitHub
parent 1a2b49393c
commit 65daa7a481
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 168 additions and 146 deletions

View file

@ -1129,11 +1129,11 @@ int pdo_sqlsrv_stmt_get_col_meta( _Inout_ pdo_stmt_t *stmt, _In_ zend_long colno
}
}
catch( core::CoreException& ) {
zval_ptr_dtor(return_value);
return FAILURE;
}
catch(...) {
zval_ptr_dtor(return_value);
DIE( "pdo_sqlsrv_stmt_get_col_meta: Unknown exception occurred while retrieving metadata." );
}

View file

@ -988,7 +988,7 @@ void core_sqlsrv_sensitivity_metadata( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC )
return;
}
if (stmt->current_sensitivity_metadata != NULL) {
if (stmt->current_sensitivity_metadata) {
// Already cached, so return
return;
}
@ -1873,7 +1873,7 @@ void core_get_field_common( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_i
// be returned as a zval.
case SQLSRV_PHPTYPE_DATETIME:
{
char* field_value_temp = NULL;
sqlsrv_malloc_auto_ptr<char> field_value_temp;
SQLLEN field_len_temp = 0;
field_value_temp = static_cast<char*>(sqlsrv_malloc(MAX_DATETIME_STRING_LEN));
@ -1882,8 +1882,7 @@ void core_get_field_common( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_i
SQLRETURN r = stmt->current_results->get_data(field_index + 1, SQL_C_CHAR, field_value_temp, MAX_DATETIME_STRING_LEN, &field_len_temp, true TSRMLS_CC);
if (r == SQL_NO_DATA || field_len_temp == SQL_NULL_DATA) {
sqlsrv_free(field_value_temp);
field_value_temp = NULL;
field_value_temp.reset();
field_len_temp = 0;
}
@ -1892,6 +1891,7 @@ void core_get_field_common( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT field_i
}
field_value = field_value_temp;
field_value_temp.transferred();
*field_len = field_len_temp;
break;
@ -2428,7 +2428,9 @@ void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC )
zend_string* key = NULL;
void* output_param_temp = NULL;
ZEND_HASH_FOREACH_KEY_PTR( params_ht, index, key, output_param_temp ) {
try {
ZEND_HASH_FOREACH_KEY_PTR(params_ht, index, key, output_param_temp)
{
sqlsrv_output_param* output_param = static_cast<sqlsrv_output_param*>(output_param_temp);
zval* value_z = Z_REFVAL_P(output_param->param_z);
switch (Z_TYPE_P(value_z)) {
@ -2464,7 +2466,8 @@ void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC )
break;
}
CHECK_CUSTOM_ERROR(str_len > (output_param->original_buffer_len - null_size), stmt,
SQLSRV_ERROR_OUTPUT_PARAM_TRUNCATED, output_param->param_num + 1 ) {
SQLSRV_ERROR_OUTPUT_PARAM_TRUNCATED, output_param->param_num + 1)
{
throw core::CoreException();
}
@ -2472,8 +2475,7 @@ void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC )
// A length value of SQL_NO_TOTAL for SQLBindParameter indicates that the buffer contains up to
// output_param->original_buffer_len data and is NULL terminated.
// The IF statement can be true when using connection pooling with unixODBC 2.3.4.
if ( str_len == SQL_NO_TOTAL )
{
if (str_len == SQL_NO_TOTAL) {
str_len = output_param->original_buffer_len - null_size;
}
@ -2493,7 +2495,8 @@ void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC )
char* outString = NULL;
SQLLEN outLen = 0;
bool result = convert_string_from_utf16(output_param->encoding, reinterpret_cast<const SQLWCHAR*>(str), int(str_len / sizeof(SQLWCHAR)), &outString, outLen);
CHECK_CUSTOM_ERROR(!result, stmt, SQLSRV_ERROR_OUTPUT_PARAM_ENCODING_TRANSLATE, get_last_error_message()) {
CHECK_CUSTOM_ERROR(!result, stmt, SQLSRV_ERROR_OUTPUT_PARAM_ENCODING_TRANSLATE, get_last_error_message())
{
throw core::CoreException();
}
@ -2535,7 +2538,8 @@ void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC )
// first check if its value is out of range
double dval = Z_DVAL_P(value_z);
if (dval > INT_MAX || dval < INT_MIN) {
CHECK_CUSTOM_ERROR(true, stmt, SQLSRV_ERROR_DOUBLE_CONVERSION_FAILED) {
CHECK_CUSTOM_ERROR(true, stmt, SQLSRV_ERROR_DOUBLE_CONVERSION_FAILED)
{
throw core::CoreException();
}
}
@ -2553,7 +2557,12 @@ void finalize_output_parameters( _Inout_ sqlsrv_stmt* stmt TSRMLS_DC )
}
value_z = NULL;
} ZEND_HASH_FOREACH_END();
}
catch (core::CoreException&) {
// empty the hash table due to exception caught
zend_hash_clean(Z_ARRVAL(stmt->output_params));
throw;
}
// empty the hash table since it's been processed
zend_hash_clean(Z_ARRVAL(stmt->output_params));
return;

View file

@ -44,7 +44,11 @@ int sqlsrv_stream_close( _Inout_ php_stream* stream, int /*close_handle*/ TSRMLS
// read from a sqlsrv stream into the buffer provided by Zend. The parameters for binary vs. char are
// set when sqlsrv_get_field is called by the user specifying which field type they want.
#if PHP_VERSION_ID >= 70400
ssize_t sqlsrv_stream_read(_Inout_ php_stream* stream, _Out_writes_bytes_(count) char* buf, _Inout_ size_t count TSRMLS_DC)
#else
size_t sqlsrv_stream_read(_Inout_ php_stream* stream, _Out_writes_bytes_(count) char* buf, _Inout_ size_t count TSRMLS_DC)
#endif
{
SQLLEN read = 0;
SQLSMALLINT c_type = SQL_C_CHAR;
@ -184,15 +188,20 @@ size_t sqlsrv_stream_read( _Inout_ php_stream* stream, _Out_writes_bytes_(count)
return static_cast<size_t>( read );
}
catch (core::CoreException&) {
#if PHP_VERSION_ID >= 70400
return -1;
#else
return 0;
#endif
}
catch (...) {
LOG(SEV_ERROR, "sqlsrv_stream_read: Unknown exception caught.");
#if PHP_VERSION_ID >= 70400
return -1;
#else
return 0;
#endif
}
}

View file

@ -24,6 +24,6 @@ if ($c !== false) {
Fatal error: Uncaught PDOException: SQLSTATE\[(28000|08001|HYT00)\]: .*\[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\](\[SQL Server\])?(Named Pipes Provider: Could not open a connection to SQL Server \[2\]\. |TCP Provider: Error code (0x2726|0x2AF9)|Login timeout expired|Login failed for user 'sa'\.) in .+(\/|\\)pdo_utf8_conn\.php:[0-9]+
Stack trace:
#0 .+(\/|\\)pdo_utf8_conn\.php\([0-9]+\): PDO->__construct\('sqlsrv:Server=l\.\.\.', 'sa', 'Sunshine4u'\)
#0 .+(\/|\\)pdo_utf8_conn\.php\([0-9]+\): PDO->__construct(\(\)|\('sqlsrv:Server=l\.\.\.', 'sa', 'Sunshine4u'\))
#1 {main}
thrown in .+(\/|\\)pdo_utf8_conn\.php on line [0-9]+

View file

@ -431,6 +431,6 @@ Test_9 : FETCH_INVALID :
Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x
Stack trace:
#0 %s: fetchAllInvalid(Object(PDO), 'PDO_MainTypes')
#0 %s: fetchAllInvalid(%S)
#1 {main}
thrown in %s on line %x

View file

@ -35,7 +35,7 @@ try {
throw new Exception( "Not A" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_PRIOR );
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}
@ -53,7 +53,7 @@ try {
throw new Exception( "Not A" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, -1 );
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}
@ -63,7 +63,7 @@ try {
throw new Exception( "Not C" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT );
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}
@ -73,7 +73,7 @@ try {
throw new Exception( "Not C" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, 1 );
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}
@ -99,7 +99,7 @@ try {
throw new Exception( "Not A" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, -1 );
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}
@ -125,7 +125,7 @@ try {
throw new Exception( "Not C" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT);
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}
@ -135,7 +135,7 @@ try {
throw new Exception( "Not A" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_PRIOR);
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}
@ -145,7 +145,7 @@ try {
throw new Exception( "Not A" );
}
$row = $stmt1->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, -1);
if( $row[ 'val' ] != false ) {
if ($row !== false) {
throw new Exception( "Not false" );
}

View file

@ -257,6 +257,6 @@ Test_9 : FETCH_INVALID :
Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x
Stack trace:
#0 %s: fetchWithStyle(Object(PDO), 'PDO_MainTypes', 'PDO::FETCH_INVA...')
#0 %s: fetchWithStyle(%S)
#1 {main}
thrown in %s on line %x

View file

@ -59,7 +59,8 @@ foreach ($dataTypes as $dataType) {
}
}
// 22018 is the SQLSTATE for any incompatible conversion errors
if ($isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018) {
$errors = sqlsrv_errors();
if (!empty($errors) && $isCompatible && $errors[0]['SQLSTATE'] == 22018) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}

View file

@ -69,7 +69,8 @@ foreach ($dataTypes as $dataType) {
}
}
// 22018 is the SQLSTATE for any incompatible conversion errors
if ($isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018) {
$errors = sqlsrv_errors();
if (!empty($errors) && $isCompatible && $errors[0]['SQLSTATE'] == 22018) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}

View file

@ -57,7 +57,8 @@ foreach ($dataTypes as $dataType) {
}
}
// 22018 is the SQLSTATE for any incompatible conversion errors
if ($isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018) {
$errors = sqlsrv_errors();
if (!empty($errors) && $isCompatible && $errors[0]['SQLSTATE'] == 22018) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}

View file

@ -44,7 +44,8 @@ function fetchData($conn, $table, $size)
echo "Expect this to fail\n";
} else {
$error = 'Memory limit of 1 KB exceeded for buffered query';
if (strpos(sqlsrv_errors()[0]['message'], $error) === false) {
$errors = sqlsrv_errors();
if (!empty($errors) && strpos($errors[0]['message'], $error) === false) {
print_r(sqlsrv_errors());
}
}