Skip to content

Commit

Permalink
Expose TDS version as \PDO::DBLIB_ATTR_TDS_VERSION attribute on \PDO …
Browse files Browse the repository at this point in the history
…instance
  • Loading branch information
fandrieu authored and adambaratz committed Nov 10, 2017
1 parent 50421b3 commit b760b46
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ PHP NEWS
. Implemented request #69592 (allow 0-column rowsets to be skipped
automatically). (fandrieu)
. Fixed bug #74243 (allow locales.conf to drive datetime format). (fandrieu)
. Expose TDS version as \PDO::DBLIB_ATTR_TDS_VERSION attribute on \PDO
instance. (fandrieu)

- PDO_OCI:
. Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized
Expand Down
71 changes: 71 additions & 0 deletions ext/pdo_dblib/dblib_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,73 @@ static int dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
}
}

static void dblib_get_tds_version(zval *return_value, int tds)
{
switch (tds) {
case DBTDS_2_0:
ZVAL_STRING(return_value, "2.0");
break;

case DBTDS_3_4:
ZVAL_STRING(return_value, "3.4");
break;

case DBTDS_4_0:
ZVAL_STRING(return_value, "4.0");
break;

case DBTDS_4_2:
ZVAL_STRING(return_value, "4.2");
break;

case DBTDS_4_6:
ZVAL_STRING(return_value, "4.6");
break;

case DBTDS_4_9_5:
ZVAL_STRING(return_value, "4.9.5");
break;

case DBTDS_5_0:
ZVAL_STRING(return_value, "5.0");
break;

#ifdef DBTDS_7_0
case DBTDS_7_0:
ZVAL_STRING(return_value, "7.0");
break;
#endif

#ifdef DBTDS_7_1
case DBTDS_7_1:
ZVAL_STRING(return_value, "7.1");
break;
#endif

#ifdef DBTDS_7_2
case DBTDS_7_2:
ZVAL_STRING(return_value, "7.2");
break;
#endif

#ifdef DBTDS_7_3
case DBTDS_7_3:
ZVAL_STRING(return_value, "7.3");
break;
#endif

#ifdef DBTDS_7_4
case DBTDS_7_4:
ZVAL_STRING(return_value, "7.4");
break;
#endif

default:
ZVAL_FALSE(return_value);
break;
}
}

static int dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value)
{
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
Expand All @@ -320,6 +387,10 @@ static int dblib_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_valu
ZVAL_STRING(return_value, dbversion());
break;

case PDO_DBLIB_ATTR_TDS_VERSION:
dblib_get_tds_version(return_value, dbtds(H->link));
break;

case PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS:
ZVAL_BOOL(return_value, H->skip_empty_rowsets);
break;
Expand Down
1 change: 1 addition & 0 deletions ext/pdo_dblib/pdo_dblib.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ PHP_MINIT_FUNCTION(pdo_dblib)
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_QUERY_TIMEOUT", (long) PDO_DBLIB_ATTR_QUERY_TIMEOUT);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER", (long) PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_VERSION", (long) PDO_DBLIB_ATTR_VERSION);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_TDS_VERSION", (long) PDO_DBLIB_ATTR_TDS_VERSION);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_SKIP_EMPTY_ROWSETS", (long) PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_DATETIME_CONVERT", (long) PDO_DBLIB_ATTR_DATETIME_CONVERT);

Expand Down
1 change: 1 addition & 0 deletions ext/pdo_dblib/php_pdo_dblib_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ enum {
PDO_DBLIB_ATTR_QUERY_TIMEOUT,
PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER,
PDO_DBLIB_ATTR_VERSION,
PDO_DBLIB_ATTR_TDS_VERSION,
PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS,
PDO_DBLIB_ATTR_DATETIME_CONVERT,
};
Expand Down
17 changes: 17 additions & 0 deletions ext/pdo_dblib/tests/dbtds.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
PDO_DBLIB: \PDO::DBLIB_ATTR_TDS_VERSION exposes a string or false
--SKIPIF--
<?php
if (!extension_loaded('pdo_dblib')) die('skip not loaded');
require __DIR__ . '/config.inc';
?>
--FILE--
<?php
require __DIR__ . '/config.inc';

$version = $db->getAttribute(PDO::DBLIB_ATTR_TDS_VERSION);
var_dump((is_string($version) && strlen($version)) || $version === false);

?>
--EXPECT--
bool(true)

0 comments on commit b760b46

Please sign in to comment.