Changes made to source and tests to support PHP 7.3 (#822)
* Changes made to support php 7.3 * Correct use of the smart pointer * Fixed the tests for 7.3 * Some clean up for array_init() * Fixed formattings and clean up
This commit is contained in:
parent
bd34cabdd2
commit
b6d815bfc9
|
@ -546,7 +546,7 @@ int pdo_sqlsrv_db_handle_factory( _Inout_ pdo_dbh_t *dbh, _In_opt_ zval *driver_
|
||||||
ALLOC_HASHTABLE( pdo_conn_options_ht );
|
ALLOC_HASHTABLE( pdo_conn_options_ht );
|
||||||
|
|
||||||
core::sqlsrv_zend_hash_init( *g_pdo_henv_cp, pdo_conn_options_ht, 10 /* # of buckets */,
|
core::sqlsrv_zend_hash_init( *g_pdo_henv_cp, pdo_conn_options_ht, 10 /* # of buckets */,
|
||||||
ZVAL_INTERNAL_DTOR, 0 /*persistent*/ TSRMLS_CC );
|
ZVAL_PTR_DTOR, 0 /*persistent*/ TSRMLS_CC );
|
||||||
|
|
||||||
// Either of g_pdo_henv_cp or g_pdo_henv_ncp can be used to propogate the error.
|
// Either of g_pdo_henv_cp or g_pdo_henv_ncp can be used to propogate the error.
|
||||||
dsn_parser = new ( sqlsrv_malloc( sizeof( conn_string_parser ))) conn_string_parser( *g_pdo_henv_cp, dbh->data_source,
|
dsn_parser = new ( sqlsrv_malloc( sizeof( conn_string_parser ))) conn_string_parser( *g_pdo_henv_cp, dbh->data_source,
|
||||||
|
|
|
@ -512,7 +512,7 @@ bool pdo_sqlsrv_handle_dbh_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned
|
||||||
msg = static_cast<char*>( sqlsrv_malloc( msg_len ) );
|
msg = static_cast<char*>( sqlsrv_malloc( msg_len ) );
|
||||||
core_sqlsrv_format_message( msg, static_cast<unsigned int>( msg_len ), WARNING_TEMPLATE, error->sqlstate, error->native_code,
|
core_sqlsrv_format_message( msg, static_cast<unsigned int>( msg_len ), WARNING_TEMPLATE, error->sqlstate, error->native_code,
|
||||||
error->native_message );
|
error->native_message );
|
||||||
php_error( E_WARNING, msg );
|
php_error(E_WARNING, "%s", msg.get());
|
||||||
}
|
}
|
||||||
ctx.set_last_error( error );
|
ctx.set_last_error( error );
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -693,9 +693,9 @@ public:
|
||||||
// free the original pointer and assign a new pointer. Use NULL to simply free the pointer.
|
// free the original pointer and assign a new pointer. Use NULL to simply free the pointer.
|
||||||
void reset( _In_opt_ HashTable* ptr = NULL )
|
void reset( _In_opt_ HashTable* ptr = NULL )
|
||||||
{
|
{
|
||||||
if( _ptr ) {
|
if (_ptr != NULL) {
|
||||||
zend_hash_destroy( _ptr );
|
zend_hash_destroy(_ptr);
|
||||||
FREE_HASHTABLE( _ptr );
|
FREE_HASHTABLE(_ptr);
|
||||||
}
|
}
|
||||||
_ptr = ptr;
|
_ptr = ptr;
|
||||||
}
|
}
|
||||||
|
@ -2377,10 +2377,13 @@ namespace core {
|
||||||
|
|
||||||
inline void sqlsrv_array_init( _Inout_ sqlsrv_context& ctx, _Out_ zval* new_array TSRMLS_DC)
|
inline void sqlsrv_array_init( _Inout_ sqlsrv_context& ctx, _Out_ zval* new_array TSRMLS_DC)
|
||||||
{
|
{
|
||||||
int zr = ::array_init(new_array);
|
#if PHP_VERSION_ID < 70300
|
||||||
CHECK_ZEND_ERROR( zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
|
CHECK_ZEND_ERROR(::array_init(new_array), ctx, SQLSRV_ERROR_ZEND_HASH) {
|
||||||
throw CoreException();
|
throw CoreException();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
array_init(new_array);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void sqlsrv_php_stream_from_zval_no_verify( _Inout_ sqlsrv_context& ctx, _Outref_result_maybenull_ php_stream*& stream, _In_opt_ zval* stream_z TSRMLS_DC )
|
inline void sqlsrv_php_stream_from_zval_no_verify( _Inout_ sqlsrv_context& ctx, _Outref_result_maybenull_ php_stream*& stream, _In_opt_ zval* stream_z TSRMLS_DC )
|
||||||
|
|
|
@ -352,11 +352,11 @@ void die( _In_opt_ const char* msg, ... )
|
||||||
va_start( format_args, msg );
|
va_start( format_args, msg );
|
||||||
DWORD rc = FormatMessage( FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, last_err_msg, sizeof( last_err_msg ), &format_args );
|
DWORD rc = FormatMessage( FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, last_err_msg, sizeof( last_err_msg ), &format_args );
|
||||||
va_end( format_args );
|
va_end( format_args );
|
||||||
if( rc == 0 ) {
|
if (rc == 0) {
|
||||||
php_error( E_ERROR, reinterpret_cast<const char*>( INTERNAL_FORMAT_ERROR ));
|
php_error(E_ERROR, "%s", reinterpret_cast<const char*>(INTERNAL_FORMAT_ERROR));
|
||||||
}
|
}
|
||||||
|
|
||||||
php_error( E_ERROR, last_err_msg );
|
php_error(E_ERROR, "%s", last_err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -889,7 +889,9 @@ PHP_FUNCTION( sqlsrv_fetch_object )
|
||||||
fci.object = Z_OBJ_P( &retval_z );
|
fci.object = Z_OBJ_P( &retval_z );
|
||||||
|
|
||||||
memset( &fcic, 0, sizeof( fcic ));
|
memset( &fcic, 0, sizeof( fcic ));
|
||||||
|
#if PHP_VERSION_ID < 70300
|
||||||
fcic.initialized = 1;
|
fcic.initialized = 1;
|
||||||
|
#endif
|
||||||
fcic.function_handler = class_entry->constructor;
|
fcic.function_handler = class_entry->constructor;
|
||||||
fcic.calling_scope = class_entry;
|
fcic.calling_scope = class_entry;
|
||||||
|
|
||||||
|
@ -1806,10 +1808,14 @@ void fetch_fields_common( _Inout_ ss_sqlsrv_stmt* stmt, _In_ zend_long fetch_typ
|
||||||
field_names.transferred();
|
field_names.transferred();
|
||||||
}
|
}
|
||||||
|
|
||||||
int zr = array_init( &fields );
|
int zr = SUCCESS;
|
||||||
CHECK_ZEND_ERROR( zr, stmt, SQLSRV_ERROR_ZEND_HASH ) {
|
#if PHP_VERSION_ID < 70300
|
||||||
throw ss::SSException();
|
CHECK_ZEND_ERROR(array_init(&fields), stmt, SQLSRV_ERROR_ZEND_HASH) {
|
||||||
}
|
throw ss::SSException();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
array_init(&fields);
|
||||||
|
#endif
|
||||||
|
|
||||||
for( int i = 0; i < num_cols; ++i ) {
|
for( int i = 0; i < num_cols; ++i ) {
|
||||||
SQLLEN field_len = -1;
|
SQLLEN field_len = -1;
|
||||||
|
|
|
@ -498,18 +498,21 @@ PHP_FUNCTION( sqlsrv_errors )
|
||||||
|
|
||||||
LOG_FUNCTION( "sqlsrv_errors" );
|
LOG_FUNCTION( "sqlsrv_errors" );
|
||||||
|
|
||||||
if(( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags ) == FAILURE ) ||
|
if(( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags ) == FAILURE ) ||
|
||||||
( flags != SQLSRV_ERR_ALL && flags != SQLSRV_ERR_ERRORS && flags != SQLSRV_ERR_WARNINGS )) {
|
( flags != SQLSRV_ERR_ALL && flags != SQLSRV_ERR_ERRORS && flags != SQLSRV_ERR_WARNINGS )) {
|
||||||
LOG( SEV_ERROR, "An invalid parameter was passed to %1!s!.", _FN_ );
|
LOG( SEV_ERROR, "An invalid parameter was passed to %1!s!.", _FN_ );
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
int result;
|
zval err_z;
|
||||||
zval err_z;
|
ZVAL_UNDEF(&err_z);
|
||||||
ZVAL_UNDEF( &err_z );
|
#if PHP_VERSION_ID < 70300
|
||||||
result = array_init( &err_z );
|
if (array_init(&err_z) == FAILURE) {
|
||||||
if( result == FAILURE ) {
|
RETURN_FALSE;
|
||||||
RETURN_FALSE;
|
}
|
||||||
}
|
#else
|
||||||
|
array_init(&err_z);
|
||||||
|
#endif
|
||||||
|
|
||||||
if( flags == SQLSRV_ERR_ALL || flags == SQLSRV_ERR_ERRORS ) {
|
if( flags == SQLSRV_ERR_ALL || flags == SQLSRV_ERR_ERRORS ) {
|
||||||
if( Z_TYPE( SQLSRV_G( errors )) == IS_ARRAY && !sqlsrv_merge_zend_hash( &err_z, &SQLSRV_G( errors ) TSRMLS_CC )) {
|
if( Z_TYPE( SQLSRV_G( errors )) == IS_ARRAY && !sqlsrv_merge_zend_hash( &err_z, &SQLSRV_G( errors ) TSRMLS_CC )) {
|
||||||
zval_ptr_dtor(&err_z);
|
zval_ptr_dtor(&err_z);
|
||||||
|
@ -746,10 +749,13 @@ sqlsrv_error_const* get_error_message( _In_ unsigned int sqlsrv_error_code ) {
|
||||||
void copy_error_to_zval( _Inout_ zval* error_z, _In_ sqlsrv_error_const* error, _Inout_ zval* reported_chain, _Inout_ zval* ignored_chain,
|
void copy_error_to_zval( _Inout_ zval* error_z, _In_ sqlsrv_error_const* error, _Inout_ zval* reported_chain, _Inout_ zval* ignored_chain,
|
||||||
_In_ bool warning TSRMLS_DC )
|
_In_ bool warning TSRMLS_DC )
|
||||||
{
|
{
|
||||||
|
#if PHP_VERSION_ID < 70300
|
||||||
if( array_init( error_z ) == FAILURE ) {
|
if (array_init(error_z) == FAILURE) {
|
||||||
DIE( "Fatal error during error processing" );
|
DIE( "Fatal error during error processing" );
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
array_init(error_z);
|
||||||
|
#endif
|
||||||
|
|
||||||
// sqlstate
|
// sqlstate
|
||||||
zval temp;
|
zval temp;
|
||||||
|
@ -828,7 +834,6 @@ bool handle_errors_and_warnings( _Inout_ sqlsrv_context& ctx, _Inout_ zval* repo
|
||||||
size_t prev_reported_cnt = 0;
|
size_t prev_reported_cnt = 0;
|
||||||
bool reported_chain_was_null = false;
|
bool reported_chain_was_null = false;
|
||||||
bool ignored_chain_was_null = false;
|
bool ignored_chain_was_null = false;
|
||||||
int zr = SUCCESS;
|
|
||||||
zval error_z;
|
zval error_z;
|
||||||
ZVAL_UNDEF(&error_z);
|
ZVAL_UNDEF(&error_z);
|
||||||
sqlsrv_error_auto_ptr error;
|
sqlsrv_error_auto_ptr error;
|
||||||
|
@ -837,10 +842,13 @@ bool handle_errors_and_warnings( _Inout_ sqlsrv_context& ctx, _Inout_ zval* repo
|
||||||
if( Z_TYPE_P( reported_chain ) == IS_NULL ) {
|
if( Z_TYPE_P( reported_chain ) == IS_NULL ) {
|
||||||
|
|
||||||
reported_chain_was_null = true;
|
reported_chain_was_null = true;
|
||||||
zr = array_init( reported_chain );
|
#if PHP_VERSION_ID < 70300
|
||||||
if( zr == FAILURE ) {
|
if (array_init(reported_chain) == FAILURE) {
|
||||||
DIE( "Fatal error in handle_errors_and_warnings" );
|
DIE( "Fatal error during error processing" );
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
array_init(reported_chain);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
prev_reported_cnt = zend_hash_num_elements( Z_ARRVAL_P( reported_chain ));
|
prev_reported_cnt = zend_hash_num_elements( Z_ARRVAL_P( reported_chain ));
|
||||||
|
@ -851,11 +859,14 @@ bool handle_errors_and_warnings( _Inout_ sqlsrv_context& ctx, _Inout_ zval* repo
|
||||||
|
|
||||||
if( Z_TYPE_P( ignored_chain ) == IS_NULL ) {
|
if( Z_TYPE_P( ignored_chain ) == IS_NULL ) {
|
||||||
|
|
||||||
ignored_chain_was_null = true;
|
ignored_chain_was_null = true;
|
||||||
zr = array_init( ignored_chain );
|
#if PHP_VERSION_ID < 70300
|
||||||
if( zr == FAILURE ) {
|
if (array_init(ignored_chain) == FAILURE) {
|
||||||
DIE( "Fatal error in handle_errors_and_warnings" );
|
DIE( "Fatal error in handle_errors_and_warnings" );
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
array_init( ignored_chain );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ sqlsrv_close returns true even if an error happens.
|
||||||
echo "Test successfully done.\n";
|
echo "Test successfully done.\n";
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Warning: sqlsrv_close() expects parameter 1 to be resource, boolean given in %Ssqlsrv_errors.php on line %x
|
Warning: sqlsrv_close() expects parameter 1 to be resource, bool%S given in %Ssqlsrv_errors.php on line %x
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
|
@ -153,7 +153,7 @@ Array
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, integer given in %Ssqlsrv_errors.php on line %x
|
Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, int%S given in %Ssqlsrv_errors.php on line %x
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
|
@ -172,7 +172,7 @@ Warning: sqlsrv_close(): supplied resource is not a valid ss_sqlsrv_conn resourc
|
||||||
|
|
||||||
Warning: sqlsrv_close() expects parameter 1 to be resource, null given in %Ssqlsrv_errors.php on line %x
|
Warning: sqlsrv_close() expects parameter 1 to be resource, null given in %Ssqlsrv_errors.php on line %x
|
||||||
|
|
||||||
Warning: sqlsrv_close() expects parameter 1 to be resource, integer given in %Ssqlsrv_errors.php on line %x
|
Warning: sqlsrv_close() expects parameter 1 to be resource, int%S given in %Ssqlsrv_errors.php on line %x
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
crash caused by a statement being orphaned when an error occurred during sqlsrv_conn_execute.
|
crash caused by a statement being orphaned when an error occurred during sqlsrv_conn_execute.
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||||
|
|
||||||
require( 'MsCommon.inc' );
|
require( 'MsCommon.inc' );
|
||||||
|
|
||||||
$conn1 = Connect();
|
$conn1 = Connect();
|
||||||
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM Servers");
|
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM Servers");
|
||||||
sqlsrv_close($conn1);
|
sqlsrv_close($conn1);
|
||||||
$row1 = sqlsrv_fetch_array($stmt1);
|
$row1 = sqlsrv_fetch_array($stmt1);
|
||||||
$conn3 = Connect();
|
$conn3 = Connect();
|
||||||
|
|
||||||
echo "Test successful\n";
|
echo "Test successful\n";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTREGEX--
|
--EXPECTREGEX--
|
||||||
Warning: sqlsrv_fetch_array\(\) expects parameter 1 to be resource, boolean given in .+(\/|\\)test_conn_execute\.php on line 11
|
Warning: sqlsrv_fetch_array\(\) expects parameter 1 to be resource, bool(ean){0,1} given in .+(\/|\\)test_conn_execute\.php on line 11
|
||||||
Test successful
|
Test successful
|
||||||
|
|
|
@ -1,61 +1,61 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
password with non alphanumeric characters
|
password with non alphanumeric characters
|
||||||
--DESCRIPTION--
|
--DESCRIPTION--
|
||||||
The first three cases should have no problem connecting. Only the last case fails because the
|
The first three cases should have no problem connecting. Only the last case fails because the
|
||||||
right curly brace should be escaped with another right brace.
|
right curly brace should be escaped with another right brace.
|
||||||
In Azure for this test to pass do not specify any particular database when connecting
|
In Azure for this test to pass do not specify any particular database when connecting
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||||
|
|
||||||
require 'MsSetup.inc';
|
require 'MsSetup.inc';
|
||||||
function toConnect($options = array())
|
function toConnect($options = array())
|
||||||
{
|
{
|
||||||
global $server;
|
global $server;
|
||||||
|
|
||||||
// this function makes a connection to the server WITHOUT specifying the database
|
// this function makes a connection to the server WITHOUT specifying the database
|
||||||
return sqlsrv_connect($server, $options);
|
return sqlsrv_connect($server, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn = toConnect(array( "UID" => "test_password", "pwd" => "! ;4triou" ));
|
$conn = toConnect(array( "UID" => "test_password", "pwd" => "! ;4triou" ));
|
||||||
if (!$conn)
|
if (!$conn)
|
||||||
{
|
{
|
||||||
$errors = sqlsrv_errors();
|
$errors = sqlsrv_errors();
|
||||||
echo( $errors[0]["message"]);
|
echo( $errors[0]["message"]);
|
||||||
}
|
}
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
|
|
||||||
$conn = toConnect(array( "UID" => "test_password2", "pwd" => "!}} ;4triou" ));
|
$conn = toConnect(array( "UID" => "test_password2", "pwd" => "!}} ;4triou" ));
|
||||||
if (!$conn)
|
if (!$conn)
|
||||||
{
|
{
|
||||||
$errors = sqlsrv_errors();
|
$errors = sqlsrv_errors();
|
||||||
echo( $errors[0]["message"]);
|
echo( $errors[0]["message"]);
|
||||||
}
|
}
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
|
|
||||||
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}}" ));
|
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}}" ));
|
||||||
if (!$conn)
|
if (!$conn)
|
||||||
{
|
{
|
||||||
$errors = sqlsrv_errors();
|
$errors = sqlsrv_errors();
|
||||||
echo( $errors[0]["message"]);
|
echo( $errors[0]["message"]);
|
||||||
}
|
}
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
|
|
||||||
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}" ));
|
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}" ));
|
||||||
if ($conn)
|
if ($conn)
|
||||||
{
|
{
|
||||||
echo( "Shouldn't have connected" );
|
echo( "Shouldn't have connected" );
|
||||||
}
|
}
|
||||||
$errors = sqlsrv_errors();
|
$errors = sqlsrv_errors();
|
||||||
echo $errors[0]["message"];
|
echo $errors[0]["message"];
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
|
|
||||||
print "Test successful";
|
print "Test successful";
|
||||||
?>
|
?>
|
||||||
--EXPECTREGEX--
|
--EXPECTREGEX--
|
||||||
An unescaped right brace \(}\) was found in either the user name or password. All right braces must be escaped with another right brace \(}}\)\.
|
An unescaped right brace \(}\) was found in either the user name or password. All right braces must be escaped with another right brace \(}}\)\.
|
||||||
Warning: sqlsrv_close\(\) expects parameter 1 to be resource, boolean given in .+(\/|\\)test_non_alpha_password\.php on line 45
|
Warning: sqlsrv_close\(\) expects parameter 1 to be resource, bool(ean){0,1} given in .+(\/|\\)test_non_alpha_password\.php on line 45
|
||||||
Test successful
|
Test successful
|
||||||
|
|
Loading…
Reference in a new issue