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

implement throwing exception when ATTR_PERSISTENT is in connection #324

Merged
merged 4 commits into from
Mar 20, 2017
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
7 changes: 6 additions & 1 deletion source/pdo_sqlsrv/pdo_dbh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ int pdo_sqlsrv_db_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC)
CHECK_CUSTOM_ERROR( driver_options && Z_TYPE_P( driver_options ) != IS_ARRAY, *g_henv_cp, SQLSRV_ERROR_CONN_OPTS_WRONG_TYPE ) {
throw core::CoreException();
}

// throws PDOException if the ATTR_PERSISTENT is in connection options
CHECK_CUSTOM_ERROR( dbh->is_persistent, *g_henv_cp, PDO_SQLSRV_ERROR_UNSUPPORTED_DBH_ATTR ) {
dbh->refcount--;
throw pdo::PDOException();
}

// Initialize the options array to be passed to the core layer
ALLOC_HASHTABLE( pdo_conn_options_ht );

Expand Down
48 changes: 48 additions & 0 deletions test/pdo_sqlsrv/pdo_065_construct_persistent.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
Exception is thrown if the unsupported attribute ATTR_PERSISTENT is put into the connection options
--SKIPIF--
--FILE--
<?php
include 'pdo_tools.inc';
require_once("autonomous_setup.php");
$database = "tempdb";
$dsn = "sqlsrv:Server = $serverName;Database = $database;";
try{
echo "Testing a connection with ATTR_PERSISTENT...\n";
// setting PDO::ATTR_PERSISTENT in PDO constructor returns an exception
$attr = array(PDO::ATTR_PERSISTENT => true);
$conn = new PDO( $dsn, $username, $password, $attr);

//free the connection
$conn=null;
}
catch( PDOException $e ) {
echo "Exception from unsupported attribute (ATTR_PERSISTENT) is caught\n";
//exit;
}
try{
echo "\nTesting new connection after exception thrown in previous connection...\n";
$tableName1 = GetTempTableName('tab1');
$conn = new PDO( $dsn, $username, $password );
$sql = "CREATE TABLE $tableName1 (c1 int, c2 varchar(10))";
$stmt = $conn->query($sql);
$ret = $conn->exec("INSERT INTO $tableName1 VALUES(1, 'column2')");
$stmt = $conn->query("SELECT * FROM $tableName1");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result['c1'] == 1 && $result['c2'] == 'column2') {
echo "Test successfully";
}
//free the statement and connection
$stmt = null;
$conn = null;
}
catch( PDOException $e ) {
var_dump( $e);
}
?>
--EXPECT--
Testing a connection with ATTR_PERSISTENT...
Exception from unsupported attribute (ATTR_PERSISTENT) is caught

Testing new connection after exception thrown in previous connection...
Test successfully
33 changes: 33 additions & 0 deletions test/pdo_sqlsrv/pdo_065_construct_prefetch.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Exception is thrown for the unsupported connection attribute ATTR_PREFETCH only if it is set after PDO::ERRMODE_EXCEPTION is turned on
--SKIPIF--
--FILE--
<?php
include 'pdo_tools.inc';
require_once("autonomous_setup.php");
$database = "tempdb";
$dsn = "sqlsrv:Server = $serverName;Database = $database;";
try{
echo "Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION...\n";
$attr = array(PDO::ATTR_PREFETCH => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$conn = new PDO( $dsn, $username, $password, $attr);
echo "Error from supported attribute (ATTR_PREFETCH) is silented\n\n";
$conn=null;

echo "Testing a connection with ATTR_PREFETCH after ERRMODE_EXCEPTION...\n";
$attr = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PREFETCH => true);
$conn = new PDO( $dsn, $username, $password, $attr);
//free the connection
$conn=null;
}
catch( PDOException $e ) {
echo "Exception from unsupported attribute (ATTR_PREFETCH) is caught\n";
//exit;
}
?>
--EXPECT--
Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION...
Error from supported attribute (ATTR_PREFETCH) is silented

Testing a connection with ATTR_PREFETCH after ERRMODE_EXCEPTION...
Exception from unsupported attribute (ATTR_PREFETCH) is caught