Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 18 additions & 1 deletion ext/pdo_odbc/odbc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ static bool odbc_handle_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
}
}

static int pdo_odbc_get_info_string(pdo_dbh_t *dbh, SQLUSMALLINT type, zval *val)
{
RETCODE rc;
SQLSMALLINT out_len;
char buf[256];
pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;
rc = SQLGetInfo(H->dbc, type, (SQLPOINTER)buf, sizeof(buf), &out_len);
/* returning -1 is treated as an error, not as unsupported */
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
return -1;
}
ZVAL_STRINGL(val, buf, out_len);
return 1;
}

static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
{
pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;
Expand All @@ -359,9 +374,11 @@ static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
return 1;

case PDO_ATTR_SERVER_VERSION:
return pdo_odbc_get_info_string(dbh, SQL_DBMS_VER, val);
case PDO_ATTR_SERVER_INFO:
return pdo_odbc_get_info_string(dbh, SQL_DBMS_NAME, val);
case PDO_ATTR_PREFETCH:
case PDO_ATTR_TIMEOUT:
case PDO_ATTR_SERVER_INFO:
case PDO_ATTR_CONNECTION_STATUS:
break;
case PDO_ODBC_ATTR_ASSUME_UTF8:
Expand Down
24 changes: 24 additions & 0 deletions ext/pdo_odbc/tests/get_attribute_server.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
PDO ODBC getAttribute SERVER_INFO and SERVER_VERSION
--SKIPIF--
<?php
if (!extension_loaded('pdo_odbc')) print 'skip not loaded';
require 'ext/pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
require 'ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory('ext/pdo_odbc/tests/common.phpt');
// Obviously, we can't assume what driver is being used, so just check strings
// Example driver output (MariaDB ODBC):
// PDO::ATTR_SERVER_INFO: MariaDB
// PDO::ATTR_SERVER_VERSION: 10.04.000018
// As well as IBM i ODBC:
// PDO::ATTR_SERVER_INFO: DB2/400 SQL
// PDO::ATTR_SERVER_VERSION: 07.02.0015
var_dump($db->getAttribute(PDO::ATTR_SERVER_INFO));
var_dump($db->getAttribute(PDO::ATTR_SERVER_VERSION));
--EXPECTF--
string(%d) "%s"
string(%d) "%s"