diff --git a/source/pdo_sqlsrv/pdo_dbh.cpp b/source/pdo_sqlsrv/pdo_dbh.cpp index 0d8e18be..6bea9c6e 100644 --- a/source/pdo_sqlsrv/pdo_dbh.cpp +++ b/source/pdo_sqlsrv/pdo_dbh.cpp @@ -431,7 +431,11 @@ 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 ) { + throw pdo::PDOException(); + } + // Initialize the options array to be passed to the core layer ALLOC_HASHTABLE( pdo_conn_options_ht ); diff --git a/test/pdo_sqlsrv/pdo_065_construct_persistent.phpt b/test/pdo_sqlsrv/pdo_065_construct_persistent.phpt new file mode 100644 index 00000000..361a9625 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_065_construct_persistent.phpt @@ -0,0 +1,46 @@ +--TEST-- +Exception is thrown if the unsupported attribute ATTR_PERSISTENT is put into the connection options +--SKIPIF-- +--FILE-- + true); + $conn = new PDO( $dsn, $username, $password, $attr); + + //free the statement and connection + $stmt=null; + $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"; + } +} +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 diff --git a/test/pdo_sqlsrv/pdo_065_construct_prefetch.phpt b/test/pdo_sqlsrv/pdo_065_construct_prefetch.phpt new file mode 100644 index 00000000..c3a90cfc --- /dev/null +++ b/test/pdo_sqlsrv/pdo_065_construct_prefetch.phpt @@ -0,0 +1,34 @@ +--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-- + 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"; + + 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 statement and connection + $stmt=null; + $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