diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc new file mode 100644 index 000000000..6158e870e --- /dev/null +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -0,0 +1,1803 @@ +getAttribute(PDO::ATTR_CLIENT_VERSION)["DriverVer"]; + $server_ver = $conn->getAttribute(PDO::ATTR_SERVER_VERSION); + $msodbcsql_maj = explode(".", $msodbcsql_ver)[0]; + if ($msodbcsql_maj < 17 || explode('.', $server_ver)[0] < 13) { + return false; + } + return true; +} + + +/** + * Connect to the database specified in MsSetup.inc; Column Encryption keywords automatically added when $keystore is not none + * @param string $keywords : string to append to the dsn string in PDO::_construct + * @param array $options : attributes to pass to PDO::_construct + * @param int $errmode : specifies how the driver reports failures: one of PDO::ERRMODE_EXCEPTION, PDO::ERRMODE_WARNING, or PDO::ERRMODE_SILENT; default is PDO::ERRMODE_EXCEPTION + * @param bool $disableCE : flag for disabling column encryption even when keystore is NOT none + * for testing fetching encrypted data when connection column encryption is off + * @return PDO connection object + */ +function connect($keywords = '', $options=array(), $errmode = PDO::ERRMODE_EXCEPTION, $disableCE = false) +{ + try { + // simply use $databaseName from MsSetup.inc to facilitate testing in Azure, + // which does not support switching databases + require("MsSetup.inc"); + $dsn = getDSN($server, $databaseName, $keywords, $disableCE); + $conn = new PDO($dsn, $uid, $pwd, $options); + if ($errmode == PDO::ERRMODE_EXCEPTION || $errmode == PDO::ERRMODE_WARNING || $errmode == PDO::ERRMODE_SILENT) { + $conn->setAttribute(PDO::ATTR_ERRMODE, $errmode); + } else { + printf("connect: The errmode provided must be one of exception, warning, or silent.\n"); + } + return $conn; + } catch (PDOException $e) { + var_dump($e->errorInfo); + } catch (Exception $e) { + var_dump($e->errorInfo); + exit; + } +} + + +/** + * @param string $sqlsrvserver : server name + * @param string $database : database name + * @param string $keywords : string to append to the dsn string in PDO::_construct + * @param bool $disableCE : flag for disabling column encryption even when keystore is NOT none + * @return string dsn string used for PDO constructor + */ +function getDSN($sqlsrvserver, $database, $keywords = '', $disableCE = false) +{ + require("MsSetup.inc"); + $dsn = ""; + if ($sqlsrvserver) { + $dsn .= "sqlsrv:Server=$sqlsrvserver;"; + } else { + printf("getDSN: the sqlsrvserver provided must not be null.\n"); + exit; + } + if ($database) { + $dsn .= "database=$database;"; + } + if ($keystore != "none" && !$disableCE) { + $dsn .= "ColumnEncryption=Enabled;"; + } + if ($keystore == "ksp" && !$disableCE) { + require('AE_Ksp.inc'); + $ksp_path = getKSPPath(); + $dsn .= "CEKeystoreProvider=$ksp_path;CEKeystoreName=$ksp_name;CEKeystoreEncryptKey=$encrypt_key;"; + } + if ($keywords) { + $dsn .= $keywords; + } + return $dsn; +} + + +/** + * @return string CEK name depending on the connection keywords + */ +function getCekName() +{ + require 'MsSetup.inc'; + $cekName = ''; + switch ($keystore) { + case "none": + $cekName = ''; + break; + case "win": + $cekName = 'AEColumnKey'; + break; + case "ksp": + $cekName = 'CustomCEK'; + break; + case "akv": + $cekName = 'AKVColumnKey'; + break; + default: + echo "getCekName: Invalid keystore name.\n"; + } + return $cekName; +} + + +/** + * class for encapsulating column metadata needed for creating a table + */ +class ColumnMeta +{ + public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5)) + public $colName; //column name + public $encType; //randomized or deterministic; default is deterministic + public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) ) + + public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic") + { + if (is_null($colName)) { + $this->colName = get_default_colname($dataType); + } else { + $this->colName = $colName; + } + $this->dataType = $dataType; + $this->encType = $encType; + $this->options = $options; + } + /** + * @return string column definition for creating a table + */ + public function getColDef() + { + //return getColDef($this->colName, $this->dataType, $this->options, $this->encType); + $append = " "; + + // an identity column is not encrypted because a select query with identity column as the where clause is often run and the user want to have to bind parameter every time + if (isColEncrypted() && stripos($this->options, "identity") === false) { + $cekName = getCekName(); + if (stripos($this->dataType, "char") !== false) { + $append .= "COLLATE Latin1_General_BIN2 "; + } + $append .= sprintf("ENCRYPTED WITH (ENCRYPTION_TYPE = %s, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = $cekName) ", $this->encType); + } + $append .= $this->options; + $colDef = "[" . $this->colName . "] " . $this->dataType . $append; + return $colDef; + } +} + + +/** + * @return string default column name when a name is not provided in the ColumnMeta class + */ +function getDefaultColName($dataType) +{ + $colName = "c_" . str_replace(",", "_", str_replace("(", "_", $dataType)); + $colName = rtrim($colName, ")"); + return $colName; +} + + +/** + * Create a table + * @param object $conn : PDO connection object + * @param string $tbname : name of the table to be created + * @param array $columnMetaArr : array of key value pair with column name as key and datatype as value, or array of columnMeta objects, which contain metadata for one column + * @param array $inputs : an associative array column name and its value; value may be a literal value or a ColumnMeta object + * @param bool $disableCE : flag for disabling column encryption even when keystore is NOT none + * for creating table with datatypes not support for encryption + * @return int reporting the number of rows affected (should always be 0 for creating table) + */ +function createTable($conn, $tbname, $columnMetaArr, $disableCE = false) +{ + try { + dropTable($conn, $tbname); + $colDef = ""; + foreach ($columnMetaArr as $key => $value) { + if (!is_object($value)) { + $cm = new ColumnMeta($value, $key); + $colDef = $colDef . $cm->getColDef() . ", "; + } elseif (get_class($value) == "ColumnMeta") { + $colDef = $colDef . $value->getColDef() . ", "; + } else { + printf("createTable: The input provided must be an associative array of literal values or ColumnMeta objects.\n"); + exit; + } + } + $colDef = rtrim($colDef, ", "); + $createSql = "CREATE TABLE $tbname ($colDef)"; + $numRows = $conn->exec($createSql); + return $numRows; + } catch (PDOException $e) { + var_dump($e->errorInfo); + } catch (Exception $e) { + var_dump($e->errorInfo); + exit; + } +} + + +/** + * class for encapsulating optional parameters for PDOStatement::bindParam + */ +class BindParamOp +{ + public $parameter; //parameter identifier. Parameter name or 1-based index of the parameter + public $variable; //name of the PHP variable to bind + public $pdoType; //PDO_PARAM_ type specified for PDOStatement::bindParam + public $length; //length specified for PDOStatement::bindParam + public $options; //options specified for PDOStatement::bindParam + + public function __construct($parameter, $variable, $pdoType = null, $length = null, $options = null) + { + $this->parameter = $parameter; + $this->variable = $variable; + + $pdoParams = array("PDO::PARAM_BOOL", "PDO::PARAM_NULL", "PDO::PARAM_INT", "PDO::PARAM_STR", "PDO::PARAM_LOB"); + if (in_array($pdoType, $pdoParams)) { + $this->pdoType = $pdoType; + } else { + prinft("BindParamOp construct: The pdoType provided must be one of PDO::PARAM_BOOL, PDO::PARAM_NULL, PDO::PARAM_INT, PDO::PARAM_STR, or PDO::PARAM_LOB.\n"); + exit; + } + + if ($length >= 0) { + $this->length = $length; + } else { + printf("BindParamOp construct: The length provided must be greater or equal to 0.\n"); + exit; + } + + $encodingAttrs = array("PDO::SQLSRV_ENCODING_BINARY", "PDO::SQLSRV_ENCODING_SYSTEM", "PDO::SQLSRV_ENCODING_UTF8", "PDO::SQLSRV_ENCODING_DEFAULT"); + if (in_array($options, $encodingAttrs)) { + $this->options = $options; + } else { + printf("BindParamOp construct: The option provided must be one of PDO::SQLSRV_ENCODING_BINARY, PDO::SQLSRV_ENCODING_SYSTEM, PDO::SQLSRV_ENCODING_UTF8, PDO::SQLSRV_ENCODING_DEFAULT"); + } + } + /** + * @param object $stmt : PDO Statement object + */ + public function bindWithOp($stmt) + { + // get the constant values of pdoType, and option + $pdoType = null; + $options = null; + if (!is_null($this->pdoType)) { + $pdoType = constant($this->pdoType); + } + if (!is_null($this->options)) { + $options = constant($this->options); + } + $stmt->bindParam($this->parameter, $this->variable, $pdoType, $this->length, $options); + } +} + + +/** + * Insert a row into a table + * @param object $conn : PDO connection object + * @param string $tbname : name of the table for the row to be inserted + * @param array $inputs : an associative array column name and its value; value may be a literal value or a BindParamOp object + * @param string $api : PDO_SQLSRV API used for executing the insert query + * accepted values: "exec", "query", "prepareDirect", "prepareExecuteBind", "prepareBindParam" + * @param bool $r : true if the row was successfully inserted, otherwise false. Default value is null to make this parameter optional. + * @return object PDOStatement object of the insert statement + */ +function insertRow($conn, $tbname, $inputs, $api = null, &$r = null) +{ + try { + // set the default API being called depending on if column is encrypted + if (is_null($api)) { + if (!isColEncrypted()) { + $api = "query"; + } else { + $api = "prepareBindParam"; + } + } + $stmt = null; + if (!isColEncrypted() && $api != "prepareExecuteBind" && $api != "prepareBindParam") { + $insertSql = getInsertSqlComplete($tbname, $inputs); + switch ($api) { + case "exec": + $conn->exec($insertSql); + break; + case "query": + $stmt = $conn->query($insertSql); + break; + case "prepareDirect": + $stmt = $conn->prepare($insertSql); + $r = $stmt->execute(); + break; + } + } else { + // if AE is on, must bind param + $insertSql = getInsertSqlPlaceholders($tbname, $inputs); + $stmt = $conn->prepare($insertSql); + if ($api == "prepareExecuteBind") { + $params = array_values($inputs); + $r = $stmt->execute($params); + } else { + $i = 1; + foreach ($inputs as $key => $value) { + if (!is_object($value)) { + $stmt->bindParam($i, $inputs[$key]); + } elseif (get_class($value) == "BindParamOp") { + $value->bindWithOp($stmt); + } else { + printf("insertRow: The inputs provided must be a literal value or a BindParamOp object.\n"); + exit; + } + $i++; + } + $r = $stmt->execute(); + } + } + return $stmt; + } catch (PDOException $e) { + var_dump($e->errorInfo); + } catch (Exception $e) { + var_dump($e->errorInfo); + exit; + } +} + + +/** + * @param string $tbname : name of the table for an insert sql + * @param array $inputs : associative array containing a key value pair of column name and data to put into an insert sql string + * @return string a complete insert sql string + */ +function getInsertSqlComplete($tbname, $inputs) +{ + $colStr = "INSERT INTO $tbname ("; + $valStr = "VALUES ("; + if (empty($inputs)) { + echo "getInsertSqlComplete: inputs for inserting a row cannot be empty.\n"; + return; + } + foreach ($inputs as $key => $value) { + $colStr .= $key . ", "; + if (is_null($value)) { + $valStr .= "null, "; + } elseif (is_string($value)) { + $valStr .= "'" . $value . "', "; + } else { + $valStr .= $value . ", "; + } + } + $colStr = rtrim($colStr, ", ") . ") "; + $valStr = rtrim($valStr, ", ") . ") "; + $insertSql = $colStr . $valStr; + return $insertSql; +} + + +/** + * @param string $tbname : name of the table for an insert sql + * @param array $input : associative array containing a key value pair of column name and data to put into an insert sql string + * @return string an insert sql string with "?" placeholders for all values + */ +function getInsertSqlPlaceholders($tbname, $inputs) +{ + if (empty($inputs)) { + echo "getInsertSqlPlaceholders: inputs for inserting a row cannot be empty.\n"; + return ""; + } + $colStr = "INSERT INTO $tbname ("; + $valStr = "VALUES ("; + foreach ($inputs as $key => $value) { + $colStr .= $key . ", "; + } + $colStr = rtrim($colStr, ", ") . ") "; + $valStr .= getSeqPlaceholders(count($inputs)) . ") "; + $insertSql = $colStr . $valStr; + return $insertSql; +} + + +/** + * @param string $spname : name of the stored procedure + * @param int $num : number of parameters needed for the stored procedure + * @return string a call stored procedure sql string with "?" placeholders for all parameters + */ +function getCallProcSqlPlaceholders($spname, $num) +{ + $callStr = "{CALL $spname ("; + $callStr .= getSeqPlaceholders($num) . ")} "; + return $callStr; +} + + +/** + * @param int $num : number of placeholders needed + * @return string a string containing $num number of repeated "?" placeholders delimited by ", " + */ +function getSeqPlaceholders($num) +{ + if ($num <= 0) { + echo "getSeqPlaceholders: num provided for creating a sequence of placeholders cannot be less than 0.\n"; + return; + } + $placeholderStr = str_repeat("?, ", $num); + $placeholderStr = rtrim($placeholderStr, ", "); + return $placeholderStr; +} + + +/** + * Fetch all rows and all columns given a table name, and print them + * @param object $conn : PDO connection object + * @param string $tbname : name of the table to fetch from + */ +function fetchAll($conn, $tbname) +{ + try { + $sql = "SELECT * FROM $tbname"; + $stmt = $conn->query($sql); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + foreach ($row as $key => $value) { + print("$key: $value\n"); + } + } + } catch (PDOException $e) { + var_dump($e->errorInfo); + } catch (Exception $e) { + var_dump($e->errorInfo); + exit; + } +} + + +/** + * Use PDOStatement::fetchAll to fetch all rows given a table name + * @param object $conn : PDO connection object + * @param string $tbname : name of the table to fetch from + * @param string $fetchStyle : fetch_style argument passed to PDOStatement::fetchAll + * @return array rows in a result set + */ +function selectAll($conn, $tbname, $fetchStyle = null) +{ + try { + $sql = "SELECT * FROM $tbname"; + $stmt = $conn->query($sql); + if ($fetchStyle) { + $fetchStyle = constant($fetchStyle); + } + $data = $stmt->fetchAll($fetchStyle); + return $data; + } catch (PDOException $e) { + var_dump($e->errorInfo); + } catch (Exception $e) { + var_dump($e->errorInfo); + exit; + } +} + + +/** + * Use PDOStatement::fetch to fetch a row given a table name + * @param object $conn : PDO connection object + * @param string $tbname : name of the table to fetch from + * @param string $fetchStyle : fetch_style argument passed to PDOStatement::fetch + * @return array a row from the result set + */ +function selectRow($conn, $tbname, $fetchStyle = null) +{ + try { + $sql = "SELECT * FROM $tbname"; + $stmt = $conn->query($sql); + $row = $stmt->fetch(constant($fetchStyle)); + return $row; + } catch (PDOException $e) { + var_dump($e->errorInfo); + } catch (Exception $e) { + var_dump($e->errorInfo); + exit; + } +} + + +/** + * @return bool false if $keystore specified in MsSetup.inc is none, otherwise return true + */ +function isColEncrypted() +{ + require 'MsSetup.inc'; + if ($keystore == "none" || !$dataEncrypted) { + return false; + } else { + return true; + } +} + + +// Create and insert +function create_and_insert_table1($conn) +{ + global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1; + + try { + $create_query = + + "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $table1 . "') AND type in (N'U')) + DROP TABLE " . $table1 . + + " CREATE TABLE [dbo].[" . $table1 . "]( + [IntCol] [int] NULL, + [CharCol] [char](10) NULL, + [NCharCol] [nchar](10) NULL, + [DateTimeCol] [datetime] NULL, + [VarcharCol] [varchar](50) NULL, + [NVarCharCol] [nvarchar](50) NULL, + [FloatCol] [float] NULL, + [XmlCol] [xml] NULL + ) ON [PRIMARY] + "; + + $conn->query($create_query); + + for ($i = 0 ; $i <= 1; ++ $i) { + $insert_query = + "INSERT INTO PDO_Types_1 VALUES (". + $int_col[$i] . $comma . + $string_col[$i] . $comma . + $string_col[$i] . $comma . + "Convert(datetime, ". $date_col[$i] . ")" . $comma . + $string_col[$i] . $comma . + $string_col[$i] . $comma . + $decimal_col[$i] . $comma . + $xml_col[$i] . + ")"; + + $conn->query($insert_query); + } + } catch (Exception $e) { + var_dump($e); + exit; + } +} + +function create_and_insert_table2($conn) +{ + try { + //Timestamp is not present. + //VARIANT is not supported. + global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1, $table2; + + $create_query = + "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'".$table2."') AND type in (N'U')) DROP TABLE " . $table2 . + + " CREATE TABLE " .$table2 . " ( + [BigIntCol] [bigint] NULL, + [BinaryCol] [binary](5) NULL, + [BitCol] [bit] NULL, + [CharCol] [char](10) NULL, + [DateCol] [date] NULL, + [DateTimeCol] [datetime] NULL, + [DateTime2Col] [datetime2](7) NULL, + [DTOffsetCol] [datetimeoffset](7) NULL, + [DecimalCol] [decimal](18, 0) NULL, + [FloatCol] [float] NULL, + [ImageCol] [image] NULL, + [IntCol] [int] NULL, + [MoneyCol] [money] NULL, + [NCharCol] [nchar](10) NULL, + [NTextCol] [ntext] NULL, + [NumCol] [numeric](18, 0) NULL, + [NVarCharCol] [nvarchar](50) NULL, + [NVarCharMaxCol] [nvarchar](max) NULL, + [RealCol] [real] NULL, + [SmallDTCol] [smalldatetime] NULL, + [SmallIntCol] [smallint] NULL, + [SmallMoneyCol] [smallmoney] NULL, + [TextCol] [text] NULL, + [TimeCol] [time](7) NULL, + [TinyIntCol] [tinyint] NULL, + [Guidcol] [uniqueidentifier] NULL, + [VarbinaryCol] [varbinary](50) NULL, + [VarbinaryMaxCol] [varbinary](max) NULL, + [VarcharCol] [varchar](50) NULL, + [VarcharMaxCol] [varchar](max) NULL, + [XmlCol] [xml] NULL + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + + "; + + $stmt = $conn->query($create_query); + + for ($i =0; $i<= 0 ; ++ $i) { + $insert_query = + + " INSERT INTO " .$table2 . " VALUES (". + $int_col[$i] . $comma . + $binary_col[$i] . $comma . + "0" . $comma . + $string_col[$i] . $comma . + "Convert(date, ". $date_col[$i] . $closing_brace . + "Convert(datetime, ". $date_col[$i] . $closing_brace . + "Convert(datetime2(7),". $date_col[$i] . $closing_brace . + "Convert(datetimeoffset(7)," . $date_col[$i] . $closing_brace . + $decimal_col[$i] . $comma . + $decimal_col[$i] .$comma . + $binary_col[$i] . $comma . + $int_col[$i] . $comma . + $decimal_col[$i] . $comma . + $string_col[$i]. $comma . + $large_string_col[$i]. $comma. + $int_col[$i]. $comma . + $string_col[$i]. $comma . + $large_string_col[$i]. $comma . + $decimal_col[$i]. $comma . + "Convert(smalldatetime, ". $date_col[$i]. $closing_brace . + $int_col[$i]. $comma . + $decimal_col[$i]. $comma . + $large_string_col[$i]. $comma . + "Convert(time(7), ". $date_col[$i] . $closing_brace . + $int_col[$i] . $comma . + $guid_col[$i] . $comma . + $binary_col[$i] . $comma . + $binary_col[$i] . $comma . + $string_col[$i] . $comma . + $large_string_col[$i] . $comma . + $xml_col[$i] . + ")"; + + $stmt = $conn->query($insert_query); + } + } catch (Exception $e) { + var_dump($e); + exit; + } +} + +function teardown() +{ + // TBD +} + + +function my_print_r($to_print) +{ + global $verbose; + if ($verbose) { + print_r($to_print); + } +} + + +function TestMode() +{ + $testMode = getenv('PHPT_EXEC'); + return ($testMode ? true : false); +} + +function IsPdoMode() +{ + require 'MsSetup.inc'; + return (($driverType === true) ? true : false); +} + + +function TraceMode() +{ + require 'MsSetup.inc'; + return ((!TestMode() && $traceEnabled) ? true : false); +} + +function IsMarsSupported() +{ + require 'MsSetup.inc'; + return ($marsMode ? true : false); +} + +function IsDaasMode() +{ + require 'MsSetup.inc'; + return ($daasMode ? true : false); +} + +function FatalError($errorMsg) +{ + if (!IsPdoMode()) { + handle_errors(); + } + die("$errorMsg\n"); +} + +function Trace($msg) +{ + if (TraceMode()) { + echo $msg; + } +} + +function TraceEx($msg, $exitMode) +{ + if ($exitMode) { + FatalError($msg); + } else { + Trace("$msg\n"); + } +} + +function TraceData($sqlType, $data) +{ + if (TraceMode()) { + $msg = strtoupper(" $sqlType:"); + echo "$msg\t"; + if (strlen($msg) <= 7) { + echo "\t"; + } + if (strlen($msg) <= 15) { + echo "\t"; + } + echo "$data\n" +; + } +} + +function StartTest($testName) +{ + require 'MsSetup.inc'; + + if (TraceMode()) { + echo "$PhpDriver: starting \"$testName\" test...\n\n"; + } + + if (!extension_loaded(IsPdoMode() ? "pdo" : "sqlsrv")) { + die("$PhpDriver cannot be loaded."); + } + + // Set timezone + $tz = ini_get('date.timezone'); + if (strcmp($tz, "") == 0) { + date_default_timezone_set('America/Los_Angeles'); + $tz = date_default_timezone_get(); + } + Trace("Timezone: $tz.\n"); +} + +function EndTest($testName) +{ + require 'MsSetup.inc'; + + if (TraceMode()) { + echo "\n$PhpDriver: " +; + } + echo "Test \"$testName\" completed successfully.\n" +; +} + + +function Setup() +{ + set_time_limit(0); + + if (IsPdoMode()) { // PDO setup + } else { // PHP setup + sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_ALL); + sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL); + sqlsrv_configure('WarningsReturnAsErrors', 1); + } +} + +function Configure($param, $expected) +{ + if (!IsPdoMode()) { + sqlsrv_configure($param, $expected); + $actual = sqlsrv_get_config($param); + + if ($actual == $expected) { + Trace("Set configuration parameter $param = $actual.\n"); + } else { + die("Failed to set configuration parameter $param = $expected."); + } + } +} + +function getTableName($table = '') +{ + $timestamp = round(microtime(true)*1000); + + if (strlen($table) == 0) { + $table = 'php_test_table'; + } + + return $table . '_' . $timestamp; +} + +function getProcName($proc = '') +{ + // A temporary stored procedure name with the '#' prefix will be + // automatically dropped once the connection is closed. Otherwise, + // the caller should take care of dropping the temp procedure afterwards. + + $timestamp = round(microtime(true)*1000); + + if (strlen($proc) == 0) { + $proc = 'php_test_proc'; + } + + return $proc . '_' . $timestamp; +} + +function PDOConnect($className, $serverName, $user, $pwd, $exitMode) +{ + require 'MsSetup.inc'; + $conn = null; + + try { + // simply use $databaseName from MsSetup.inc to facilitate testing in Azure, + // which does not support switching databases + $conn = new $className("sqlsrv:Server=$serverName;Database=$databaseName", $user, $pwd, $connectionOptions); + $conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM); + } catch (PDOException $e) { + $conn = null; + TraceEx("\nFailed to connect to $serverName: ".$e->getMessage(), $exitMode); + } + + return ($conn); +} + + +function ExecuteQuery($conn, $tsql) +{ + $stmt = null; + + if (IsPdoMode()) { // PDO + try { + $stmt = $conn->query($tsql); + } catch (PDOException $e) { + $stmt = null; + FatalError("Query execution failed for $tsql: ".$e->getMessage()); + } + } else { // PHP + $stmt = sqlsrv_query($conn, $tsql); + if ($stmt === false) { + FatalError("Query execution failed for $tsql"); + } + } + return ($stmt); +} + + +function PrepareQuery($conn, $tsql) +{ + $stmt = null; + + if (IsPdoMode()) { // PDO + try { + $stmt = $conn->prepare($tsql); + } catch (PDOException $e) { + $stmt = null; + FatalError("Query preparation failed for $tsql: ".$e->getMessage()); + } + } else { // PHP + $stmt = sqlsrv_prepare($conn, $tsql); + if ($stmt === false) { + FatalError("Query preparation failed for $tsql"); + } + } + + return ($stmt); +} + + +function ExecuteQueryEx($conn, $tsql, $modeDirect) +{ + $stmt = null; + + if ($modeDirect) { // direct execution + if (IsPdoMode()) { // PDO + try { + $stmt = $conn->query($tsql); + } catch (PDOException $e) { + $stmt = null; + } + } else { // PHP + $stmt = sqlsrv_query($conn, $tsql); + } + } else { + $stmt = PrepareQuery($conn, $tsql); + if (IsPdoMode()) { + $stmt->execute(); + } else { + sqlsrv_execute($stmt); + } + } + + return ($stmt); +} + + +function GetSqlType($k) +{ + switch ($k) { + case 1: return ("int"); + case 2: return ("tinyint"); + case 3: return ("smallint"); + case 4: return ("bigint"); + case 5: return ("bit"); + case 6: return ("float"); + case 7: return ("real"); + case 8: return ("decimal(28,4)"); + case 9: return ("numeric(32,4)"); + case 10: return ("money"); + case 11: return ("smallmoney"); + case 12: return ("char(512)"); + case 13: return ("varchar(512)"); + case 14: return ("varchar(max)"); + case 15: return ("nchar(512)"); + case 16: return ("nvarchar(512)"); + case 17: return ("nvarchar(max)"); + case 18: return ("text"); + case 19: return ("ntext"); + case 20: return ("binary(512)"); + case 21: return ("varbinary(512)"); + case 22: return ("varbinary(max)"); + case 23: return ("image"); + case 24: return ("uniqueidentifier"); + case 25: return ("datetime"); + case 26: return ("smalldatetime"); + case 27: return ("timestamp"); + case 28: return ("xml"); + default: break; + } + return ("udt"); +} + +function GetDriverType($k, $dataSize) +{ + switch ($k) { + case 1: return (SQLSRV_SQLTYPE_INT); + case 2: return (SQLSRV_SQLTYPE_TINYINT); + case 3: return (SQLSRV_SQLTYPE_SMALLINT); + case 4: return (SQLSRV_SQLTYPE_BIGINT); + case 5: return (SQLSRV_SQLTYPE_BIT); + case 6: return (SQLSRV_SQLTYPE_FLOAT); + case 7: return (SQLSRV_SQLTYPE_REAL); + case 8: return (SQLSRV_SQLTYPE_DECIMAL(28, 4)); + case 9: return (SQLSRV_SQLTYPE_NUMERIC(32, 4)); + case 10: return (SQLSRV_SQLTYPE_MONEY); + case 11: return (SQLSRV_SQLTYPE_SMALLMONEY); + case 12: return (SQLSRV_SQLTYPE_CHAR($dataSize)); + case 13: return (SQLSRV_SQLTYPE_VARCHAR($dataSize)); + case 14: return (SQLSRV_SQLTYPE_VARCHAR('max')); + case 15: return (SQLSRV_SQLTYPE_NCHAR($dataSize)); + case 16: return (SQLSRV_SQLTYPE_NVARCHAR($dataSize)); + case 17: return (SQLSRV_SQLTYPE_NVARCHAR('max')); + case 18: return (SQLSRV_SQLTYPE_TEXT); + case 19: return (SQLSRV_SQLTYPE_NTEXT); + case 20: return (SQLSRV_SQLTYPE_BINARY($dataSize)); + case 21: return (SQLSRV_SQLTYPE_VARBINARY($dataSize)); + case 22: return (SQLSRV_SQLTYPE_VARBINARY('max')); + case 23: return (SQLSRV_SQLTYPE_IMAGE); + case 24: return (SQLSRV_SQLTYPE_UNIQUEIDENTIFIER); + case 25: return (SQLSRV_SQLTYPE_DATETIME); + case 26: return (SQLSRV_SQLTYPE_SMALLDATETIME); + case 27: return (SQLSRV_SQLTYPE_TIMESTAMP); + case 28: return (SQLSRV_SQLTYPE_XML); + default: break; + } + return (SQLSRV_SQLTYPE_UDT); +} + +function IsStreamable($k) +{ + switch ($k) { + case 12: return (true); // nchar(512) + case 13: return (true); // varchar(512) + case 14: return (true); // varchar(max) + case 15: return (true); // nchar(512) + case 16: return (true); // nvarchar(512) + case 17: return (true); // nvarchar(max) + case 18: return (true); // text + case 19: return (true); // ntext + case 20: return (true); // binary + case 21: return (true); // varbinary(512) + case 22: return (true); // varbinary(max) + case 23: return (true); // image + case 28: return (true); // xml + default: break; + } + return (false); +} + +function IsNumeric($k) +{ + switch ($k) { + case 1: return (true); // int + case 2: return (true); // tinyint + case 3: return (true); // smallint + case 4: return (true); // bigint + case 5: return (true); // bit + case 6: return (true); // float + case 7: return (true); // real + case 8: return (true); // decimal(28,4) + case 9: return (true); // numeric(32,4) + case 10: return (true); // money + case 11: return (true); // smallmoney + default: break; + } + return (false); +} + +function IsChar($k) +{ + switch ($k) { + case 12: return (true); // nchar(512) + case 13: return (true); // varchar(512) + case 14: return (true); // varchar(max) + case 15: return (true); // nchar(512) + case 16: return (true); // nvarchar(512) + case 17: return (true); // nvarchar(max) + case 18: return (true); // text + case 19: return (true); // ntext + case 28: return (true); // xml + default: break; + } + return (false); +} + +function IsBinary($k) +{ + switch ($k) { + case 20: return (true); // binary + case 21: return (true); // varbinary(512) + case 22: return (true); // varbinary(max) + case 23: return (true); // image + default: break; + } + return (false); +} + +function IsDateTime($k) +{ + switch ($k) { + case 25: return (true); // datetime + case 26: return (true); // smalldatetime + case 27: return (true); // timestamp + default: break; + } + return (false); +} + +function IsUnicode($k) +{ + switch ($k) { + case 15: return (true); // nchar(512) + case 16: return (true); // nvarchar(512) + case 17: return (true); // nvarchar(max) + case 19: return (true); // ntext + default: break; + } + return (false); +} + +function IsUpdatable($k) +{ + switch ($k) { + case 27: return (false); // timestamp + default: break; + } + return (true); +} + +function IsLiteral($k) +{ + switch ($k) { + case 12: return (true); // nchar(512) + case 13: return (true); // varchar(512) + case 14: return (true); // varchar(max) + case 15: return (true); // nchar(512) + case 16: return (true); // nvarchar(512) + case 17: return (true); // nvarchar(max) + case 18: return (true); // text + case 19: return (true); // ntext + case 24: return (true); // uniqueidentifier + case 25: return (true); // datetime + case 26: return (true); // smalldatetime + case 28: return (true); // xml + default: break; + } + return (false); +} + +function GetMetadata($k, $info) +{ + if (strcasecmp($info, 'Name') == 0) { + return (getColName($k)); + } + if (strcasecmp($info, 'Size') == 0) { + return (getColSize($k)); + } + if (strcasecmp($info, 'Precision') == 0) { + return (getColPrecision($k)); + } + if (strcasecmp($info, 'Scale') == 0) { + return (getColScale($k)); + } + if (strcasecmp($info, 'Nullable') == 0) { + return (getColNullable($k)); + } + return (""); +} + +function GetColName($k) +{ + switch ($k) { + case 1: return ("c1_int"); + case 2: return ("c2_tinyint"); + case 3: return ("c3_smallint"); + case 4: return ("c4_bigint"); + case 5: return ("c5_bit"); + case 6: return ("c6_float"); + case 7: return ("c7_real"); + case 8: return ("c8_decimal"); + case 9: return ("c9_numeric"); + case 10: return ("c10_money"); + case 11: return ("c11_smallmoney"); + case 12: return ("c12_char"); + case 13: return ("c13_varchar"); + case 14: return ("c14_varchar_max"); + case 15: return ("c15_nchar"); + case 16: return ("c16_nvarchar"); + case 17: return ("c17_nvarchar_max"); + case 18: return ("c18_text"); + case 19: return ("c19_ntext"); + case 20: return ("c20_binary"); + case 21: return ("c21_varbinary"); + case 22: return ("c22_varbinary_max"); + case 23: return ("c23_image"); + case 24: return ("c24_uniqueidentifier"); + case 25: return ("c25_datetime"); + case 26: return ("c26_smalldatetime"); + case 27: return ("c27_timestamp"); + case 28: return ("c28_xml"); + default: break; + } + return (""); +} + + +function GetColSize($k) +{ + switch ($k) { + case 12: return ("512"); + case 13: return ("512"); + case 14: return ("0"); + case 15: return ("512"); + case 16: return ("512"); + case 17: return ("0"); + case 18: return ("2147483647"); + case 19: return ("1073741823"); + case 20: return ("512"); + case 21: return ("512"); + case 22: return ("0)"); + case 23: return ("2147483647"); + case 24: return ("36"); + //case 25: return ("23"); + //case 26: return ("16"); + case 27: return ("8"); + case 28: return ("0"); + default: break; + } + return (""); +} + +function GetColPrecision($k) +{ + switch ($k) { + case 1: return ("10"); + case 2: return ("3"); + case 3: return ("5"); + case 4: return ("19"); + case 5: return ("1"); + case 6: return ("53"); + case 7: return ("24"); + case 8: return ("28"); + case 9: return ("32"); + case 10: return ("19"); + case 11: return ("10"); + case 25: return ("23"); + case 26: return ("16"); + default: break; + } + return (""); +} + +function GetColScale($k) +{ + switch ($k) { + case 8: return ("4"); + case 9: return ("4"); + case 10: return ("4"); + case 11: return ("4"); + case 25: return ("3"); + case 26: return ("0"); + default: break; + } + return (""); +} + +function GetColNullable($k) +{ + return (IsUpdatable($k) ? "1" : "0"); +} + +function GetSampleData($k) +{ + switch ($k) { + case 1: // int + return ("123456789"); + + case 2: // tinyint + return ("234"); + + case 3: // smallint + return ("5678"); + + case 4: // bigint + return ("123456789987654321"); + + + case 5: // bit + return ("1"); + + case 6: // float + return ("123.456"); + + case 7: // real + return ("789.012"); + + case 8: // decimal + return ("12.34"); + + case 9: // numeric + return ("567.89"); + + case 10:// money + return ("321.54"); + + case 11:// smallmoney + return ("67.89"); + + case 12:// char + case 15:// nchar + return ("The quick brown fox jumps over the lazy dog"); + + case 13:// varchar + case 16:// nvarchar + return ("The quick brown fox jumps over the lazy dog 9876543210"); + + case 14:// varchar(max) + case 17:// nvarchar(max) + return ("The quick brown fox jumps over the lazy dog 0123456789"); + + case 18:// text + case 19:// ntext + return ("0123456789 The quick brown fox jumps over the lazy dog"); + + case 20:// binary + return ("0123456789"); + + case 21:// varbinary + return ("01234567899876543210"); + + case 22:// varbinary(max) + return ("98765432100123456789"); + + case 23:// image + return ("01234567899876543210"); + + case 24:// uniqueidentifier + return ("12345678-9012-3456-7890-123456789012"); + + case 25:// datetime + case 26:// smalldatetime + return (date("Y-m-d")); + + case 27:// timestamp + return (null); + + case 28:// xml + return ("The quick brown fox jumps over the lazy dog0123456789"); + + default: + break; + } + + return (null); +} + + +function CreateDB($conn, $dbName) +{ + Trace("Creating database $dbName ..."); + $tsql = "CREATE DATABASE [$dbName]"; + DropDB($conn, $dbName); + + if (IsPdoMode()) { + $outcome = $conn->exec($tsql); + if ($outcome === false) { + FatalError("Failed to create test database: $dbName"); + } + } else { + $stmt = sqlsrv_query($conn, $tsql); + if ($stmt === false) { + FatalError("Failed to create test database: $dbName"); + } + sqlsrv_free_stmt($stmt); + } + Trace(" completed successfully.\n"); +} + +function DropDB($conn, $dbName) +{ + $tsql = "DROP DATABASE [$dbName]"; + if (IsPdoMode()) { + $mode = $conn->getAttribute(PDO::ATTR_ERRMODE); + + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); + + $outcome = $conn->exec($tsql); + $conn->setAttribute(PDO::ATTR_ERRMODE, $mode); + } else { + $stmt = sqlsrv_query($conn, $tsql); + if ($stmt === false) { + } else { + sqlsrv_free_stmt($stmt); + } + } +} + +/* +function CreateTable($conn, $tableName) +{ + $dataType = "[c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_nchar] nchar(512), [c16_nvarchar] nvarchar(512), [c17_nvarchar_max] nvarchar(max), [c18_text] text, [c19_ntext] ntext, [c20_binary] binary(512), [c21_varbinary] varbinary(512), [c22_varbinary_max] varbinary(max), [c23_image] image, [c24_uniqueidentifier] uniqueidentifier, [c25_datetime] datetime, [c26_smalldatetime] smalldatetime, [c27_timestamp] timestamp, [c28_xml] xml"; + CreateTableEx($conn, $tableName, $dataType); + if (IsDaasMode()) + { + $colIndex = "[c1_int], [c2_tinyint], [c3_smallint], [c4_bigint], [c5_bit], [c6_float], [c7_real], [c8_decimal], [c9_numeric]"; + CreateTableIndex($conn, $tableName, $colIndex); + } +} +*/ +function CreateTableEx($conn, $tableName, $dataType) +{ + Trace("Creating table $tableName ..."); + $tsql = "CREATE TABLE [$tableName] ($dataType)"; + DropTable($conn, $tableName); + + if (IsPdoMode()) { + $outcome = $conn->exec($tsql); + if ($outcome === false) { + FatalError("Failed to create test table: $tsql"); + } + } else { + $stmt = sqlsrv_query($conn, $tsql); + if ($stmt === false) { + FatalError("Failed to create test table: $tsql"); + } + sqlsrv_free_stmt($stmt); + } + Trace(" completed successfully.\n"); +} + + +function CreateTableIndex($conn, $tableName, $colIndex) +{ + require 'MsSetup.inc'; + CreateTableIndexEx($conn, $tableName, $tableIndex, $colIndex); +} + + +function CreateTableIndexEx($conn, $tableName, $tableIndex, $colIndex) +{ + Trace("Creating table index for $tableName ..."); + $sqlIndex = "CREATE CLUSTERED INDEX [$tableIndex] ON [$tableName]($colIndex)"; + if (IsPdoMode()) { + $outcome = $conn->exec($sqlIndex); + if ($outcome === false) { + FatalError("Failed to create clustered index for test table: $sqlIndex"); + } + } else { + $stmt = sqlsrv_query($conn, $sqlIndex); + if ($stmt === false) { + FatalError("Failed to create clustered index for test table: $sqlIndex"); + } + sqlsrv_free_stmt($stmt); + } + Trace(" completed successfully.\n"); +} + +function CreateUniqueIndex($conn, $tableName, $colIndex) +{ + require 'MsSetup.inc'; + CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex); +} + +function CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex) +{ + Trace("Creating unique table index for $tableName ..."); + $sqlIndex = "CREATE UNIQUE INDEX [$tableIndex] ON [$tableName]($colIndex)"; + if (IsPdoMode()) { + $outcome = $conn->exec($sqlIndex); + if ($outcome === false) { + FatalError("Failed to create unique index for test table: $sqlIndex"); + } + } else { + $stmt = sqlsrv_query($conn, $sqlIndex); + if ($stmt === false) { + FatalError("Failed to create unique index for test table: $sqlIndex"); + } + sqlsrv_free_stmt($stmt); + } + Trace(" completed successfully.\n"); +} + +function dropTable($conn, $tableName) +{ + $tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName"; + if (IsPdoMode()) { + $mode = $conn->getAttribute(PDO::ATTR_ERRMODE); + + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); + + $outcome = $conn->exec($tsql); + $conn->setAttribute(PDO::ATTR_ERRMODE, $mode); + } else { + $stmt = sqlsrv_query($conn, $tsql); + if ($stmt === false) { + } else { + sqlsrv_free_stmt($stmt); + } + } +} + + +function SelectFromTable($conn, $tableName) +{ + return (SelectFromTableEx($conn, $tableName, null)); +} + +function SelectFromTableEx($conn, $tableName, $cond) +{ + if (($cond != null) && (strlen($cond) > 0)) { + return (SelectQuery($conn, "SELECT * FROM [$tableName] WHERE $cond")); + } else { + return (SelectQuery($conn, "SELECT * FROM [$tableName]")); + } +} + +function SelectQuery($conn, $query) +{ + return (SelectQueryEx($conn, $query, null)); +} + +function SelectQueryEx($conn, $query, $options) +{ + $numFields = 0; + if (IsPDOMode()) { + $stmt = ExecuteQuery($conn, $query); + $numFields = $stmt->columnCount(); + } else { + if ($options != null) { + $stmt = sqlsrv_query($conn, $query, null, $options); + } else { + $stmt = sqlsrv_query($conn, $query); + } + if ($stmt === false) { + FatalError("Failed to query test table"); + } + + $numFields = sqlsrv_num_fields($stmt); + } + if ($numFields <= 0) { + die("Unexpected number of fields: .$numFields"); + } + return ($stmt); +} + +function RowCount($stmt) +{ + $rowCount = 0; + if (IsPdoMode()) { + while ($stmt->fetchColumn()) { + $rowCount++; + } + } else { + while (sqlsrv_fetch($stmt)) { + $rowCount++; + } + } + return ($rowCount); +} + + +function NumRows($conn, $tableName) +{ + $stmt = SelectFromTable($conn, $tableName); + $rowCount = RowCount($stmt); + if (IsPdoMode()) { + $stmt = null; + } else { + sqlsrv_free_stmt($stmt); + } + + return ($rowCount); +} + + +function InsertQuery($tableName) +{ + include_once 'MsData_UTF8.inc'; + return (InsertQueryExUTF8($tableName, rand(1, 20))); +} + +function InsertRows($conn, $tableName, $rowCount) +{ + Trace("Inserting $rowCount rows into $tableName ..."); + $count = 0; + for ($i = 0; $i < $rowCount; $i++) { + if (InsertRow($conn, $tableName)) { + $count++; + } + } + Trace(" completed successfully.\n"); + if ($count != $rowCount) { + die("$count rows inserted instead of $rowCount\n"); + } + return ($count); +} + +function InsertRowsByRange($conn, $tableName, $minIndex, $maxIndex) +{ + $rowCount = $maxIndex - $minIndex + 1; + if ($rowCount > 0) { + Trace("Inserting $rowCount rows into $tableName ..."); + for ($i = $minIndex; $i <= $maxIndex; $i++) { + InsertRowByIndex($conn, $tableName, $i); + } + Trace(" completed successfully.\n"); + } +} +/* +function InsertRow($conn, $tableName) +{ + $tsql = InsertQuery($tableName); + $stmt = null; + + if (IsPdoMode()) + { + $stmt = $conn->exec($tsql); + } + else + { + $stmt = sqlsrv_query($conn, $tsql); + } + return (InsertCheck($stmt)); +} +*/ +function InsertRowEx($conn, $tableName, $dataCols, $dataValues, $dataOptions) +{ + $tsql = "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)"; + $stmt = null; + + if (IsPdoMode()) { + $stmt = $conn->exec($tsql); + } else { + $stmt = sqlsrv_query($conn, $tsql, $dataOptions); + } + return (InsertCheck($stmt)); +} + +function InsertRowByIndex($conn, $tableName, $index) +{ + $tsql = InsertQueryEx($tableName, $index); + $stmt = null; + + if (IsPdoMode()) { + $stmt = $conn->exec($tsql); + } else { + $stmt = sqlsrv_query($conn, $tsql); + } + return (InsertCheck($stmt)); +} + +function InsertStream($conn, $tableName, $dataCols, $dataValues, $dataOptions, $atExec) +{ + $tsql = "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)"; + $stmt = null; + + if (IsPdoMode()) { + $stmt = $conn->exec($tsql); + } else { + if ($atExec) { + $stmt = sqlsrv_query($conn, $tsql, $dataOptions, array('SendStreamParamsAtExec' => 1)); + } else { + $stmt = sqlsrv_query($conn, $tsql, $dataOptions); + if ($stmt) { + while (sqlsrv_send_stream_data($stmt)) { + } + } + } + } + + return (InsertCheck($stmt)); +} + + +function InsertCheck($stmt) +{ + $numRows = 0; + + if ($stmt === false) { + FatalError("Failed to insert row into test table"); + } + if (IsPdoMode()) { + $numRows = $stmt; + } else { + $numRows = sqlsrv_rows_affected($stmt); + sqlsrv_free_stmt($stmt); + } + if ($numRows != 1) { + die("Unexpected row count at insert: ".$numRows); + } + return (true); +} + +function GetInsertData($rowIndex, $colIndex, $skip) +{ + $query = InsertQueryEx("TestTable", $rowIndex); + $data = strstr($query, "(("); + $pos = 1; + if ($data === false) { + die("Failed to retrieve data on row $rowIndex"); + } + $data = substr($data, 2); + + while ($pos < ($colIndex - $skip)) { + $data = strstr($data, ", ("); + $pos++; + if ($data === false) { + die("Failed to retrieve data on row $rowIndex, column $pos"); + } + $data = substr($data, 3); + } + $pos = strpos($data, ")"); + if ($pos === false) { + die("Failed to isolate data on row $rowIndex, column $pos"); + } + $data = substr($data, 0, $pos); + if (strcasecmp($data, "null") == 0) { + $data = ""; + } + if (IsUnicode($colIndex)) { // N'data' + $data = substr($data, 2, strlen($data) - 3); + } elseif (IsLiteral($colIndex)) { // 'data' + $data = substr($data, 1, strlen($data) - 2); + } elseif (IsBinary($colIndex)) { // 0xdata + $data = substr($data, 2); + } + return (trim($data)); +} + +function CreateProc($conn, $procName, $procArgs, $procCode) +{ + DropProc($conn, $procName); + + if (!IsPdoMode()) { + $stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($procArgs) AS BEGIN $procCode END"); + if ($stmt === false) { + FatalError("Failed to create test procedure"); + } + sqlsrv_free_stmt($stmt); + } else { + $stmt = $conn->query("CREATE PROC [$procName] ($procArgs) AS BEGIN $procCode END"); + } +} + +function dropProc($conn, $procName) +{ + if (!IsPdoMode()) { + $stmt = sqlsrv_query($conn, "DROP PROC [$procName]"); + sqlsrv_free_stmt($stmt); + } else { + $query = "IF OBJECT_ID('[$procName]', 'P') IS NOT NULL DROP PROCEDURE [$procName]"; + $stmt = $conn->query($query); + } +} + +function CallProc($conn, $procName, $procArgs, $procValues) +{ + $stmt = CallProcEx($conn, $procName, "", $procArgs, $procValues); + sqlsrv_free_stmt($stmt); +} + +function CallProcEx($conn, $procName, $procPrefix, $procArgs, $procValues) +{ + $stmt = sqlsrv_query($conn, "{ $procPrefix CALL [$procName] ($procArgs)}", $procValues); + if ($stmt === false) { + FatalError("Failed to call test procedure"); + } + return ($stmt); +} + + +function CreateFunc($conn, $funcName, $funcArgs, $retType, $funcCode) +{ + DropFunc($conn, $funcName); + $stmt = sqlsrv_query($conn, "CREATE FUNCTION [$funcName] ($funcArgs) RETURNS $retType AS BEGIN $funcCode END"); + if ($stmt === false) { + FatalError("Failed to create test function"); + } + sqlsrv_free_stmt($stmt); +} + +function DropFunc($conn, $funcName) +{ + $stmt = sqlsrv_query($conn, "DROP FUNCTION [$funcName]"); + if ($stmt === false) { + } else { + sqlsrv_free_stmt($stmt); + } +} + + +function CallFunc($conn, $funcName, $funcArgs, $funcValues) +{ + $stmt = sqlsrv_query($conn, "{ ? = CALL [$funcName]($funcArgs)}", $funcValues); + if ($stmt === false) { + FatalError("Failed to call test function"); + } + sqlsrv_free_stmt($stmt); +} + +function handle_errors() +{ + $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); + $count = count($errors); + if ($count == 0) { + $errors = sqlsrv_errors(SQLSRV_ERR_ALL); + $count = count($errors); + } + if ($count > 0) { + for ($i = 0; $i < $count; $i++) { + Trace($errors[$i]['message']."\n"); + } + } +} + +function str2hex($dataIn) +{ + $dataOut = ""; + $len = strlen($dataIn); + for ($i = 0; $i < $len; $i++) { + $ch = strtoupper(substr($dataIn, $i, 1)); + if ($ch == "A") { + $dataOut = $dataOut."41"; + } elseif ($ch == "B") { + $dataOut = $dataOut."42"; + } elseif ($ch == "C") { + $dataOut = $dataOut."43"; + } elseif ($ch == "D") { + $dataOut = $dataOut."44"; + } elseif ($ch == "E") { + $dataOut = $dataOut."45"; + } elseif ($ch == "F") { + $dataOut = $dataOut."46"; + } else { + $dataOut = $dataOut."3".$ch; + } + } + return ($dataOut); +} + +function PhpVersionComponents(&$major, &$minor, &$sub) +{ + $str_version = phpversion(); + + $major = strtok($str_version, "."); + $minor = strtok("."); + $sub = strtok("."); +} diff --git a/test/functional/pdo_sqlsrv/pdo_002_connect_app.phpt b/test/functional/pdo_sqlsrv/pdo_002_connect_app.phpt index c385a77bd..5eb0ae194 100644 --- a/test/functional/pdo_sqlsrv/pdo_002_connect_app.phpt +++ b/test/functional/pdo_sqlsrv/pdo_002_connect_app.phpt @@ -1,32 +1,37 @@ --TEST-- Connection option APP name unicode --SKIPIF-- - + --FILE-- query($query); -while ( $row = $stmt->fetch(PDO::FETCH_NUM) ){ - echo $row[0]."\n"; -} + $stmt = $conn->query($query); + while ($row = $stmt->fetch(PDO::FETCH_NUM)) { + echo $row[0]."\n"; + } -$stmt = $conn->query($query); -while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ){ - echo $row['']."\n"; -} + $stmt = $conn->query($query); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + echo $row['']."\n"; + } -// Free the connection -$conn=null; -echo "Done" + // Free the connection and statement + unset($stmt); + unset($conn); + echo "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECTREGEX-- diff --git a/test/functional/pdo_sqlsrv/pdo_011_quote.phpt b/test/functional/pdo_sqlsrv/pdo_011_quote.phpt index abfe88165..d0cb320a5 100644 --- a/test/functional/pdo_sqlsrv/pdo_011_quote.phpt +++ b/test/functional/pdo_sqlsrv/pdo_011_quote.phpt @@ -1,50 +1,54 @@ --TEST-- Insert with quoted parameters --SKIPIF-- - + --FILE-- quote( $param ); - -// Create a temporary table -$tableName = '#tmpTable'; -$query = "CREATE TABLE $tableName (col1 VARCHAR(10), col2 VARCHAR(20))"; -$stmt = $conn->exec($query); -if( $stmt === false ) { die(); } - -// Inserd data -$query = "INSERT INTO $tableName VALUES( ?, '1' )"; -$stmt = $conn->prepare( $query ); -$stmt->execute(array($param)); - -// Inserd data -$query = "INSERT INTO $tableName VALUES( ?, ? )"; -$stmt = $conn->prepare( $query ); -$stmt->execute(array($param, $param2)); - -// Query -$query = "SELECT * FROM $tableName"; -$stmt = $conn->query($query); -while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){ - print_r( $row['col1'] ." was inserted\n" ); +require_once("MsCommon_mid-refactor.inc"); + +try { + // Connect + $conn = connect(); + + $param = 'a \' g'; + $param2 = $conn->quote($param); + + // Create a temporary table + $tableName = getTableName(); + $stmt = createTable($conn, $tableName, array("col1" => "varchar(10)", "col2" => "varchar(20)")); + + // Insert data + if (!isColEncrypted()) { + $query = "INSERT INTO $tableName VALUES(?, '1')"; + $stmt = $conn->prepare($query); + $stmt->execute(array($param)); + } else { + insertRow($conn, $tableName, array("col1" => $param, "col2" => "1"), "prepareExecuteBind"); + } + + // Insert data + insertRow($conn, $tableName, array("col1" => $param, "col2" => $param2), "prepareExecuteBind"); + + // Query + $query = "SELECT * FROM $tableName"; + $stmt = $conn->query($query); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + print_r($row['col1'] ." was inserted\n"); + } + + // Revert the inserts + $query = "delete from $tableName where col1 = ?"; + $stmt = $conn->prepare($query); + $stmt->execute(array($param)); + + //free the statement and connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -// Revert the inserts -$query = "delete from $tableName where col1 = ?"; -$stmt = $conn->prepare( $query ); -$stmt->execute(array($param)); - -//free the statement and connection -$stmt=null; -$conn=null; ?> --EXPECT-- a ' g was inserted -a ' g was inserted - +a ' g was inserted \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_012_bind_param.phpt b/test/functional/pdo_sqlsrv/pdo_012_bind_param.phpt index bb28a2c71..bc82a5723 100644 --- a/test/functional/pdo_sqlsrv/pdo_012_bind_param.phpt +++ b/test/functional/pdo_sqlsrv/pdo_012_bind_param.phpt @@ -1,24 +1,28 @@ --TEST-- uses an input/output parameter --SKIPIF-- - + --FILE-- query("IF OBJECT_ID('dbo.sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE dbo.sp_ReverseString"); -$dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)"); -$stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?"); -$string = "123456789"; -$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048); -$stmt->execute(); -print "Result: ".$string."\n"; // Expect 987654321 + dropProc($dbh, "sp_ReverseString"); + $dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)"); + $stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?"); + $string = "123456789"; + $stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048); + $stmt->execute(); + print "Result: ".$string."\n"; // Expect 987654321 -//free the statement and connection -$stmt = null; -$dbh = null; + //free the statement and connection + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- Result: 987654321 diff --git a/test/functional/pdo_sqlsrv/pdo_013_row_count.phpt b/test/functional/pdo_sqlsrv/pdo_013_row_count.phpt index 54014382a..f09357384 100644 --- a/test/functional/pdo_sqlsrv/pdo_013_row_count.phpt +++ b/test/functional/pdo_sqlsrv/pdo_013_row_count.phpt @@ -1,48 +1,86 @@ --TEST-- Number of rows in a result set --SKIPIF-- - + --FILE-- exec("CREATE TABLE $tableName (c1 VARCHAR(32))"); -$stmt=null; + // Create table + $tableName = getTableName(); + createTable($conn, $tableName, array("c1" => "varchar(32)")); -// Insert data -$query = "INSERT INTO $tableName VALUES ('Salmon'),('Butterfish'),('Cod'),('NULL'),('Crab')"; -$stmt = $conn->query($query); -$res[] = $stmt->rowCount(); + if (!isColEncrypted()) { + // Insert data + $query = "INSERT INTO $tableName VALUES ('Salmon'),('Butterfish'),('Cod'),('NULL'),('Crab')"; + $stmt = $conn->query($query); + $res[] = $stmt->rowCount(); + + // Update data + $query = "UPDATE $tableName SET c1='Salmon' WHERE c1='Cod'"; + $stmt = $conn->query($query); + $res[] = $stmt->rowCount(); + + // Update data + $query = "UPDATE $tableName SET c1='Salmon' WHERE c1='NULL'"; + $stmt = $conn->query($query); + $res[] = $stmt->rowCount(); -// Update data -$query = "UPDATE $tableName SET c1='Salmon' WHERE c1='Cod'"; -$stmt = $conn->query($query); -$res[] = $stmt->rowCount(); + // Update data + $query = "UPDATE $tableName SET c1='Salmon' WHERE c1='NO_NAME'"; + $stmt = $conn->query($query); + $res[] = $stmt->rowCount(); -// Update data -$query = "UPDATE $tableName SET c1='Salmon' WHERE c1='NULL'"; -$stmt = $conn->query($query); -$res[] = $stmt->rowCount(); + // Update data + $query = "UPDATE $tableName SET c1='N/A'"; + $stmt = $conn->query($query); + $res[] = $stmt->rowCount(); + + unset($stmt); + } else { + // Insert data + // bind parameter does not work with inserting multiple rows in one SQL command, thus need to insert each row separately + $query = "INSERT INTO $tableName VALUES (?)"; + $stmt = $conn->prepare($query); + $params = array("Salmon", "Butterfish", "Cod", "NULL", "Crab"); + foreach ($params as $param) { + $stmt->execute(array($param)); + } + $res[] = count($params); + + // Update data + $query = "UPDATE $tableName SET c1=? WHERE c1=?"; + $stmt = $conn->prepare($query); + $stmt->execute(array("Salmon", "Cod")); + $res[] = $stmt->rowCount(); + + // Update data + $stmt->execute(array("Salmon", "NULL")); + $res[] = $stmt->rowCount(); + + // Update data + $stmt->execute(array("Salmon", "NO_NAME")); + $res[] = $stmt->rowCount(); + + $query = "UPDATE $tableName SET c1=?"; + $stmt = $conn->prepare($query); + $stmt->execute(array("N/A")); + $res[] = $stmt->rowCount(); + + unset($stmt); + } -// Update data -$query = "UPDATE $tableName SET c1='Salmon' WHERE c1='NO_NAME'"; -$stmt = $conn->query($query); -$res[] = $stmt->rowCount(); + print_r($res); -// Update data -$query = "UPDATE $tableName SET c1='N/A'"; -$stmt = $conn->query($query); -$res[] = $stmt->rowCount(); - -print_r($res); - -$stmt=null; -$conn=null; -print "Done" + dropTable($conn, $tableName); + unset($conn); + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- Array diff --git a/test/functional/pdo_sqlsrv/pdo_014_integer_custom_formats.phpt b/test/functional/pdo_sqlsrv/pdo_014_integer_custom_formats.phpt index a5983666d..0ea34e18d 100644 --- a/test/functional/pdo_sqlsrv/pdo_014_integer_custom_formats.phpt +++ b/test/functional/pdo_sqlsrv/pdo_014_integer_custom_formats.phpt @@ -1,47 +1,58 @@ --TEST-- Number MAX_INT to string with custom formats --SKIPIF-- - + --FILE-- exec($query); - -// Query number with custom format -$query ="SELECT CAST($sample as varchar) + '.00'"; -$stmt = $conn->query($query); -$data = $stmt->fetchColumn(); -var_dump ($data); - -// Insert data using bind parameters -$query = "INSERT INTO $tableName VALUES(:p0)"; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); - -// Fetching. Prepare with client buffered cursor -$query = "SELECT TOP 1 cast(col1 as varchar) + '.00 EUR' FROM $tableName"; -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//Free the statement and connection -$stmt = null; -$conn = null; - -print "Done"; +require_once("MsCommon_mid-refactor.inc"); + +try{ + /* Sample number MAX_INT */ + $sample = 2*(2**30-1)+1; + var_dump ($sample); + + /* Connect */ + $conn = connect(); + + // Create table + $tableName = 'testCustomFormats'; + createTable($conn, $tableName, array("col1" => "int")); + + // Query number with custom format + $query = "SELECT CAST($sample as varchar) + '.00'"; + $stmt = $conn->query($query); + $data = $stmt->fetchColumn(); + var_dump($data); + + // Insert data using bind parameters + $query = "INSERT INTO $tableName VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); + + // Fetching. Prepare with client buffered cursor + if (!isColEncrypted()) + $query = "SELECT TOP 1 cast(col1 as varchar) + '.00 EUR' FROM $tableName"; + else + // cannot explicitly cast data to another type from an encrypted column + $query = "SELECT TOP 1 col1 FROM $tableName"; + + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + if (isColEncrypted()) + $value .= ".00 EUR"; + var_dump($value); + + //Free the statement and connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_015_integer_custom_formats_pooling.phpt b/test/functional/pdo_sqlsrv/pdo_015_integer_custom_formats_pooling.phpt index 63ba3a597..ec43ce5d6 100644 --- a/test/functional/pdo_sqlsrv/pdo_015_integer_custom_formats_pooling.phpt +++ b/test/functional/pdo_sqlsrv/pdo_015_integer_custom_formats_pooling.phpt @@ -1,53 +1,66 @@ --TEST-- Number MAX_INT to string with custom formats, see pdo_014. Pooling enabled. --SKIPIF-- - + --FILE-- query("select 1"); -$conn0 = null; - -/* Connect */ -$conn = new PDO("sqlsrv:server=$server;database=$databaseName;ConnectionPooling=$pooling", $uid, $pwd); - -// Create a temporary table -$tableName = '#testFormats'; -$query = "CREATE TABLE $tableName (col1 INT)"; -$stmt = $conn->exec($query); - -// Query number with custom format -$query ="SELECT CAST($sample as varchar) + '.00'"; -$stmt = $conn->query($query); -$data = $stmt->fetchColumn(); -var_dump ($data); - -// Insert data using bind parameters -$query = "INSERT INTO $tableName VALUES(:p0)"; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); - -// Fetching. Prepare with client buffered cursor -$query = "SELECT TOP 1 cast(col1 as varchar) + '.00 EUR' FROM $tableName"; -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//Free the statement and connection -$stmt = null; -$conn = null; - -print "Done"; +require_once("MsCommon_mid-refactor.inc"); + +try { + $pooling = true; + + /* Sample number MAX_INT */ + $sample = 2*(2**30-1)+1; + + /* Connect + create a new pool */ + $conn0 = connect("ConnectionPooling=$pooling"); + $conn0->query("select 1"); + unset($conn0); + + /* Connect */ + $conn = connect("ConnectionPooling=$pooling"); + + // Create a temporary table + $tableName = 'testFormats'; + createTable($conn, $tableName, array("col1" => "int")); + + // Query number with custom format + $query = "SELECT CAST($sample as varchar) + '.00'"; + $stmt = $conn->query($query); + $data = $stmt->fetchColumn(); + var_dump($data); + + // Insert data using bind parameters + $query = "INSERT INTO $tableName VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); + + // Fetching. Prepare with client buffered cursor + if (!isColEncrypted()) { + $query = "SELECT TOP 1 cast(col1 as varchar) + '.00 EUR' FROM $tableName"; + } else { + // cannot explicitly cast data to another type from an encrypted column + $query = "SELECT TOP 1 col1 FROM $tableName"; + } + + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + if (isColEncrypted()) { + $value .= ".00 EUR"; + } + var_dump($value); + + //Free the statement and connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_016.phpt b/test/functional/pdo_sqlsrv/pdo_016.phpt index f8d835291..d4616a9eb 100644 --- a/test/functional/pdo_sqlsrv/pdo_016.phpt +++ b/test/functional/pdo_sqlsrv/pdo_016.phpt @@ -1,41 +1,44 @@ --TEST-- Bind integer parameters; allow fetch numeric types. --SKIPIF-- - + --FILE-- exec($sql); - -// Insert data using bind parameters -$sql = "INSERT INTO $tableName VALUES (:num1, :num2)"; -$stmt = $conn->prepare($sql); -$stmt->bindParam(':num1', $sample[0], PDO::PARAM_INT); -$stmt->bindParam(':num2', $sample[1], PDO::PARAM_INT); -$stmt->execute(); - -// Fetch, get data -$sql = "SELECT * FROM $tableName"; -$stmt = $conn->query($sql); -$row = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($row); - -// Close connection -$stmt = null; -$conn = null; - -print "Done"; +require_once("MsCommon_mid-refactor.inc"); + +try { + /* Sample numbers MIN_INT, MAX_INT */ + $sample = array(-2**31, 2**31-1); + + /* Connect */ + $conn = connect('', array(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => TRUE)); + + // Create table + $tableName = 'testPDO016'; + createTable($conn, $tableName, array("c1" => "int", "c2" => "int")); + + // Insert data using bind parameters + $sql = "INSERT INTO $tableName VALUES (:num1, :num2)"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':num1', $sample[0], PDO::PARAM_INT); + $stmt->bindParam(':num2', $sample[1], PDO::PARAM_INT); + $stmt->execute(); + + // Fetch, get data + $sql = "SELECT * FROM $tableName"; + $stmt = $conn->query($sql); + $row = $stmt->fetch(PDO::FETCH_NUM); + var_dump($row); + + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_017.phpt b/test/functional/pdo_sqlsrv/pdo_017.phpt index a745b8661..69a84a50a 100644 --- a/test/functional/pdo_sqlsrv/pdo_017.phpt +++ b/test/functional/pdo_sqlsrv/pdo_017.phpt @@ -1,40 +1,51 @@ --TEST-- Fetch string with new line and tab characters --SKIPIF-- - + --FILE-- exec($sql); + // Create table + $tableName = 'pdo_017'; + createTable($conn, $tableName, array("c1" => "varchar(32)", "c2" => "char(32)", "c3" => "nvarchar(32)", "c4" => "nchar(32)")); -// Bind parameters and insert data -$sql = "INSERT INTO $tableName VALUES (:val1, :val2, :val3, :val4)"; -$value = "I USE\nMSPHPSQL\tDRIVERS WITH PHP7"; -$stmt = $conn->prepare($sql); -$stmt->bindParam(':val1', $value); -$stmt->bindParam(':val2', $value); -$stmt->bindParam(':val3', $value); -$stmt->bindParam(':val4', $value); -$stmt->execute(); + // Bind parameters and insert data + $sql = "INSERT INTO $tableName VALUES (:val1, :val2, :val3, :val4)"; + $value = "I USE\nMSPHPSQL\tDRIVERS WITH PHP7"; + $stmt = $conn->prepare($sql); + $stmt->bindParam(':val1', $value); + $stmt->bindParam(':val2', $value); + $stmt->bindParam(':val3', $value); + $stmt->bindParam(':val4', $value); + $stmt->execute(); -// Get data -$sql = "SELECT UPPER(c1) AS VARCHAR, UPPER(c2) AS CHAR, - UPPER(c3) AS NVARCHAR, UPPER(c4) AS NCHAR FROM $tableName"; -$stmt = $conn->query($sql); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -var_dump($row); + // Get data + if (!isColEncrypted()) { + $sql = "SELECT UPPER(c1) AS VARCHAR, UPPER(c2) AS CHAR, + UPPER(c3) AS NVARCHAR, UPPER(c4) AS NCHAR FROM $tableName"; + $stmt = $conn->query($sql); + } else { + // upper function is not supported in Always Encrypted + $sql = "SELECT c1 AS VARCHAR, c2 AS CHAR, + c3 AS NVARCHAR, c4 AS NCHAR FROM $tableName"; + $stmt = $conn->query($sql); + } + $row = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($row); -// Close connection -$stmt=null; -$conn=null; -print "Done" + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_018_next_result_set.phpt b/test/functional/pdo_sqlsrv/pdo_018_next_result_set.phpt index db95b6150..b8849aa78 100644 --- a/test/functional/pdo_sqlsrv/pdo_018_next_result_set.phpt +++ b/test/functional/pdo_sqlsrv/pdo_018_next_result_set.phpt @@ -1,56 +1,91 @@ --TEST-- Moves the cursor to the next result set --SKIPIF-- - + --FILE-- exec($sql); - -// Insert data using bind parameters -$sql = "INSERT INTO $tableName VALUES (?,?)"; -for($t=200; $t<220; $t++) { - $stmt = $conn->prepare($sql); - $stmt->bindParam(1, $t); - $ts = sha1($t); - $stmt->bindParam(2, $ts); - $stmt->execute(); -} +require_once("MsCommon_mid-refactor.inc"); + +try { + /* Connect */ + $conn = connect(); + + // Create table + $tableName = 'testResultSet'; + createTable($conn, $tableName, array("c1" => "int", "c2" => "varchar(40)")); -// Fetch, get data and move the cursor to the next result set -$sql = "SELECT * from $tableName WHERE c1 = '204' OR c1 = '210'; - SELECT Top 3 * FROM $tableName ORDER BY c1 DESC"; -$stmt = $conn->query($sql); -$data1 = $stmt->fetchAll(PDO::FETCH_ASSOC); -$stmt->nextRowset(); -$data2 = $stmt->fetchAll(PDO::FETCH_NUM); + // Insert data using bind parameters + $sql = "INSERT INTO $tableName VALUES (?,?)"; + $inputs = array(); + for ($t=200; $t<220; $t++) { + $stmt = $conn->prepare($sql); + $stmt->bindParam(1, $t); + $ts = sha1($t); + $stmt->bindParam(2, $ts); + $stmt->execute(); + array_push($inputs, array($t, $ts)); + } -// Array: FETCH_ASSOC -foreach ($data1 as $a) -echo $a['c1'] . "|" . $a['c2'] . "\n"; + // Fetch, get data and move the cursor to the next result set + if (!isColEncrypted()) { + $sql = "SELECT * from $tableName WHERE c1 = '204' OR c1 = '210'; + SELECT Top 3 * FROM $tableName ORDER BY c1 DESC"; + $stmt = $conn->query($sql); + $expected = array(array(219, sha1(219)), array(218, sha1(218)), array(217, sha1(217))); + } else { + // ORDER BY does not work for encrypted columns. In + //https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine, + //the Feature Details section states that operators such as greater/less than does not work for encrypted columns, and ORDER BY is based on that + $sql = "SELECT * FROM $tableName WHERE c1 = ? OR c1 = ?; + SELECT Top 3 * FROM $tableName"; + $stmt = $conn->prepare($sql); + $stmt->execute(array('204', '210')); + } + $data1 = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->nextRowset(); + $data2 = $stmt->fetchAll(PDO::FETCH_NUM); -// Array: FETCH_NUM -foreach ($data2 as $a) -echo $a[0] . "|" . $a[1] . "\n"; + // Array: FETCH_ASSOC + foreach ($data1 as $a) { + echo $a['c1'] . "|" . $a['c2'] . "\n"; + } -// Close connection -$stmt = null; -$conn = null; + // Array: FETCH_NUM + if (!isColEncrypted()) { + $i = 0; + foreach ($data2 as $a) { + if ($expected[$i][0] != $a[0] || $expected[$i][1] != $a[1]) { + echo "Values in row $i does not match the expected output.\n"; + } + $i++; + } + } else { + // don't know the order of the result set; simply compare to see if the result set is in $inputs + foreach ($data2 as $a) { + $match = false; + foreach ($inputs as $input) { + if ($a[0] == $input[0] && $a[1] == $input[1]) { + $match = true; + } + } + if (!$match) { + echo "Value fetched for $a[0] is incorrect.\n"; + } + } + } -print "Done"; + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($con); + + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- 204|1cc641954099c249e0e4ef0402da3fd0364d95f0 210|135debd4837026bf06c7bfc5d1e0c6a31611af1d -219|c0ba17c23a26ff8c314478bc69f30963a6e4a754 -218|3d5bdf107de596ce77e8ce48a61b585f52bbb61d -217|49e3d046636e06b2d82ee046db8e6eb9a2e11e16 Done diff --git a/test/functional/pdo_sqlsrv/pdo_019_next_result_set_pooling.phpt b/test/functional/pdo_sqlsrv/pdo_019_next_result_set_pooling.phpt index 0213325bf..6f36216c5 100644 --- a/test/functional/pdo_sqlsrv/pdo_019_next_result_set_pooling.phpt +++ b/test/functional/pdo_sqlsrv/pdo_019_next_result_set_pooling.phpt @@ -1,61 +1,96 @@ --TEST-- Moves the cursor to the next result set with pooling enabled --SKIPIF-- - + --FILE-- query("SELECT 1"); -$conn0 = null; - -// Connect -$conn = new PDO("sqlsrv:server=$server; database=$databaseName;ConnectionPooling=1", $uid, $pwd); - -// Create table -$tableName = '#nextResultPooling'; -$sql = "CREATE TABLE $tableName (c1 INT, c2 XML)"; -$stmt = $conn->exec($sql); - -// Insert data using bind parameters -$sql = "INSERT INTO $tableName VALUES (?,?)"; -for($t=200; $t<220; $t++) { - $stmt = $conn->prepare($sql); - $stmt->bindParam(1, $t); - $ts = substr(sha1($t),0,5); - $stmt->bindParam(2, $ts); - $stmt->execute(); -} +require_once("MsCommon_mid-refactor.inc"); + +try { + // Create a pool + $conn0 = connect("ConnectionPooling=1"); + $conn0->query("SELECT 1"); + unset($conn0); + + // Connect + $conn = connect("ConnectionPooling=1"); -// Fetch, get data and move the cursor to the next result set -$sql = "SELECT * from $tableName WHERE c1 = '204' OR c1 = '210'; - SELECT Top 3 * FROM $tableName ORDER BY c1 DESC"; -$stmt = $conn->query($sql); -$data1 = $stmt->fetchAll(PDO::FETCH_ASSOC); -$stmt->nextRowset(); -$data2 = $stmt->fetchAll(PDO::FETCH_NUM); + // Create table + $tableName = 'nextResultPooling'; + createTable($conn, $tableName, array("c1" => "int", "c2" => "varchar(10)")); -// Array: FETCH_ASSOC -foreach ($data1 as $a) -echo $a['c1']."|".$a['c2']."\n"; + // Insert data using bind parameters + $sql = "INSERT INTO $tableName VALUES (?,?)"; + $inputs = array(); + for ($t=200; $t<220; $t++) { + $stmt = $conn->prepare($sql); + $stmt->bindParam(1, $t); + $ts = substr(sha1($t), 0, 5); + $stmt->bindParam(2, $ts); + $stmt->execute(); + array_push($inputs, array($t, $ts)); + } -// Array: FETCH_NUM -foreach ($data2 as $a) -echo $a[0] . "|".$a[1]."\n"; + // Fetch, get data and move the cursor to the next result set + if (!isColEncrypted()) { + $sql = "SELECT * from $tableName WHERE c1 = '204' OR c1 = '210'; + SELECT Top 3 * FROM $tableName ORDER BY c1 DESC"; + $stmt = $conn->query($sql); + $expected = array(array(219, substr(sha1(219), 0, 5)), array(218, substr(sha1(218), 0, 5)), array(217, substr(sha1(217), 0, 5))); + } else { + // ORDER BY does not work for encrypted columns. In + //https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine, + //the Feature Details section states that operators such as greater/less than does not work for encrypted columns, and ORDER BY is based on that + $sql = "SELECT * FROM $tableName WHERE c1 = ? OR c1 = ?; + SELECT Top 3 * FROM $tableName"; + $stmt = $conn->prepare($sql); + $stmt->execute(array('204', '210')); + } + $data1 = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->nextRowset(); + $data2 = $stmt->fetchAll(PDO::FETCH_NUM); -// Close connection -$stmt = null; -$conn = null; + // Array: FETCH_ASSOC + foreach ($data1 as $a) { + echo $a['c1']."|".$a['c2']."\n"; + } -print "Done"; + // Array: FETCH_NUM + if (!isColEncrypted()) { + $i = 0; + foreach ($data2 as $a) { + if ($expected[$i][0] != $a[0] || $expected[$i][1] != $a[1]) { + echo "Values in row $i does not match the expected output.\n"; + } + $i++; + } + } else { + // don't know the order of the result set; simply compare to see if the result set is in $inputs + foreach ($data2 as $a) { + $match = false; + foreach ($inputs as $input) { + if ($a[0] == $input[0] && $a[1] == $input[1]) { + $match = true; + } + } + if (!$match) { + echo "Value fetched for $a[0] is incorrect.\n"; + } + } + } + + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- 204|1cc64 210|135de -219|c0ba1 -218|3d5bd -217|49e3d Done diff --git a/test/functional/pdo_sqlsrv/pdo_020_bind_params_array.phpt b/test/functional/pdo_sqlsrv/pdo_020_bind_params_array.phpt index e552ccf75..577ec0c53 100644 --- a/test/functional/pdo_sqlsrv/pdo_020_bind_params_array.phpt +++ b/test/functional/pdo_sqlsrv/pdo_020_bind_params_array.phpt @@ -1,50 +1,53 @@ --TEST-- Bind parameters using an array --SKIPIF-- - + --FILE-- exec($sql); - -// Insert data using bind parameters -$sql = "INSERT INTO $tableName VALUES (?,?)"; -for($t=100; $t<103; $t++) { - $stmt = $conn->prepare($sql); - $ts = substr(sha1($t),0,5); - $params = array($t,$ts); - $stmt->execute($params); +require_once("MsCommon_mid-refactor.inc"); + +try { + // Connect + $conn = connect(); + + // Create table + $tableName = 'bindParams'; + $sql = "CREATE TABLE $tableName (ID TINYINT, SID CHAR(5))"; + $stmt = $conn->exec($sql); + + createTable($conn, $tableName, array("ID" => "tinyint", "SID" => "char(5)")); + + // Insert data using bind parameters + $sql = "INSERT INTO $tableName VALUES (?,?)"; + for ($t=100; $t<103; $t++) { + $stmt = $conn->prepare($sql); + $ts = substr(sha1($t),0,5); + $params = array($t,$ts); + $stmt->execute($params); + } + + // Query, but do not fetch + $sql = "SELECT * from $tableName"; + $stmt = $conn->query($sql); + + // Insert duplicate row, ID = 100 + $t = 100; + insertRow($conn, $tableName, array( "ID" => $t, "SID" => substr( sha1( $t ), 0, 5 )), "prepareExecuteBind"); + + // Fetch. The result set should not contain duplicates + $data = $stmt->fetchAll(); + foreach ($data as $a) + echo $a['ID'] . "|" . $a['SID'] . "\n"; + + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -// Query, but do not fetch -$sql = "SELECT * from $tableName"; -$stmt = $conn->query($sql); - -// Insert duplicate row, ID = 100 -$t = 100; -$sql = "INSERT INTO $tableName VALUES (?,?)"; -$stmt1 = $conn->prepare($sql); -$ts = substr(sha1($t),0,5); -$params = array($t,$ts); -$stmt1->execute($params); - -// Fetch. The result set should not contain duplicates -$data = $stmt->fetchAll(); -foreach ($data as $a) -echo $a['ID'] . "|" . $a['SID'] . "\n"; - -// Close connection -$stmt = null; -$conn = null; - -print "Done"; ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_021_extended_ascii.phpt b/test/functional/pdo_sqlsrv/pdo_021_extended_ascii.phpt index 78d1e618f..6e80c2bf8 100644 --- a/test/functional/pdo_sqlsrv/pdo_021_extended_ascii.phpt +++ b/test/functional/pdo_sqlsrv/pdo_021_extended_ascii.phpt @@ -1,45 +1,47 @@ --TEST-- Bind parameters VARCHAR(n) extended ASCII --SKIPIF-- - + --FILE-- exec($sql); + // Create table + $tableName = 'extendedAscii'; + createTable( $conn, $tableName, array("code" => "char(2)", "city" => "varchar(32)")); -// Insert data using bind parameters -$sql = "INSERT INTO $tableName VALUES (?,?)"; + // Insert data using bind parameters + $sql = "INSERT INTO $tableName VALUES (?,?)"; -// First row -$stmt = $conn->prepare($sql); -$params = array("FI","Järvenpää"); -$stmt->execute($params); + // First row + $stmt = $conn->prepare($sql); + $params = array("FI","Järvenpää"); + $stmt->execute($params); -// Second row -$params = array("DE","München"); -$stmt->execute($params); + // Second row + $params = array("DE","München"); + $stmt->execute($params); -// Query, fetch -$sql = "SELECT * from $tableName"; -$stmt = $conn->query($sql); -$data = $stmt->fetchAll(); + // Query, fetch + $data = selectAll($conn, $tableName); -// Print out -foreach ($data as $a) -echo $a[0] . "|" . $a[1] . "\n"; + // Print out + foreach ($data as $a) + echo $a[0] . "|" . $a[1] . "\n"; -// Close connection -$stmt = null; -$conn = null; + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); -print "Done"; + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_022_xml_bind_value.phpt b/test/functional/pdo_sqlsrv/pdo_022_xml_bind_value.phpt index d57e9e56c..64ffa50bb 100644 --- a/test/functional/pdo_sqlsrv/pdo_022_xml_bind_value.phpt +++ b/test/functional/pdo_sqlsrv/pdo_022_xml_bind_value.phpt @@ -1,17 +1,17 @@ --TEST-- Unicode XML message using bindValue() --SKIPIF-- - + --FILE-- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +$conn = connect(); // Create a temporary table $tableName = '#testXMLBindValue'; +// XML encrypted is not supported, thus do not create table with encrypted columns $sql = "CREATE TABLE $tableName (ID INT PRIMARY KEY NOT NULL IDENTITY, XMLMessage XML)"; $stmt = $conn->exec($sql); @@ -29,8 +29,7 @@ $xml2 = ' '; // Insert data -try -{ +try { $stmt = $conn->prepare("INSERT INTO $tableName (XMLMessage) VALUES (:msg)"); $stmt->bindValue(':msg', $xml1); $stmt->execute(); @@ -38,19 +37,17 @@ try $stmt = $conn->prepare("INSERT INTO $tableName (XMLMessage) VALUES (?)"); $stmt->bindValue(1, $xml2); $stmt->execute(); -} -catch (PDOException $ex) { +} catch (PDOException $ex) { echo "Error: " . $ex->getMessage(); } // Get data -$stmt = $conn->query("select * from $tableName"); -$row = $stmt->fetchAll(PDO::FETCH_ASSOC); -var_dump($row); - +$row = selectAll($conn, $tableName, "PDO::FETCH_ASSOC"); +var_dump($row); + // Close connection -$stmt=null; -$conn=null; +unset($stmt); +unset($conn); print "Done" ?> diff --git a/test/functional/pdo_sqlsrv/pdo_023.phpt b/test/functional/pdo_sqlsrv/pdo_023.phpt index 4b0814934..0786f0989 100644 --- a/test/functional/pdo_sqlsrv/pdo_023.phpt +++ b/test/functional/pdo_sqlsrv/pdo_023.phpt @@ -1,32 +1,38 @@ --TEST-- Bind values with PDO::PARAM_BOOL, enable/disable fetch numeric type attribute --SKIPIF-- + --FILE-- setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, FALSE); -Test(); + // Set PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE = false (default) + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, FALSE); + Test(); -// Set PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE = true -$conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, TRUE); -Test(); + // Set PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE = true + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, TRUE); + Test(); -// Close connection -$stmt = null; -$conn = null; + // Close connection + unset($stmt); + unset($conn); -print "Done"; + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} // Generic test starts here function Test() @@ -34,13 +40,8 @@ function Test() global $conn, $tableName, $sample; // Drop table if exists - $sql = "IF OBJECT_ID('$tableName') IS NOT NULL DROP TABLE $tableName"; - $stmt = $conn->query($sql); + createTable($conn, $tableName, array("c1" => "int", "c2" => "bit")); - // Create table - $sql = "CREATE TABLE $tableName (c1 INT, c2 BIT)"; - $stmt = $conn->query($sql) ?: die(); - // Insert data using bind values $sql = "INSERT INTO $tableName VALUES (:v1, :v2)"; $stmt = $conn->prepare($sql); @@ -56,8 +57,13 @@ function Test() $row = $stmt->fetchAll(PDO::FETCH_NUM); // Print out - for($i=0; $i<$stmt->rowCount(); $i++) - { var_dump($row[$i][0]); var_dump($row[$i][1]); } + for ($i=0; $i<$stmt->rowCount(); $i++) { + var_dump($row[$i][0]); var_dump($row[$i][1]); + } + + // clean up + dropTable( $conn, $tableName ); + unset( $stmt ); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_033_binary_unicode.phpt b/test/functional/pdo_sqlsrv/pdo_033_binary_unicode.phpt index 18f43904c..04462ee40 100644 --- a/test/functional/pdo_sqlsrv/pdo_033_binary_unicode.phpt +++ b/test/functional/pdo_sqlsrv/pdo_033_binary_unicode.phpt @@ -1,46 +1,46 @@ --TEST-- Insert binary HEX data then fetch it back as string --DESCRIPTION-- -Insert binary HEX data into an nvarchar field then read it back as UTF-8 string +Insert binary HEX data into an nvarchar field then read it back as UTF-8 string --SKIPIF-- - + --FILE-- exec($sql); + $tableName = 'pdo_033test'; + createTable($conn, $tableName, array("c1" => "nvarchar(100)")); - $input = pack( "H*", '49006427500048005000' ); // I'LOVE_SYMBOL'PHP + $input = pack("H*", '49006427500048005000'); // I'LOVE_SYMBOL'PHP + $result; + $stmt = insertRow($conn, $tableName, array("c1" => new BindParamOp(1, $input, "PDO::PARAM_STR", 0, "PDO::SQLSRV_ENCODING_BINARY")), "prepareBindParam", $result); - $stmt = $conn->prepare("INSERT INTO $tableName (c1) VALUES (?)"); - $stmt->bindParam(1, $input, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); - $result = $stmt->execute(); - if (! $result) + if (!$result) { echo "Failed to insert!\n"; + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + exit; + } $stmt = $conn->query("SELECT * FROM $tableName"); $utf8 = $stmt->fetchColumn(); - echo "\n". $utf8 ."\n"; + echo "$utf8\n"; - $stmt = null; - $conn = null; + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } -catch (Exception $e) -{ - echo $e->getMessage(); -} - -print "Done"; +print "Done"; ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt b/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt index 3dbc370d8..2a8236b39 100644 --- a/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt +++ b/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt @@ -1,20 +1,18 @@ --TEST-- GitHub Issue #35 binary encoding error when binding by name --SKIPIF-- - + --FILE-- exec($sql); + // Create a table + $tableName = "testTableIssue35"; + createTable($conn, $tableName, array("Value" => "varbinary(max)")); // Insert data using bind parameters $sql = "INSERT INTO $tableName VALUES (?)"; @@ -34,14 +32,14 @@ function test() var_dump($val1 === $value); // Close connection - $stmt = null; - $conn = null; + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + print "Done\n"; +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -test(); -print "Done"; ?> --EXPECT-- bool(true) -Done - +Done \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_040_error_information.phpt b/test/functional/pdo_sqlsrv/pdo_040_error_information.phpt index c2e10320c..9de1bcd53 100644 --- a/test/functional/pdo_sqlsrv/pdo_040_error_information.phpt +++ b/test/functional/pdo_sqlsrv/pdo_040_error_information.phpt @@ -1,41 +1,60 @@ --TEST-- Retrieve error information; supplied values does not match table definition --SKIPIF-- - + --FILE-- exec($sql); + // Create table + $tableName = 'pdo_040test'; + // common function insertRow() is not used here since the test deliberately executes an invalid insertion statement + // thus it's not necessary to create an encrypted column for testing column encryption + $sql = "CREATE TABLE $tableName (code INT)"; + $stmt = $conn->exec($sql); -// Insert data using bind parameters -// Number of supplied values does not match table definition -$sql = "INSERT INTO $tableName VALUES (?,?)"; -$stmt = $conn->prepare($sql); -$params = array(2010,"London"); + // Insert data using bind parameters + // Number of supplied values does not match table definition + $sql = "INSERT INTO $tableName VALUES (?,?)"; + $stmt = $conn->prepare($sql); + $params = array(2010,"London"); -// SQL statement has an error, which is then reported -$stmt->execute($params); -print_r($stmt->errorInfo()); + // SQL statement has an error, which is then reported + $stmt->execute($params); + $error = $stmt->errorInfo(); -// Close connection -$stmt = null; -$conn = null; + $success = true; + if (!isColEncrypted()) { + // 21S01 is the expected ODBC Column name or number of supplied values does not match table definition error + if ($error[0] != "21S01") { + $success = false; + } + } else { + // 07009 is the expected ODBC Invalid Descriptor Index error + if ($error[0] != "07009") { + $success = false; + } + } -print "Done"; + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + + if ($success) { + print "Done"; + } else { + var_dump($error); + } +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> ---EXPECTREGEX-- -Array -\( - \[0\] => 21S01 - \[1\] => 213 - \[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Column name or number of supplied values does not match table definition\. -\) +--EXPECT-- Done diff --git a/test/functional/pdo_sqlsrv/pdo_060_prepare_execute_fetch_pooling_default.phpt b/test/functional/pdo_sqlsrv/pdo_060_prepare_execute_fetch_pooling_default.phpt index afb516b39..3d644c48b 100644 --- a/test/functional/pdo_sqlsrv/pdo_060_prepare_execute_fetch_pooling_default.phpt +++ b/test/functional/pdo_sqlsrv/pdo_060_prepare_execute_fetch_pooling_default.phpt @@ -1,60 +1,53 @@ --TEST-- Prepare, execute statement and fetch with pooling unset (default) --SKIPIF-- - + --FILE-- TRUE); -// Create a pool -$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;", - $uid, $pwd, $connection_options['pdo']); -$conn0 = null; + // Create a pool + $conn0 = connect('', $connection_options); + unset($conn0); -// Connection can use an existing pool -$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;", - $uid, $pwd, $connection_options['pdo']); + // Connection can use an existing pool + $conn = connect('', $connection_options); + + // Create table + $tableName = 'pdo_060_test'; + createTable($conn, $tableName, array("Столица" => "nvarchar(32)", "year" => "int")); -// Create table -$tableName = 'pdo_060_test'; -$sql = "CREATE TABLE $tableName (Столица NVARCHAR(32), year INT)"; -$stmt = $conn->query($sql); + // Insert data + insertRow($conn, $tableName, array("Столица" => "Лондон", "year" => 2012), "prepareExecuteBind"); -// Insert data -$sql = "INSERT INTO $tableName VALUES (?,?)"; -$stmt = $conn->prepare($sql); -$stmt->execute(array("Лондон",2012)); + // Get data + $row = selectRow($conn, $tableName, "PDO::FETCH_ASSOC"); + var_dump($row); + unset($conn); -// Get data -$stmt = $conn->query("SELECT * FROM $tableName"); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -var_dump($row); -$conn = null; + // Create a new pool + $conn0 = connect(); + unset($conn0); + + // Connection can use an existing pool + $conn = connect(); -// Create a new pool -$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;", - $uid, $pwd); -$conn0 = null; - -// Connection can use an existing pool -$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;", - $uid, $pwd); - -// Get data -$stmt = $conn->query("SELECT * FROM $tableName"); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -var_dump($row); - - -$conn->query("DROP TABLE $tableName"); - -// Close connection -$stmt=null; -$conn=null; -print "Done" + // Get data + $row = selectRow($conn, $tableName, "PDO::FETCH_ASSOC"); + var_dump($row); + + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + print "Done\n"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- array(2) { @@ -69,4 +62,4 @@ array(2) { ["year"]=> string(4) "2012" } -Done +Done \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_061_prepare_execute_fetch_pooling_enabled.phpt b/test/functional/pdo_sqlsrv/pdo_061_prepare_execute_fetch_pooling_enabled.phpt index b56273554..987e0529a 100644 --- a/test/functional/pdo_sqlsrv/pdo_061_prepare_execute_fetch_pooling_enabled.phpt +++ b/test/functional/pdo_sqlsrv/pdo_061_prepare_execute_fetch_pooling_enabled.phpt @@ -1,59 +1,53 @@ --TEST-- Prepare, execute statement and fetch with pooling enabled --SKIPIF-- - + --FILE-- TRUE); -// Create a pool -$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;", - $uid, $pwd, $connection_options['pdo']); -$conn0 = null; + // Create a pool + $conn0 = connect('ConnectionPooling=1', $connection_options); + unset($conn0); -// Connection can use an existing pool -$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;", - $uid, $pwd, $connection_options['pdo']); + // Connection can use an existing pool + $conn = connect('ConnectionPooling=1', $connection_options); -// Create table -$tableName = 'pdo_061test'; -$sql = "CREATE TABLE $tableName (Столица NVARCHAR(32), year INT)"; -$stmt = $conn->query($sql); + // Create table + $tableName = 'pdo_061test'; + createTable($conn, $tableName, array("Столица" => "nvarchar(32)", "year" => "int")); -// Insert data -$sql = "INSERT INTO $tableName VALUES (?,?)"; -$stmt = $conn->prepare($sql); -$stmt->execute(array("Лондон",2012)); + // Insert data + insertRow($conn, $tableName, array("Столица" => "Лондон", "year" => 2012), "prepareExecuteBind"); -// Get data -$stmt = $conn->query("SELECT * FROM $tableName"); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -var_dump($row); -$conn = null; + // Get data + $row = selectRow($conn, $tableName, "PDO::FETCH_ASSOC"); + var_dump($row); + unset($conn); -// Create a new pool -$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;", - $uid, $pwd); -$conn0 = null; - -// Connection can use an existing pool -$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;", - $uid, $pwd); + // Create a new pool + $conn0 = connect('ConnectionPooling=1'); + unset($conn0); + + // Connection can use an existing pool + $conn = connect('ConnectionPooling=1'); -// Get data -$stmt = $conn->query("SELECT * FROM $tableName"); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -var_dump($row); - -$conn->query("DROP TABLE $tableName"); - -// Close connection -$stmt=null; -$conn=null; -print "Done" + // Get data + $row = selectRow($conn, $tableName, "PDO::FETCH_ASSOC"); + var_dump($row); + + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + print "Done\n"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- array(2) { @@ -68,4 +62,4 @@ array(2) { ["year"]=> string(4) "2012" } -Done +Done \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_062_prepare_execute_fetch_pooling_disabled.phpt b/test/functional/pdo_sqlsrv/pdo_062_prepare_execute_fetch_pooling_disabled.phpt index 8dcc9f1ab..71eba77ac 100644 --- a/test/functional/pdo_sqlsrv/pdo_062_prepare_execute_fetch_pooling_disabled.phpt +++ b/test/functional/pdo_sqlsrv/pdo_062_prepare_execute_fetch_pooling_disabled.phpt @@ -1,60 +1,53 @@ --TEST-- Prepare, execute statement and fetch with pooling disabled --SKIPIF-- - + --FILE-- TRUE); -// Create a pool -$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;", - $uid, $pwd, $connection_options['pdo']); -$conn0 = null; + // Create a pool + $conn0 = connect('ConnectionPooling=0', $connection_options); + unset($conn0); -// Connection can use an existing pool -$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;", - $uid, $pwd, $connection_options['pdo']); + // Connection can use an existing pool + $conn = connect('ConnectionPooling=0', $connection_options); -// Create table -$tableName = 'pdo_62test'; -$sql = "CREATE TABLE $tableName (Столица NVARCHAR(32), year INT)"; -$stmt = $conn->exec($sql); + // Create table + $tableName = 'pdo_62test'; + createTable($conn, $tableName, array("Столица" => "nvarchar(32)", "year" => "int")); -// Insert data -$sql = "INSERT INTO $tableName VALUES (?,?)"; -$stmt = $conn->prepare($sql); -$stmt->execute(array("Лондон",2012)); + // Insert data + insertRow($conn, $tableName, array( "Столица" => "Лондон", "year" => 2012 ), "prepareExecuteBind"); -// Get data -$stmt = $conn->query("SELECT * FROM $tableName"); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -var_dump($row); -$conn = null; + // Get data + $row = selectRow($conn, $tableName, "PDO::FETCH_ASSOC"); + var_dump($row); + unset($conn); -// Create a new pool -$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;", - $uid, $pwd); -$conn0 = null; - -// Connection can use an existing pool? -$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;", - $uid, $pwd); + // Create a new pool + $conn0 = connect('ConnectionPooling=0'); + unset($conn0); + + // Connection can use an existing pool? + $conn = connect('ConnectionPooling=0'); -// Get data -$stmt = $conn->query("SELECT * FROM $tableName"); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -var_dump($row); - + // Get data + $row = selectRow($conn, $tableName, "PDO::FETCH_ASSOC"); + var_dump($row); -$conn->query("DROP TABLE $tableName"); - -// Close connection -$stmt=null; -$conn=null; -print "Done" + // Close connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); + print "Done\n"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- array(2) { @@ -69,4 +62,4 @@ array(2) { ["year"]=> string(4) "2012" } -Done +Done \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_065_construct_persistent.phpt b/test/functional/pdo_sqlsrv/pdo_065_construct_persistent.phpt index 705946154..883da0299 100644 --- a/test/functional/pdo_sqlsrv/pdo_065_construct_persistent.phpt +++ b/test/functional/pdo_sqlsrv/pdo_065_construct_persistent.phpt @@ -1,46 +1,45 @@ --TEST-- Exception is thrown if the unsupported attribute ATTR_PERSISTENT is put into the connection options --SKIPIF-- - + --FILE-- true); - $conn = new PDO( $dsn, $uid, $pwd, $attr); - - //free the connection - $conn=null; -} -catch( PDOException $e ) { + $dsn = getDSN($server, $databaseName); + $attr = array(PDO::ATTR_PERSISTENT => true); + $conn = new PDO($dsn, $uid, $pwd, $attr); + //free the connection + unset($conn); +} catch (PDOException $e) { echo "Exception from unsupported attribute (ATTR_PERSISTENT) is caught\n"; } -try{ - - require_once 'MsCommon.inc'; - +try { echo "\nTesting new connection after exception thrown in previous connection...\n"; - $tableName1 = GetTempTableName('tab1'); - $conn = new PDO( $dsn, $uid, $pwd ); - $sql = "CREATE TABLE $tableName1 (c1 int, c2 varchar(10))"; - $stmt = $conn->exec($sql); - $ret = $conn->exec("INSERT INTO $tableName1 VALUES(1, 'column2')"); - $stmt = $conn->query("SELECT * FROM $tableName1"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); + $tableName1 = getTableName('tab1'); + $conn = connect(); + createTable($conn, $tableName1, array("c1" => "int", "c2" => "varchar(10)")); + insertRow($conn, $tableName1, array("c1" => 1, "c2" => "column2"), "exec"); + + $result = selectRow($conn, $tableName1, "PDO::FETCH_ASSOC"); if ($result['c1'] == 1 && $result['c2'] == 'column2') { - echo "Test successfully completed"; + echo "Test successfully completed\n"; } - //free the statement and connection - $stmt = null; - $conn = null; -} -catch( PDOException $e ) { - var_dump( $e); + //free the statement and connection + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e); } -?> +?> --EXPECT-- Testing a connection with ATTR_PERSISTENT... Exception from unsupported attribute (ATTR_PERSISTENT) is caught diff --git a/test/functional/pdo_sqlsrv/pdo_065_construct_prefetch.phpt b/test/functional/pdo_sqlsrv/pdo_065_construct_prefetch.phpt index d262d2ce4..e0be3f60f 100644 --- a/test/functional/pdo_sqlsrv/pdo_065_construct_prefetch.phpt +++ b/test/functional/pdo_sqlsrv/pdo_065_construct_prefetch.phpt @@ -3,29 +3,36 @@ Test unsupported connection attribute ATTR_PREFETCH --DESCRIPTION-- 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, $uid, $pwd, $attr); + $dsn = "sqlsrv:Server = $server;database = $databaseName"; + if ($keystore != "none") + $dsn .= "ColumnEncryption=Enabled;"; + if ($keystore == "ksp") { + require_once("AE_Ksp.inc"); + $ksp_path = getKSPPath(); + $dsn .= "CEKeystoreProvider=$ksp_path;CEKeystoreName=$ksp_name;CEKeystoreEncryptKey=$encrypt_key;"; + } + + $attr = array(PDO::ATTR_PREFETCH => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); + $conn = new PDO($dsn, $uid, $pwd, $attr); echo "Error from supported attribute (ATTR_PREFETCH) is silented\n\n"; - $conn=null; + unset($conn); 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, $uid, $pwd, $attr); + $conn = new PDO($dsn, $uid, $pwd, $attr); //free the connection - $conn=null; -} -catch( PDOException $e ) { + unset($conn); +} 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 diff --git a/test/functional/pdo_sqlsrv/pdo_069_fetch_empty_nvarchar_buffered.phpt b/test/functional/pdo_sqlsrv/pdo_069_fetch_empty_nvarchar_buffered.phpt index e99d05fb9..381aa5b15 100644 --- a/test/functional/pdo_sqlsrv/pdo_069_fetch_empty_nvarchar_buffered.phpt +++ b/test/functional/pdo_sqlsrv/pdo_069_fetch_empty_nvarchar_buffered.phpt @@ -1,31 +1,34 @@ --TEST-- GitHub issue #69 - fetching an empty nvarchar using client buffer --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$sql = "EXEC dbo.sp_executesql -N'DECLARE @x nvarchar(max) -SET @x = '''' -- empty string -SELECT @x AS [Empty_Nvarchar_Max]'"; +try { + $conn = connect(); + + $sql = "EXEC dbo.sp_executesql + N'DECLARE @x nvarchar(max) + SET @x = '''' -- empty string + SELECT @x AS [Empty_Nvarchar_Max]'"; -$stmt = $conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); + $stmt = $conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); -$return = $stmt->fetchAll( PDO::FETCH_ASSOC ); -print_r($return); + $return = $stmt->fetchAll(PDO::FETCH_ASSOC); + print_r($return); -// Free the statement and connection resources. -$stmt = null; -$conn = null; + // Free the statement and connection resources. + unset($stmt); + unset($conn); -print "Done"; + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- Array diff --git a/test/functional/pdo_sqlsrv/pdo_092_emulate_prepare_statement_utf8.phpt b/test/functional/pdo_sqlsrv/pdo_092_emulate_prepare_statement_utf8.phpt index 9bacaf8e5..24ab4c153 100644 --- a/test/functional/pdo_sqlsrv/pdo_092_emulate_prepare_statement_utf8.phpt +++ b/test/functional/pdo_sqlsrv/pdo_092_emulate_prepare_statement_utf8.phpt @@ -1,68 +1,74 @@ --TEST-- Test emulate prepare utf8 encoding set at the statement level --SKIPIF-- - + --FILE-- prepare("DROP TABLE TEST", $pdo_options); - $st->execute(); -} -catch(\Exception $e) {} + // Create table + $tbname = "TEST"; + createTable($connection, $tbname, array( new ColumnMeta("int", "id", "IDENTITY(1,1) NOT NULL"), "name" => "nvarchar(max)")); -// Recreate -$st = $connection->prepare("CREATE TABLE TEST([id] [int] IDENTITY(1,1) NOT NULL, [name] nvarchar(max))", $pdo_options); -$st->execute(); + $prefix = '가각'; + $name = '가각ácasa'; + $name2 = '가각sample2'; -$prefix = '가각'; -$name = '가각ácasa'; -$name2 = '가각sample2'; - -$pdo_options[PDO::ATTR_EMULATE_PREPARES] = FALSE; -$st = $connection->prepare("INSERT INTO TEST(name) VALUES(:p0)", $pdo_options); -$st->execute(['p0' => $name]); + $pdo_options[PDO::ATTR_EMULATE_PREPARES] = false; + $st = $connection->prepare("INSERT INTO $tbname (name) VALUES (:p0)", $pdo_options); + $st->execute(['p0' => $name]); -$pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE; -$st = $connection->prepare("INSERT INTO TEST(name) VALUES(:p0)", $pdo_options); -$st->execute(['p0' => $name2]); - -$statement = $connection->prepare("SELECT * FROM TEST WHERE NAME LIKE :p0", $pdo_options); -$statement->execute(['p0' => "$prefix%"]); -foreach ($statement as $row) { - echo "\n" . 'FOUND: ' . $row['name']; -} + // Always Encrypted does not support emulate prepare + if (!isColEncrypted()) { + $pdo_options[PDO::ATTR_EMULATE_PREPARES] = true; + } + $st = $connection->prepare("INSERT INTO $tbname (name) VALUES (:p0)", $pdo_options); + $st->execute(['p0' => $name2]); -$pdo_options = array(); -$pdo_options[PDO::ATTR_EMULATE_PREPARES] = FALSE; -$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE; -$pdo_options[PDO::SQLSRV_ATTR_ENCODING] = PDO::SQLSRV_ENCODING_UTF8; -$statement = $connection->prepare("SELECT * FROM TEST WHERE NAME LIKE :p0", $pdo_options); -$statement->execute(['p0' => "$prefix%"]); -foreach ($statement as $row) { - echo "\n" . 'FOUND: ' . $row['name']; -} -$stmt = NULL; -$connection = NULL; + if (!isColEncrypted()) { + $statement1 = $connection->prepare("SELECT * FROM $tbname WHERE NAME LIKE :p0", $pdo_options); + $statement1->execute(['p0' => "$prefix%"]); + $pdo_options[PDO::ATTR_EMULATE_PREPARES] = false; + $statement2 = $connection->prepare("SELECT * FROM $tbname WHERE NAME LIKE :p0", $pdo_options); + $statement2->execute(['p0' => "$prefix%"]); + } else { + $statement1 = $connection->prepare("SELECT * FROM $tbname", $pdo_options); + $statement1->execute(); + $statement2 = $connection->prepare("SELECT * FROM $tbname", $pdo_options); + $statement2->execute(); + } + foreach ($statement1 as $row) { + echo 'FOUND: ' . $row['name'] . "\n"; + } + foreach ($statement2 as $row) { + echo 'FOUND: ' . $row['name'] . "\n"; + } + dropTable($connection, $tbname); + unset($stmt); + unset($connection); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- FOUND: 가각ácasa FOUND: 가각sample2 FOUND: 가각ácasa -FOUND: 가각sample2 \ No newline at end of file +FOUND: 가각sample2 diff --git a/test/functional/pdo_sqlsrv/pdo_138_unicode_column_name.phpt b/test/functional/pdo_sqlsrv/pdo_138_unicode_column_name.phpt index 04c86e20a..bb4ddd926 100644 --- a/test/functional/pdo_sqlsrv/pdo_138_unicode_column_name.phpt +++ b/test/functional/pdo_sqlsrv/pdo_138_unicode_column_name.phpt @@ -1,59 +1,9 @@ --TEST-- Github 138. Test for Unicode Column Metadata. --SKIPIF-- - + --FILE-- &$field_value) { - $placeholder = $placeholder_prefix . $max_placeholder++; - $blob_key = $placeholder . $blob_suffix; - if (isset($columnInformation['blobs'][$field_name])) { - $blobs[$blob_key] = fopen('php://memory', 'a'); - fwrite($blobs[$blob_key], $field_value); - rewind($blobs[$blob_key]); - $this->bindParam($placeholder, $blobs[$blob_key], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); - } - else { - // Even though not a blob, make sure we retain a copy of these values. - $blobs[$blob_key] = $field_value; - $this->bindParam($placeholder, $blobs[$blob_key], PDO::PARAM_STR); - } - } - } -} - - -/** - * - * @param string $connection_id - * - * @return PDO - */ -function connection($connection_id) { - include 'MsSetup.inc'; - $host = $server; - $database = $databaseName; - $username = $uid; - $password = $pwd; - - static $connections = array(); - if (!isset($connections[$connection_id])) { - $connection_options['pdo'] = array(); - $connection_options['pdo'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; - - $cnn = new PDO("sqlsrv:server=$host;Database=$database", $username, $password, $connection_options['pdo']); - $cnn->setAttribute(PDO::ATTR_STATEMENT_CLASS, [MyStatement::class]); - $connections[$connection_id] = $cnn; - } - return $connections[$connection_id]; -} - /** * Summary of prepare * @@ -63,117 +13,63 @@ function connection($connection_id) { */ function prepare($connection, $query) { $pdo_options = array(); - $pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE; - $pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE; + // emulate and binding parameter with direct query are not support in Always Encrypted + if ( !isColEncrypted() ) + { + $pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE; + $pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE; + } $pdo_options[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL; $pdo_options[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE] = PDO::SQLSRV_CURSOR_BUFFERED; return $connection->prepare($query, $pdo_options); } -/** - * Summary of execute - * - * @param PDO $connection - * @param string $query - * - * @param PDOStatement; - */ -function execute($connection, $query, array $args = array()) { - $st = prepare($connection, $query); - foreach ($args as $key => $value) { - if (is_numeric($value)) { - $st->bindValue($key, $value, PDO::PARAM_INT); - } - else { - $st->bindValue($key, $value, PDO::PARAM_STR); - } - } - - $st->execute(); - - // Bind column types properly. - $null = array(); - $st->columnNames = array(); - for ($i = 0; $i < $st->columnCount(); $i++) { - $meta = $st->getColumnMeta($i); - $st->columnNames[]= $meta['name']; - $sqlsrv_type = $meta['sqlsrv:decl_type']; - $parts = explode(' ', $sqlsrv_type); - $type = reset($parts); - switch($type) { - case 'varbinary': - $null[$i] = NULL; - $st->bindColumn($i + 1, $null[$i], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); - break; - case 'int': - case 'bit': - case 'smallint': - case 'tinyint': - case 'bigint': - $null[$i] = NULL; - $st->bindColumn($i + 1, $null[$i], PDO::PARAM_INT); - break; - } - } - - return $st; -} - - //******************************************************* // TEST BEGIN //******************************************************* -$connection = connection('default'); +require_once("MsCommon_mid-refactor.inc"); -// Drop try { - execute($connection, 'DROP TABLE [mytáble]'); -} -catch(Exception $e) {} + $connection = connect(); -$tablescript = <<bindValue(':db_insert0', 'a', PDO::PARAM_STR); + $st->bindValue(':db_insert1', 'b', PDO::PARAM_STR); + $st->bindValue(':db_insert2', 'c', PDO::PARAM_STR); -$st->bindValue(':db_insert0', 'a', PDO::PARAM_STR); -$st->bindValue(':db_insert1', 'b', PDO::PARAM_STR); -$st->bindValue(':db_insert2', 'c', PDO::PARAM_STR); + $st->execute(); -$st->execute(); + $st = prepare($connection, "SELECT * FROM $tbname"); -$st = prepare($connection, 'SELECT * FROM [mytáble]'); + $st->execute(); -$st->execute(); + while ($row = $st->fetchAll()) { + $row = reset($row); + echo (isset($row['id']) ? "OK" : "FAIL") , "\n"; + echo (isset($row['tésting']) ? "OK" : "FAIL") , "\n"; + echo (isset($row['väriable']) ? "OK" : "FAIL") , "\n"; + } -while($row = $st->fetchAll()){ - $row = reset($row); - echo (isset($row['id']) ? "OK" : "FAIL") , "\n"; - echo (isset($row['tésting']) ? "OK" : "FAIL") , "\n"; - echo (isset($row['väriable']) ? "OK" : "FAIL") , "\n"; -} + for ($i = 0; $i < $st->columnCount(); $i++) { + $meta = $st->getColumnMeta($i); + echo $meta['name'] , "\n"; + } -for ($i = 0; $i < $st->columnCount(); $i++) { - $meta = $st->getColumnMeta($i); - echo $meta['name'] , "\n"; + dropTable($connection, $tbname); + unset($st); + unset($connection); +} catch (PDOException $e) { + var_dump($e->errorInfo); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_mix_binary.phpt b/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_mix_binary.phpt index 81d9f6223..a74208788 100644 --- a/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_mix_binary.phpt +++ b/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_mix_binary.phpt @@ -1,29 +1,20 @@ --TEST-- Test emulate prepare with mix bound param encodings including binary data --SKIPIF-- - + --FILE-- &$field_value) { $placeholder = $placeholder_prefix . $max_placeholder++; - $blob_key = $placeholder . $blob_suffix; if (isset($columnInformation['blobs'][$field_name])) { - $blobs[$blob_key] = fopen('php://memory', 'a'); - fwrite($blobs[$blob_key], $field_value); - rewind($blobs[$blob_key]); - $this->bindParam($placeholder, $blobs[$blob_key], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $this->bindParam($placeholder, $field_value, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); } else { // Even though not a blob, make sure we retain a copy of these values. - $blobs[$blob_key] = $field_value; - $this->bindParam($placeholder, $blobs[$blob_key], PDO::PARAM_STR); + $this->bindParam($placeholder, $field_value, PDO::PARAM_STR); } } } @@ -32,79 +23,95 @@ class MyStatement extends PDOStatement { //******************************************************* // TEST BEGIN //******************************************************* - -$connection_options['pdo'] = array(); -$connection_options['pdo'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; +require_once("MsCommon_mid-refactor.inc"); -$database = "tempdb"; -$cnn = new PDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd, $connection_options['pdo']); -$cnn->setAttribute(PDO::ATTR_STATEMENT_CLASS, [MyStatement::class]); - -// Drop try { + $cnn = connect(); + $cnn->setAttribute(PDO::ATTR_STATEMENT_CLASS, [MyStatement::class]); + + // Drop + $tbname = "watchdog"; + dropTable($cnn, $tbname); + $pdo_options = array(); - $pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE; - $pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE; + if (!isColEncrypted()) { + $pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE; + $pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE; + + $cm_arr = array(new ColumnMeta("int", "wid", "IDENTITY(1,1) NOT NULL"), + new ColumnMeta("int", "uid", "NOT NULL CONSTRAINT [watchdog_uid_df] DEFAULT ((0))"), + new ColumnMeta("nvarchar(64)", "type", "NOT NULL CONSTRAINT [watchdog_type_df] DEFAULT ('')"), + new ColumnMeta("nvarchar(max)", "message", "NOT NULL"), + new ColumnMeta("varbinary(max)", "variables", "NOT NULL"), + new ColumnMeta("smallint", "severity", "NOT NULL CONSTRAINT [watchdog_severity_df] DEFAULT ((0))"), + new ColumnMeta("nvarchar(255)", "link", "NULL CONSTRAINT [watchdog_link_df] DEFAULT ('')"), + new ColumnMeta("nvarchar(max)", "location", "NOT NULL"), + new ColumnMeta("nvarchar(max)", "referer", "NULL"), + new ColumnMeta("nvarchar(128)", "hostname", "NOT NULL CONSTRAINT [watchdog_hostname_df] DEFAULT ('')"), + new ColumnMeta("int", "timestamp", "NOT NULL CONSTRAINT [watchdog_timestamp_df] DEFAULT ((0))")); + } else { + // Emulate prepare and using direct query for binding parameters are not supported in Always encrypted + $pdo_options[PDO::ATTR_EMULATE_PREPARES] = FALSE; + $pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = FALSE; + + // Default constraints are unsupported on encrypted columns + $cm_arr = array(new ColumnMeta("int", "wid", "IDENTITY(1,1) NOT NULL"), + new ColumnMeta("int", "uid", "NOT NULL"), + new ColumnMeta("nvarchar(64)", "type", "NOT NULL"), + new ColumnMeta("nvarchar(max)", "message", "NOT NULL"), + new ColumnMeta("varbinary(max)", "variables", "NOT NULL"), + new ColumnMeta("smallint", "severity", "NOT NULL"), + new ColumnMeta("nvarchar(255)", "link"), + new ColumnMeta("nvarchar(max)", "location", "NOT NULL"), + new ColumnMeta("nvarchar(max)", "referer"), + new ColumnMeta("nvarchar(128)", "hostname", "NOT NULL"), + new ColumnMeta("int", "timestamp", "NOT NULL")); + } + $pdo_options[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL; $pdo_options[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE] = PDO::SQLSRV_CURSOR_BUFFERED; - $st = $cnn->prepare('DROP TABLE WATCHDOG', $pdo_options); - - $st->execute(); -} -catch(\Exception $e) {} - -$tablescript = <<prepare($tablescript, $pdo_options); -$st->execute(); -$query = <<prepare($query, $pdo_options); - -$st->BindValues($values, $blobs, ':db_insert', $columnInformation); -$st->execute(); + $cd_arr = array(); + foreach ($cm_arr as $cm) { + array_push( $cd_arr, $cm->getColDef()); + } + + $tablescript = "CREATE TABLE [dbo].[$tbname]( + $cd_arr[0], $cd_arr[1], $cd_arr[2], $cd_arr[3], $cd_arr[4], $cd_arr[5], $cd_arr[6], $cd_arr[7], $cd_arr[8], $cd_arr[9], $cd_arr[10], + CONSTRAINT [watchdog_pkey] PRIMARY KEY CLUSTERED + ( + [wid] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]"; + + // Recreate + $st = $cnn->prepare($tablescript); + $st->execute(); + + $query = "INSERT INTO [$tbname] ([uid], [type], [message], [variables], [severity], [link], [location], [referer], [hostname], [timestamp]) OUTPUT (Inserted.wid) VALUES + (:db_insert0, :db_insert1, :db_insert2, :db_insert3, :db_insert4, :db_insert5, :db_insert6, :db_insert7, :db_insert8, :db_insert9)"; + + $values_encoded = 'YToxMDp7czozOiJ1aWQiO2k6MDtzOjQ6InR5cGUiO3M6MzoicGhwIjtzOjc6Im1lc3NhZ2UiO3M6NTE6IiV0eXBlOiBAbWVzc2FnZSBpbiAlZnVuY3Rpb24gKGxpbmUgJWxpbmUgb2YgJWZpbGUpLiI7czo5OiJ2YXJpYWJsZXMiO3M6MjE4ODoiYTo1OntzOjU6IiV0eXBlIjtzOjQ1OiJEcnVwYWxcQ29yZVxEYXRhYmFzZVxEYXRhYmFzZUV4Y2VwdGlvbldyYXBwZXIiO3M6ODoiQG1lc3NhZ2UiO3M6MTkxMzoiU1FMU1RBVEVbSU1TU1BdOiBBbiBlcnJvciBvY2N1cnJlZCB0cmFuc2xhdGluZyB0aGUgcXVlcnkgc3RyaW5nIHRvIFVURi0xNjogTm8gbWFwcGluZyBmb3IgdGhlIFVuaWNvZGUgY2hhcmFjdGVyIGV4aXN0cyBpbiB0aGUgdGFyZ2V0IG11bHRpLWJ5dGUgY29kZSBwYWdlLg0KLjogTUVSR0UgSU5UTyBbY2FjaGVfZGF0YV0gX3RhcmdldA0KVVNJTkcgKFNFTEVDVCBULiogRlJPTSAodmFsdWVzKDpkYl9pbnNlcnRfcGxhY2Vob2xkZXJfMCwgOmRiX2luc2VydF9wbGFjZWhvbGRlcl8xLCA6ZGJfaW5zZXJ0X3BsYWNlaG9sZGVyXzIsIDpkYl9pbnNlcnRfcGxhY2Vob2xkZXJfMywgOmRiX2luc2VydF9wbGFjZWhvbGRlcl80LCA6ZGJfaW5zZXJ0X3BsYWNlaG9sZGVyXzUsIDpkYl9pbnNlcnRfcGxhY2Vob2xkZXJfNikpIGFzIFQoW2NpZF0sIFtleHBpcmVdLCBbY3JlYXRlZF0sIFt0YWdzXSwgW2NoZWNrc3VtXSwgW2RhdGFdLCBbc2VyaWFsaXplZF0pKSBfc291cmNlDQpPTiBfdGFyZ2V0LltjaWRdID0gX3NvdXJjZS5bY2lkXQ0KV0hFTiBNQVRDSEVEIFRIRU4gVVBEQVRFIFNFVCBfdGFyZ2V0LltleHBpcmVdID0gX3NvdXJjZS5bZXhwaXJlXSwgX3RhcmdldC5bY3JlYXRlZF0gPSBfc291cmNlLltjcmVhdGVkXSwgX3RhcmdldC5bdGFnc10gPSBfc291cmNlLlt0YWdzXSwgX3RhcmdldC5bY2hlY2tzdW1dID0gX3NvdXJjZS5bY2hlY2tzdW1dLCBfdGFyZ2V0LltkYXRhXSA9IF9zb3VyY2UuW2RhdGFdLCBfdGFyZ2V0LltzZXJpYWxpemVkXSA9IF9zb3VyY2UuW3NlcmlhbGl6ZWRdDQpXSEVOIE5PVCBNQVRDSEVEIFRIRU4gSU5TRVJUIChbY2lkXSwgW2V4cGlyZV0sIFtjcmVhdGVkXSwgW3RhZ3NdLCBbY2hlY2tzdW1dLCBbZGF0YV0sIFtzZXJpYWxpemVkXSkgVkFMVUVTIChfc291cmNlLltjaWRdLCBfc291cmNlLltleHBpcmVdLCBfc291cmNlLltjcmVhdGVkXSwgX3NvdXJjZS5bdGFnc10sIF9zb3VyY2UuW2NoZWNrc3VtXSwgX3NvdXJjZS5bZGF0YV0sIF9zb3VyY2UuW3NlcmlhbGl6ZWRdKQ0KT1VUUFVUICRhY3Rpb247OyBBcnJheQooCiAgICBbOmRiX2luc2VydF9wbGFjZWhvbGRlcl8wXSA9PiBBcnJheQogICAgICAgICgKICAgICAgICAgICAgW3ZhbHVlXSA9PiByb3V0ZTovOlhERUJVR19TRVNTSU9OX1NUQVJUPTU4RTFDMUM0CiAgICAgICAgICAgIFtkYXRhdHlwZV0gPT4gMgogICAgICAgICkKCiAgICBbOmRiX2luc2VydF9wbGFjZWhvbGRlcl8xXSA9PiBBcnJheQogICAgICAgICgKICAgICAgICAgICAgW3ZhbHVlXSA9PiAtMQogICAgICAgICAgICBbZGF0YXR5cGVdID0+IDIKICAgICAgICApCgogICAgWzpkYl9pbnNlcnRfcGxhY2Vob2xkZXJfMl0gPT4gQXJyYXkKICAgICAgICAoCiAgICAgICAgICAgIFt2YWx1ZV0gPT4gMTQ3MDIwNTc3My43CiAgICAgICAgICAgIFtkYXRhdHlwZV0gPT4gMgogICAgICAgICkKCiAgICBbOmRiX2luc2VydF9wbGFjZWhvbGRlcl8zXSA9PiBBcnJheQogICAgICAgICgKICAgICAgICAgICAgW3ZhbHVlXSA9PiByb3V0ZV9tYXRjaAogICAgICAgICAgICBbZGF0YXR5cGVdID0+IDIKICAgICAgICApCgogICAgWzpkYl9pbnNlcnRfcGxhY2Vob2xkZXJfNF0gPT4gQXJyYXkKICAgICAgICAoCiAgICAgICAgICAgIFt2YWx1ZV0gPT4gNAogICAgICAgICAgICBbZGF0YXR5cGVdID0+IDIKICAgICAgICApCgogICAgWzpkYl9pbnNlcnRfcGxhY2Vob2xkZXJfNV0gPT4gQXJyYXkKICAgICAgICAoCiAgICAgICAgICAgIFt2YWx1ZV0gPT4gUmVzb3VyY2UgaWQgIzQKICAgICAgICAgICAgW2RhdGF0eXBlXSA9PiAzCiAgICAgICAgKQoKICAgIFs6ZGJfaW5zZXJ0X3BsYWNlaG9sZGVyXzZdID0+IEFycmF5CiAgICAgICAgKAogICAgICAgICAgICBbdmFsdWVdID0+IDEKICAgICAgICAgICAgW2RhdGF0eXBlXSA9PiAyCiAgICAgICAgKQoKKQoiO3M6OToiJWZ1bmN0aW9uIjtzOjY1OiJEcnVwYWxcQ29yZVxSb3V0aW5nXFJvdXRlUHJvdmlkZXItPmdldFJvdXRlQ29sbGVjdGlvbkZvclJlcXVlc3QoKSI7czo1OiIlZmlsZSI7czo1MjoiRDpcZDhcY29yZVxsaWJcRHJ1cGFsXENvcmVcUm91dGluZ1xSb3V0ZVByb3ZpZGVyLnBocCI7czo1OiIlbGluZSI7aToxNjc7fSI7czo4OiJzZXZlcml0eSI7aTozO3M6NDoibGluayI7czowOiIiO3M6ODoibG9jYXRpb24iO3M6NjQ6Imh0dHA6Ly9sb2NhbC5kN3Rlc3QuY29tL2luZGV4LnBocC8/WERFQlVHX1NFU1NJT05fU1RBUlQ9NThFMUMxQzQiO3M6NzoicmVmZXJlciI7czowOiIiO3M6ODoiaG9zdG5hbWUiO3M6OToiMTI3LjAuMC4xIjtzOjk6InRpbWVzdGFtcCI7aToxNDcwMjA1Nzc0O30='; + $columninformation_encoded = 'YTo3OntzOjg6ImlkZW50aXR5IjtzOjM6IndpZCI7czoxMDoiaWRlbnRpdGllcyI7YToxOntzOjM6IndpZCI7czozOiJ3aWQiO31zOjc6ImNvbHVtbnMiO2E6MTE6e3M6Mzoid2lkIjthOjE0OntzOjQ6Im5hbWUiO3M6Mzoid2lkIjtzOjEwOiJtYXhfbGVuZ3RoIjtpOjQ7czo5OiJwcmVjaXNpb24iO2k6MTA7czoxNDoiY29sbGF0aW9uX25hbWUiO047czoxMToiaXNfbnVsbGFibGUiO2k6MDtzOjE0OiJpc19hbnNpX3BhZGRlZCI7aTowO3M6MTE6ImlzX2lkZW50aXR5IjtpOjE7czoxMToiaXNfY29tcHV0ZWQiO2k6MDtzOjQ6InR5cGUiO3M6MzoiaW50IjtzOjEwOiJkZWZpbml0aW9uIjtOO3M6MTM6ImRlZmF1bHRfdmFsdWUiO047czoxMToic3Fsc3J2X3R5cGUiO3M6MzoiaW50IjtzOjEyOiJkZXBlbmRlbmNpZXMiO2E6MDp7fXM6NzoiaW5kZXhlcyI7YToxOntpOjA7czoxMzoid2F0Y2hkb2dfcGtleSI7fX1zOjM6InVpZCI7YToxNDp7czo0OiJuYW1lIjtzOjM6InVpZCI7czoxMDoibWF4X2xlbmd0aCI7aTo0O3M6OToicHJlY2lzaW9uIjtpOjEwO3M6MTQ6ImNvbGxhdGlvbl9uYW1lIjtOO3M6MTE6ImlzX251bGxhYmxlIjtpOjA7czoxNDoiaXNfYW5zaV9wYWRkZWQiO2k6MDtzOjExOiJpc19pZGVudGl0eSI7aTowO3M6MTE6ImlzX2NvbXB1dGVkIjtpOjA7czo0OiJ0eXBlIjtzOjM6ImludCI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtzOjU6IigoMCkpIjtzOjExOiJzcWxzcnZfdHlwZSI7czozOiJpbnQiO3M6MTI6ImRlcGVuZGVuY2llcyI7YTowOnt9czo3OiJpbmRleGVzIjthOjE6e2k6MDtzOjc6InVpZF9pZHgiO319czo0OiJ0eXBlIjthOjE0OntzOjQ6Im5hbWUiO3M6NDoidHlwZSI7czoxMDoibWF4X2xlbmd0aCI7aTo2NDtzOjk6InByZWNpc2lvbiI7aTowO3M6MTQ6ImNvbGxhdGlvbl9uYW1lIjtzOjIwOiJMYXRpbjFfR2VuZXJhbF9DSV9BSSI7czoxMToiaXNfbnVsbGFibGUiO2k6MDtzOjE0OiJpc19hbnNpX3BhZGRlZCI7aToxO3M6MTE6ImlzX2lkZW50aXR5IjtpOjA7czoxMToiaXNfY29tcHV0ZWQiO2k6MDtzOjQ6InR5cGUiO3M6NzoidmFyY2hhciI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtzOjQ6IignJykiO3M6MTE6InNxbHNydl90eXBlIjtzOjExOiJ2YXJjaGFyKDY0KSI7czoxMjoiZGVwZW5kZW5jaWVzIjthOjA6e31zOjc6ImluZGV4ZXMiO2E6MTp7aTowO3M6ODoidHlwZV9pZHgiO319czo3OiJtZXNzYWdlIjthOjEzOntzOjQ6Im5hbWUiO3M6NzoibWVzc2FnZSI7czoxMDoibWF4X2xlbmd0aCI7aTotMTtzOjk6InByZWNpc2lvbiI7aTowO3M6MTQ6ImNvbGxhdGlvbl9uYW1lIjtzOjIwOiJMYXRpbjFfR2VuZXJhbF9DSV9BSSI7czoxMToiaXNfbnVsbGFibGUiO2k6MDtzOjE0OiJpc19hbnNpX3BhZGRlZCI7aToxO3M6MTE6ImlzX2lkZW50aXR5IjtpOjA7czoxMToiaXNfY29tcHV0ZWQiO2k6MDtzOjQ6InR5cGUiO3M6ODoibnZhcmNoYXIiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7TjtzOjExOiJzcWxzcnZfdHlwZSI7czoxMzoibnZhcmNoYXIobWF4KSI7czoxMjoiZGVwZW5kZW5jaWVzIjthOjA6e319czo5OiJ2YXJpYWJsZXMiO2E6MTM6e3M6NDoibmFtZSI7czo5OiJ2YXJpYWJsZXMiO3M6MTA6Im1heF9sZW5ndGgiO2k6LTE7czo5OiJwcmVjaXNpb24iO2k6MDtzOjE0OiJjb2xsYXRpb25fbmFtZSI7TjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo5OiJ2YXJiaW5hcnkiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7TjtzOjExOiJzcWxzcnZfdHlwZSI7czoxNDoidmFyYmluYXJ5KG1heCkiO3M6MTI6ImRlcGVuZGVuY2llcyI7YTowOnt9fXM6ODoic2V2ZXJpdHkiO2E6MTQ6e3M6NDoibmFtZSI7czo4OiJzZXZlcml0eSI7czoxMDoibWF4X2xlbmd0aCI7aToyO3M6OToicHJlY2lzaW9uIjtpOjU7czoxNDoiY29sbGF0aW9uX25hbWUiO047czoxMToiaXNfbnVsbGFibGUiO2k6MDtzOjE0OiJpc19hbnNpX3BhZGRlZCI7aTowO3M6MTE6ImlzX2lkZW50aXR5IjtpOjA7czoxMToiaXNfY29tcHV0ZWQiO2k6MDtzOjQ6InR5cGUiO3M6ODoic21hbGxpbnQiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7czo1OiIoKDApKSI7czoxMToic3Fsc3J2X3R5cGUiO3M6ODoic21hbGxpbnQiO3M6MTI6ImRlcGVuZGVuY2llcyI7YTowOnt9czo3OiJpbmRleGVzIjthOjE6e2k6MDtzOjEyOiJzZXZlcml0eV9pZHgiO319czo0OiJsaW5rIjthOjEzOntzOjQ6Im5hbWUiO3M6NDoibGluayI7czoxMDoibWF4X2xlbmd0aCI7aTotMTtzOjk6InByZWNpc2lvbiI7aTowO3M6MTQ6ImNvbGxhdGlvbl9uYW1lIjtzOjIwOiJMYXRpbjFfR2VuZXJhbF9DSV9BSSI7czoxMToiaXNfbnVsbGFibGUiO2k6MTtzOjE0OiJpc19hbnNpX3BhZGRlZCI7aToxO3M6MTE6ImlzX2lkZW50aXR5IjtpOjA7czoxMToiaXNfY29tcHV0ZWQiO2k6MDtzOjQ6InR5cGUiO3M6ODoibnZhcmNoYXIiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7TjtzOjExOiJzcWxzcnZfdHlwZSI7czoxMzoibnZhcmNoYXIobWF4KSI7czoxMjoiZGVwZW5kZW5jaWVzIjthOjA6e319czo4OiJsb2NhdGlvbiI7YToxMzp7czo0OiJuYW1lIjtzOjg6ImxvY2F0aW9uIjtzOjEwOiJtYXhfbGVuZ3RoIjtpOi0xO3M6OToicHJlY2lzaW9uIjtpOjA7czoxNDoiY29sbGF0aW9uX25hbWUiO3M6MjA6IkxhdGluMV9HZW5lcmFsX0NJX0FJIjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo4OiJudmFyY2hhciI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtOO3M6MTE6InNxbHNydl90eXBlIjtzOjEzOiJudmFyY2hhcihtYXgpIjtzOjEyOiJkZXBlbmRlbmNpZXMiO2E6MDp7fX1zOjc6InJlZmVyZXIiO2E6MTM6e3M6NDoibmFtZSI7czo3OiJyZWZlcmVyIjtzOjEwOiJtYXhfbGVuZ3RoIjtpOi0xO3M6OToicHJlY2lzaW9uIjtpOjA7czoxNDoiY29sbGF0aW9uX25hbWUiO3M6MjA6IkxhdGluMV9HZW5lcmFsX0NJX0FJIjtzOjExOiJpc19udWxsYWJsZSI7aToxO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo4OiJudmFyY2hhciI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtOO3M6MTE6InNxbHNydl90eXBlIjtzOjEzOiJudmFyY2hhcihtYXgpIjtzOjEyOiJkZXBlbmRlbmNpZXMiO2E6MDp7fX1zOjg6Imhvc3RuYW1lIjthOjEzOntzOjQ6Im5hbWUiO3M6ODoiaG9zdG5hbWUiO3M6MTA6Im1heF9sZW5ndGgiO2k6MTI4O3M6OToicHJlY2lzaW9uIjtpOjA7czoxNDoiY29sbGF0aW9uX25hbWUiO3M6MjA6IkxhdGluMV9HZW5lcmFsX0NJX0FJIjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo3OiJ2YXJjaGFyIjtzOjEwOiJkZWZpbml0aW9uIjtOO3M6MTM6ImRlZmF1bHRfdmFsdWUiO3M6NDoiKCcnKSI7czoxMToic3Fsc3J2X3R5cGUiO3M6MTI6InZhcmNoYXIoMTI4KSI7czoxMjoiZGVwZW5kZW5jaWVzIjthOjA6e319czo5OiJ0aW1lc3RhbXAiO2E6MTM6e3M6NDoibmFtZSI7czo5OiJ0aW1lc3RhbXAiO3M6MTA6Im1heF9sZW5ndGgiO2k6NDtzOjk6InByZWNpc2lvbiI7aToxMDtzOjE0OiJjb2xsYXRpb25fbmFtZSI7TjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjA7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czozOiJpbnQiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7czo1OiIoKDApKSI7czoxMToic3Fsc3J2X3R5cGUiO3M6MzoiaW50IjtzOjEyOiJkZXBlbmRlbmNpZXMiO2E6MDp7fX19czoxMzoiY29sdW1uc19jbGVhbiI7YToxMTp7czozOiJ3aWQiO2E6MTM6e3M6NDoibmFtZSI7czozOiJ3aWQiO3M6MTA6Im1heF9sZW5ndGgiO2k6NDtzOjk6InByZWNpc2lvbiI7aToxMDtzOjE0OiJjb2xsYXRpb25fbmFtZSI7TjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjA7czoxMToiaXNfaWRlbnRpdHkiO2k6MTtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czozOiJpbnQiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7TjtzOjExOiJzcWxzcnZfdHlwZSI7czozOiJpbnQiO3M6NzoiaW5kZXhlcyI7YToxOntpOjA7czoxMzoid2F0Y2hkb2dfcGtleSI7fX1zOjM6InVpZCI7YToxMzp7czo0OiJuYW1lIjtzOjM6InVpZCI7czoxMDoibWF4X2xlbmd0aCI7aTo0O3M6OToicHJlY2lzaW9uIjtpOjEwO3M6MTQ6ImNvbGxhdGlvbl9uYW1lIjtOO3M6MTE6ImlzX251bGxhYmxlIjtpOjA7czoxNDoiaXNfYW5zaV9wYWRkZWQiO2k6MDtzOjExOiJpc19pZGVudGl0eSI7aTowO3M6MTE6ImlzX2NvbXB1dGVkIjtpOjA7czo0OiJ0eXBlIjtzOjM6ImludCI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtzOjU6IigoMCkpIjtzOjExOiJzcWxzcnZfdHlwZSI7czozOiJpbnQiO3M6NzoiaW5kZXhlcyI7YToxOntpOjA7czo3OiJ1aWRfaWR4Ijt9fXM6NDoidHlwZSI7YToxMzp7czo0OiJuYW1lIjtzOjQ6InR5cGUiO3M6MTA6Im1heF9sZW5ndGgiO2k6NjQ7czo5OiJwcmVjaXNpb24iO2k6MDtzOjE0OiJjb2xsYXRpb25fbmFtZSI7czoyMDoiTGF0aW4xX0dlbmVyYWxfQ0lfQUkiO3M6MTE6ImlzX251bGxhYmxlIjtpOjA7czoxNDoiaXNfYW5zaV9wYWRkZWQiO2k6MTtzOjExOiJpc19pZGVudGl0eSI7aTowO3M6MTE6ImlzX2NvbXB1dGVkIjtpOjA7czo0OiJ0eXBlIjtzOjc6InZhcmNoYXIiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7czo0OiIoJycpIjtzOjExOiJzcWxzcnZfdHlwZSI7czoxMToidmFyY2hhcig2NCkiO3M6NzoiaW5kZXhlcyI7YToxOntpOjA7czo4OiJ0eXBlX2lkeCI7fX1zOjc6Im1lc3NhZ2UiO2E6MTI6e3M6NDoibmFtZSI7czo3OiJtZXNzYWdlIjtzOjEwOiJtYXhfbGVuZ3RoIjtpOi0xO3M6OToicHJlY2lzaW9uIjtpOjA7czoxNDoiY29sbGF0aW9uX25hbWUiO3M6MjA6IkxhdGluMV9HZW5lcmFsX0NJX0FJIjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo4OiJudmFyY2hhciI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtOO3M6MTE6InNxbHNydl90eXBlIjtzOjEzOiJudmFyY2hhcihtYXgpIjt9czo5OiJ2YXJpYWJsZXMiO2E6MTI6e3M6NDoibmFtZSI7czo5OiJ2YXJpYWJsZXMiO3M6MTA6Im1heF9sZW5ndGgiO2k6LTE7czo5OiJwcmVjaXNpb24iO2k6MDtzOjE0OiJjb2xsYXRpb25fbmFtZSI7TjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo5OiJ2YXJiaW5hcnkiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7TjtzOjExOiJzcWxzcnZfdHlwZSI7czoxNDoidmFyYmluYXJ5KG1heCkiO31zOjg6InNldmVyaXR5IjthOjEzOntzOjQ6Im5hbWUiO3M6ODoic2V2ZXJpdHkiO3M6MTA6Im1heF9sZW5ndGgiO2k6MjtzOjk6InByZWNpc2lvbiI7aTo1O3M6MTQ6ImNvbGxhdGlvbl9uYW1lIjtOO3M6MTE6ImlzX251bGxhYmxlIjtpOjA7czoxNDoiaXNfYW5zaV9wYWRkZWQiO2k6MDtzOjExOiJpc19pZGVudGl0eSI7aTowO3M6MTE6ImlzX2NvbXB1dGVkIjtpOjA7czo0OiJ0eXBlIjtzOjg6InNtYWxsaW50IjtzOjEwOiJkZWZpbml0aW9uIjtOO3M6MTM6ImRlZmF1bHRfdmFsdWUiO3M6NToiKCgwKSkiO3M6MTE6InNxbHNydl90eXBlIjtzOjg6InNtYWxsaW50IjtzOjc6ImluZGV4ZXMiO2E6MTp7aTowO3M6MTI6InNldmVyaXR5X2lkeCI7fX1zOjQ6ImxpbmsiO2E6MTI6e3M6NDoibmFtZSI7czo0OiJsaW5rIjtzOjEwOiJtYXhfbGVuZ3RoIjtpOi0xO3M6OToicHJlY2lzaW9uIjtpOjA7czoxNDoiY29sbGF0aW9uX25hbWUiO3M6MjA6IkxhdGluMV9HZW5lcmFsX0NJX0FJIjtzOjExOiJpc19udWxsYWJsZSI7aToxO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo4OiJudmFyY2hhciI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtOO3M6MTE6InNxbHNydl90eXBlIjtzOjEzOiJudmFyY2hhcihtYXgpIjt9czo4OiJsb2NhdGlvbiI7YToxMjp7czo0OiJuYW1lIjtzOjg6ImxvY2F0aW9uIjtzOjEwOiJtYXhfbGVuZ3RoIjtpOi0xO3M6OToicHJlY2lzaW9uIjtpOjA7czoxNDoiY29sbGF0aW9uX25hbWUiO3M6MjA6IkxhdGluMV9HZW5lcmFsX0NJX0FJIjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjE7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czo4OiJudmFyY2hhciI7czoxMDoiZGVmaW5pdGlvbiI7TjtzOjEzOiJkZWZhdWx0X3ZhbHVlIjtOO3M6MTE6InNxbHNydl90eXBlIjtzOjEzOiJudmFyY2hhcihtYXgpIjt9czo3OiJyZWZlcmVyIjthOjEyOntzOjQ6Im5hbWUiO3M6NzoicmVmZXJlciI7czoxMDoibWF4X2xlbmd0aCI7aTotMTtzOjk6InByZWNpc2lvbiI7aTowO3M6MTQ6ImNvbGxhdGlvbl9uYW1lIjtzOjIwOiJMYXRpbjFfR2VuZXJhbF9DSV9BSSI7czoxMToiaXNfbnVsbGFibGUiO2k6MTtzOjE0OiJpc19hbnNpX3BhZGRlZCI7aToxO3M6MTE6ImlzX2lkZW50aXR5IjtpOjA7czoxMToiaXNfY29tcHV0ZWQiO2k6MDtzOjQ6InR5cGUiO3M6ODoibnZhcmNoYXIiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7TjtzOjExOiJzcWxzcnZfdHlwZSI7czoxMzoibnZhcmNoYXIobWF4KSI7fXM6ODoiaG9zdG5hbWUiO2E6MTI6e3M6NDoibmFtZSI7czo4OiJob3N0bmFtZSI7czoxMDoibWF4X2xlbmd0aCI7aToxMjg7czo5OiJwcmVjaXNpb24iO2k6MDtzOjE0OiJjb2xsYXRpb25fbmFtZSI7czoyMDoiTGF0aW4xX0dlbmVyYWxfQ0lfQUkiO3M6MTE6ImlzX251bGxhYmxlIjtpOjA7czoxNDoiaXNfYW5zaV9wYWRkZWQiO2k6MTtzOjExOiJpc19pZGVudGl0eSI7aTowO3M6MTE6ImlzX2NvbXB1dGVkIjtpOjA7czo0OiJ0eXBlIjtzOjc6InZhcmNoYXIiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7czo0OiIoJycpIjtzOjExOiJzcWxzcnZfdHlwZSI7czoxMjoidmFyY2hhcigxMjgpIjt9czo5OiJ0aW1lc3RhbXAiO2E6MTI6e3M6NDoibmFtZSI7czo5OiJ0aW1lc3RhbXAiO3M6MTA6Im1heF9sZW5ndGgiO2k6NDtzOjk6InByZWNpc2lvbiI7aToxMDtzOjE0OiJjb2xsYXRpb25fbmFtZSI7TjtzOjExOiJpc19udWxsYWJsZSI7aTowO3M6MTQ6ImlzX2Fuc2lfcGFkZGVkIjtpOjA7czoxMToiaXNfaWRlbnRpdHkiO2k6MDtzOjExOiJpc19jb21wdXRlZCI7aTowO3M6NDoidHlwZSI7czozOiJpbnQiO3M6MTA6ImRlZmluaXRpb24iO047czoxMzoiZGVmYXVsdF92YWx1ZSI7czo1OiIoKDApKSI7czoxMToic3Fsc3J2X3R5cGUiO3M6MzoiaW50Ijt9fXM6NToiYmxvYnMiO2E6MTp7czo5OiJ2YXJpYWJsZXMiO2I6MTt9czo3OiJpbmRleGVzIjthOjQ6e3M6MTM6IndhdGNoZG9nX3BrZXkiO2E6MTU6e3M6MTA6ImluZGV4X25hbWUiO3M6MTM6IndhdGNoZG9nX3BrZXkiO3M6OToidHlwZV9kZXNjIjtzOjk6IkNMVVNURVJFRCI7czo5OiJpc191bmlxdWUiO2k6MTtzOjEzOiJkYXRhX3NwYWNlX2lkIjtpOjE7czoxNDoiaWdub3JlX2R1cF9rZXkiO2k6MDtzOjE0OiJpc19wcmltYXJ5X2tleSI7aToxO3M6MjA6ImlzX3VuaXF1ZV9jb25zdHJhaW50IjtpOjA7czoxMToiZmlsbF9mYWN0b3IiO2k6MDtzOjk6ImlzX3BhZGRlZCI7aTowO3M6MTE6ImlzX2Rpc2FibGVkIjtpOjA7czoxNToiaXNfaHlwb3RoZXRpY2FsIjtpOjA7czoxNToiYWxsb3dfcm93X2xvY2tzIjtpOjE7czoxNjoiYWxsb3dfcGFnZV9sb2NrcyI7aToxO3M6MTg6ImlzX2luY2x1ZGVkX2NvbHVtbiI7aTowO3M6NzoiY29sdW1ucyI7YToxOntpOjE7YTozOntzOjQ6Im5hbWUiO3M6Mzoid2lkIjtzOjE3OiJpc19kZXNjZW5kaW5nX2tleSI7aTowO3M6MTE6ImtleV9vcmRpbmFsIjtpOjE7fX19czo4OiJ0eXBlX2lkeCI7YToxNTp7czoxMDoiaW5kZXhfbmFtZSI7czo4OiJ0eXBlX2lkeCI7czo5OiJ0eXBlX2Rlc2MiO3M6MTI6Ik5PTkNMVVNURVJFRCI7czo5OiJpc191bmlxdWUiO2k6MDtzOjEzOiJkYXRhX3NwYWNlX2lkIjtpOjE7czoxNDoiaWdub3JlX2R1cF9rZXkiO2k6MDtzOjE0OiJpc19wcmltYXJ5X2tleSI7aTowO3M6MjA6ImlzX3VuaXF1ZV9jb25zdHJhaW50IjtpOjA7czoxMToiZmlsbF9mYWN0b3IiO2k6MDtzOjk6ImlzX3BhZGRlZCI7aTowO3M6MTE6ImlzX2Rpc2FibGVkIjtpOjA7czoxNToiaXNfaHlwb3RoZXRpY2FsIjtpOjA7czoxNToiYWxsb3dfcm93X2xvY2tzIjtpOjE7czoxNjoiYWxsb3dfcGFnZV9sb2NrcyI7aToxO3M6MTg6ImlzX2luY2x1ZGVkX2NvbHVtbiI7aTowO3M6NzoiY29sdW1ucyI7YToxOntpOjE7YTozOntzOjQ6Im5hbWUiO3M6NDoidHlwZSI7czoxNzoiaXNfZGVzY2VuZGluZ19rZXkiO2k6MDtzOjExOiJrZXlfb3JkaW5hbCI7aToxO319fXM6NzoidWlkX2lkeCI7YToxNTp7czoxMDoiaW5kZXhfbmFtZSI7czo3OiJ1aWRfaWR4IjtzOjk6InR5cGVfZGVzYyI7czoxMjoiTk9OQ0xVU1RFUkVEIjtzOjk6ImlzX3VuaXF1ZSI7aTowO3M6MTM6ImRhdGFfc3BhY2VfaWQiO2k6MTtzOjE0OiJpZ25vcmVfZHVwX2tleSI7aTowO3M6MTQ6ImlzX3ByaW1hcnlfa2V5IjtpOjA7czoyMDoiaXNfdW5pcXVlX2NvbnN0cmFpbnQiO2k6MDtzOjExOiJmaWxsX2ZhY3RvciI7aTowO3M6OToiaXNfcGFkZGVkIjtpOjA7czoxMToiaXNfZGlzYWJsZWQiO2k6MDtzOjE1OiJpc19oeXBvdGhldGljYWwiO2k6MDtzOjE1OiJhbGxvd19yb3dfbG9ja3MiO2k6MTtzOjE2OiJhbGxvd19wYWdlX2xvY2tzIjtpOjE7czoxODoiaXNfaW5jbHVkZWRfY29sdW1uIjtpOjA7czo3OiJjb2x1bW5zIjthOjE6e2k6MTthOjM6e3M6NDoibmFtZSI7czozOiJ1aWQiO3M6MTc6ImlzX2Rlc2NlbmRpbmdfa2V5IjtpOjA7czoxMToia2V5X29yZGluYWwiO2k6MTt9fX1zOjEyOiJzZXZlcml0eV9pZHgiO2E6MTU6e3M6MTA6ImluZGV4X25hbWUiO3M6MTI6InNldmVyaXR5X2lkeCI7czo5OiJ0eXBlX2Rlc2MiO3M6MTI6Ik5PTkNMVVNURVJFRCI7czo5OiJpc191bmlxdWUiO2k6MDtzOjEzOiJkYXRhX3NwYWNlX2lkIjtpOjE7czoxNDoiaWdub3JlX2R1cF9rZXkiO2k6MDtzOjE0OiJpc19wcmltYXJ5X2tleSI7aTowO3M6MjA6ImlzX3VuaXF1ZV9jb25zdHJhaW50IjtpOjA7czoxMToiZmlsbF9mYWN0b3IiO2k6MDtzOjk6ImlzX3BhZGRlZCI7aTowO3M6MTE6ImlzX2Rpc2FibGVkIjtpOjA7czoxNToiaXNfaHlwb3RoZXRpY2FsIjtpOjA7czoxNToiYWxsb3dfcm93X2xvY2tzIjtpOjE7czoxNjoiYWxsb3dfcGFnZV9sb2NrcyI7aToxO3M6MTg6ImlzX2luY2x1ZGVkX2NvbHVtbiI7aTowO3M6NzoiY29sdW1ucyI7YToxOntpOjE7YTozOntzOjQ6Im5hbWUiO3M6ODoic2V2ZXJpdHkiO3M6MTc6ImlzX2Rlc2NlbmRpbmdfa2V5IjtpOjA7czoxMToia2V5X29yZGluYWwiO2k6MTt9fX19czoxNzoicHJpbWFyeV9rZXlfaW5kZXgiO3M6MTM6IndhdGNoZG9nX3BrZXkiO30='; + + $values = unserialize(base64_decode($values_encoded)); + $columnInformation = unserialize(base64_decode($columninformation_encoded)); + + /** @var MyStatement */ + $st = $cnn->prepare($query, $pdo_options); -$st = $cnn->query("SELECT * FROM [watchdog]"); -var_dump($st->fetchAll(PDO::FETCH_ASSOC)); + $st->BindValues($values, ':db_insert', $columnInformation); + $st->execute(); -$st = NULL; -$cnn = NULL; + $st = $cnn->query("SELECT * FROM [$tbname]"); + var_dump($st->fetchAll(PDO::FETCH_ASSOC)); + dropTable($cnn, $tbname); + unset($st); + unset($cnn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- array(1) { diff --git a/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_pos_placehodlers.phpt b/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_pos_placehodlers.phpt index 9a346b8d8..c089e694e 100644 --- a/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_pos_placehodlers.phpt +++ b/test/functional/pdo_sqlsrv/pdo_140_emulate_prepare_pos_placehodlers.phpt @@ -1,66 +1,47 @@ --TEST-- Test emulate prepare with mix bound param encodings and positional placeholders (i.e., using '?' as placeholders) --SKIPIF-- - + --FILE-- prepare('DROP TABLE WATCHDOG', $pdo_options); - - $st->execute(); -} -catch(\Exception $e) {} - -$tablescript = <<prepare($tablescript, $pdo_options); -$st->execute(); - -$query = <<prepare($query, $pdo_options); -$system_param = 'system encoded string'; -$utf8_param = '가각ácasa'; -$binary_param = fopen('php://memory', 'a'); -fwrite($binary_param, 'asdgasdgasdgsadg'); -rewind($binary_param); + $tbname = "watchdog"; + createTable( $cnn, $tbname, array( "system_encoding" => "nvarchar(128)", "utf8_encoding" => "nvarchar(128)", "binary_encoding" => "varbinary(max)")); -$st->bindParam(1, $system_param, PDO::PARAM_STR); -$st->bindParam(2, $utf8_param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$st->bindParam(3, $binary_param, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $system_param = 'system encoded string'; + $utf8_param = '가각ácasa'; + $binary_param = fopen('php://memory', 'a'); + fwrite($binary_param, 'asdgasdgasdgsadg'); + rewind($binary_param); -$st->execute(); + $inputs = array("system_encoding" => $system_param, + "utf8_encoding" => new BindParamOp( 2, $utf8_param, "PDO::PARAM_STR", 0, "PDO::SQLSRV_ENCODING_UTF8" ), + "binary_encoding" => new BindParamOp( 3, $binary_param, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY" )); -$st = $cnn->query("SELECT * FROM [watchdog]"); -var_dump($st->fetchAll()); + insertRow($cnn, $tbname, $inputs, "prepareBindParam"); -$st = NULL; -$cnn = NULL; + $data = selectAll($cnn, $tbname); + var_dump($data); + dropTable($cnn, $tbname); + unset($st); + unset($cnn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- array(1) { diff --git a/test/functional/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt b/test/functional/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt index 76970f630..0e94b1050 100644 --- a/test/functional/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt +++ b/test/functional/pdo_sqlsrv/pdo_228_setAttribute_clientbuffermaxkbsize.phpt @@ -1,53 +1,56 @@ --TEST-- sqlsrv_has_rows() using a forward and scrollable cursor --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -// Create temporary table2 -$tableName1 = '#pdo_228_1'; -$tableName2 = '#pdo_228_2'; - -$stmt = $conn->exec("CREATE TABLE $tableName1 ([c1_int] int, [c2_varchar] varchar(1000))"); -$query = "INSERT INTO $tableName1 (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>åBã_ý*ah¢rOĪ,ßo¢¢a|BÖäzU£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))"; -$stmt = $conn->query($query); - -$stmt = $conn->exec("CREATE TABLE $tableName2 ([c1_int] int, [c2_varchar] varchar(max))"); -$query = "INSERT INTO $tableName2 (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>åBã_ý*ah¢rOĪ,ßo¢¢a|BÖäzU£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))"; -$stmt = $conn->query($query); - -$size = 2; -$stmt = $conn->prepare("SELECT * FROM $tableName1", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size)); -$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE')); -echo("Client Buffer Size in KB: $attr\n"); -$stmt->execute(); -$numRows = 0; -while ($result = $stmt->fetch()) - $numRows++; - -echo ("Number of rows: $numRows\n"); - -$size = 3; -$stmt = $conn->prepare("SELECT * FROM $tableName2", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size)); -$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE')); -echo("Client Buffer Size in KB: $attr\n"); -$stmt->execute(); -$numRows = 0; -while ($result = $stmt->fetch()) - $numRows++; - -echo ("Number of rows: $numRows\n"); - -$stmt=null; -$conn=null; -print "Done" +require_once("MsCommon_mid-refactor.inc"); + +try { + // Connect + $conn = connect(); + + // Create 2 tables + $tableName1 = 'pdo_228_1'; + $tableName2 = 'pdo_228_2'; + + createTable($conn,$tableName1, array("c1_int" => "int", "c2_varchar" => "varchar(1000)")); + insertRow($conn, $tableName1, array("c1_int" => 990021574, "c2_varchar" => ">vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>åBã_ý*ah¢rOĪ,ßo¢¢a|BÖäzU£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£")); + + createTable($conn,$tableName2, array("c1_int" => "int", "c2_varchar" => "varchar(max)")); + insertRow($conn, $tableName2, array("c1_int" => 990021574, "c2_varchar" => ">vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>åBã_ý*ah¢rOĪ,ßo¢¢a|BÖäzU£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£")); + + $size = 2; + $stmt = $conn->prepare("SELECT * FROM $tableName1", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size)); + $attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE')); + echo("Client Buffer Size in KB: $attr\n"); + $stmt->execute(); + $numRows = 0; + while ($result = $stmt->fetch()) { + $numRows++; + } + echo ("Number of rows: $numRows\n"); + + $size = 3; + $stmt = $conn->prepare("SELECT * FROM $tableName2", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size)); + $attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE')); + echo("Client Buffer Size in KB: $attr\n"); + $stmt->execute(); + $numRows = 0; + while ($result = $stmt->fetch()) { + $numRows++; + } + + echo ("Number of rows: $numRows\n"); + + dropTable($conn, $tableName1); + dropTable($conn, $tableName2); + unset($stmt); + unset($conn); + print "Done"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_267_closeCursor.phpt b/test/functional/pdo_sqlsrv/pdo_267_closeCursor.phpt index fe26aaf05..d0559af1b 100644 --- a/test/functional/pdo_sqlsrv/pdo_267_closeCursor.phpt +++ b/test/functional/pdo_sqlsrv/pdo_267_closeCursor.phpt @@ -1,26 +1,26 @@ --TEST-- Test closeCursor with a stmt before/after execute and fetch. --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + $conn = connect(); + $sql = "select 123 as 'IntCol'"; // prepare a stmt but don't execute, then closeCursor. - $stmt = $conn->prepare("select 123 as 'IntCol'"); + $stmt = $conn->prepare($sql); $ret = $stmt->closeCursor(); var_dump($ret); $ret = $stmt->closeCursor(); var_dump($ret); // prepare a stmt and execute, then closeCursor. - $stmt = $conn->prepare("select 123 as 'IntCol'"); + $stmt = $conn->prepare($sql); $stmt->execute(); $ret = $stmt->closeCursor(); var_dump($ret); @@ -30,7 +30,7 @@ try // use two stmt, execute, and fetch, then closeCursor. // use one with client side buffering. - $stmt1 = $conn->query("select 123 as 'IntCol'"); + $stmt1 = $conn->query($sql); $stmt2 = $conn->prepare("select 'abc' as 'Charcol'", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); $result = $stmt1->fetch(PDO::FETCH_NUM); print_r($result[0]); @@ -44,14 +44,12 @@ try $ret = $stmt2->closeCursor(); var_dump($ret); - $stmt1 = null; - $stmt2 = null; - $stmt = null; - $conn = null; - + unset($stmt1); + unset($stmt2); + unset($stmt); + unset($conn); } - -catch( PDOException $e ) { +catch(PDOException $e) { var_dump($e); exit; } diff --git a/test/functional/pdo_sqlsrv/pdo_270_fetch_binary.phpt b/test/functional/pdo_sqlsrv/pdo_270_fetch_binary.phpt index 500d58d07..f3f52b80a 100644 --- a/test/functional/pdo_sqlsrv/pdo_270_fetch_binary.phpt +++ b/test/functional/pdo_sqlsrv/pdo_270_fetch_binary.phpt @@ -4,90 +4,96 @@ Test fetch from binary, varbinary, varbinary(max), image columns, without settin Verifies GitHub issue 270 is fixed, users could not retrieve the data as inserted in binary columns without setting the binary encoding either on stmt or using bindCoulmn encoding. This test verifies that the data inserted in binary columns can be retrieved using fetch, fetchColumn, fetchObject, and fetchAll functions. --SKIPIF-- - + --FILE-- exec($sql); + $colmeta_arr = array($columns[0] => "binary(50)", $columns[1] => "varbinary(50)", $columns[2] => "varbinary(max)"); + $icon = base64_decode("This is some text to test retrieving from binary type columns"); + $inputs = array($columns[0] => new BindParamOp(1, $icon, "PDO::PARAM_LOB", null, "PDO::SQLSRV_ENCODING_BINARY"), + $columns[1] => new BindParamOp(2, $icon, "PDO::PARAM_LOB", null, "PDO::SQLSRV_ENCODING_BINARY"), + $columns[2] => new BindParamOp(3, $icon, "PDO::PARAM_LOB", null, "PDO::SQLSRV_ENCODING_BINARY")); -$icon = base64_decode("This is some text to test retrieving from binary type columns"); + if (!isColEncrypted()) { + // image is not supported for encryption + array_push($columns, 'col4'); + $colmeta_arr += array($columns[3] => "image"); + $inputs += array( $columns[3] => new BindParamOp(4, $icon, "PDO::PARAM_LOB", null, "PDO::SQLSRV_ENCODING_BINARY")); + } + + createTable($conn, $tableName, $colmeta_arr); -// Insert data using bind parameters -$sql = "INSERT INTO $tableName($columns[0], $columns[1], $columns[2], $columns[3]) VALUES(?, ?, ?, ?)"; -$stmt = $conn->prepare($sql); -$stmt->bindParam(1, $icon, PDO::PARAM_LOB, null, PDO::SQLSRV_ENCODING_BINARY); -$stmt->bindParam(2, $icon, PDO::PARAM_LOB, null, PDO::SQLSRV_ENCODING_BINARY); -$stmt->bindParam(3, $icon, PDO::PARAM_LOB, null, PDO::SQLSRV_ENCODING_BINARY); -$stmt->bindParam(4, $icon, PDO::PARAM_LOB, null, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); + // Insert data using bind parameters + insertRow($conn, $tableName, $inputs, "prepareBindParam"); -// loop through each column in the table -foreach ($columns as $col){ - test_fetch($conn, $tableName, $col, $icon); -} -// DROP table -$conn->query("DROP TABLE $tableName") ?: die(); + // loop through each column in the table + foreach ($columns as $col) { + testFetch($conn, $tableName, $col, $icon); + } + // DROP table + dropTable($conn, $tableName); -//free statement and connection -$stmt = null; -$conn = null; + //free statement and connection + unset($stmt); + unset($conn); -print_r("Test finished successfully"); + print_r("Test finished successfully\n"); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} -//calls various fetch methods -function test_fetch($conn, $tableName, $columnName, $input){ - + //calls various fetch methods +function testFetch($conn, $tableName, $columnName, $input) +{ $len = strlen($input); $result = ""; $sql = "SELECT $columnName from $tableName"; - - $stmt = $conn->query($sql); + $stmt = $conn->query($sql); $stmt->bindColumn(1, $result, PDO::PARAM_LOB); $stmt->fetch(PDO::FETCH_BOUND); //binary is fixed size, to evaluate output, compare it using strncmp - if( strncmp($result, $input, $len) !== 0){ + if (strncmp($result, $input, $len) !== 0) { print_r("\nRetrieving using bindColumn failed"); } $result = ""; - $stmt = $conn->query($sql); - $stmt->bindColumn(1, $result, PDO::PARAM_LOB, 0 , PDO::SQLSRV_ENCODING_BINARY); + $stmt = $conn->query($sql); + $stmt->bindColumn(1, $result, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); $stmt->fetch(PDO::FETCH_BOUND); - if( strncmp($result, $input, $len) !== 0){ + if (strncmp($result, $input, $len) !== 0) { print_r("\nRetrieving using bindColumn with encoding set failed"); } $result = ""; - $stmt = $conn->query($sql); + $stmt = $conn->query($sql); $result = $stmt->fetchColumn(); - if( strncmp($result, $input, $len) !== 0){ + if (strncmp($result, $input, $len) !== 0) { print_r("\nRetrieving using fetchColumn failed"); } $result = ""; - $stmt = $conn->query($sql); + $stmt = $conn->query($sql); $result = $stmt->fetchObject(); - if( strncmp($result->$columnName, $input, $len) !== 0){ + if (strncmp($result->$columnName, $input, $len) !== 0) { print_r("\nRetrieving using fetchObject failed"); } $result = ""; - $stmt = $conn->query($sql); - $result = $stmt->fetchAll( PDO::FETCH_COLUMN ); - if( strncmp($result[0], $input, $len) !== 0){ + $stmt = $conn->query($sql); + $result = $stmt->fetchAll(PDO::FETCH_COLUMN); + if (strncmp($result[0], $input, $len) !== 0) { print_r("\nRetrieving using fetchAll failed"); } + unset($stmt); } - ?> --EXPECT-- Test finished successfully diff --git a/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq.phpt b/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq.phpt index c0d35ed7d..774463659 100644 --- a/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq.phpt +++ b/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq.phpt @@ -1,61 +1,75 @@ --TEST-- Provide name in lastInsertId to retrieve the last sequence number --SKIPIF-- + --FILE-- -query($sql); + return $stmt->fetchColumn(); +} + +try { $database = "tempdb"; - $conn = new PDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd); - + $conn = connect(); + // sequence is only supported in SQL server 2012 and up (or version 11 and up) // Output Done once the server version is found to be < 11 $version_arr = explode(".", $conn->getAttribute(PDO::ATTR_SERVER_VERSION)); if ($version_arr[0] < 11) { echo "Done\n"; - } - else { - $tableName1 = GetTempTableName('tab1', false); - $tableName2 = GetTempTableName('tab2', false); + } else { + $tableName1 = getTableName('tab1'); + $tableName2 = getTableName('tab2'); $sequenceName = 'sequence1'; - - $stmt = $conn->query("IF OBJECT_ID('$sequenceName', 'SO') IS NOT NULL DROP SEQUENCE $sequenceName"); - $sql = "CREATE TABLE $tableName1 (seqnum INTEGER NOT NULL PRIMARY KEY, SomeNumber INT)"; - $stmt = $conn->query($sql); - $sql = "CREATE TABLE $tableName2 (ID INT IDENTITY(1,2), SomeValue char(10))"; - $stmt = $conn->query($sql); - + + createTable($conn, $tableName1, array( new ColumnMeta("int", "seqnum", "NOT NULL PRIMARY KEY"), "SomeNumer" => "int")); + createTable($conn, $tableName2, array( new ColumnMeta("int", "ID", "IDENTITY(1,2)"), "SomeValue" => "char(10)")); + $conn->exec("IF OBJECT_ID('$sequenceName', 'SO') IS NOT NULL DROP SEQUENCE $sequenceName"); $sql = "CREATE SEQUENCE $sequenceName AS INTEGER START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 100 CYCLE"; - $stmt = $conn->query($sql); - - $ret = $conn->exec("INSERT INTO $tableName1 VALUES( NEXT VALUE FOR $sequenceName, 20 )"); - $ret = $conn->exec("INSERT INTO $tableName1 VALUES( NEXT VALUE FOR $sequenceName, 40 )"); - $ret = $conn->exec("INSERT INTO $tableName1 VALUES( NEXT VALUE FOR $sequenceName, 60 )"); - $ret = $conn->exec("INSERT INTO $tableName2 VALUES( '20' )"); + $conn->exec($sql); + + if (!isColEncrypted()) { + $conn->exec("INSERT INTO $tableName1 VALUES( NEXT VALUE FOR $sequenceName, 20 )"); + $conn->exec("INSERT INTO $tableName1 VALUES( NEXT VALUE FOR $sequenceName, 40 )"); + $conn->exec("INSERT INTO $tableName1 VALUES( NEXT VALUE FOR $sequenceName, 60 )"); + } else { + // if column seqnum is encrypted, need to get "NEXT VALUE FOR $sequenceName" separately first and then bind param + $sql = "INSERT INTO $tableName1 VALUES( ?, ? )"; + $stmt = $conn->prepare($sql); + $nextSeq = getNextSeq($conn, $sequenceName); + $stmt->execute(array($nextSeq, 20)); + $nextSeq = getNextSeq($conn, $sequenceName); + $stmt->execute(array($nextSeq, 40)); + $nextSeq = getNextSeq($conn, $sequenceName); + $stmt->execute(array($nextSeq, 60)); + } + insertRow($conn, $tableName2, array("SomeValue" => "20")); + // return the last sequence number is sequence name is provided $lastSeq = $conn->lastInsertId($sequenceName); - // defaults to $tableName2 -- because it returns the last inserted id value + // defaults to $tableName2 -- because it returns the last inserted row id value $lastRow = $conn->lastInsertId(); - + if ($lastSeq == 3 && $lastRow == 1) { echo "Done\n"; - } - else { + } else { echo "sequence value or identity does not match as expected\n"; } - $stmt = $conn->query("DROP TABLE $tableName1"); - $stmt = $conn->query("DROP TABLE $tableName2"); - $stmt = $conn->query("DROP SEQUENCE $sequenceName"); - $stmt = null; + dropTable($conn, $tableName1); + dropTable($conn, $tableName2); + $conn->exec("DROP SEQUENCE $sequenceName"); + unset($stmt); } - $conn = null; -} -catch (Exception $e){ + unset($conn); +} catch (Exception $e) { echo "Exception $e\n"; } - + ?> --EXPECT-- -Done \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq_2.phpt b/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq_2.phpt index 6782d6c59..ba8c22dc2 100644 --- a/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq_2.phpt +++ b/test/functional/pdo_sqlsrv/pdo_278_lastinsertid_seq_2.phpt @@ -1,64 +1,85 @@ --TEST-- LastInsertId returns the last sequences operating on the same table --SKIPIF-- + --FILE-- query($sql); + return $stmt->fetchColumn(); +} + +try { + $conn = connect(); -try{ - $database = "tempdb"; - $conn = new PDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd); - // sequence is only supported in SQL server 2012 and up (or version 11 and up) // Output Done once the server version is found to be < 11 $version_arr = explode(".", $conn->getAttribute(PDO::ATTR_SERVER_VERSION)); if ($version_arr[0] < 11) { echo "Done\n"; - } - else { - $tableName = GetTempTableName('tab', false); + } else { + $tableName = getTableName('tab'); $sequence1 = 'sequence1'; $sequence2 = 'sequenceNeg1'; - $stmt = $conn->query("IF OBJECT_ID('$sequence1', 'SO') IS NOT NULL DROP SEQUENCE $sequence1"); - $stmt = $conn->query("IF OBJECT_ID('$sequence2', 'SO') IS NOT NULL DROP SEQUENCE $sequence2"); - $sql = "CREATE TABLE $tableName (ID INT IDENTITY(1,1), SeqNumInc INTEGER NOT NULL PRIMARY KEY, SomeNumber INT)"; - $stmt = $conn->query($sql); + createTable($conn, $tableName, array( new ColumnMeta("int", "ID", "IDENTITY(1,1)"), new ColumnMeta("int", "SeqNumInc", "NOT NULL PRIMARY KEY"), "SomeNumber" => "int")); + $conn->exec("IF OBJECT_ID('$sequence1', 'SO') IS NOT NULL DROP SEQUENCE $sequence1"); + $conn->exec("IF OBJECT_ID('$sequence2', 'SO') IS NOT NULL DROP SEQUENCE $sequence2"); $sql = "CREATE SEQUENCE $sequence1 AS INTEGER START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 100"; - $stmt = $conn->query($sql); - + $stmt = $conn->exec($sql); $sql = "CREATE SEQUENCE $sequence2 AS INTEGER START WITH 200 INCREMENT BY -1 MINVALUE 101 MAXVALUE 200"; - $stmt = $conn->query($sql); - $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence1, 20 )"); - $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence2, 180 )"); - $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence1, 40 )"); - $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence2, 160 )"); - $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence1, 60 )"); - $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence2, 140 )"); + $stmt = $conn->exec($sql); + + if (!isColEncrypted()) { + $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence1, 20 )"); + $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence2, 180 )"); + $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence1, 40 )"); + $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence2, 160 )"); + $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence1, 60 )"); + $ret = $conn->exec("INSERT INTO $tableName VALUES( NEXT VALUE FOR $sequence2, 140 )"); + } else { + // if column seqnum is encrypted, need to get "NEXT VALUE FOR $sequenceName" separately first and then bind param + $sql = "INSERT INTO $tableName VALUES( ?, ? )"; + $stmt = $conn->prepare($sql); + $nextSeq1 = getNextSeq($conn, $sequence1); + $stmt->execute(array( $nextSeq1, 20 )); + $nextSeq2 = getNextSeq($conn, $sequence2); + $stmt->execute(array( $nextSeq2, 180 )); + $nextSeq1 = getNextSeq($conn, $sequence1); + $stmt->execute(array( $nextSeq1, 40 )); + $nextSeq2 = getNextSeq($conn, $sequence2); + $stmt->execute(array( $nextSeq2, 160 )); + $nextSeq1 = getNextSeq($conn, $sequence1); + $stmt->execute(array( $nextSeq1, 60 )); + $nextSeq2 = getNextSeq($conn, $sequence2); + $stmt->execute(array( $nextSeq2, 140 )); + } // return the last sequence number of 'sequence1' $lastSeq1 = $conn->lastInsertId($sequence1); - + // return the last sequence number of 'sequenceNeg1' $lastSeq2 = $conn->lastInsertId($sequence2); - + // providing a table name in lastInsertId should return an empty string $lastSeq3 = $conn->lastInsertId($tableName); - + if ($lastSeq1 == 3 && $lastSeq2 == 198 && $lastSeq3 == "") { echo "Done\n"; } - $stmt = $conn->query("DROP TABLE $tableName"); - $stmt = $conn->query("DROP SEQUENCE $sequence1"); - $stmt = $conn->query("DROP SEQUENCE $sequence2"); - $stmt = null; + dropTable($conn, $tableName); + $stmt = $conn->exec("DROP SEQUENCE $sequence1"); + $stmt = $conn->exec("DROP SEQUENCE $sequence2"); + unset($stmt); } - $conn = null; -} - catch (Exception $e){ + unset($conn); +} catch (Exception $e) { echo "Exception $e\n"; } - + ?> --EXPECT-- -Done \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/pdo_308_empty_output_param.phpt b/test/functional/pdo_sqlsrv/pdo_308_empty_output_param.phpt index 4aa5f8bea..423c6ea4a 100644 --- a/test/functional/pdo_sqlsrv/pdo_308_empty_output_param.phpt +++ b/test/functional/pdo_sqlsrv/pdo_308_empty_output_param.phpt @@ -1,46 +1,49 @@ --TEST-- -GitHub issue #308 - empty string set to output parameter on stored procedure +GitHub issue #308 - empty string set to output parameter on stored procedure --DESCRIPTION-- Verifies GitHub issue 308 is fixed, empty string returned as output parameter will remain an empty string. --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$procName = GetTempProcName(); - -$sql = "CREATE PROCEDURE $procName @TEST VARCHAR(200)='' OUTPUT -AS BEGIN -SET NOCOUNT ON; -SET @TEST=''; -SELECT HELLO_WORLD_COLUMN='THIS IS A COLUMN IN A SINGLE DATASET'; -END"; -$stmt = $conn->exec($sql); - -$sql = "EXEC $procName @Test = :Test"; -$stmt = $conn->prepare($sql); -$out = ''; -$stmt->bindParam(':Test', $out, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 200); -$stmt->execute(); - -$result = $stmt->fetchAll(); -$stmt->closeCursor(); - -echo "OUT value: "; -var_dump($out); - -// Free the statement and connection resources. -$stmt = null; -$conn = null; - -print "Done"; -?> +require_once("MsCommon_mid-refactor.inc"); + +try { + // Connect + $conn = connect(); + + $procName = getProcName(); + + $sql = "CREATE PROCEDURE $procName @TEST VARCHAR(200)='' OUTPUT + AS BEGIN + SET NOCOUNT ON; + SET @TEST=''; + SELECT HELLO_WORLD_COLUMN='THIS IS A COLUMN IN A SINGLE DATASET'; + END"; + $stmt = $conn->exec($sql); + + $sql = "EXEC $procName @Test = :Test"; + $stmt = $conn->prepare($sql); + $out = ''; + $stmt->bindParam(':Test', $out, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 200); + $stmt->execute(); + + $result = $stmt->fetchAll(); + $stmt->closeCursor(); + + echo "OUT value: "; + var_dump($out); + + // Free the statement and connection resources. + dropProc($conn, $procName); + unset($stmt); + unset($conn); + + print "Done\n"; +} catch (PDOException $e) { + var_dump($e->errorInfo); +} +?> --EXPECT-- OUT value: string(0) "" -Done \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/pdo_336_pho_exec_empty_result_set_error.phpt b/test/functional/pdo_sqlsrv/pdo_336_pho_exec_empty_result_set_error.phpt index 1f0194cc8..fab0cb779 100644 --- a/test/functional/pdo_sqlsrv/pdo_336_pho_exec_empty_result_set_error.phpt +++ b/test/functional/pdo_sqlsrv/pdo_336_pho_exec_empty_result_set_error.phpt @@ -3,55 +3,58 @@ GitHub issue #336 - PDO::exec should not return an error with query returning SQ --DESCRIPTION-- Verifies GitHub issue 336 is fixed, PDO::exec on query returning SQL_NO_DATA will not give an error --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$sql = "DELETE FROM foo_table WHERE id = 42"; -$sqlWithParameter = "DELETE FROM foo_table WHERE id = :id"; -$sqlParameter = 42; - -$Statement = $conn->exec("IF OBJECT_ID('foo_table', 'U') IS NOT NULL DROP TABLE foo_table"); -$Statement = $conn->exec("CREATE TABLE foo_table (id BIGINT PRIMARY KEY NOT NULL IDENTITY, intField INT NOT NULL)"); -$Statement = $conn->exec("INSERT INTO foo_table (intField) VALUES(3)"); - -//test prepare, not args -$stmt = $conn->prepare($sql); -$stmt->execute(); -if ($conn->errorCode() == "00000") - echo "prepare OK\n"; -else - echo "unexpected error at prepare"; - -//test prepare, with args -$stmt = $conn->prepare($sqlWithParameter); -$stmt->execute(array(':id' => $sqlParameter)); -if ($conn->errorCode() == "00000") - echo "prepare with args OK\n"; -else - echo "unexpected error at prepare with args"; - -//test direct exec -$stmt = $conn->exec($sql); -$err = $conn->errorCode(); -if ($stmt == 0 && $err == "00000") - echo "direct exec OK\n"; -else - if ($stmt != 0) +// Connect +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + + $tbname = "foo_table"; + createTable($conn, $tbname, array(new ColumnMeta("bigint", "id", "PRIMARY KEY NOT NULL IDENTITY"), new ColumnMeta("int", "intField", "NOT NULL"))); + insertRow($conn, $tbname, array("intField" => 3), "exec"); + + //test prepare, not args + $sql = "DELETE FROM foo_table WHERE id = 42"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + if ($conn->errorCode() == "00000") { + echo "prepare OK\n"; + } else { + echo "unexpected error at prepare"; + } + + //test prepare, with args + $sqlWithParameter = "DELETE FROM foo_table WHERE id = :id"; + $sqlParameter = 42; + $stmt = $conn->prepare($sqlWithParameter); + $stmt->execute(array(':id' => $sqlParameter)); + if ($conn->errorCode() == "00000") { + echo "prepare with args OK\n"; + } else { + echo "unexpected error at prepare with args"; + } + + //test direct exec + $numrow = $conn->exec($sql); + $err = $conn->errorCode(); + if ($numrow == 0 && $err == "00000") { + echo "direct exec OK\n"; + } elseif ($numrow != 0) { echo "unexpected row returned at direct exec\n"; - if ($err != "00000") + } + if ($err != "00000") { echo "unexpected error at direct exec"; - -$Statement = $conn->exec("IF OBJECT_ID('foo_table', 'U') IS NOT NULL DROP TABLE foo_table"); - -$stmt = NULL; -$Statement = NULL; -$conn = NULL; + } + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_378_out_param_error.phpt b/test/functional/pdo_sqlsrv/pdo_378_out_param_error.phpt index ab8ec7a37..9d1832cde 100644 --- a/test/functional/pdo_sqlsrv/pdo_378_out_param_error.phpt +++ b/test/functional/pdo_sqlsrv/pdo_378_out_param_error.phpt @@ -3,57 +3,65 @@ This test verifies that GitHub issue #378 is fixed in pdo_sqlsrv. --DESCRIPTION-- GitHub issue #378 - output parameters appends garbage info when variable is initialized with different data type steps to reproduce the issue: -1- create a store procedure with print and output parameter -2- initialize output parameters to a different data type other than the type declared in sp. +1 - create a store procedure with print and output parameter +2 - initialize output parameters to a different data type other than the type declared in sp. 3 - call sp. +--SKIPIF-- + --FILE-- errorInfo()); -} - -//----------------Main--------------------------- -$procName = GetTempProcName(); -createSP($conn, $procName); -executeSP($conn, $procName); -$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -executeSP($conn, $procName); -echo "Done"; +try { + $conn = connect(); + if (!$conn) { + print_r($conn->errorInfo()); + } + //----------------Main--------------------------- + $procName = getProcName(); + createSP($conn, $procName); + executeSP($conn, $procName); + executeSP($conn, $procName); + dropProc($conn, $procName); + echo "Done\n"; + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} //-------------------functions------------------- -function createSP($conn, $procName){ - - $sp_sql="create proc $procName @p1 integer, @p2 integer, @p3 integer output - as - begin - select @p3 = @p1 + @p2 - print @p3 - end - "; - $stmt = $conn->exec($sp_sql); - if ($stmt === false) { print("Failed to create stored procedure"); } +function createSP($conn, $procName) +{ + $sp_sql="create proc $procName @p1 integer, @p2 integer, @p3 integer output + as + begin + select @p3 = @p1 + @p2 + print @p3 + end"; + $stmt = $conn->exec($sp_sql); + if ($stmt === false) { + print("Failed to create stored procedure"); + } } -function executeSP($conn, $procName){ - $expected = 3; - $stmt = $conn->prepare("{call $procName( ?, ?, ? )}"); - $stmt->bindParam(1, $v1); - $stmt->bindParam(2, $v2); - $stmt->bindParam(3, $v3, PDO::PARAM_INT, 10); - $v1 = 1; - $v2 = 2; - $v3 = 'str'; - $stmt->execute(); - if (!$stmt) { - print_r($stmt->errorInfo()); - } - if ( $v3 != $expected ) { - print("The expected value is $expected, actual value is $v3\n"); - } +function executeSP($conn, $procName) +{ + $expected = 3; + $stmt = $conn->prepare("{call $procName( ?, ?, ? )}"); + $stmt->bindParam(1, $v1); + $stmt->bindParam(2, $v2); + $stmt->bindParam(3, $v3, PDO::PARAM_INT, 10); + $v1 = 1; + $v2 = 2; + $v3 = 'str'; + $stmt->execute(); + if (!$stmt) { + print_r($stmt->errorInfo()); + } + if ($v3 != $expected) { + print("The expected value is $expected, actual value is $v3\n"); + } + unset($stmt); } ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt b/test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt index a636c7fcc..dc80e35b5 100644 --- a/test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt +++ b/test/functional/pdo_sqlsrv/pdo_538_quote_nul.phpt @@ -1,28 +1,24 @@ --TEST-- Test the PDO::quote() method with a string containing '\0' character --SKIPIF-- - + --FILE-- quote($str); print("Quoted: " . str_replace("\0", "{NUL}", $str) . "\n"); -} - -catch( PDOException $e ) { +} catch (PDOException $e) { die("Connection error: " . $e->getMessage()); } -?> - +?> --EXPECT-- Original: XX{NUL}XX -Quoted: 'XX{NUL}XX' \ No newline at end of file +Quoted: 'XX{NUL}XX' diff --git a/test/functional/pdo_sqlsrv/pdo_bindparam_inout_binary_encoding.phpt b/test/functional/pdo_sqlsrv/pdo_bindparam_inout_binary_encoding.phpt index 362a06e4a..5df1b4e3f 100644 --- a/test/functional/pdo_sqlsrv/pdo_bindparam_inout_binary_encoding.phpt +++ b/test/functional/pdo_sqlsrv/pdo_bindparam_inout_binary_encoding.phpt @@ -1,48 +1,41 @@ --TEST-- bind inout param with PDO::SQLSRV_ENCODING_BINARY --SKIPIF-- - + --FILE-- query($sql); -$stmt = null; - -$sql = "CREATE TABLE my_table (value varchar(20), name varchar(20))"; -$stmt = $pdo->query($sql); -$stmt = null; - -$sql = "INSERT INTO my_table (value, name) VALUES ('Initial string', 'name')"; -$stmt = $pdo->query($sql); -$stmt = null; - -$value = 'Some string value.'; -$name = 'name'; - -$sql = "UPDATE my_table SET value = :value WHERE name = :name"; - -$stmt = $pdo->prepare($sql); - -$stmt->bindParam(':value', $value, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->bindParam(':name', $name); - -$stmt->execute(); -$stmt = null; - -$sql = "SELECT * FROM my_table"; -$stmt = $pdo->query($sql); -$result = $stmt->fetch(PDO::FETCH_ASSOC); -print_r($result); - -$stmt->closeCursor(); -$pdo = null; +require_once("MsCommon_mid-refactor.inc"); + +try { + $pdo = connect(); + + $tbname = "my_table"; + createTable($pdo, $tbname, array("value" => "varchar(20)", "name" => "varchar(20)")); + insertRow($pdo, $tbname, array( "value" => "Initial string", "name" => "name" )); + + $value = 'Some string value.'; + $name = 'name'; + + $sql = "UPDATE my_table SET value = :value WHERE name = :name"; + $stmt = $pdo->prepare($sql); + $stmt->bindParam(':value', $value, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->bindParam(':name', $name); + $stmt->execute(); + + $result = selectRow($pdo, $tbname, "PDO::FETCH_ASSOC"); + print_r($result); + + $stmt->closeCursor(); + dropTable($pdo, $tbname); + unset($stmt); + unset($pdo); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- Array ( [value] => Some string value. [name] => name -) \ No newline at end of file +) diff --git a/test/functional/pdo_sqlsrv/pdo_connection_quote.phpt b/test/functional/pdo_sqlsrv/pdo_connection_quote.phpt index 623060a78..d3865d0a2 100644 --- a/test/functional/pdo_sqlsrv/pdo_connection_quote.phpt +++ b/test/functional/pdo_sqlsrv/pdo_connection_quote.phpt @@ -1,75 +1,49 @@ --TEST-- testing the quote method with different inputs and then test with a empty query --SKIPIF-- - + --FILE-- quote("1'2'3'4'5'6'7'8", PDO::PARAM_INT); var_dump($output1); - + $output2 = $conn->quote("{ABCD}'{EFGH}", PDO::PARAM_STR); var_dump($output2); - - $output3 = $conn->quote("The quick brown fox jumps over the lazy dog0123456789"); - var_dump($output3); + + $output3 = $conn->quote("The quick brown fox jumps over the lazy dog0123456789"); + var_dump($output3); $stmt = $conn->query(""); - if ($stmt != false) - { + if ($stmt != false) { echo("Empty query was expected to fail!\n"); - } - + } + unset($stmt); + $stmt1 = $conn->prepare($output2); $result = $stmt1->execute(); - if ($result != false) - { + if ($result != false) { echo("This query was expected to fail!\n"); } - $stmt1 = null; - + unset($stmt1); + $stmt2 = $conn->query($output3); - if ($stmt2 != false) - { + if ($stmt2 != false) { echo("This query was expected to fail!\n"); - } - - $conn = null; -} - -function Repro() -{ - StartTest("pdo_connection_quote"); - echo "\nStarting test...\n"; - try - { - Quote(); - } - catch (Exception $e) - { - echo $e->getMessage(); } - echo "\nDone\n"; - EndTest("pdo_connection_quote"); -} - -Repro(); + unset($stmt2); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); +} ?> --EXPECT-- - -Starting test... string(24) "'1''2''3''4''5''6''7''8'" string(16) "'{ABCD}''{EFGH}'" string(118) "'The quick brown fox jumps over the lazy dog0123456789'" - -Done -Test "pdo_connection_quote" completed successfully. diff --git a/test/functional/pdo_sqlsrv/pdo_construct.phpt b/test/functional/pdo_sqlsrv/pdo_construct.phpt index 77c3b5e0b..6521f23de 100644 --- a/test/functional/pdo_sqlsrv/pdo_construct.phpt +++ b/test/functional/pdo_sqlsrv/pdo_construct.phpt @@ -1,34 +1,28 @@ --TEST-- Test PDO::__Construct by passing connection options and attributes. --SKIPIF-- - + --FILE-- 3, - PDO::ATTR_CASE => 2, - PDO::ATTR_PREFETCH => false, - PDO::ATTR_TIMEOUT => 35, - PDO::ATTR_ERRMODE => 2, - PDO::ATTR_STRINGIFY_FETCHES => true, - PDO::SQLSRV_ATTR_DIRECT_QUERY => true, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE => 5120, - PDO::SQLSRV_ATTR_DIRECT_QUERY => true - ); - - $dsn = "sqlsrv:Server = $server;" . - "ConnectionPooling = false;" . +try { + $attr = array( PDO::SQLSRV_ATTR_ENCODING => 3, + PDO::ATTR_CASE => 2, + PDO::ATTR_PREFETCH => false, + PDO::ATTR_TIMEOUT => 35, + PDO::ATTR_ERRMODE => 2, + PDO::ATTR_STRINGIFY_FETCHES => true, + PDO::SQLSRV_ATTR_DIRECT_QUERY => true, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE => 5120, + PDO::SQLSRV_ATTR_DIRECT_QUERY => true ); + + $dsn = "ConnectionPooling = false;" . "APP = whatever;" . "LoginTimeout = 1;" . "ApplicationIntent = ReadOnly;" . - "Database = $databaseName;" . "Encrypt = false;" . "Failover_Partner = whatever;" . "MultipleActiveResultSets = true;" . @@ -38,18 +32,13 @@ try "TraceOn = true;" . "TransactionIsolation = " . PDO::SQLSRV_TXN_READ_UNCOMMITTED . ";" . "TrustServerCertificate = false;" . - "WSID = whatever;" - ; - $conn = new PDO( $dsn, $uid, $pwd, $attr); - - echo "Test Successful"; -} -catch( PDOException $e ) { - var_dump( $e ); + "WSID = whatever;"; + $conn = connect($dsn, $attr); + echo "Test Successful\n"; +} catch (PDOException $e) { + var_dump($e); exit; } -?> - +?> --EXPECT-- - Test Successful diff --git a/test/functional/pdo_sqlsrv/pdo_construct_TransactionIsolation.phpt b/test/functional/pdo_sqlsrv/pdo_construct_TransactionIsolation.phpt index df9af6086..557a3bb6e 100644 --- a/test/functional/pdo_sqlsrv/pdo_construct_TransactionIsolation.phpt +++ b/test/functional/pdo_sqlsrv/pdo_construct_TransactionIsolation.phpt @@ -1,38 +1,32 @@ --TEST-- Test PDO::__Construct connection option TransactionIsolation --SKIPIF-- - + --FILE-- errorInfo); } -catch( PDOException $e ) { - var_dump( $e->errorInfo ); - exit; -} -?> - +?> --EXPECT-- - Test Successful Test Successful Test Successful @@ -45,4 +39,4 @@ array(3) { int(-63) [2]=> string(88) "An invalid value was specified for the keyword 'TransactionIsolation' in the DSN string." -} \ No newline at end of file +} diff --git a/test/functional/pdo_sqlsrv/pdo_construct_attr.phpt b/test/functional/pdo_sqlsrv/pdo_construct_attr.phpt index 753e875bf..92dfc4757 100644 --- a/test/functional/pdo_sqlsrv/pdo_construct_attr.phpt +++ b/test/functional/pdo_sqlsrv/pdo_construct_attr.phpt @@ -1,52 +1,43 @@ --TEST-- Test PDO::__Construct by passing different connection attributes --SKIPIF-- - + --FILE-- 3, +try { + $attr = array( PDO::SQLSRV_ATTR_ENCODING => 3, PDO::ATTR_CASE => 2, PDO::ATTR_PREFETCH => false, - PDO::ATTR_TIMEOUT => 35, + PDO::ATTR_TIMEOUT => 35, PDO::ATTR_STRINGIFY_FETCHES => true, PDO::SQLSRV_ATTR_DIRECT_QUERY => true, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE => 10240, - PDO::SQLSRV_ATTR_DIRECT_QUERY => true - ); - - $dsn = "sqlsrv:Server = $server; database = $databaseName"; - - $conn = new PDO( $dsn, $uid, $pwd, $attr); - + PDO::SQLSRV_ATTR_DIRECT_QUERY => true ); + + $conn = connect("", $attr); + $stmt = $conn->prepare("SELECT 1"); $stmt->execute(); - + // fetch result, which should be stringified since ATTR_STRINGIFY_FETCHES is on - var_dump(($stmt->fetch(PDO::FETCH_ASSOC))); - - $stmt = NULL; - $conn = NULL; + var_dump($stmt->fetch(PDO::FETCH_ASSOC)); - - echo "Test Successful"; -} -catch( PDOException $e ) { - var_dump( $e ); + unset($stmt); + unset($conn); + + echo "Test Successful\n"; +} catch (PDOException $e) { + var_dump($e); exit; } -?> - +?> --EXPECT-- - array(1) { [""]=> string(1) "1" } -Test Successful \ No newline at end of file +Test Successful diff --git a/test/functional/pdo_sqlsrv/pdo_construct_conn_options.phpt b/test/functional/pdo_sqlsrv/pdo_construct_conn_options.phpt index d4be30d43..decabe06b 100644 --- a/test/functional/pdo_sqlsrv/pdo_construct_conn_options.phpt +++ b/test/functional/pdo_sqlsrv/pdo_construct_conn_options.phpt @@ -1,20 +1,16 @@ --TEST-- Test PDO::__Construct by passing connection options --SKIPIF-- - + --FILE-- - +?> --EXPECT-- - -Test Successful \ No newline at end of file +Test Successful diff --git a/test/functional/pdo_sqlsrv/pdo_errorMode.phpt b/test/functional/pdo_sqlsrv/pdo_errorMode.phpt index 2261fc87b..0a04e0258 100644 --- a/test/functional/pdo_sqlsrv/pdo_errorMode.phpt +++ b/test/functional/pdo_sqlsrv/pdo_errorMode.phpt @@ -1,39 +1,36 @@ --TEST-- Test different error modes. The queries will try to do a select on a table that does not exist on database. --SKIPIF-- - + --FILE-- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM temp_table"; - try{ + try { $q = $db->query($sql); - } catch ( Exception $e ){ + } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(); } } -function testWarning(){ - $db = connect(); - $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); +function testWarning() +{ + $db = connect("", array(), PDO::ERRMODE_WARNING); $sql = "SELECT * FROM temp_table"; $q = $db->query($sql); } -function testSilent(){ - $db = connect(); - $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); +function testSilent() +{ + $db = connect("", array(), PDO::ERRMODE_SILENT); $sql = "SELECT * FROM temp_table"; $q = $db->query($sql); } - testException(); testWarning(); testSilent(); diff --git a/test/functional/pdo_sqlsrv/pdo_errorinfo_emulateprepare.phpt b/test/functional/pdo_sqlsrv/pdo_errorinfo_emulateprepare.phpt index 19e7f8f4c..29c4426a0 100644 --- a/test/functional/pdo_sqlsrv/pdo_errorinfo_emulateprepare.phpt +++ b/test/functional/pdo_sqlsrv/pdo_errorinfo_emulateprepare.phpt @@ -1,108 +1,88 @@ --TEST-- Test errorInfo when prepare with and without emulate prepare --SKIPIF-- - + --FILE-- PDO::ERRMODE_WARNING)); - -//drop, create and insert -$conn->query("IF OBJECT_ID('dbo.test_table', 'U') IS NOT NULL DROP TABLE dbo.test_table"); -$conn->query("CREATE TABLE [dbo].[test_table](c1 int, c2 int)"); -$conn->query("INSERT INTO [dbo].[test_table] VALUES (1, 10)"); -$conn->query("INSERT INTO [dbo].[test_table] VALUES (2, 20)"); - -echo "\n****testing with emulate prepare****\n"; -$stmt = $conn->prepare("SELECT c2 FROM test_table WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => true)); - -$int_col = 1; -//bind param with the wrong parameter name to test for errorInfo -$stmt->bindParam(':in', $int_col); - -$stmt->execute(); - -echo "Statement error info:\n"; -print_r($stmt->errorInfo()); - -if ($stmt->errorInfo()[1] == NULL && $stmt->errorInfo()[2] == NULL) { - echo "stmt native code and native message are NULL.\n"; -} -else { - echo "stmt native code and native message should be NULL.\n"; +require_once("MsCommon_mid-refactor.inc"); + +try { + // connection with and without column encryption returns different warning since column encryption cannot use emulate prepare + // turn ERRMODE to silent to compare the errorCode in the test + $conn = connect("", array(), PDO::ERRMODE_SILENT); + + //drop, create and insert + $tbname = "test_table"; + createTable($conn, $tbname, array("c1" => "int", "c2" => "int")); + + insertRow($conn, $tbname, array( "c1" => 1, "c2" => 10 )); + insertRow($conn, $tbname, array( "c1" => 2, "c2" => 20 )); + + echo "\n****testing with emulate prepare****\n"; + // Do not support emulate prepare with Always Encrypted + if (!isColEncrypted()) { + $stmt = $conn->prepare("SELECT c2 FROM $tbname WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => true)); + } else { + $stmt = $conn->prepare("SELECT c2 FROM $tbname WHERE c1= :int"); + } + + $int_col = 1; + //bind param with the wrong parameter name to test for errorInfo + $stmt->bindParam(':in', $int_col); + $stmt->execute(); + + $stmt_error = $stmt->errorInfo(); + if (!isColEncrypted()) { + if ($stmt_error[0] != "HY093") { + echo "SQLSTATE should be HY093 when Emulate Prepare is true.\n"; + print_r($stmt_error); + } + } else { + if ($stmt_error[0] != "07002") { + echo "SQLSTATE should be 07002 for syntax error in a parameterized query.\n"; + print_r($stmt_error); + } + } + + $conn_error = $conn->errorInfo(); + if ($conn_error[0] != "00000") { + echo "Connection error SQLSTATE should be 00000.\n"; + print_r($conn_error); + } + + echo "\n****testing without emulate prepare****\n"; + $stmt2 = $conn->prepare("SELECT c2 FROM $tbname WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => false)); + + $int_col = 2; + //bind param with the wrong parameter name to test for errorInfo + $stmt2->bindParam(':it', $int_col); + $stmt2->execute(); + + $stmt_error = $stmt2->errorInfo(); + if ($stmt_error[0] != "07002") { + echo "SQLSTATE should be 07002 for syntax error in a parameterized query.\n"; + print_r($stmt_error); + } + + $conn_error = $conn->errorInfo(); + if ($conn_error[0] != "00000") { + echo "Connection error SQLSTATE should be 00000.\n"; + print_r($conn_error); + } + + dropTable($conn, $tbname); + unset($stmt); + unset($stmt2); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -echo "Connection error info:\n"; -print_r($conn->errorInfo()); - -if ($conn->errorInfo()[1] == NULL && $conn->errorInfo()[2] == NULL) { - echo "conn native code and native message are NULL.\n"; -} -else { - echo "conn native code and native message shoud be NULL.\n"; -} - -echo "\n****testing without emulate prepare****\n"; -$stmt2 = $conn->prepare("SELECT c2 FROM test_table WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => false)); - -$int_col = 2; -//bind param with the wrong parameter name to test for errorInfo -$stmt2->bindParam(':it', $int_col); - -$stmt2->execute(); - -echo "Statement error info:\n"; -print_r($stmt2->errorInfo()); - -echo "Connection error info:\n"; -print_r($conn->errorInfo()); - -$conn->query("IF OBJECT_ID('dbo.test_table', 'U') IS NOT NULL DROP TABLE dbo.test_table"); -$stmt = NULL; -$stmt2 = NULL; -$conn = NULL; ?> --EXPECTREGEX-- \*\*\*\*testing with emulate prepare\*\*\*\* -Warning: PDOStatement::execute\(\): SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+ - -Warning: PDOStatement::execute\(\): SQLSTATE\[HY093\]: Invalid parameter number in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+ -Statement error info: -Array -\( - \[0\] => HY093 - \[1\] => - \[2\] => -\) -stmt native code and native message are NULL\. -Connection error info: -Array -\( - \[0\] => 00000 - \[1\] => - \[2\] => -\) -conn native code and native message are NULL\. +Warning: PDOStatement::(bindParam|execute)\(\): SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+ \*\*\*\*testing without emulate prepare\*\*\*\* Warning: PDOStatement::bindParam\(\): SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+ - -Warning: PDOStatement::execute\(\): SQLSTATE\[07002\]: COUNT field incorrect: 0 \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]COUNT field incorrect or syntax error in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+ -Statement error info: -Array -\( - \[0\] => 07002 - \[1\] => 0 - \[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]COUNT field incorrect or syntax error -\) -Connection error info: -Array -\( - \[0\] => 00000 - \[1\] => - \[2\] => -\) \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_exec.phpt b/test/functional/pdo_sqlsrv/pdo_exec.phpt index ee9093046..0249f1b33 100644 --- a/test/functional/pdo_sqlsrv/pdo_exec.phpt +++ b/test/functional/pdo_sqlsrv/pdo_exec.phpt @@ -1,47 +1,58 @@ --TEST-- Test the PDO::exec() method. --SKIPIF-- - + --FILE-- exec($sql); - if($numRows === false) - { - die("Create table failed\n"); - } - var_dump($numRows); - $sql = "INSERT INTO #tmp_table VALUES(1, 'A')"; - $numRows = $db->exec($sql); + $tbname = "tmp_table"; + $numRows = createTable($db, $tbname, array( new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "val" => "varchar(10)")); var_dump($numRows); - $sql = "INSERT INTO #tmp_table VALUES(2, 'B')"; - $numRows = $db->exec($sql); - var_dump($numRows); + if (!isColEncrypted()) { + $sql = "INSERT INTO $tbname VALUES(1, 'A')"; + $numRows = $db->exec($sql); + var_dump($numRows); - $numRows = $db->exec("UPDATE #tmp_table SET val = 'X' WHERE id > 0"); - var_dump($numRows); - - $numRows = $db->exec("DELETE FROM #tmp_table"); + $sql = "INSERT INTO $tbname VALUES(2, 'B')"; + $numRows = $db->exec($sql); + var_dump($numRows); + + $numRows = $db->exec("UPDATE $tbname SET val = 'X' WHERE id > 0"); + var_dump($numRows); + } else { + // cannot use exec for insertion and update with Always Encrypted + $stmt = insertRow($db, $tbname, array( "id" => 1, "val" => "A" )); + $numRows = $stmt->rowCount(); + var_dump($numRows); + + $stmt = insertRow($db, $tbname, array( "id" => 2, "val" => "B" )); + $numRows = $stmt->rowCount(); + var_dump($numRows); + + // greater or less than operator is not support for encrypted columns + $sql = "UPDATE $tbname SET val = ?"; + $stmt = $db->prepare($sql); + $stmt->execute(array( "X" )); + $numRows = $stmt->rowCount(); + var_dump($numRows); + } + + $numRows = $db->exec("DELETE FROM $tbname"); var_dump($numRows); - -} -catch( PDOException $e ) { - var_dump( $e ); + dropTable($db, $tbname); + unset($stmt); + unset($db); +} catch (PDOException $e) { + var_dump($e); exit; } - - -?> +?> --EXPECT-- int(0) int(1) diff --git a/test/functional/pdo_sqlsrv/pdo_exec_invalid_query.phpt b/test/functional/pdo_sqlsrv/pdo_exec_invalid_query.phpt index 8fb0d4f14..5709d931e 100644 --- a/test/functional/pdo_sqlsrv/pdo_exec_invalid_query.phpt +++ b/test/functional/pdo_sqlsrv/pdo_exec_invalid_query.phpt @@ -1,29 +1,31 @@ --TEST-- direct execution of an invalid query --SKIPIF-- - + --FILE-- exec("IF OBJECT_ID('table1', 'U') IS NOT NULL DROP TABLE table1"); - // execute a query with typo (spelling error in CREATE) - $conn->exec("CRETE TABLE table1(id INT NOT NULL PRIMARY KEY, val VARCHAR(10)) "); - print_r( $conn->errorCode() ); + $conn->exec("CRETE TABLE $tbname (id INT NOT NULL PRIMARY KEY, val VARCHAR(10)) "); + print_r($conn->errorCode()); echo "\n"; - + // execute a properly formatted query - $conn->exec("CREATE TABLE table1(id INT NOT NULL PRIMARY KEY, val VARCHAR(10)) "); - print_r( $conn->errorCode() ); + $conn->exec("CREATE TABLE $tbname (id INT NOT NULL PRIMARY KEY, val VARCHAR(10)) "); + print_r($conn->errorCode()); echo "\n"; - + // drop table1 and free connections - $conn->exec("DROP TABLE table1"); - $conn = NULL; + dropTable($conn, $tbname); + unset($conn); ?> --EXPECT-- 42000 -00000 \ No newline at end of file +00000 diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_complex_transactions.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_complex_transactions.phpt index 9e4102310..c1439023a 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_complex_transactions.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_complex_transactions.phpt @@ -1,98 +1,94 @@ --TEST-- Test transactions commit, rollback and aborting in between --SKIPIF-- - + --FILE-- query("CREATE TABLE $tableName ([c1_int] int, [c2_real] real)"); - $stmt = null; + createTable($conn, $tableName, array("c1_int" => "int", "c2_real" => "real")); $stmtSelect = $conn->prepare("SELECT * FROM $tableName"); $stmtDelete = $conn->prepare("DELETE TOP(3) FROM $tableName"); - + // insert ten rows $numRows = 10; - InsertData($conn, $tableName, $numRows); - FetchData($stmtSelect, $tableName, $numRows); - + insertData($conn, $tableName, $numRows); + fetchData($stmtSelect, $tableName, $numRows); + $conn->beginTransaction(); - $stmtDelete->execute(); + $stmtDelete->execute(); $rowsAffected = $stmtDelete->rowCount(); $conn->commit(); echo "Committed deleting 3 rows\n"; - + $numRows = $numRows - $rowsAffected; - FetchData($stmtSelect, $tableName, $numRows); - + fetchData($stmtSelect, $tableName, $numRows); + $conn->beginTransaction(); - $stmtDelete->execute(); + $stmtDelete->execute(); $conn->rollback(); echo "Rolled back\n"; - - FetchData($stmtSelect, $tableName, $numRows); + + fetchData($stmtSelect, $tableName, $numRows); $conn->beginTransaction(); - $stmtDelete->execute(); + $stmtDelete->execute(); $rowsAffected = $stmtDelete->rowCount(); $conn->commit(); echo "Committed deleting 3 rows\n"; - + $numRows = $numRows - $rowsAffected; - FetchData($stmtSelect, $tableName, $numRows); - + fetchData($stmtSelect, $tableName, $numRows); + $conn->beginTransaction(); - $stmtDelete->execute(); + $stmtDelete->execute(); $conn->rollback(); echo "Rolled back\n"; - - FetchData($stmtSelect, $tableName, $numRows); + + fetchData($stmtSelect, $tableName, $numRows); $conn->beginTransaction(); - $stmtDelete->execute(); + $stmtDelete->execute(); - echo "Deletion aborted\n"; + echo "Deletion aborted\n"; - return $numRows; + return $numRows; } -function InsertData($conn, $tableName, $count) +function insertData($conn, $tableName, $count) { $stmt = $conn->prepare("INSERT INTO $tableName (c1_int, c2_real) VALUES (?, ?)"); - for ($i = 0; $i < $count; $i++) - { + for ($i = 0; $i < $count; $i++) { $v1 = $i + 1; $v2 = $v1 * 1.5; $stmt->bindValue(1, $v1); $stmt->bindValue(2, $v2); - $stmt->execute(); + $stmt->execute(); } } -function FetchData($stmt, $tableName, $numRows, $fetchMode = false) +function fetchData($stmt, $tableName, $numRows, $fetchMode = false) { $numFetched = 0; - $stmt->execute(); - if ($fetchMode) - { - $stmt->setFetchMode(PDO::FETCH_LAZY); - while ($result = $stmt->fetch()) - $numFetched++; - } - else - { - while ($result = $stmt->fetch(PDO::FETCH_LAZY)) + $stmt->execute(); + if ($fetchMode) { + $stmt->setFetchMode(PDO::FETCH_LAZY); + while ($result = $stmt->fetch()) { + $numFetched++; + } + } else { + while ($result = $stmt->fetch(PDO::FETCH_LAZY)) { $numFetched++; + } } - + echo "Number of rows fetched: $numFetched\n"; - if ($numFetched != $numRows) - { + if ($numFetched != $numRows) { echo "Expected $numRows rows.\n"; } } @@ -101,50 +97,34 @@ function FetchData($stmt, $tableName, $numRows, $fetchMode = false) // RunTest // //-------------------------------------------------------------------- -function RunTest() -{ - StartTest("pdo_fetch_complex_transactions"); - echo "\nTest begins...\n"; - try - { - include("MsSetup.inc"); - - // Connect - $conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - - $conn2 = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd); - $conn2->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - - $tableName = GetTempTableName('testTransaction', false); - - // ComplexTransaction() returns number of rows left in $tableName - $numRows = ComplexTransaction($conn, $tableName); - // disconnect first connection, transaction aborted - $conn = null; - - // select table using the second connection - $stmt = $conn2->prepare("SELECT * FROM $tableName"); - FetchData($stmt, $tableName, $numRows, true); - - // drop test table - $conn2->query("DROP TABLE $tableName"); - $conn2 = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_fetch_complex_transactions"); -} -RunTest(); +echo "Test begins...\n"; +try { + // Connect + $conn = connect(); + $conn2 = connect(); + $tableName = getTableName('testTransaction'); + + // complexTransaction() returns number of rows left in $tableName + $numRows = complexTransaction($conn, $tableName); + // disconnect first connection, transaction aborted + unset($conn); + + // select table using the second connection + $stmt = $conn2->prepare("SELECT * FROM $tableName"); + fetchData($stmt, $tableName, $numRows, true); + + // drop test table + dropTable($conn2, $tableName); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); +} +echo "Done\n"; ?> --EXPECT-- - -Test begins... +Test begins... Number of rows fetched: 10 Committed deleting 3 rows Number of rows fetched: 7 @@ -156,6 +136,4 @@ Rolled back Number of rows fetched: 4 Deletion aborted Number of rows fetched: 4 - Done -Test "pdo_fetch_complex_transactions" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_binary.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_binary.phpt index a9c3e9658..51cc61477 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_binary.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_binary.phpt @@ -1,83 +1,88 @@ --TEST-- prepare with cursor buffered and fetch a varbinary column --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 'asdgasdgasdgsadg'; - -$query = 'CREATE TABLE #TESTTABLE (exist varbinary(max))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindParam(':p0', $sample, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); - -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -$stmt = null; -$conn = null; - +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + $sample = 'asdgasdgasdgsadg'; + + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c1" => "varbinary(max)")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':p0', $sample, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); + + $query = "SELECT TOP 1 * FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_char.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_char.phpt index 5c501003a..0e8e61e68 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_char.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_char.phpt @@ -1,83 +1,88 @@ --TEST-- prepare with cursor buffered and fetch a varchar column --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = "eight"; - -$query = 'CREATE TABLE #TESTTABLE (exist varchar(10))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_STR); -$stmt->execute(); - -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -$stmt = null; -$conn = null; - +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + $sample = "eight"; + + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c1" => "varchar(10)")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_STR); + $stmt->execute(); + + $query = "SELECT TOP 1 * FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_datetime.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_datetime.phpt index c698f14bb..9c85317f4 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_datetime.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_datetime.phpt @@ -1,83 +1,88 @@ --TEST-- prepare with cursor buffered and fetch a datetime column --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = '2012-06-18 10:34:09'; - -$query = 'CREATE TABLE #TESTTABLE (exist datetime)'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindParam(':p0', $sample, PDO::PARAM_LOB); -$stmt->execute(); - -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -$stmt = null; -$conn = null; - +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + $sample = '2012-06-18 10:34:09'; + + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c1" => "datetime")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindParam(':p0', $sample, PDO::PARAM_LOB); + $stmt->execute(); + + $query = "SELECT TOP 1 * FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal.phpt index 173fd6d84..b9243ce19 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal.phpt @@ -1,83 +1,88 @@ --TEST-- prepare with cursor buffered and fetch a decimal column --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 1234567890.1234; - -$query = 'CREATE TABLE #TESTTABLE (exist decimal(16, 6))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); - -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -$stmt = null; -$conn = null; - +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + $sample = 1234567890.1234; + + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c1" => "decimal(16,6)")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); + + $query = "SELECT TOP 1 * FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal_bindColumn_int.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal_bindColumn_int.phpt index 9a5d8c336..50457ed1b 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal_bindColumn_int.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_decimal_bindColumn_int.phpt @@ -1,91 +1,96 @@ --TEST-- prepare with cursor buffered and fetch a decimal column with the column bound and specified to pdo type int --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 1234567890.1234; - -$query = 'CREATE TABLE #TESTTABLE (exist decimal(18, 8))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); - -$query = 'SELECT exist FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($decimal_col); - -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($decimal_col); - -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($decimal_col); - -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($decimal_col); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($decimal_col); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($decimal_col); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($decimal_col); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $decimal_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($decimal_col); - -$stmt = null; -$conn = null; - +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + $sample = 1234567890.1234; + + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c1" => "decimal(18,8)")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); + + $query = "SELECT c1 FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $decimal_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($decimal_col); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float.phpt index f8c9ba083..101958fad 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float.phpt @@ -1,103 +1,108 @@ --TEST-- prepare with cursor buffered and fetch a float column --SKIPIF-- - + --FILE-- "float(53)")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); + + $query = "SELECT TOP 1 * FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + print "no buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + print "no buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + print "no buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + //prepare with client buffered cursor + print "buffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + print "buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + print "buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + print "buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + $ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; + print "\nFetched value = Input? $ok\n\n"; + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } -require_once("MsSetup.inc"); -$conn = new PDO( "sqlsrv:server=$server; database=$databaseName", $uid, $pwd); -$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 1234567890.1234; - -$query = 'CREATE TABLE #TESTTABLE (exist float(53))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); - -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -print "no buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -print "no buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -print "no buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -//prepare with client buffered cursor -print "buffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -print "buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -print "buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -print "buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); -$ok = FlatsAreEqual($sample, $value) ? 'TRUE' : 'FALSE'; -print "\nFetched value = Input? $ok\n\n"; - -$stmt = null; -$conn = null; - ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float_bindColumn_lob.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float_bindColumn_lob.phpt index 3e387cc80..4239aef53 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float_bindColumn_lob.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_float_bindColumn_lob.phpt @@ -1,95 +1,100 @@ --TEST-- prepare with cursor buffered and fetch a float column with the column bound and specified to type LOB --SKIPIF-- - + --FILE-- "float(53)")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); + + $query = "SELECT exist FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); + $value = $stmt->fetch(); + var_dump($float_col); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } -require_once("MsSetup.inc"); -$conn = new PDO( "sqlsrv:server=$server; database=$databaseName", $uid, $pwd); -$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 1234567890.1234; - -$query = 'CREATE TABLE #TESTTABLE (exist float(53))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); - -$query = 'SELECT exist FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $float_col, PDO::PARAM_LOB); -$value = $stmt->fetch(); -var_dump ($float_col); - -$stmt = null; -$conn = null; - ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int.phpt index b56b31d3f..4ae0fe74d 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int.phpt @@ -1,83 +1,88 @@ --TEST-- prepare with cursor buffered and fetch a int column --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 1234567890; - -$query = 'CREATE TABLE #TESTTABLE (exist int)'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); +require_once("MsCommon_mid-refactor.inc"); -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; +try { + $conn = connect(); + $sample = 1234567890; -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c1" => "int")); -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); + $query = "SELECT TOP 1 * FROM $tbname"; -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + //prepare with no buffered cursor +print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default $stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -$stmt = null; -$conn = null; - + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int_bindColumn_int.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int_bindColumn_int.phpt index be84ad134..95ef8d9ea 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int_bindColumn_int.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_int_bindColumn_int.phpt @@ -1,92 +1,96 @@ --TEST-- prepare with cursor buffered and fetch a int column with the column bound and specified as pdo type int --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$sample = 1234567890; +require_once("MsCommon_mid-refactor.inc"); -$query = 'CREATE TABLE #TESTTABLE (exist int)'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); +try { + $conn = connect(); + $sample = 1234567890; -$query = 'SELECT exist FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c1" => "int")); -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); + $query = "SELECT c1 FROM $tbname"; -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + //prepare with no buffered cursor +print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default $stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $int_col, PDO::PARAM_INT); -$value = $stmt->fetch( PDO::FETCH_BOUND ); -var_dump ($int_col); - -$stmt = null; -$conn = null; - + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $int_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($int_col); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money.phpt index 6a0c2ba43..5c327fb04 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money.phpt @@ -1,83 +1,93 @@ --TEST-- prepare with cursor buffered and fetch a money column --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 1234567890.1234; - -$query = 'CREATE TABLE #TESTTABLE (exist money)'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); +require_once("MsCommon_mid-refactor.inc"); -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; +try { + $conn = connect(); + $sample = 1234567890.1234; -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); + $tbname = "TESTTABLE"; + if (!isColEncrypted()) { + createTable($conn, $tbname, array("c1" => "money")); + } else { + // inserting money types is not supported for Always Encrypted; use decimal(19,4) instead + createTable($conn, $tbname, array("c1" => "decimal(19,4)")); + } -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); + $query = "SELECT TOP 1 * FROM $tbname"; -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + //prepare with no buffered cursor +print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default $stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -$stmt = null; -$conn = null; - + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money_bindColumn_int.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money_bindColumn_int.phpt index 09a6114bb..afda28dd1 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money_bindColumn_int.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_money_bindColumn_int.phpt @@ -1,93 +1,101 @@ --TEST-- prepare with cursor buffered and fetch a money column with the column bound and specified as pdo type int --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$sample = 1234567890.1234; +require_once("MsCommon_mid-refactor.inc"); -$query = 'CREATE TABLE #TESTTABLE (exist money)'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->execute(); +try { + $conn = connect(); + $sample = 1234567890.1234; -$query = 'SELECT exist FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); + $tbname = "TESTTABLE"; + if (!isColEncrypted()) { + createTable($conn, $tbname, array("c1" => "money")); + } else { + // inserting money types is not supported for Always Encrypted; use decimal(19,4) instead + createTable($conn, $tbname, array("c1" => "decimal(19,4)")); + } -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->execute(); -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); + $query = "SELECT c1 FROM $tbname"; -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + //prepare with no buffered cursor +print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default $stmt = $conn->prepare($query); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$stmt->bindColumn('exist', $money_col, PDO::PARAM_INT); -$value = $stmt->fetch(PDO::FETCH_BOUND); -var_dump ($money_col); - - -$stmt = null; -$conn = null; - + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $stmt->bindColumn('c1', $money_col, PDO::PARAM_INT); + $value = $stmt->fetch(PDO::FETCH_BOUND); + var_dump($money_col); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_multicolumns.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_multicolumns.phpt index 3028c37ae..292f974d9 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_multicolumns.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_multicolumns.phpt @@ -3,94 +3,111 @@ prepare with cursor buffered and fetch from numeric columns. --DESCRIPTION-- Uses buffered cursor to fetch from float, int, and decimal columns that have positive, negative and zero value. --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = 1234567890.1234; -$sample1 = -1234567890.1234; -$sample2 = 1; -$sample3 = -1; -$sample4 = 0.5; -$sample5 = -0.55; +try { + $conn = connect(); + $sample = 1234567890.1234; + $sample1 = -1234567890.1234; + $sample2 = 1; + $sample3 = -1; + $sample4 = 0.5; + $sample5 = -0.55; -$query = 'CREATE TABLE #TESTTABLE (a float(53), neg_a float(53), b int, neg_b int, c decimal(16, 6), neg_c decimal(16, 6), zero int, zerof float(53), zerod decimal(16,6))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0, :p1, :p2, :p3, :p4, :p5, 0, 0, 0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_INT); -$stmt->bindValue(':p1', $sample1, PDO::PARAM_INT); -$stmt->bindValue(':p2', $sample2, PDO::PARAM_INT); -$stmt->bindValue(':p3', $sample3, PDO::PARAM_INT); -$stmt->bindValue(':p4', $sample4, PDO::PARAM_INT); -$stmt->bindValue(':p5', $sample5, PDO::PARAM_INT); -$stmt->execute(); + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("a" => "float(53)", "neg_a" => "float(53)", + "b" => "int", "neg_b" => "int", + "c" => "decimal(16,6)", "neg_c" => "decimal(16,6)", + "zero" => "int", "zerof" => "float(53)", "zerod" => "decimal(16,6)")); + + if (!isColEncrypted()) { + $query = "INSERT INTO $tbname VALUES(:p0, :p1, :p2, :p3, :p4, :p5, 0, 0, 0)"; + $stmt = $conn->prepare($query); + } else { + // Encrypted columns require all inputs to be bound + $query = "INSERT INTO $tbname VALUES(:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8)"; + $stmt = $conn->prepare($query); + $zero = 0; + $stmt->bindValue(':p6', $zero, PDO::PARAM_INT); + $stmt->bindValue(':p7', $zero, PDO::PARAM_INT); + $stmt->bindValue(':p8', $zero, PDO::PARAM_INT); + } + $stmt->bindValue(':p0', $sample, PDO::PARAM_INT); + $stmt->bindValue(':p1', $sample1, PDO::PARAM_INT); + $stmt->bindValue(':p2', $sample2, PDO::PARAM_INT); + $stmt->bindValue(':p3', $sample3, PDO::PARAM_INT); + $stmt->bindValue(':p4', $sample4, PDO::PARAM_INT); + $stmt->bindValue(':p5', $sample5, PDO::PARAM_INT); + $stmt->execute(); -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; + $query = "SELECT TOP 1 * FROM $tbname"; -//prepare with no buffered cursor + //prepare with no buffered cursor print "\nno buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default $stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetch(PDO::FETCH_NUM); -var_dump ($value); + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); -$stmt = null; -$conn = null; + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetch(PDO::FETCH_NUM); + var_dump($value); + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off @@ -268,4 +285,3 @@ array(9) { [8]=> string(7) ".000000" } - diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_strings_to_integers.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_strings_to_integers.phpt index 3df828a9b..382f4ee67 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_strings_to_integers.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_strings_to_integers.phpt @@ -1,139 +1,138 @@ --TEST-- prepare with cursor buffered and fetch various columns with the column bound and specified to pdo type int --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - - $decimal = -2345209.3103; - $numeric = 987234.9919; - $salary = "3456789.15"; - $debt = "98765.99"; - - $query = 'CREATE TABLE #TESTTABLE ([c_decimal] decimal(28,4), [c_numeric] numeric(32,4), [c_varchar] varchar(20), [c_nvarchar] nvarchar(20))'; - - $stmt = $conn->exec($query); - - $query = 'INSERT INTO #TESTTABLE VALUES(:p0, :p1, :p2, :p3)'; - $stmt = $conn->prepare($query); - $stmt->bindValue(':p0', $decimal); - $stmt->bindValue(':p1', $numeric); - $stmt->bindValue(':p2', $salary); - $stmt->bindValue(':p3', $debt); - $stmt->execute(); - - $decimal2 = $decimal * 2; - $numeric2 = $numeric * 2; - $salary2 = $salary * 2; - $debt2 = $debt * 2; - - $stmt->bindValue(':p0', $decimal2); - $stmt->bindValue(':p1', $numeric2); - $stmt->bindValue(':p2', $salary2); - $stmt->bindValue(':p3', $debt2); - $stmt->execute(); - - $decimal3 = $decimal * 3; - $numeric3 = $numeric * 3; - $salary3 = $salary * 3; - $debt3 = $debt * 3; - - $stmt->bindValue(':p0', $decimal3); - $stmt->bindValue(':p1', $numeric3); - $stmt->bindValue(':p2', $salary3); - $stmt->bindValue(':p3', $debt3); - $stmt->execute(); - - $stmt = null; - - echo ("Input values:\n\torginal:$decimal\t$numeric\t$salary\t$debt\n\tdoubles:$decimal2\t$numeric2\t$salary2\t$debt2\n\ttriples:$decimal3\t$numeric3\t$salary3\t$debt3\n"); - - $query = 'SELECT * FROM #TESTTABLE'; - - // prepare with no buffered cursor - echo "\n\nComparing results (stringify off, fetch_numeric on):\n"; - // no buffered cursor, stringify off, fetch_numeric on - $conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); - $stmt1 = $conn->prepare($query); - $stmt1->execute(); - - // buffered cursor, stringify off, fetch_numeric on - $conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); - $stmt2 = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt2->execute(); - - compareResults($stmt1, $stmt2); - - $stmt1 = null; - $stmt2 = null; - - echo "\n\nComparing results (stringify off, fetch_numeric off):\n"; - // no buffered cursor, stringify off, fetch_numeric off - $conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); - $conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); - $stmt1 = $conn->prepare($query); - $stmt1->execute(); - - // buffered cursor, stringify off, fetch_numeric off - $conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); - $conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); - $stmt2 = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt2->execute(); - - compareResults($stmt1, $stmt2); - - $stmt1 = null; - $stmt2 = null; - - $conn = null; +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + $decimal = -2345209.3103; + $numeric = 987234.9919; + $salary = "3456789.15"; + $debt = "98765.99"; + + $tbname = "TESTTABLE"; + createTable($conn, $tbname, array("c_decimal" => "decimal(28,4)", "c_numeric" => "numeric(32,4)", + "c_varchar" => "varchar(20)", "c_nvarchar" => "nvarchar(20)")); + + $query = "INSERT INTO $tbname VALUES(:p0, :p1, :p2, :p3)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $decimal); + $stmt->bindValue(':p1', $numeric); + $stmt->bindValue(':p2', $salary); + $stmt->bindValue(':p3', $debt); + $stmt->execute(); + + $decimal2 = $decimal * 2; + $numeric2 = $numeric * 2; + $salary2 = $salary * 2; + $debt2 = $debt * 2; + + $stmt->bindValue(':p0', $decimal2); + $stmt->bindValue(':p1', $numeric2); + $stmt->bindValue(':p2', $salary2); + $stmt->bindValue(':p3', $debt2); + $stmt->execute(); + + $decimal3 = $decimal * 3; + $numeric3 = $numeric * 3; + $salary3 = $salary * 3; + $debt3 = $debt * 3; + + $stmt->bindValue(':p0', $decimal3); + $stmt->bindValue(':p1', $numeric3); + $stmt->bindValue(':p2', $salary3); + $stmt->bindValue(':p3', $debt3); + $stmt->execute(); + + unset($stmt); + + echo("Input values:\n\torginal:$decimal\t$numeric\t$salary\t$debt\n\tdoubles:$decimal2\t$numeric2\t$salary2\t$debt2\n\ttriples:$decimal3\t$numeric3\t$salary3\t$debt3\n"); + + $query = "SELECT * FROM $tbname"; + + // prepare with no buffered cursor + echo "\n\nComparing results (stringify off, fetch_numeric on):\n"; + // no buffered cursor, stringify off, fetch_numeric on + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt1 = $conn->prepare($query); + $stmt1->execute(); + + // buffered cursor, stringify off, fetch_numeric on + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt2 = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt2->execute(); + + compareResults($stmt1, $stmt2); + + unset($stmt1); + unset($stmt2); + + echo "\n\nComparing results (stringify off, fetch_numeric off):\n"; + // no buffered cursor, stringify off, fetch_numeric off + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt1 = $conn->prepare($query); + $stmt1->execute(); + + // buffered cursor, stringify off, fetch_numeric off + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt2 = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt2->execute(); + + compareResults($stmt1, $stmt2); + + unset($stmt1); + unset($stmt1); + + DropTable($conn, $tbname); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); } function compareResults($stmt1, $stmt2) { - $stmt1->bindColumn('c_decimal', $decimal_col1, PDO::PARAM_INT); - $stmt1->bindColumn('c_numeric', $numeric_col1, PDO::PARAM_INT); - $stmt1->bindColumn('c_varchar', $salary_col1, PDO::PARAM_INT); - $stmt1->bindColumn('c_nvarchar', $debt_col1, PDO::PARAM_INT); - - $stmt2->bindColumn('c_decimal', $decimal_col2, PDO::PARAM_INT); - $stmt2->bindColumn('c_numeric', $numeric_col2, PDO::PARAM_INT); - $stmt2->bindColumn('c_varchar', $salary_col2, PDO::PARAM_INT); - $stmt2->bindColumn('c_nvarchar', $debt_col2, PDO::PARAM_INT); - - $numRows = 3; - for ($i = 1; $i <= $numRows; $i++) - { - echo "\nreading row " . $i . "\n"; - - $value1 = $stmt1->fetch( PDO::FETCH_BOUND ); - $value2 = $stmt2->fetch( PDO::FETCH_BOUND ); - - compareData($decimal_col1, $decimal_col2); - compareData($numeric_col1, $numeric_col2); - compareData($salary_col1, $salary_col2); - compareData($debt_col1, $debt_col2); - } + $stmt1->bindColumn('c_decimal', $decimal_col1, PDO::PARAM_INT); + $stmt1->bindColumn('c_numeric', $numeric_col1, PDO::PARAM_INT); + $stmt1->bindColumn('c_varchar', $salary_col1, PDO::PARAM_INT); + $stmt1->bindColumn('c_nvarchar', $debt_col1, PDO::PARAM_INT); + + $stmt2->bindColumn('c_decimal', $decimal_col2, PDO::PARAM_INT); + $stmt2->bindColumn('c_numeric', $numeric_col2, PDO::PARAM_INT); + $stmt2->bindColumn('c_varchar', $salary_col2, PDO::PARAM_INT); + $stmt2->bindColumn('c_nvarchar', $debt_col2, PDO::PARAM_INT); + + $numRows = 3; + for ($i = 1; $i <= $numRows; $i++) { + echo "\nreading row " . $i . "\n"; + + $value1 = $stmt1->fetch(PDO::FETCH_BOUND); + $value2 = $stmt2->fetch(PDO::FETCH_BOUND); + + compareData($decimal_col1, $decimal_col2); + compareData($numeric_col1, $numeric_col2); + compareData($salary_col1, $salary_col2); + compareData($debt_col1, $debt_col2); + } } function compareData($data1, $data2) { - if ($data1 != $data2) - echo "Not matched!\n"; - else - echo "Matched!\n"; - - echo ("\tExpected: "); var_dump ($data1); - echo ("\tActual: "); var_dump ($data2); + if ($data1 != $data2) { + echo "Not matched!\n"; + } else { + echo "Matched!\n"; + } + + echo("\tExpected: "); + var_dump($data1); + echo("\tActual: "); + var_dump($data2); } - -test(); - ?> --EXPECT-- Input values: diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_unicode.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_unicode.phpt index 83259f63e..6379438e6 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_unicode.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursorBuffered_unicode.phpt @@ -1,83 +1,88 @@ --TEST-- prepare with cursor buffered and fetch a nvarchar column --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -$sample = "가각"; - -$query = 'CREATE TABLE #TESTTABLE (exist nvarchar(10))'; -$stmt = $conn->exec($query); -$query = 'INSERT INTO #TESTTABLE VALUES(:p0)'; -$stmt = $conn->prepare($query); -$stmt->bindValue(':p0', $sample, PDO::PARAM_STR); -$stmt->execute(); - -$query = 'SELECT TOP 1 * FROM #TESTTABLE'; - -//prepare with no buffered cursor -print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nno buffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -//prepare with client buffered cursor -print "\nbuffered cursor, stringify off, fetch_numeric off\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify off, fetch_numeric on\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric on\n"; -$conn->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -print "\nbuffered cursor, stringify on, fetch_numeric off\n"; -$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); -$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); -$stmt->execute(); -$value = $stmt->fetchColumn(); -var_dump ($value); - -$stmt = null; -$conn = null; - +require_once("MsCommon_mid-refactor.inc"); + +try { + $conn = connect(); + $sample = "가각"; + + $tbname = "TERSTTABLE"; + createTable($conn, $tbname, array("c1" => "nvarchar(10)")); + + $query = "INSERT INTO $tbname VALUES(:p0)"; + $stmt = $conn->prepare($query); + $stmt->bindValue(':p0', $sample, PDO::PARAM_STR); + $stmt->execute(); + + $query = "SELECT TOP 1 * FROM $tbname"; + + //prepare with no buffered cursor + print "no buffered cursor, stringify off, fetch_numeric off\n"; //stringify and fetch_numeric is off by default + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nno buffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + //prepare with client buffered cursor + print "\nbuffered cursor, stringify off, fetch_numeric off\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify off, fetch_numeric on\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric on\n"; + $conn->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + print "\nbuffered cursor, stringify on, fetch_numeric off\n"; + $conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, false); + $stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->execute(); + $value = $stmt->fetchColumn(); + var_dump($value); + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- no buffered cursor, stringify off, fetch_numeric off diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_cursor_scroll_random.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_cursor_scroll_random.phpt index 6bafee2ea..a0bb02f94 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_cursor_scroll_random.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_cursor_scroll_random.phpt @@ -1,141 +1,160 @@ --TEST-- -Test with cursor scroll and select different rows in some random order +Test with cursor scroll and select different rows in some random order --SKIPIF-- - + --FILE-- exec("CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit)"); + createTable($conn, $tableName, array("c1_int" => "int", "c2_tinyint" => "tinyint", "c3_smallint" => "smallint", "c4_bigint" => "bigint", "c5_bit" => "bit")); // insert data - $numRows = InsertData($conn, $tableName); - - // select table - $stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_FWDONLY)); + $numRows = insertData($conn, $tableName); + + // select table + if (!isColEncrypted()) { + $stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array( constant('PDO::ATTR_CURSOR') => PDO::CURSOR_FWDONLY )); + } else { + // ORDER BY is not supported for encrypted columns + $stmt = $conn->prepare("SELECT * FROM $tableName", array( constant('PDO::ATTR_CURSOR') => PDO::CURSOR_FWDONLY )); + } $stmt->execute(); $numRowsFetched = 0; - while ($row = $stmt->fetch(PDO::FETCH_NUM)) - { + while ($row = $stmt->fetch(PDO::FETCH_NUM)) { echo "$row[0]\n"; $numRowsFetched++; } - - if ($numRowsFetched != $numRows) + + if ($numRowsFetched != $numRows) { echo "Number of rows fetched $numRowsFetched is wrong! Expected $numRows\n"; + } + + unset($stmt); } -function Cursor_Scroll_FetchRows($conn, $tableName) +function cursorScrollFetchRows($conn, $tableName) { - $stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL)); + if (!isColEncrypted()) { + $stmt = $conn->prepare("SELECT * FROM $tableName ORDER BY c1_int", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); + } else { + // ORDER BY is not supported for encrypted columns + // scrollable cursor is not supported for encrypted tablee; use client side buffered cursor + $stmt = $conn->prepare("SELECT * FROM $tableName", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED)); + } $stmt->execute(); - - GetFirstRow($stmt); - GetNextRow($stmt); - GetLastRow($stmt); - GetPriorRow($stmt); - GetAbsoluteRow($stmt, 7); - GetAbsoluteRow($stmt, 2); - GetRelativeRow($stmt, 3); - GetPriorRow($stmt); - GetRelativeRow($stmt, -4); - GetAbsoluteRow($stmt, 0); - GetNextRow($stmt); - GetRelativeRow($stmt, 5); - GetAbsoluteRow($stmt, -1); - GetNextRow($stmt); - GetLastRow($stmt); - GetRelativeRow($stmt, 1); + + getFirstRow($stmt); + getNextRow($stmt); + getLastRow($stmt); + getPriorRow($stmt); + getAbsoluteRow($stmt, 7); + getAbsoluteRow($stmt, 2); + getRelativeRow($stmt, 3); + getPriorRow($stmt); + getRelativeRow($stmt, -4); + getAbsoluteRow($stmt, 0); + getNextRow($stmt); + getRelativeRow($stmt, 5); + getAbsoluteRow($stmt, -1); + getNextRow($stmt); + getLastRow($stmt); + getRelativeRow($stmt, 1); + + unset($stmt); } -function InsertData($conn, $tableName) +function insertData($conn, $tableName) { $numRows = 0; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((1), (0), (null), (9223372036854775807), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((2), (null), (-32768), (9223372036854775807), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((3), (255), (-32768), (1035941737), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((4), (null), (4762), (804325764), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((5), (57), (32767), (-9223372036854775808), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((6), (201), (-32768), (450619355), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((7), (244), (-21244), (981345728), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((8), (143), (0), (-1330405117), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((9), (null), (null), (209123628), (0))"); - $numRows += $count; - $count = $conn->exec("INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit) VALUES ((10), (147), (21133), (-1), (0))"); - $numRows += $count; - + + insertRow($conn, $tableName, array("c1_int" => 1, "c2_tinyint" => 0, "c3_smallint" => null, "c4_bigint" => 922337203685477, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 2, "c2_tinyint" => null, "c3_smallint" => -32768, "c4_bigint" => 922337203685477, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 3, "c2_tinyint" => 255, "c3_smallint" => -32768, "c4_bigint" => 1035941737, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 4, "c2_tinyint" => null, "c3_smallint" => 4762, "c4_bigint" => 804325764, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 5, "c2_tinyint" => 57, "c3_smallint" => 32767, "c4_bigint" => -922337203685477, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 6, "c2_tinyint" => 201, "c3_smallint" => -32768, "c4_bigint" => 450619355, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 7, "c2_tinyint" => 244, "c3_smallint" => -21244, "c4_bigint" => 981345728, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 8, "c2_tinyint" => 143, "c3_smallint" => 0, "c4_bigint" => -1330405117, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 9, "c2_tinyint" => null, "c3_smallint" => null, "c4_bigint" => 209123628, "c5_bit" => 0)); + $numRows++; + + insertRow($conn, $tableName, array("c1_int" => 10, "c2_tinyint" => 147, "c3_smallint" => 21133, "c4_bigint" => -1, "c5_bit" => 0)); + $numRows++; + return $numRows; } -function GetFirstRow($stmt) +function getFirstRow($stmt) { - echo "\nfirst row: "; - $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_FIRST, 0); + echo "first row: "; + $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_FIRST, 0); if ($row) - { - echo "$row[0]\n"; - } + echo "$row[0]"; + echo "\n"; } -function GetNextRow($stmt) +function getNextRow($stmt) { - echo "\nnext row: "; - $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT, 0); + echo "next row: "; + $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT, 0); if ($row) - { - echo "$row[0]\n"; - } + echo "$row[0]"; + echo "\n"; } -function GetPriorRow($stmt) +function getPriorRow($stmt) { - echo "\nprior row: "; - $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR, 0); + echo "prior row: "; + $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR, 0); if ($row) - { - echo "$row[0]\n"; - } + echo "$row[0]"; + echo "\n"; } -function GetLastRow($stmt) +function getLastRow($stmt) { - echo "\nlast row: "; - $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST, 0); + echo "last row: "; + $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST, 0); if ($row) - { - echo "$row[0]\n"; - } + echo "$row[0]"; + echo "\n"; } -function GetRelativeRow($stmt, $offset) +function getRelativeRow($stmt, $offset) { - echo "\nrow $offset from the current row: "; - $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_REL, $offset); + echo "row $offset from the current row: "; + $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_REL, $offset); if ($row) - { - echo "$row[0]\n"; - } + echo "$row[0]"; + echo "\n"; } -function GetAbsoluteRow($stmt, $offset) +function getAbsoluteRow($stmt, $offset) { - echo "\nabsolute row with offset $offset: "; - $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, $offset); + echo "absolute row with offset $offset: "; + $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, $offset); if ($row) - { - echo "$row[0]\n"; - } + echo "$row[0]"; + echo "\n"; } @@ -143,39 +162,25 @@ function GetAbsoluteRow($stmt, $offset) // RunTest // //-------------------------------------------------------------------- -function RunTest() -{ - StartTest("pdo_fetch_cursor_scroll_random"); - echo "\nTest begins...\n"; - try - { - include("MsSetup.inc"); - - // Connect - $conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - - $tableName = GetTempTableName(); - - Cursor_ForwardOnly($conn, $tableName); - Cursor_Scroll_FetchRows($conn, $tableName); - - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_fetch_cursor_scroll_random"); -} -RunTest(); +echo "Test begins...\n"; +try { + // Connect + $conn = connect(); + $tableName = getTableName(); + + cursorForwardOnly($conn, $tableName); + cursorScrollFetchRows($conn, $tableName); + dropTable($conn, $tableName); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); +} +echo "Done\n"; ?> --EXPECT-- - -Test begins... +Test begins... 1 2 3 @@ -186,36 +191,20 @@ Test begins... 8 9 10 - first row: 1 - next row: 2 - last row: 10 - prior row: 9 - absolute row with offset 7: 8 - absolute row with offset 2: 3 - row 3 from the current row: 6 - prior row: 5 - row -4 from the current row: 1 - absolute row with offset 0: 1 - next row: 2 - row 5 from the current row: 7 - absolute row with offset -1: next row: 1 - last row: 10 - row 1 from the current row: Done -Test "pdo_fetch_cursor_scroll_random" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_getAttribute_clientInfo.phpt b/test/functional/pdo_sqlsrv/pdo_getAttribute_clientInfo.phpt index 894721b82..2bbfc3e66 100644 --- a/test/functional/pdo_sqlsrv/pdo_getAttribute_clientInfo.phpt +++ b/test/functional/pdo_sqlsrv/pdo_getAttribute_clientInfo.phpt @@ -1,16 +1,21 @@ --TEST-- -Test client info by calling PDO::getAttribute with PDO::ATTR_CLIENT_VERSION +Test client info by calling PDO::getAttribute with PDO::ATTR_CLIENT_VERSION +--SKIPIF-- + --FILE-- getAttribute(PDO::ATTR_CLIENT_VERSION)); -// An example using PDO::ATTR_CLIENT_VERSION -print_r($conn->getAttribute( PDO::ATTR_CLIENT_VERSION )); - -//free the connection -$conn=null; + //free the connection + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECTREGEX-- Array @@ -19,4 +24,4 @@ Array \[DriverODBCVer\] => [0-9]{1,2}\.[0-9]{1,2} \[DriverVer\] => [0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4} \[ExtensionVer\] => [0-9].[0-9]\.[0-9](-(RC[0-9]?|preview))?(\.[0-9]+)?(\+[0-9]+)? -\) \ No newline at end of file +\) diff --git a/test/functional/pdo_sqlsrv/pdo_getAvailableDrivers.phpt b/test/functional/pdo_sqlsrv/pdo_getAvailableDrivers.phpt index 57cae0a3a..3442dfdb8 100644 --- a/test/functional/pdo_sqlsrv/pdo_getAvailableDrivers.phpt +++ b/test/functional/pdo_sqlsrv/pdo_getAvailableDrivers.phpt @@ -1,23 +1,17 @@ --TEST-- Test the PDO::getAvailableDrivers() method. --SKIPIF-- - + --FILE-- +?> --EXPECT-- -Test successful. \ No newline at end of file +Test successful. diff --git a/test/functional/pdo_sqlsrv/pdo_get_attr_invalid.phpt b/test/functional/pdo_sqlsrv/pdo_get_attr_invalid.phpt index 5a33304f5..09be0c7d2 100644 --- a/test/functional/pdo_sqlsrv/pdo_get_attr_invalid.phpt +++ b/test/functional/pdo_sqlsrv/pdo_get_attr_invalid.phpt @@ -1,37 +1,31 @@ --TEST-- Test getting invalid attributes --SKIPIF-- - + --FILE-- PDO::ERRMODE_SILENT)); - - @$conn->getAttribute( PDO::ATTR_FETCH_TABLE_NAMES ); - print_r (($conn->errorInfo())[2]); +try { + $conn = connect("", array(), PDO::ERRMODE_SILENT); + + @$conn->getAttribute(PDO::ATTR_FETCH_TABLE_NAMES); + print_r(($conn->errorInfo())[2]); echo "\n"; - @$conn->getAttribute( PDO::ATTR_CURSOR ); - print_r (($conn->errorInfo())[2]); + @$conn->getAttribute(PDO::ATTR_CURSOR); + print_r(($conn->errorInfo())[2]); echo "\n"; - @$conn->getAttribute( PDO::ATTR_CONNECTION_STATUS ); - print_r (($conn->errorInfo())[2]); + @$conn->getAttribute(PDO::ATTR_CONNECTION_STATUS); + print_r(($conn->errorInfo())[2]); echo "\n"; -} -catch ( PDOException $e ){ +} catch (PDOException $e) { echo $e->getMessage(); } - -?> - +?> --EXPECT-- - An unsupported attribute was designated on the PDO object. The given attribute is only supported on the PDOStatement object. -An invalid attribute was designated on the PDO object. \ No newline at end of file +An invalid attribute was designated on the PDO object. diff --git a/test/functional/pdo_sqlsrv/pdo_get_set_attr.phpt b/test/functional/pdo_sqlsrv/pdo_get_set_attr.phpt index 4aac8bd4a..06c69b010 100644 --- a/test/functional/pdo_sqlsrv/pdo_get_set_attr.phpt +++ b/test/functional/pdo_sqlsrv/pdo_get_set_attr.phpt @@ -1,111 +1,97 @@ --TEST-- Test PDO::setAttribute() and PDO::getAttribute() methods. --SKIPIF-- - + --FILE-- -getAttribute( constant($attr) ); - var_dump( $result); - } - catch ( PDOException $e) - { + $result = $conn->getAttribute(constant($attr)); + var_dump($result); + } catch (PDOException $e) { echo $e->getMessage() . "\n"; } -} - -function set_attr( $conn, $attr, $val ) +} + +function setAttr($conn, $attr, $val) { try { - echo "Set Result $attr :\n"; - $result = $conn->setAttribute( constant($attr), $val ); - var_dump( $result); - } - catch ( PDOException $e) - { + $result = $conn->setAttribute(constant($attr), $val); + var_dump($result); + } catch (PDOException $e) { echo $e->getMessage() . "\n"; } -} - -function set_get_attr($testName, $conn, $attr, $val) +} + +function setGetAttr($testName, $conn, $attr, $val) { try { - echo "\n". $testName . ":\n"; - set_attr($conn, $attr, $val ); - get_attr($conn, $attr ); - } - catch(PDOException $e) - { + setAttr($conn, $attr, $val); + getAttr($conn, $attr); + } catch (PDOException $e) { var_dump($e); } } - -try -{ - $conn = new PDO("sqlsrv:Server=$server;database=$databaseName", $uid, $pwd); - $values = array ( "PDO::ATTR_ERRMODE" => 2, - "PDO::ATTR_SERVER_VERSION" => "whatever", - "PDO::ATTR_DRIVER_NAME" => "whatever", - "PDO::ATTR_STRINGIFY_FETCHES" => true, - "PDO::ATTR_CLIENT_VERSION" => "whatever", - "PDO::ATTR_SERVER_INFO" => "whatever", - "PDO::ATTR_CASE" => PDO::CASE_LOWER, - "PDO::SQLSRV_ATTR_ENCODING" => PDO::SQLSRV_ENCODING_SYSTEM, - "PDO::ATTR_DEFAULT_FETCH_MODE" => PDO::FETCH_ASSOC, - "PDO::ATTR_ORACLE_NULLS" => PDO::NULL_NATURAL, - "PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE" => 5120, - "PDO::SQLSRV_ATTR_DIRECT_QUERY" => true, - "PDO::ATTR_STATEMENT_CLASS" => array('CustomPDOStatement', array()), - "PDO::SQLSRV_ATTR_QUERY_TIMEOUT" => 10, - "PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE" => false - ); - - $attributes = array ( "PDO::ATTR_ERRMODE", - "PDO::ATTR_SERVER_VERSION", - "PDO::ATTR_DRIVER_NAME", - "PDO::ATTR_STRINGIFY_FETCHES", - "PDO::ATTR_CLIENT_VERSION", - "PDO::ATTR_SERVER_INFO", - "PDO::ATTR_CASE", - "PDO::SQLSRV_ATTR_ENCODING", - "PDO::ATTR_DEFAULT_FETCH_MODE", - "PDO::ATTR_ORACLE_NULLS", - "PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE", - "PDO::SQLSRV_ATTR_DIRECT_QUERY", - "PDO::ATTR_STATEMENT_CLASS", - "PDO::SQLSRV_ATTR_QUERY_TIMEOUT", - "PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE" - ); + +try { + $conn = connect(); + $values = array("PDO::ATTR_ERRMODE" => 2, + "PDO::ATTR_SERVER_VERSION" => "whatever", + "PDO::ATTR_DRIVER_NAME" => "whatever", + "PDO::ATTR_STRINGIFY_FETCHES" => true, + "PDO::ATTR_CLIENT_VERSION" => "whatever", + "PDO::ATTR_SERVER_INFO" => "whatever", + "PDO::ATTR_CASE" => PDO::CASE_LOWER, + "PDO::SQLSRV_ATTR_ENCODING" => PDO::SQLSRV_ENCODING_SYSTEM, + "PDO::ATTR_DEFAULT_FETCH_MODE" => PDO::FETCH_ASSOC, + "PDO::ATTR_ORACLE_NULLS" => PDO::NULL_NATURAL, + "PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE" => 5120, + "PDO::SQLSRV_ATTR_DIRECT_QUERY" => true, + "PDO::ATTR_STATEMENT_CLASS" => array('CustomPDOStatement', array()), + "PDO::SQLSRV_ATTR_QUERY_TIMEOUT" => 10, + "PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE" => false); + + $attributes = array("PDO::ATTR_ERRMODE", + "PDO::ATTR_SERVER_VERSION", + "PDO::ATTR_DRIVER_NAME", + "PDO::ATTR_STRINGIFY_FETCHES", + "PDO::ATTR_CLIENT_VERSION", + "PDO::ATTR_SERVER_INFO", + "PDO::ATTR_CASE", + "PDO::SQLSRV_ATTR_ENCODING", + "PDO::ATTR_DEFAULT_FETCH_MODE", + "PDO::ATTR_ORACLE_NULLS", + "PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE", + "PDO::SQLSRV_ATTR_DIRECT_QUERY", + "PDO::ATTR_STATEMENT_CLASS", + "PDO::SQLSRV_ATTR_QUERY_TIMEOUT", + "PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE"); $i = 1; - foreach( $attributes as $attr ) - { + foreach ($attributes as $attr) { $testName = "Test_". $i; $i = $i + 1; - set_get_attr($testName, $conn, $attr, $values[$attr]); + setGetAttr($testName, $conn, $attr, $values[$attr]); } -} - -catch( PDOException $e ) { - - var_dump( $e ); + unset($conn); +} catch (PDOException $e) { + var_dump($e); exit; } -?> +?> --EXPECTREGEX-- @@ -219,4 +205,4 @@ Test_15: Set Result PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE : bool\(true\) Get Result PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE : -bool\(false\) \ No newline at end of file +bool\(false\) diff --git a/test/functional/pdo_sqlsrv/pdo_invalid_conn_opt.phpt b/test/functional/pdo_sqlsrv/pdo_invalid_conn_opt.phpt index 7d38a3e0b..043621774 100644 --- a/test/functional/pdo_sqlsrv/pdo_invalid_conn_opt.phpt +++ b/test/functional/pdo_sqlsrv/pdo_invalid_conn_opt.phpt @@ -1,29 +1,20 @@ --TEST-- Test PDO::__Construct with invalid connection option --SKIPIF-- - + --FILE-- errorInfo); } -catch( PDOException $e ) { - var_dump( $e->errorInfo ); -} -?> +?> --EXPECT-- - array(3) { [0]=> string(5) "IMSSP" @@ -31,4 +22,5 @@ array(3) { int(-42) [2]=> string(64) "An invalid keyword 'InvalidKey' was specified in the DSN string." -} \ No newline at end of file +} +Test Successful \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_lastInsertId.phpt b/test/functional/pdo_sqlsrv/pdo_lastInsertId.phpt index 76678a518..7dfe4bbbf 100644 --- a/test/functional/pdo_sqlsrv/pdo_lastInsertId.phpt +++ b/test/functional/pdo_sqlsrv/pdo_lastInsertId.phpt @@ -1,44 +1,45 @@ --TEST-- Test the PDO::lastInsertId() method. --SKIPIF-- - + --FILE-- exec('CREATE TABLE #tmp_table1(id INT IDENTITY(100,2), val INT)'); - $conn->exec('CREATE TABLE #tmp_table2(id INT IDENTITY(200,2), val INT)'); - $conn->exec('CREATE TABLE #tmp_table3(id INT, val INT)'); - - $conn->exec('INSERT INTO #tmp_table1 VALUES(1)'); - $conn->exec('INSERT INTO #tmp_table2 VALUES(2)'); + createTable($conn, "table1", array(new columnMeta("int", "id", "IDENTITY(100,2)"), "val" => "int")); + createTable($conn, "table2", array(new columnMeta("int", "id", "IDENTITY(200,2)"), "val" => "int")); + createTable($conn, "table3", array("id" => "int", "val" => "int")); + + insertRow($conn, "table1", array("val" => 1), "exec"); + insertRow($conn, "table2", array("val" => 2), "exec"); $id = $conn->lastInsertId(); var_dump($id); - - $conn->exec('INSERT INTO #tmp_table2 VALUES(3)'); - $conn->exec('INSERT INTO #tmp_table1 VALUES(4)'); + + insertRow($conn, "table2", array("val" => 3), "exec"); + insertRow($conn, "table1", array("val" => 4), "exec"); $id = $conn->lastInsertId(); var_dump($id); - + // Should return empty string as the table does not have an IDENTITY column. - $conn->exec('INSERT INTO #tmp_table3 VALUES(1,1)'); + insertRow($conn, "table3", array("id" => 1, "val" => 1), "exec"); $id = $conn->lastInsertId(); - var_dump($id); -} + var_dump($id); -catch( PDOException $e ) { - var_dump( $e ); + dropTable($conn, "table1"); + dropTable($conn, "table2"); + dropTable($conn, "table3"); + unset($conn); +} catch (PDOException $e) { + var_dump($e); exit; } -?> +?> --EXPECT-- string(3) "200" string(3) "102" diff --git a/test/functional/pdo_sqlsrv/pdo_nested_query_mars.phpt b/test/functional/pdo_sqlsrv/pdo_nested_query_mars.phpt index 9d912dc8d..e86ae08ee 100644 --- a/test/functional/pdo_sqlsrv/pdo_nested_query_mars.phpt +++ b/test/functional/pdo_sqlsrv/pdo_nested_query_mars.phpt @@ -1,82 +1,70 @@ --TEST-- fetch multiple result sets with MARS on and then off --SKIPIF-- - + --FILE-- SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - $stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_varchar] varchar(20))"); - - $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (1, 'Dummy value 1')"; - $stmt = $conn->query($query); - - $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (2, 'Dummy value 2')"; - $stmt = $conn->query($query); + $tableName = getTableName(); + + $conn = connect("MultipleActiveResultSets=$on"); + + createTable($conn, $tableName, array("c1_int" => "int", "c2_varchar" => "varchar(20)")); - $query = "SELECT * FROM $tableName ORDER BY [c1_int]"; + insertRow($conn, $tableName, array("c1_int" => 1, "c2_varchar" => "Dummy value 1")); + insertRow($conn, $tableName, array("c1_int" => 2, "c2_varchar" => "Dummy value 2")); + + if (!isColEncrypted()) { + $query = "SELECT * FROM $tableName ORDER BY [c1_int]"; + } else { + // ORDER BY is not support for encrypted columns + $query = "SELECT * FROM $tableName"; + } $stmt = $conn->query($query); $numRows = 0; - while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $numRows++; + } - if ($numRows !== 2) echo "Number of rows is unexpected!\n"; - $stmt = null; + if ($numRows !== 2) { + echo "Number of rows is unexpected!\n"; + } + unset($stmt); // more than one active results $stmt1 = $conn->query($query); $stmt2 = $conn->prepare($query); $stmt2->execute(); - + echo "\nNumber of columns in First set: " . $stmt2->columnCount() . "\n"; - while ($row = $stmt1->fetch(PDO::FETCH_ASSOC)) - { - print_r($row); + while ($row = $stmt1->fetch(PDO::FETCH_ASSOC)) { + print_r($row); } echo "\nNumber of columns in Second set: " . $stmt1->columnCount() . "\n\n"; - while ($row = $stmt2->fetch(PDO::FETCH_OBJ)) - { - print_r($row); + while ($row = $stmt2->fetch(PDO::FETCH_OBJ)) { + print_r($row); } - - $stmt1 = null; - $stmt2 = null; - $conn = null; -} -function RunTest() -{ - StartTest("pdo_nested_query_mars"); - echo "\nStarting test...\n"; - try - { - NestedQuery_Mars(true); - NestedQuery_Mars(false); - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_nested_query_mars"); + dropTable($conn, $tableName); + unset($stmt1); + unset($stmt2); + unset($conn); } -RunTest(); - +echo "Starting test...\n"; +try { + NestedQuery_Mars(true); + NestedQuery_Mars(false); +} catch (Exception $e) { + echo $e->getMessage(); +} +echo "\nDone\n"; ?> --EXPECT-- - Starting test... Number of columns in First set: 2 @@ -105,4 +93,3 @@ stdClass Object ) SQLSTATE[IMSSP]: The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option. Done -Test "pdo_nested_query_mars" completed successfully. diff --git a/test/functional/pdo_sqlsrv/pdo_output_decimal.phpt b/test/functional/pdo_sqlsrv/pdo_output_decimal.phpt index c789c054f..b4512c31f 100644 --- a/test/functional/pdo_sqlsrv/pdo_output_decimal.phpt +++ b/test/functional/pdo_sqlsrv/pdo_output_decimal.phpt @@ -1,28 +1,25 @@ --TEST-- -call stored procedures with inputs of ten different datatypes to get outputs of various types +call stored procedures with inputs of ten different datatypes to get outputs of various types --SKIPIF-- - + --FILE-- exec("CREATE PROC $proc_scale (@p1 DECIMAL(18, 1), @p2 DECIMAL(18, 1), @p3 CHAR(128) OUTPUT) AS BEGIN SELECT @p3 = CONVERT(CHAR(128), @p1 + @p2) END"); - - $inValue1 = '2.1'; - $inValue2 = '5.3'; + + $inValue1 = '2.1'; + $inValue2 = '5.3'; $outValue1 = '0'; $outValue2 = '0'; - + $stmt = $conn->prepare("{CALL $proc_scale (?, ?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindValue(2, $inValue2); @@ -30,10 +27,10 @@ try $stmt->execute(); $outValue1 = trim($outValue1); - + $stmt = $conn->exec("CREATE PROC $proc_no_scale (@p1 DECIMAL, @p2 DECIMAL, @p3 CHAR(128) OUTPUT) AS BEGIN SELECT @p3 = CONVERT(CHAR(128), @p1 + @p2) END"); - + $stmt = $conn->prepare("{CALL $proc_no_scale (?, ?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindValue(2, $inValue2); @@ -41,24 +38,22 @@ try $stmt->execute(); $outValue2 = trim($outValue2); - + $expected1 = "7.4"; $expected2 = "7"; if ($outValue1 == $expected1 && $outValue2 == $expected2) { echo "Test Successfully\n"; } - - $stmt = $conn->exec("DROP PROCEDURE $proc_scale"); - $stmt = $conn->exec("DROP PROCEDURE $proc_no_scale"); - - $stmt = null; - $conn = null; -} -catch (Exception $e) -{ + + dropProc($conn, $proc_scale); + dropProc($conn, $proc_no_scale); + + unset($stmt); + unset($conn); +} catch (Exception $e) { echo $e->getMessage(); } - ?> + --EXPECT-- Test Successfully diff --git a/test/functional/pdo_sqlsrv/pdo_passwords.phpt b/test/functional/pdo_sqlsrv/pdo_passwords.phpt index cadcf9aea..c672fc95e 100644 --- a/test/functional/pdo_sqlsrv/pdo_passwords.phpt +++ b/test/functional/pdo_sqlsrv/pdo_passwords.phpt @@ -1,67 +1,57 @@ --TEST-- Test password with non alphanumeric characters --DESCRIPTION-- -The first three cases should have no problem connecting. Only the last case fails because the +The first three cases should have no problem connecting. Only the last case fails because the right curly brace should be escaped with another right brace. In Azure for this test to pass do not specify any particular database when connecting --SKIPIF-- - + --FILE-- getMessage() . "\n"); - } -try{ +try { // Test 2 - $conn = new PDO( "sqlsrv:Server=$server;ConnectionPooling=false;" , "test_password2", "!}} ;4triou"); - if(!$conn) - { + $conn = new PDO($dsn, "test_password2", "!}} ;4triou"); + if (!$conn) { echo "Test 2: Should have connected."; } -} -catch(PDOException $e){ + unset($conn); +} catch (PDOException $e) { print_r($e->getMessage() . "\n"); - } -try{ +try { // Test 3 - $conn = new PDO( "sqlsrv:Server=$server;ConnectionPooling=false;" , "test_password3", "! ;4triou}}"); - if(!$conn) - { + $conn = new PDO($dsn, "test_password3", "! ;4triou}}"); + if (!$conn) { echo "Test 3: Should have connected."; } -} -catch(PDOException $e){ + unset($conn); +} catch (PDOException $e) { print_r($e->getMessage() . "\n"); - } // Test invalid password. -try -{ +try { // Test 4 - $conn = new PDO( "sqlsrv:Server=$server;ConnectionPooling=false;" , "test_password3", "! ;4triou}"); -} -catch( PDOException $e ) { - print_r( $e->getMessage() ); + $conn = new PDO($dsn, "test_password3", "! ;4triou}"); +} catch (PDOException $e) { + print_r($e->getMessage()); exit; } - -?> + +?> --EXPECTREGEX-- SQLSTATE\[IMSSP\]: An unescaped right brace \(}\) was found in either the user name or password\. All right braces must be escaped with another right brace \(}}\)\. - - - diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_binary.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_binary.phpt index ebd524473..f31e08937 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_binary.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_binary.phpt @@ -1,70 +1,80 @@ --TEST-- prepare with emulate prepare and binding binary parameters --SKIPIF-- - + --FILE-- prepare('DROP TABLE TESTTABLE'); - $st->execute(); -} -catch(Exception $e) {} + $connection_options = array(); + $connection_options[PDO::ATTR_STRINGIFY_FETCHES] = true; + $cnn = connect("", $connection_options, PDO::ERRMODE_SILENT); -//Recreate -$st = $cnn->prepare('CREATE TABLE TESTTABLE ([COLA] varbinary(max))'); -$st->execute(); + $pdo_options = array(); + $pdo_options[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL; + $pdo_options[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE] = PDO::SQLSRV_CURSOR_BUFFERED; -$p = fopen('php://memory', 'a'); -fwrite($p, 'asdgasdgasdgsadg'); -rewind($p); + // Create Table + $tbname = getTableName(); + createTable($cnn, $tbname, array("COLA" => "varbinary(max)")); -//WORKS OK without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$st = $cnn->prepare('INSERT INTO TESTTABLE VALUES(:p0)', $pdo_options); -$st->bindParam(':p0', $p, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); -$st->execute(); + $p = fopen('php://memory', 'a'); + fwrite($p, 'asdgasdgasdgsadg'); + rewind($p); -$st = $cnn->prepare('SELECT TOP 1 * FROM TESTTABLE', $pdo_options); -$st->execute(); -$value = $st->fetch(PDO::FETCH_ASSOC); -print_r($value); + //WORKS OK without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $st = $cnn->prepare("INSERT INTO $tbname VALUES(:p0)", $pdo_options); + $st->bindParam(':p0', $p, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $st->execute(); -//EMULATE PREPARE with SQLSRV_ENCODING_BINARY -$pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE; -print_r("Prepare with emulate prepare and set encoding to binary:\n"); -$st = $cnn->prepare('INSERT INTO TESTTABLE VALUES(:p0)', $pdo_options); -$st->bindParam(':p0', $p, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); -$st->execute(); + $st = $cnn->prepare("SELECT TOP 1 * FROM $tbname", $pdo_options); + $st->execute(); + $value = $st->fetch(PDO::FETCH_ASSOC); + print_r($value); + $cnn->exec("TRUNCATE TABLE $tbname"); -$st = $cnn->prepare('SELECT * FROM TESTTABLE', $pdo_options); -$st->execute(); -$value = $st->fetch(PDO::FETCH_ASSOC); -print_r($value); + //EMULATE PREPARE with SQLSRV_ENCODING_BINARY + if (!isColEncrypted()) { + // Emulate prepare does not work fro encrypted columns + $pdo_options[PDO::ATTR_EMULATE_PREPARES] = true; + } + print_r("Prepare with emulate prepare and set encoding to binary:\n"); + rewind($p); + $st = $cnn->prepare("INSERT INTO $tbname VALUES(:p0)", $pdo_options); + $st->bindParam(':p0', $p, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $st->execute(); -//EMULATE PREPARE with no bind param options -print_r("Prepare with emulate prepare and no bindparam options:\n"); -$st = $cnn->prepare('INSERT INTO TESTTABLE VALUES(:p0)', $pdo_options); -$st->bindParam(':p0', $p, PDO::PARAM_LOB); -$st->execute(); + $st = $cnn->prepare("SELECT * FROM $tbname", $pdo_options); + $st->execute(); + $value = $st->fetch(PDO::FETCH_ASSOC); + print_r($value); + $cnn->exec("TRUNCATE TABLE $tbname"); -$st = $cnn->prepare('SELECT * FROM TESTTABLE', $pdo_options); -$st->execute(); -$value = $st->fetch(PDO::FETCH_ASSOC); -print_r($value); + //EMULATE PREPARE with no bind param options; expects an error + print_r("Prepare with emulate prepare and no bindparam options:\n"); + rewind($p); -$st = null; -$cnn = null; + $st = $cnn->prepare("INSERT INTO $tbname VALUES(:p0)", $pdo_options); + $st->bindParam(':p0', $p, PDO::PARAM_LOB); + $st->execute(); + $error = $st->errorInfo(); + if (!isColEncrypted() && $error[0] !== "42000") { + echo "Error 42000 is expected: Implicit conversion from data type varchar to varbinary(max) is not allowed.\n"; + var_dump($error); + } elseif (isColEncrypted() && $error[0] != "22018") { + echo "Error 22018 is expected: Invalid character value for cast specification.\n"; + var_dump($error); + } else { + echo "Done.\n"; + } + + dropTable($cnn, $tbname); + unset($st); + unset($cnn); +} catch (PDOException $e) { + print_r($e->errorInfo[2] . "\n"); +} ?> --EXPECTREGEX-- Prepare without emulate prepare: @@ -78,9 +88,4 @@ Array \[COLA\] => asdgasdgasdgsadg \) Prepare with emulate prepare and no bindparam options: - -Fatal error: Uncaught PDOException: SQLSTATE\[42000\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Implicit conversion from data type varchar to varbinary\(max\) is not allowed\. Use the CONVERT function to run this query\. in .+(\/|\\)pdo_prepare_emulatePrepare_binary\.php:[0-9]+ -Stack trace: -#0 .+(\/|\\)pdo_prepare_emulatePrepare_binary\.php\([0-9]+\): PDOStatement->execute\(\) -#1 {main} - thrown in .+(\/|\\)pdo_prepare_emulatePrepare_binary\.php on line [0-9]+ \ No newline at end of file +Done\. diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_char.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_char.phpt index 985cb932f..7776f1438 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_char.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_char.phpt @@ -1,78 +1,74 @@ --TEST-- prepare with emulate prepare and binding varchar --SKIPIF-- - + --FILE-- query($query); + $tableName = "fruit"; + createTable($conn, $tableName, array("name" => "varchar(max)", "calories" => "int")); -$query = "CREATE TABLE [$tableName] (name varchar(max), calories int)"; -$stmt = $conn->query($query); + insertRow($conn, $tableName, array("name" => "apple", "calories" => 150)); + insertRow($conn, $tableName, array("name" => "banana", "calories" => 175)); + insertRow($conn, $tableName, array("name" => "blueberry", "calories" => 1)); -$query = "INSERT INTO [$tableName] (name, calories) VALUES ('apple', 150)"; -$stmt = $conn->query($query); + $query = "SELECT * FROM [$tableName] WHERE name = :name"; -$query = "INSERT INTO [$tableName] (name, calories) VALUES ('banana', 175)"; -$stmt = $conn->query($query); + //prepare without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $options = array(PDO::ATTR_EMULATE_PREPARES => false); + $stmt = $conn->prepare($query, $options); + $name = 'blueberry'; + $stmt->bindParam(':name', $name); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "INSERT INTO [$tableName] (name, calories) VALUES ('blueberry', 1)"; -$stmt = $conn->query($query); + //prepare with emulate prepare and no bind param options + print_r("Prepare with emulate prepare and no bindParam options:\n"); + if (!isColEncrypted()) { + $options = array(PDO::ATTR_EMULATE_PREPARES => true); + } + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':name', $name); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "SELECT * FROM [$tableName] WHERE name = :name"; + //prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -//prepare without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false)); -$name = 'blueberry'; -$stmt->bindParam(':name', $name); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 + print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -//prepare with emulate prepare and no bind param options -print_r("Prepare with emulate prepare and no bindParam options:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$name = 'blueberry'; -$stmt->bindParam(':name', $name); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY + print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -//prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$name = 'blueberry'; -$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 -print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$name = 'blueberry'; -$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY -print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$name = 'blueberry'; -$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -$stmt = null; -$conn=null; + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- @@ -105,4 +101,4 @@ Array ( [name] => blueberry [calories] => 1 -) \ No newline at end of file +) diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_datetime.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_datetime.phpt index e06118a7f..38f4c0dc4 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_datetime.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_datetime.phpt @@ -1,81 +1,78 @@ --TEST-- prepare with emulate prepare and binding integer --SKIPIF-- - + --FILE-- query($query); + $tableName = "date_types"; + createTable($conn, $tableName, array("c1_datetime" => "datetime", "c2_nvarchar" => "nvarchar(20)")); -$query = "CREATE TABLE [$tableName] (c1_datetime datetime, c2_nvarchar nvarchar(20))"; -$stmt = $conn->query($query); + insertRow($conn, $tableName, array("c1_datetime" => "2012-06-18 10:34:09", "c2_nvarchar" => "2012-06-18 10:34:09")); + insertRow($conn, $tableName, array("c1_datetime" => "2008-11-11 13:23:44", "c2_nvarchar" => "2008-11-11 13:23:44")); + insertRow($conn, $tableName, array("c1_datetime" => "2012-09-25 19:47:00", "c2_nvarchar" => "2012-09-25 19:47:00")); -$query = "INSERT INTO [$tableName] (c1_datetime, c2_nvarchar) VALUES ('2012-06-18 10:34:09', N'2012-06-18 10:34:09')"; -$stmt = $conn->query($query); + $query = "SELECT * FROM [$tableName] WHERE c1_datetime = :c1"; -$query = "INSERT INTO [$tableName] (c1_datetime, c2_nvarchar) VALUES ('2008-11-11 13:23:44', N'2008-11-11 13:23:44')"; -$stmt = $conn->query($query); + // prepare without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $options = array(PDO::ATTR_EMULATE_PREPARES => false); + $stmt = $conn->prepare($query, $options); + $c1 = '2012-09-25 19:47:00'; + $stmt->bindParam(':c1', $c1); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "INSERT INTO [$tableName] (c1_datetime, c2_nvarchar) VALUES ('2012-09-25 19:47:00', N'2012-09-25 19:47:00')"; -$stmt = $conn->query($query); + //with emulate prepare and no bind param options + if (!isColEncrypted()) { + // emulate prepare is not supported in encrypted columns + $options = array(PDO::ATTR_EMULATE_PREPARES => true); + } + print_r("Prepare with emulate prepare and no bind param options:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "SELECT * FROM [$tableName] WHERE c1_datetime = :c1"; + //with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -// prepare without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false)); -$c1 = '2012-09-25 19:47:00'; -$stmt->bindParam(':c1', $c1); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -//with emulate prepare and no bind param options -print_r("Prepare with emulate prepare and no bind param options:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = '2012-09-25 19:47:00'; -$stmt->bindParam(':c1', $c1); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + if ($stmt->rowCount() == 0) { + print_r("No results for this query\n"); + } -//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = '2012-09-25 19:47:00'; -$stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = '2012-09-25 19:47:00'; -$stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = '2012-09-25 19:47:00'; -$stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); -if ($stmt->rowCount() == 0){ - print_r("No results for this query\n"); + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo[2]); } - -$stmt = null; -$conn=null; ?> --EXPECT-- @@ -104,4 +101,4 @@ Array [c2_nvarchar] => 2012-09-25 19:47:00 ) Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: -No results for this query \ No newline at end of file +No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt index 54e31527d..48ffca2b8 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt @@ -1,81 +1,83 @@ --TEST-- prepare with emulate prepare and binding integer --SKIPIF-- - + --FILE-- query($query); + $tableName = "number_types"; + if (!isColEncrypted()) { + createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float")); + } else { + // money is not supported for column encryption, use decimal(19,4) instead + createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "decimal(19,4)", "c3_float" => "float")); + } -$query = "CREATE TABLE [$tableName] (c1_decimal decimal, c2_money money, c3_float float)"; -$stmt = $conn->query($query); + insertRow($conn, $tableName, array("c1_decimal" => 411.1, "c2_money" => 131.11, "c3_float" => 611.111)); + insertRow($conn, $tableName, array("c1_decimal" => 422.2222, "c2_money" => 132.222, "c3_float" => 622.22)); + insertRow($conn, $tableName, array("c1_decimal" => 433.333, "c2_money" => 133.3333, "c3_float" => 633.33333)); -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (411.1, 131.11, 611.111)"; -$stmt = $conn->query($query); + $query = "SELECT * FROM [$tableName] WHERE c1_decimal = :c1"; -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (422.2222, 132.222, 622.22)"; -$stmt = $conn->query($query); + // prepare without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $options = array(PDO::ATTR_EMULATE_PREPARES => false); + $stmt = $conn->prepare($query, $options); + $c1 = 422.2222; + $stmt->bindParam(':c1', $c1); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (433.333, 133.3333, 633.33333 )"; -$stmt = $conn->query($query); + //with emulate prepare and no bind param options + print_r("Prepare with emulate prepare and no bind param options:\n"); + if (!isColEncrypted()) { + // emulate prepare is not supported for encrypted columns + $options = array(PDO::ATTR_EMULATE_PREPARES => true); + } + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "SELECT * FROM [$tableName] WHERE c1_decimal = :c1"; + //with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -// prepare without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false)); -$c1 = 422.2222; -$stmt->bindParam(':c1', $c1); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -//with emulate prepare and no bind param options -print_r("Prepare with emulate prepare and no bind param options:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = 422.2222; -$stmt->bindParam(':c1', $c1 ); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + if ($stmt->rowCount() == 0) { + print_r("No results for this query\n"); + } -//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = 422.2222; -$stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = 422.2222; -$stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c1 = 422.2222; -$stmt->bindParam(':c1', $c1, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); -if ($stmt->rowCount() == 0){ - print_r("No results for this query\n"); + dropTable($conn, $tableName); + unset($conn); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -$stmt = null; -$conn=null; ?> --EXPECT-- @@ -108,4 +110,4 @@ Array [c3_float] => 622.22000000000003 ) Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: -No results for this query \ No newline at end of file +No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_warnings.phpt b/test/functional/pdo_sqlsrv/pdo_warnings.phpt index 18891d62a..e83b766ba 100644 --- a/test/functional/pdo_sqlsrv/pdo_warnings.phpt +++ b/test/functional/pdo_sqlsrv/pdo_warnings.phpt @@ -1,29 +1,27 @@ --TEST-- Test warnings on connection and statement levels --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); - + $conn = connect("", array(), PDO::ERRMODE_WARNING); // raise a warning in connection - $conn->getAttribute( PDO::ATTR_TIMEOUT ); - - $conn->exec("IF OBJECT_ID('table1', 'U') IS NOT NULL DROP TABLE table1"); - + $conn->getAttribute(PDO::ATTR_TIMEOUT); + + $tbname = "table1"; + dropTable($conn, $tbname); + // raise a warning in statement - $statement = $conn->prepare("CRATE TABLE table1(id INT NOT NULL PRIMARY KEY, val VARCHAR(10)) "); + $statement = $conn->prepare("CRATE TABLE table1(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))"); $statement->execute(); - $statement = NULL; - $conn = NULL; -} -catch ( PDOException $e ){ - var_dump( $e->errorInfo ); + unset($statement); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); exit; } ?> @@ -35,4 +33,4 @@ Error Message: An unsupported attribute was designated on the PDO object\. Warning: PDO::getAttribute\(\): SQLSTATE\[IM001\]: Driver does not support this function: driver does not support that attribute in .+(\/|\\)pdo_warnings\.php on line [0-9]+ -Warning: PDOStatement::execute\(\): SQLSTATE\[42000\]: Syntax error or access violation: 156 \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Incorrect syntax near the keyword 'TABLE'\. in .+(\/|\\)pdo_warnings\.php on line [0-9]+ \ No newline at end of file +Warning: PDOStatement::execute\(\): SQLSTATE\[42000\]: Syntax error or access violation: 156 \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Incorrect syntax near the keyword 'TABLE'\. in .+(\/|\\)pdo_warnings\.php on line [0-9]+ diff --git a/test/functional/pdo_sqlsrv/skipif_mid-refactor.inc b/test/functional/pdo_sqlsrv/skipif_mid-refactor.inc new file mode 100644 index 000000000..4859bf32d --- /dev/null +++ b/test/functional/pdo_sqlsrv/skipif_mid-refactor.inc @@ -0,0 +1,16 @@ +