Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.6.1 hotfix #959

Merged
merged 132 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
16c41e0
Merge pull request #1 from Microsoft/dev
david-puglielli Apr 1, 2017
10ff344
Fixed the potential error reported by Prefast code analysis
yitam Jun 5, 2018
3585bf5
Merge pull request #788 from yitam/fillLastID
yitam Jun 5, 2018
44d1bb3
Use SQLSRV_ASSERT for checking NULL ptrs
yitam Jun 6, 2018
5a66610
Merge pull request #789 from yitam/moreAsserts
yitam Jun 6, 2018
f6e450b
For these AKV tests check env despite not AE connected
yitam Jun 7, 2018
90c6443
Merge pull request #791 from yitam/fixODBC13tests
yitam Jun 7, 2018
071e897
Added the driver option to run functional tests
yitam Jun 8, 2018
ea6381c
Merge pull request #793 from yitam/addDriverOption
yitam Jun 9, 2018
17fa64a
Fixed connection pooling tests for more than one ODBC drivers
yitam Jun 11, 2018
d554492
added driver option to pdo isPooled.php
yitam Jun 11, 2018
53e4da4
Merge pull request #796 from yitam/connPooltests
yitam Jun 11, 2018
81ff085
Removed win32 ifdefs re connection resiliency (#802)
yitam Jun 21, 2018
eeea787
Set the driver argument for getDSN to null by default (#798)
yitam Jun 26, 2018
ae0b95b
Changed int to SQLLEN to avoid infinite loop (#806)
yitam Jun 27, 2018
197489a
Version 5.3.0 (#803)
yitam Jun 27, 2018
aef3830
Modified AE fetch phptypes test to insert only one row at a time and…
yitam Jun 27, 2018
5aa9be7
Streamlined two very similar large column name tests (#807)
yitam Jul 3, 2018
bbfe6df
Updates to change log and readme (#811)
yitam Jul 5, 2018
af9f77e
Fixed connection resiliency tests for Unix, updated AppVeyor for ODBC…
david-puglielli Jul 11, 2018
b2f7b20
Fixed expected output
david-puglielli Jul 11, 2018
82be814
Fixed output and skipifs
david-puglielli Jul 11, 2018
0495513
Fixed skipifs and output
david-puglielli Jul 11, 2018
c1d5793
Fixed driver name
david-puglielli Jul 12, 2018
79be282
Updated installation instructions and sample script (#813)
yitam Jul 12, 2018
a18a59b
build output to debug appveyor failure
david-puglielli Jul 12, 2018
cb78977
removed debug output
david-puglielli Jul 13, 2018
9479d03
Merge pull request #814 from david-puglielli/odbc-172-update
david-puglielli Jul 13, 2018
35631cf
Streamlined two very similar large column name tests (#815)
yitam Jul 13, 2018
706c526
Changelog updated
david-puglielli Jul 18, 2018
7b720e1
changelog updated, test skipif changed to run on unix platforms
david-puglielli Jul 19, 2018
eb80227
Fixed skipif typo
david-puglielli Jul 19, 2018
6cd7dbc
Fixed typo in skipif for pdo
david-puglielli Jul 19, 2018
820bc31
Fixed some output for Travis
david-puglielli Jul 19, 2018
0f66c48
Moved error checking inside pdo connres tests
david-puglielli Jul 19, 2018
faf5ce8
Merge pull request #816 from david-puglielli/changelog-update-5.3.0
david-puglielli Jul 19, 2018
495183e
Added links back to changelog
david-puglielli Jul 19, 2018
6f0f4b7
Merge pull request #817 from david-puglielli/changelog-update-5.3.0
david-puglielli Jul 19, 2018
96efbdb
Fixed output for sqlsrv connres tests
david-puglielli Jul 19, 2018
825b429
Fixed output
david-puglielli Jul 19, 2018
6ee8c44
Fixed output again
david-puglielli Jul 19, 2018
bd34cab
Merge pull request #818 from david-puglielli/connres-test-fixes
david-puglielli Jul 20, 2018
36c45b6
Merge branch 'dev' of https://github.com/david-puglielli/msphpsql int…
david-puglielli Jul 20, 2018
f71c52d
Fixed skipifs for connres
david-puglielli Jul 23, 2018
efde09f
Tweaked per review comments
david-puglielli Jul 23, 2018
b6d815b
Changes made to source and tests to support PHP 7.3 (#822)
yitam Jul 26, 2018
7357a16
One more fix
david-puglielli Jul 26, 2018
c533ffa
Merge pull request #821 from david-puglielli/skipif-fix
david-puglielli Jul 27, 2018
adf86f1
Initialising strings with nulls
david-puglielli Jul 31, 2018
a664a5f
Removed some spaces
david-puglielli Jul 31, 2018
41a7caf
Made array index spacing consistent
david-puglielli Aug 1, 2018
026c5d1
Merge pull request #825 from david-puglielli/string-initialisation-nulls
david-puglielli Aug 1, 2018
29f4ad7
Fix for compilation problem
david-puglielli Aug 1, 2018
d699680
Merge pull request #826 from david-puglielli/string-initialisation-nulls
david-puglielli Aug 1, 2018
0b15997
Fix for compilation problem again
david-puglielli Aug 1, 2018
ba9579b
Merge pull request #827 from david-puglielli/string-initialisation-nulls
david-puglielli Aug 1, 2018
909d1fa
Before freeing stmt in destructor check if dbh driver data is NULL (…
yitam Aug 10, 2018
28a7860
Added driver to the skipif conditions (#831)
yitam Aug 17, 2018
4452a4d
Used git clone instead to download source from a branch of a tag (#832)
yitam Aug 17, 2018
6a688b3
Modified the error handling to make it more flexible (#833)
yitam Aug 20, 2018
c209b72
Enabled Spectre Mitigations (#836)
yitam Aug 24, 2018
084ab72
Incorporated changes in PR 634 to pdo_sqlsrv (#834)
yitam Aug 28, 2018
ae1b413
Modified README re user's suggestion (#841)
yitam Sep 4, 2018
e513806
Adding supporting for Azure AD access token (#837)
yitam Sep 6, 2018
7521f09
Feature request - new PDO_STMT_OPTION_FETCHES_DATETIME_TYPE flag for …
yitam Sep 17, 2018
902a032
Feature request - add ReturnDatesAsStrings option to statement level …
yitam Sep 17, 2018
88dfea3
Updated version 5.4.0-preview (#846)
yitam Sep 18, 2018
0ba11a2
Fixed sqlsrv datetime tests to connect with ColumnEncryption variable…
yitam Sep 21, 2018
432901d
Change log for 5.4.0-preview (#850)
yitam Sep 24, 2018
ff3c6a4
Merge branch 'master' into dev
yitam Sep 24, 2018
0fa3a43
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam Sep 24, 2018
32732c8
Clear AKV data after setting the connection attribute or when excepti…
yitam Sep 26, 2018
a4eb46c
Change readme links to https
BackEndTea Oct 1, 2018
3ce8eb8
Change readme links to https
BackEndTea Oct 1, 2018
097c06f
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam Oct 3, 2018
b523306
Save meta data for the fetched result set (#855)
yitam Oct 5, 2018
8e0baba
Merge remote-tracking branch 'upstream/dev' into dev
david-puglielli Oct 6, 2018
a6b1cd5
Added Mojave to macOS instructions (#862)
yitam Oct 11, 2018
36fd97e
Fixed the broken links of Appveyor status badge (#863)
yitam Oct 12, 2018
18094a6
Feature request 415 for sqlsrv (#861)
yitam Oct 12, 2018
b3072a9
Modified how to send stream data using SQLPutData and SQLParamData (#…
yitam Oct 19, 2018
2a9398f
Updated instructions to include Ubuntu 18.10 (#869)
yitam Oct 24, 2018
f4ad2ae
Feature request 415 for pdo_sqlsrv (#873)
yitam Nov 2, 2018
3679b48
Skipped some tests when running against Azure (#874)
yitam Nov 8, 2018
69e8208
Modified config files to add the compiler flag, /Qspectre (#878)
yitam Nov 13, 2018
2e13851
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam Nov 14, 2018
f831c9e
Merge branch 'master' into dev
yitam Nov 14, 2018
d51f6db
Merge the commit from master re survey image link (#880)
yitam Nov 14, 2018
78911f4
Fixed the flaws of decimal tests and added more debugging (#879)
yitam Nov 16, 2018
b69c824
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Nov 16, 2018
b2a1950
Merge remote-tracking branch 'upstream/dev' into dev
david-puglielli Nov 19, 2018
3919628
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Nov 22, 2018
8e6c181
Changed sample code to adhere to PSR standard (#887)
yitam Nov 23, 2018
1bdbf86
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Nov 23, 2018
76c595f
Decimal places for money types only (#886)
yitam Nov 28, 2018
e3d897f
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Nov 28, 2018
ae29f73
Version update for 5.5.0-preview (#889)
yitam Nov 29, 2018
cbdc01c
Fixed the error in the pdo decimal test (#890)
yitam Nov 29, 2018
313913a
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Nov 30, 2018
9195f84
Removed warning messages while compiling extensions (#892)
yitam Dec 3, 2018
2b3b7da
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Dec 3, 2018
2f92a26
Improve performance of Unicode conversions (#891)
david-puglielli Dec 4, 2018
ac8ea11
Update sqlsrv_statement_format_money_scales.phpt
yitam Dec 4, 2018
94c5a67
Change log 5.5.0-preview (#895)
yitam Dec 6, 2018
7d45079
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Dec 6, 2018
fb55bb7
updated docs for php 7.3
david-puglielli Dec 6, 2018
2124176
Fixed broken links
david-puglielli Dec 7, 2018
a8b5615
Added back Ubuntu 18.10 ODBC instruction
david-puglielli Dec 7, 2018
5d2a653
Merge pull request #899 from david-puglielli/php-7.3-update
david-puglielli Dec 7, 2018
4d2ebb9
Merge branch 'dev' of https://github.com/Microsoft/msphpsql into dev
yitam Dec 7, 2018
e30ebfa
Drop tests related to fake passwords (#905)
yitam Dec 11, 2018
d4f840f
Initialize output param buffer when allocating extra space (#907)
yitam Dec 17, 2018
85c00df
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam Dec 18, 2018
4efb54e
Enable compiling extensions statically into PHP (#904)
jjeising Dec 20, 2018
5801edd
Dropped dbname variable and set QUOTED_IDENTIFIER to ON (#911)
yitam Jan 4, 2019
25d6812
Skipped the non-applicables tests against Azure Data Warehouse (#913)
yitam Jan 7, 2019
9a37258
Support for Managed Identity for Azure resources (#875)
yitam Jan 12, 2019
d6c8cc2
Changed version 5.6.0 (#918)
yitam Jan 16, 2019
04f531d
Initialize hasLoss before passing into Convert function (#919)
yitam Jan 21, 2019
d9b6e05
Added new tests for setting client buffer size related to issue 228 (…
yitam Jan 25, 2019
9e49a17
Fixed load order issue in sqlsrv
david-puglielli Feb 5, 2019
d69015c
Merge pull request #925 from david-puglielli/shared-compilation-load-…
david-puglielli Feb 6, 2019
3b9739a
Added source indexing for symbols (#922)
yitam Feb 6, 2019
a39be12
Modified linux and mac instructions for 5.6.0 RTW (#926)
david-puglielli Feb 8, 2019
c5989d8
Change log 5.6.0 (#921)
yitam Feb 11, 2019
22450d7
Merge branch 'master' of https://github.com/Microsoft/msphpsql
yitam Feb 25, 2019
a6cee77
Issue 937 - fixed ASSERT and added new tests (#940)
yitam Feb 28, 2019
763913d
Fixed the returned values for PDOStatement::getColumnMeta (#946)
yitam Mar 8, 2019
2c8f8ca
Fix issue 955 - errors building sqlsrv alone (#956)
yitam Mar 18, 2019
3c71213
5.6.1 hotfix
yitam Mar 18, 2019
db488ca
Updated change log
yitam Mar 19, 2019
6bcae50
5.6.1 hotfix
yitam Mar 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)

## 5.6.1 - 2019-03-19
Updated PECL release packages. Here is the list of updates:

### Fixed
- Issue [#937](https://github.com/Microsoft/msphpsql/issues/937) - fixed assumptions made when calculating field or column metadata which may have resulted in application termination
- Issue [#955](https://github.com/Microsoft/msphpsql/issues/955) - modified sqlsrv config file such that it can be compiled independently of pdo_sqlsrv
- Pull Request [#946](https://github.com/Microsoft/msphpsql/pull/946) - fixed PDOStatement::getColumnMeta() to return false when something goes wrong

### Limitations
- No support for inout / output params when using sql_variant type
- No support for inout / output params when formatting decimal values
- In Linux and macOS, setlocale() only takes effect if it is invoked before the first connection. Attempting to set the locale after connecting will not work
- Always Encrypted requires [MS ODBC Driver 17+](https://docs.microsoft.com/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server)
- Only Windows Certificate Store and Azure Key Vault are supported. Custom Keystores are not yet supported
- Issue [#716](https://github.com/Microsoft/msphpsql/issues/716) - With Always Encrypted enabled, named parameters in subqueries are not supported
- [Always Encrypted limitations](https://docs.microsoft.com/sql/connect/php/using-always-encrypted-php-drivers#limitations-of-the-php-drivers-when-using-always-encrypted)

### Known Issues
- Connection pooling on Linux or macOS is not recommended with [unixODBC](http://www.unixodbc.org/) < 2.3.7
- When pooling is enabled in Linux or macOS
- unixODBC <= 2.3.4 (Linux and macOS) might not return proper diagnostic information, such as error messages, warnings and informative messages
- due to this unixODBC bug, fetch large data (such as xml, binary) as streams as a workaround. See the examples [here](https://github.com/Microsoft/msphpsql/wiki/Features#pooling)
- With ColumnEncryption enabled, calling stored procedures with XML parameters does not work (Issue [#674](https://github.com/Microsoft/msphpsql/issues/674))
- In SUSE 15, Azure Active Directory connections may fail if PHP is installed from packages (Issue [#934](https://github.com/Microsoft/msphpsql/issues/934))

## 5.6.0 - 2019-02-15
Updated PECL release packages. Here is the list of updates:

Expand Down
24 changes: 16 additions & 8 deletions source/pdo_sqlsrv/pdo_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ int pdo_sqlsrv_stmt_get_attr( _Inout_ pdo_stmt_t *stmt, _In_ zend_long attr, _In
// colno - The index of the field for which to return the metadata.
// return_value - zval* consisting of the metadata.
// Return:
// 0 for failure, 1 for success.
// FAILURE for failure, SUCCESS for success.
int pdo_sqlsrv_stmt_get_col_meta( _Inout_ pdo_stmt_t *stmt, _In_ zend_long colno, _Inout_ zval *return_value TSRMLS_DC)
{
PDO_RESET_STMT_ERROR;
Expand All @@ -1029,20 +1029,28 @@ int pdo_sqlsrv_stmt_get_col_meta( _Inout_ pdo_stmt_t *stmt, _In_ zend_long colno

try {
SQLSRV_ASSERT( stmt != NULL, "pdo_sqlsrv_stmt_get_col_meta: pdo_stmt object was null" );
SQLSRV_ASSERT( stmt->columns != NULL, "pdo_sqlsrv_stmt_get_col_meta: columns are not available." );
SQLSRV_ASSERT( Z_TYPE_P( return_value ) == IS_NULL, "Metadata already has value. Must be NULL." );

sqlsrv_malloc_auto_ptr<field_meta_data> core_meta_data;

sqlsrv_stmt* driver_stmt = static_cast<sqlsrv_stmt*>( stmt->driver_data );
SQLSRV_ASSERT( driver_stmt != NULL, "pdo_sqlsrv_stmt_get_col_meta: stmt->driver_data was null");

SQLSRV_ASSERT( colno >= 0 && colno < stmt->column_count, "pdo_sqlsrv_stmt_get_col_meta: invalid column number." );
// Based on PDOStatement::getColumnMeta API, this should return FALSE
// if the requested column does not exist in the result set, or if
// no result set exists. Thus, do not use SQLSRV_ASSERT, which causes
// the script to fail right away. Instead, log this warning if logging
// is enabled
if (colno < 0 || colno >= stmt->column_count || stmt->columns == NULL) {
LOG( SEV_WARNING, "Invalid column number %1!d!", colno );
return FAILURE;
}

core_meta_data = core_sqlsrv_field_metadata( driver_stmt, (SQLSMALLINT) colno TSRMLS_CC );
// initialize the array to nothing, as PDO requires us to create it
core::sqlsrv_array_init( *driver_stmt, return_value TSRMLS_CC );

sqlsrv_malloc_auto_ptr<field_meta_data> core_meta_data;

core_meta_data = core_sqlsrv_field_metadata( driver_stmt, (SQLSMALLINT) colno TSRMLS_CC );

// add the following fields: flags, native_type, driver:decl_type, table
add_assoc_long( return_value, "flags", 0 );

Expand Down Expand Up @@ -1088,14 +1096,14 @@ int pdo_sqlsrv_stmt_get_col_meta( _Inout_ pdo_stmt_t *stmt, _In_ zend_long colno
}
catch( core::CoreException& ) {

return 0;
return FAILURE;
}
catch(...) {

DIE( "pdo_sqlsrv_stmt_get_col_meta: Unknown exception occurred while retrieving metadata." );
}

return 1;
return SUCCESS;
}


Expand Down
2 changes: 1 addition & 1 deletion source/shared/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// Increase Patch for backward compatible fixes.
#define SQLVERSION_MAJOR 5
#define SQLVERSION_MINOR 6
#define SQLVERSION_PATCH 0
#define SQLVERSION_PATCH 1
#define SQLVERSION_BUILD 0

// For previews, set this constant to 1. Otherwise, set it to 0
Expand Down
2 changes: 1 addition & 1 deletion source/sqlsrv/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if( PHP_SQLSRV != "no" ) {
if (CHECK_LIB("odbc32.lib", "sqlsrv") && CHECK_LIB("odbccp32.lib", "sqlsrv") &&
CHECK_LIB("version.lib", "sqlsrv") && CHECK_LIB("psapi.lib", "sqlsrv")&&
CHECK_HEADER_ADD_INCLUDE( "core_sqlsrv.h", "CFLAGS_SQLSRV", configure_module_dirname + "\\shared")) {
if (PHP_PDO_SQLSRV == "no" || PHP_SQLSRV_SHARED) {
if (PHP_SQLSRV_SHARED || PHP_PDO_SQLSRV == "no") {
ADD_SOURCES( configure_module_dirname + "\\shared", shared_src_class, "sqlsrv" );
}
CHECK_HEADER_ADD_INCLUDE("sql.h", "CFLAGS_SQLSRV_ODBC");
Expand Down
2 changes: 1 addition & 1 deletion source/sqlsrv/stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ SQLSMALLINT get_resultset_meta_data(_Inout_ sqlsrv_stmt * stmt)
throw;
}

SQLSRV_ASSERT(num_cols > 0 && stmt->current_meta_data.size() == num_cols, "Meta data vector out of sync" );
SQLSRV_ASSERT(stmt->current_meta_data.size() == num_cols, "Meta data vector out of sync" );

return num_cols;
}
Expand Down
122 changes: 122 additions & 0 deletions test/functional/pdo_sqlsrv/pdo_937_metadata.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
--TEST--
GitHub issue 937 - getting metadata will not fail after an UPDATE / DELETE statement
--DESCRIPTION--
Verifies that getColumnMeta will not fail after processing an UPDATE / DELETE query that returns no fields. Instead, it should simply return FALSE because no result set exists.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsSetup.inc");
require_once("MsCommon_mid-refactor.inc");

$tableName = 'pdoTestTable_938';
$procName = 'pdoTestProc_938';

function checkMetaData($stmt)
{
$metadata = $stmt->getColumnMeta(0);
if ($metadata !== FALSE) {
echo "Expects FALSE because no result set exists!\n";
}
}

try {
$conn = connect();

dropTable($conn, $tableName);
dropProc($conn, $procName);

$tsql = "CREATE TABLE $tableName([id] [int] NOT NULL, [name] [varchar](10) NOT NULL)";
$conn->query($tsql);

$id = 3;
$tsql = "INSERT INTO $tableName VALUES ($id, 'abcde')";
$conn->query($tsql);

$tsql = "UPDATE $tableName SET name = 'updated' WHERE id = $id";
$stmt = $conn->prepare($tsql);
$stmt->execute();
$numCol = $metadata = $stmt->columnCount();
echo "Number of columns after UPDATE: $numCol\n";
checkMetaData($stmt);

$tsql = "SELECT * FROM $tableName";
$stmt = $conn->query($tsql);
$numCol = $metadata = $stmt->columnCount();
for ($i = 0; $i < $numCol; $i++) {
$metadata = $stmt->getColumnMeta($i);
var_dump($metadata);
}

createProc($conn, $procName, "@id int, @val varchar(10) OUTPUT", "SELECT @val = name FROM $tableName WHERE id = @id");

$value = '';
$tsql = "{CALL [$procName] (?, ?)}";
$stmt = $conn->prepare($tsql);
$stmt->bindParam(1, $id, PDO::PARAM_INT);
$stmt->bindParam(2, $value, PDO::PARAM_STR, 10);
$stmt->execute();
$numCol = $metadata = $stmt->columnCount();
echo "Number of columns after PROCEDURE: $numCol\n";
echo "Value returned: $value\n";
checkMetaData($stmt);

$query = "DELETE FROM $tableName WHERE name = 'updated'";
$stmt = $conn->query($query);
$numCol = $metadata = $stmt->columnCount();
echo "Number of columns after DELETE: $numCol\n";
checkMetaData($stmt);
} catch (PDOException $e) {
echo $e->getMessage() . PHP_EOL;
}

dropTable($conn, $tableName);
dropProc($conn, $procName);

unset($stmt);
unset($conn);

?>
--EXPECT--
Number of columns after UPDATE: 0
array(8) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(3) "int"
["native_type"]=>
string(6) "string"
["table"]=>
string(0) ""
["pdo_type"]=>
int(2)
["name"]=>
string(2) "id"
["len"]=>
int(10)
["precision"]=>
int(0)
}
array(8) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(7) "varchar"
["native_type"]=>
string(6) "string"
["table"]=>
string(0) ""
["pdo_type"]=>
int(2)
["name"]=>
string(4) "name"
["len"]=>
int(10)
["precision"]=>
int(0)
}
Number of columns after PROCEDURE: 0
Value returned: updated
Number of columns after DELETE: 0
3 changes: 1 addition & 2 deletions test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,4 @@ array(7) {

Warning: PDOStatement::getColumnMeta(): SQLSTATE[42P10]: Invalid column reference: column number must be non-negative in %s on line %x
bool(false)

Fatal error: pdo_sqlsrv_stmt_get_col_meta: invalid column number. in %s on line %x
bool(false)
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,4 @@ array(7) {

Warning: PDOStatement::getColumnMeta(): SQLSTATE[42P10]: Invalid column reference: column number must be non-negative in %s on line %x
bool(false)

Fatal error: pdo_sqlsrv_stmt_get_col_meta: invalid column number. in %s on line %x
bool(false)
125 changes: 125 additions & 0 deletions test/functional/sqlsrv/srv_937_metadata.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
--TEST--
GitHub issue #937 - getting metadata will not fail after an UPDATE / DELETE statement
--DESCRIPTION--
Verifies that sqlsrv_field_metadata will return an empty array after processing an
UPDATE / DELETE query that returns no fields.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');

$conn = connect();
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}

$tableName = 'srvTestTable_938';
$procName = 'srvTestProc_938';

dropTable($conn, $tableName);
dropProc($conn, $procName);

// Create the test table
$tsql = "CREATE TABLE $tableName([id] [int] NOT NULL,
[dummyColumn] [varchar](10) NOT NULL
)";
$stmt = sqlsrv_query($conn, $tsql);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}

$id = 5;
$tsql = "INSERT INTO $tableName VALUES ($id, 'dummy')";
$stmt = sqlsrv_query($conn, $tsql);
if (!$stmt) {
fatalError("Failed to insert a row into table $tableName\n");
}

$tsql = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $tsql);
$fieldmeta = sqlsrv_field_metadata($stmt);
var_dump($fieldmeta);

$tsql = "UPDATE $tableName SET dummyColumn = 'updated' WHERE id = $id";
$stmt = sqlsrv_prepare($conn, $tsql);
sqlsrv_execute($stmt);
$fieldmeta = sqlsrv_field_metadata($stmt);
var_dump($fieldmeta);

createProc($conn, $procName, "@id int, @val varchar(10) OUTPUT", "SELECT @val = dummyColumn FROM $tableName WHERE id = @id");

$value = '';
$tsql = "{CALL [$procName] (?, ?)}";
$stmt = sqlsrv_prepare(
$conn,
$tsql,
array(array($id, SQLSRV_PARAM_IN),
array(&$value, SQLSRV_PARAM_OUT)
)
);
$result = sqlsrv_execute($stmt);
if (!$result) {
fatalError("Failed to invoke stored procedure $procName\n");
}

echo "The value returned: $value\n";

$fieldmeta = sqlsrv_field_metadata($stmt);
var_dump($fieldmeta);

$options = array("Scrollable" => "buffered");
$tsql = "DELETE FROM $tableName WHERE dummyColumn = 'updated'";
$stmt = sqlsrv_query($conn, $tsql, array(), $options);
$fieldmeta = sqlsrv_field_metadata($stmt);
var_dump($fieldmeta);

dropTable($conn, $tableName);
dropProc($conn, $procName);

sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

?>
--EXPECT--
array(2) {
[0]=>
array(6) {
["Name"]=>
string(2) "id"
["Type"]=>
int(4)
["Size"]=>
NULL
["Precision"]=>
int(10)
["Scale"]=>
NULL
["Nullable"]=>
int(0)
}
[1]=>
array(6) {
["Name"]=>
string(11) "dummyColumn"
["Type"]=>
int(12)
["Size"]=>
int(10)
["Precision"]=>
NULL
["Scale"]=>
NULL
["Nullable"]=>
int(0)
}
}
array(0) {
}
The value returned: updated
array(0) {
}
array(0) {
}