Refactored SQLSRV tests to test AE with various data types

This commit is contained in:
Jenny Tam 2017-10-23 17:04:35 -07:00
parent b59fa30241
commit c55ad3ed9f
49 changed files with 1418 additions and 1348 deletions

View file

@ -220,16 +220,6 @@ function executeQueryEx($conn, $query, $modeDirect)
return ($stmt);
}
function createTable($conn, $tableName)
{
trace("Creating table $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);
trace(" completed successfully.\n");
}
function createTableEx($conn, $tableName, $dataType)
{
$sql = "CREATE TABLE [$tableName] ($dataType)";
@ -288,7 +278,6 @@ function dropTable($conn, $tableName)
}
}
function selectFromTable($conn, $tableName)
{
return (selectFromTableEx($conn, $tableName, null));
@ -345,84 +334,6 @@ function numRows($conn, $tableName)
return ($rowCount);
}
function insertQueryData($tableName, $index)
{
if (UseUTF8data()) {
include_once 'MsData_UTF8.inc';
return (InsertQueryExUTF8($tableName, $index));
} else {
include_once 'MsData.inc';
return (InsertQueryEx($tableName, $index));
}
}
function insertQuery($tableName)
{
return (insertQueryData($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)
{
$query = insertQuery($tableName);
$stmt = sqlsrv_query($conn, $query);
return (insertCheck($stmt));
}
function insertRowEx($conn, $tableName, $dataCols, $dataValues, $dataOptions)
{
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions);
return (insertCheck($stmt));
}
function insertRowByIndex($conn, $tableName, $index)
{
$query = insertQueryData($tableName, $index);
$stmt = sqlsrv_query($conn, $query);
return (insertCheck($stmt));
}
function insertStream($conn, $tableName, $dataCols, $dataValues, $dataOptions, $atExec)
{
if ($atExec) {
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions, array('SendStreamParamsAtExec' => 1));
} else {
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions);
if ($stmt) {
while (sqlsrv_send_stream_data($stmt)) {
}
}
}
return (insertCheck($stmt));
}
function insertCheck($stmt)
{
if ($stmt === false) {
@ -436,56 +347,12 @@ function insertCheck($stmt)
return (true);
}
function getInsertData($rowIndex, $colIndex, $skip)
{
$query = insertQueryData("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);
}
// Is it's XML type, we can't use the closing bracket as the next delimiter
// because a bracket can be part of the xml data, unless the data is null
$pos = strpos($data, ")");
if ($pos === false) {
die("Failed to isolate data on row $rowIndex, column $pos");
}
$tmp = substr($data, 0, $pos); // don't replace $data in case it's xml data
if (strcasecmp($tmp, "null") == 0 || strlen($tmp) == 0) { // data can actually be blank for null
$tmp = "";
} elseif (IsXml($colIndex)) {
$str = ">')"; // use the XML closing angle bracket as the delimiter
$pos = strpos($data, $str);
$tmp = substr($data, 0, $pos + 2);
}
$data = $tmp; // update $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);
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($procArgs) AS BEGIN $procCode END");
if ($stmt === false) {
fatalError("Failed to create test procedure");
fatalError("Failed to create test procedure", true);
}
sqlsrv_free_stmt($stmt);
}
@ -509,7 +376,7 @@ 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");
fatalError("Failed to call test procedure", true);
}
return ($stmt);
}
@ -542,10 +409,14 @@ function callFunc($conn, $funcName, $funcArgs, $funcValues)
sqlsrv_free_stmt($stmt);
}
function fatalError($errorMsg)
function fatalError($errorMsg, $print = false)
{
SetUTF8Data(false);
handleErrors();
if ($print) {
printErrors();
} else {
handleErrors();
}
die($errorMsg."\n");
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -28,22 +28,67 @@ const INSERT_PREPARE_PARAMS = 4;
*/
class ColumnMeta
{
public $colName;
public $dataType; // a string that includes the size of the type if necessary (e.g., decimal(10,5))
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 $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, $deterministic = true)
protected $encryptable; // whether Always Encrypted supports this column
public function __construct($dataType, $colName = null, $options = null, $deterministic = true, $noEncrypt = false)
{
if (is_null($colName)) {
$this->colName = getDefaultColname($dataType);
} else {
$this->colName = $colName;
}
$this->encType = ($deterministic ? "deterministic" : "randomized");
if (empty($dataType)) {
echo "Data type can not be null or empty!\n";
}
$this->dataType = $dataType;
$this->options = $options;
// first asssumes the column is not encryptable
$this->encryptable = false;
if (!$noEncrypt) {
$this->checkIfUnsupported();
}
}
/**
* if Always Encrypted not supported for this data type set $noEncryption to false
* @return void
*/
protected function checkIfUnsupported()
{
$this->encryptable = true;
// Always Encrypted is not supported for columns with the IDENTITY property
// or any column using one of the following datatypes:
//
// xml, timestamp, image, ntext, text, sql_variant, hierarchyid, geography, geometry, alias,
// user defined-types.
// https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine
if (stripos($this->options, "identity") !== false) {
$this->encryptable = false;
// } elseif (stripos($this->dataType, "money") !== false) {
// // this is a limitation in ODBC, including money and smallmoney
// $this->encryptable = false;
} elseif (!strcasecmp($this->dataType, "xml") ||
!strcasecmp($this->dataType, "timestamp") ||
!strcasecmp($this->dataType, "image") ||
!strcasecmp($this->dataType, "ntext") ||
!strcasecmp($this->dataType, "text") ||
!strcasecmp($this->dataType, "sql_variant") ||
!strcasecmp($this->dataType, "hierarchyid") ||
!strcasecmp($this->dataType, "geography") ||
!strcasecmp($this->dataType, "geometry") ||
!strcasecmp($this->dataType, "alias")) {
$this->encryptable = false;
}
}
/**
* @return string column definition for creating a table
@ -52,8 +97,7 @@ class ColumnMeta
{
$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) {
if (isColEncrypted() && $this->encryptable) {
$cekName = getCekName();
if (stripos($this->dataType, "char") !== false) {
$append .= "COLLATE Latin1_General_BIN2 ";
@ -83,6 +127,7 @@ class BindParamOption
$this->phpType = $phpType;
$this->sqlType = $sqlType;
}
/**
* @param mix $var : variable to bind to the SQL statement parameter
* @return array needed to bind parameter in sqlsrv_prepare
@ -93,7 +138,7 @@ class BindParamOption
$direction = null;
$phpType = null;
$sqlType = null;
if ($this->direction) {
if ($this->direction) {
if (in_array($this->direction, array(SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, SQLSRV_PARAM_INOUT))) {
$direction = constant($this->direction);
} else {
@ -102,9 +147,16 @@ class BindParamOption
}
if ($this->phpType) {
try {
$phpType = constant($this->phpType);
$arr = explode("(", $this->phpType);
$type = $arr[0];
if (count($arr) > 1) {
$enc = rtrim($arr[1], ")");
$phpType = call_user_func($type, constant($enc));
} else {
$phpType = constant($this->phpType);
}
} catch (Exception $e) {
// there's something wrong with the input php type
// there's something wrong with the input php type
echo $e->getMessage();
}
}
@ -134,7 +186,7 @@ class BindParamOption
$sqlType = constant($type);
}
} catch (Exception $e) {
// there's something wrong with the input SQL type
// there's something wrong with the input SQL type
echo $e->getMessage();
}
}
@ -195,7 +247,7 @@ function getInsertSqlComplete($tbname, $inputs)
foreach ($inputs as $key => $value) {
$colStr .= $key . ", ";
if (is_null($value)) {
echo "getInsertSqlComplete: value provided for input $value is null.\n";
$valStr .= "null, ";
} elseif (is_string($value)) {
$valStr .= "'" . $value . "', ";
} else {
@ -258,7 +310,7 @@ function getSeqPlaceholders($num)
}
/**
* @return bool false if $keystore specified in MsSetup.inc is none or data not encrypted,
* @return bool false if $keystore specified in MsSetup.inc is none or data not encrypted,
* otherwise return true
*/
function isColEncrypted()
@ -307,8 +359,8 @@ function connect($options = array(), $disableCE = false)
if ($keystore == "ksp") {
require('AE_Ksp.inc');
$ksp_path = getKSPPath();
$ksp_options = array("CEKeystoreProvider"=>$ksp_path,
"CEKeystoreName"=>$ksp_name,
$ksp_options = array("CEKeystoreProvider"=>$ksp_path,
"CEKeystoreName"=>$ksp_name,
"CEKeystoreEncryptKey"=>$encrypt_key);
$connectionOptions = array_merge($connectionOptions, $ksp_options);
}
@ -325,6 +377,7 @@ function connect($options = array(), $disableCE = false)
* @param object $conn : sqlsrv connection object
* @param string $tbname : name of the table to be created
* @param array $columnMetaArr : array of ColumnMeta objects, which contain metadata for one column
* @return object sqlsrv statement
*/
function createTable($conn, $tbname, $columnMetaArr)
{
@ -336,18 +389,18 @@ function createTable($conn, $tbname, $columnMetaArr)
}
$colDef = rtrim($colDef, ", ");
$createSql = "CREATE TABLE $tbname ( $colDef )";
sqlsrv_query($conn, $createSql);
return sqlsrv_query($conn, $createSql);
}
/**
* Insert a row into a table
* @param object $conn : sqlsrv 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, which may be a
* @param array $inputs : an associative array column name and its value, which may be a
* literal or a BindParamOption object
* @param bool $r : true if the row was successfully inserted, otherwise false. Default value is null to make this parameter optional.
* $param string $api : SQLSRV API used for executing the insert query
* accepted values: INSERT_QUERY, INSERT_PREPARE, INSERT_QUERY_PARAMS, INSERT_PREPARE_PARAMS
* accepted values: INSERT_QUERY, INSERT_PREPARE, INSERT_QUERY_PARAMS, INSERT_PREPARE_PARAMS
* @return object sqlsrv statement object of the insert statement
*/
function insertRow($conn, $tbname, $inputs, &$r = null, $api = INSERT_QUERY)
@ -361,7 +414,9 @@ function insertRow($conn, $tbname, $inputs, &$r = null, $api = INSERT_QUERY)
break;
case INSERT_PREPARE:
$stmt = sqlsrv_prepare($conn, $insertSql);
$r = sqlsrv_execute($stmt);
if ($stmt) {
$r = sqlsrv_execute($stmt);
}
break;
}
} else {
@ -370,32 +425,106 @@ function insertRow($conn, $tbname, $inputs, &$r = null, $api = INSERT_QUERY)
$params = array();
foreach ($inputs as $key => $input) {
if (is_object($input)) {
array_push($params, $input->bindParamArr($inputs[$key]));
array_push($params, $input->bindParamArr($input->value));
} else {
array_push($params, $inputs[$key]);
}
}
// use prepare for inserts when AE is enabled
if (isColEncrypted() || $api == INSERT_PREPARE_PARAMS) {
$stmt = sqlsrv_prepare($conn, $insertSql, $params);
$r = sqlsrv_execute($stmt);
if ($stmt) {
$r = sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $insertSql, $params);
}
}
}
return $stmt;
}
/**
* Perform a simple select from a table with or without where condition(s)
* @param resource $conn : connection resource
* @param string $tbname : name of the table
* @param string $conds : string of condition(s) with placeholders, null by default
* @param array $values : array of parameters, null by default
* @return object sqlsrv statement upon success or false otherwise
*/
function selectFromTable($conn, $tbname, $conds = null, $values = null)
{
$sql = "SELECT * FROM $tbname";
return executeQuery($conn, $sql, $conds, $values);
}
/**
* Perform a query from a table with or without where condition(s)
* @param resource $conn : connection resource
* @param string $sql : T-SQL query
* @param string $conds : string of condition(s) with placeholders, null by default
* @param array $values : array of parameters, null by default
* @return object sqlsrv statement upon success or false otherwise
*/
function executeQuery($conn, $sql, $conds = null, $values = null)
{
// when AE is enabled, use sqlsrv_prepare() to handle fields with unlimited size
if (!isColEncrypted() && (is_null($conds) || empty($values))) {
$stmt = sqlsrv_query($conn, $sql);
} else {
if (is_string($conds) && is_array($values)) {
$sql = $sql . " WHERE $conds ";
$stmt = sqlsrv_prepare($conn, $sql, $values);
} else {
$stmt = sqlsrv_prepare($conn, $sql);
}
if ($stmt) {
$r = sqlsrv_execute($stmt);
if (!$r) {
fatalError("executeQuery: failed to execute \'$sql\'!", true);
}
}
}
if (!$stmt) {
fatalError("executeQuery: failed to run query \'$sql\'!", true);
}
return $stmt;
}
/**
* Similar to executeQuery() but with query options
* @return object sqlsrv statement upon success or false otherwise
*/
function executeQueryEx($conn, $sql, $options)
{
// when AE is enabled, use sqlsrv_prepare() to handle fields with unlimited size
if (!isColEncrypted()) {
$stmt = sqlsrv_query($conn, $sql, null, $options);
} else {
$stmt = sqlsrv_prepare($conn, $sql, null, $options);
if ($stmt) {
$r = sqlsrv_execute($stmt);
if (!$r) {
fatalError("executeQueryEx: failed to execute \'$sql\'!", true);
}
}
}
if (!$stmt) {
fatalError("executeQueryEx: failed to run query \'$sql\'!", true);
}
return $stmt;
}
/**
* Fetch all rows and all columns given a table name, and print them
* @param resource $conn : connection resource
* @param string $tbname : name of the table to fetch from
* @param string $tbname : name of the table to fetch from
*/
function fetchAll($conn, $tbname)
{
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query($conn, $sql);
$stmt = selectFromTable($conn, $tbname);
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
foreach ($row as $key => $value) {
if (is_object($value)) {
@ -410,6 +539,201 @@ function fetchAll($conn, $tbname)
}
}
/**
* Create a test table with columns of various types given a table name,
* all deterministic if AE is enabled
* @param resource $conn : connection resource
* @param string $tbname : name of the table to create
* @return object sqlsrv statement
*/
function createTestTable($conn, $tbname)
{
$columns = array(new ColumnMeta('int', 'c1_int'),
new ColumnMeta('tinyint', 'c2_tinyint'),
new ColumnMeta('smallint', 'c3_smallint'),
new ColumnMeta('bigint', 'c4_bigint'),
new ColumnMeta('bit', 'c5_bit'),
new ColumnMeta('float', 'c6_float'),
new ColumnMeta('real', 'c7_real'),
new ColumnMeta('decimal(28,4)', 'c8_decimal'),
new ColumnMeta('numeric(32,4)', 'c9_numeric'),
new ColumnMeta('money', 'c10_money', null, true, true),
new ColumnMeta('smallmoney', 'c11_smallmoney', null, true, true),
new ColumnMeta('char(512)', 'c12_char'),
new ColumnMeta('varchar(512)', 'c13_varchar'),
new ColumnMeta('varchar(max)', 'c14_varchar_max'),
new ColumnMeta('nchar(512)', 'c15_nchar'),
new ColumnMeta('nvarchar(512)', 'c16_nvarchar'),
new ColumnMeta('nvarchar(max)', 'c17_nvarchar_max'),
new ColumnMeta('text', 'c18_text'),
new ColumnMeta('ntext', 'c19_ntext'),
new ColumnMeta('binary(512)', 'c20_binary'),
new ColumnMeta('varbinary(512)', 'c21_varbinary'),
new ColumnMeta('varbinary(max)', 'c22_varbinary_max'),
new ColumnMeta('image', 'c23_image'),
new ColumnMeta('uniqueidentifier', 'c24_uniqueidentifier'),
new ColumnMeta('datetime', 'c25_datetime'),
new ColumnMeta('smalldatetime', 'c26_smalldatetime'),
new ColumnMeta('timestamp', 'c27_timestamp'),
new ColumnMeta('xml', 'c28_xml'),
);
return createTable($conn, $tbname, $columns);
}
/**
* Insert the specified number of rows with test data into the test table
* @param resource $conn : connection resource
* @param string $tbname : name of the table to create
* @param int $rowCount : number of test rows to be inserted
* @return number of rows inserted
*/
function insertTestRows($conn, $tbame, $rowCount)
{
$count = 0;
for ($i = 0; $i < $rowCount; $i++) {
if (insertTestRow($conn, $tbame, rand(1, 20))) {
$count++;
}
}
if ($count != $rowCount) {
die("$count rows inserted instead of $rowCount\n");
}
return ($count);
}
/**
* Insert a number of rows with test data into the test table given the indexes
* @param resource $conn : connection resource
* @param string $tbname : name of the table to create
* @param int $minIndex : index of the first row to be inserted
* @param int $maxIndex : index of the last row to be inserted
* @return number of rows inserted
*/
function insertTestRowsByRange($conn, $tbame, $minIndex, $maxIndex)
{
$count = 0;
$rowCount = $maxIndex - $minIndex + 1;
if ($rowCount > 0) {
for ($i = $minIndex; $i <= $maxIndex; $i++) {
if (insertTestRow($conn, $tbame, $i)) {
$count++;
}
}
}
if ($count != $rowCount) {
die("$count rows inserted instead of $rowCount\n");
}
return ($count);
}
/**
* Insert one or more specific rows of test data into the test table
* @param resource $conn : connection resource
* @param string $tbname : name of the table to create
* @param int $index : the index of a certain row of test data
* @return object sqlsrv statement upon success or false otherwise
*/
function insertTestRow($conn, $tbname, $index)
{
if ($index < 1 || $index > 20) {
echo("Invalid row index $index for test data!\n");
return false;
}
// get array of input values
$inputArray = getInsertArray($index);
if (empty($inputArray)) {
fatalError("getInsertSqlComplete: inputs for inserting a row cannot be empty");
}
$result = null;
if (isColEncrypted()) {
$stmt = insertRow($conn, $tbname, $inputArray, $result, INSERT_PREPARE_PARAMS);
} else {
// do not use the generic insertRow as the binary data needs some pre-processing
// before calling sqlsrv_query()
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
$col = 1;
foreach ($inputArray as $key => $value) {
$colStr .= $key . ", ";
if (is_array($value)) {
$value = $value[0];
// this might be an input to a decimal, a numeric or a binary field
if (isBinary($col)) {
$value = "0x" . $value; // annotate the input string as a hex string
}
}
if (is_null($value)) {
$valStr .= "null, ";
} elseif (is_string($value) && !isBinary($col)) {
$valStr .= "'" . $value . "', ";
} else {
$valStr .= $value . ", ";
}
$col++;
}
$colStr = rtrim($colStr, ", ") . ") ";
$valStr = rtrim($valStr, ", ") . ") ";
$insertSql = $colStr . $valStr;
$stmt = sqlsrv_query($conn, $insertSql);
}
if (!$stmt || $result === false) {
fatalError("insertTestRow: failed to insert row $index!\n", true);
}
return $stmt;
}
/**
* Get a row of data to be inserted into the test table
* @param int $index : the index of a certain row of test data
* @return an array of key-value pairs
*/
function getInsertArray($index)
{
if (! UseUTF8data()) {
require_once('MsData.inc');
} else {
require_once('MsData_UTF8.inc');
}
// get array of input values
return getTestData($index);
}
/**
* Get test data based on the row and column
* @param int $rowIndex : the row index
* @param int $colIndex : the column index
* @return data of mixed type or null if something went wrong
*/
function getInsertData($rowIndex, $colIndex)
{
// get array of input values
$inputArray = getInsertArray($rowIndex);
if (empty($inputArray)) {
fatalError("getInsertData: failed to retrieve data at row $rowIndex and column $colIndex.\n");
}
$count = 0;
foreach ($inputArray as $key => $value) {
if (++$count == $colIndex) {
if (is_array($value)) {
return $value[0];
} else {
return $value;
}
break;
}
}
return null;
}
} // end of namespace AlwaysEncrypted
namespace {
@ -449,7 +773,7 @@ function getSqlType($k)
return ("udt");
}
function getDriverType($k, $dataSize)
function getDriverType($k, $dataSize = 512)
{
switch ($k) {
case 1: return (SQLSRV_SQLTYPE_INT);
@ -497,7 +821,7 @@ function isXml($k)
function isStreamable($k)
{
switch ($k) {
case 12: return (true); // nchar(512)
case 12: return (true); // char(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
@ -666,7 +990,9 @@ function getColName($k)
case 26: return ("c26_smalldatetime");
case 27: return ("c27_timestamp");
case 28: return ("c28_xml");
default: break;
default:
fatalError("Invalid column index $k");
break;
}
return ("");
}

View file

@ -8,7 +8,7 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function Info()
function info()
{
ob_start();
phpinfo();
@ -21,7 +21,7 @@ function Info()
$testName = "Driver Loading";
startTest($testName);
preg_match('/sqlsrv support.*/', Info(), $matches);
preg_match('/sqlsrv support.*/', info(), $matches);
var_dump($matches);
endTest($testName);

View file

@ -6,12 +6,12 @@ Verifies as well that invalid connection attempts fail as expected.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ConnectionTest()
function connectionTest()
{
$testName = "Connection";
startTest($testName);
@ -37,21 +37,12 @@ function ConnectionTest()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
ConnectionTest();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
connectionTest();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Connection" completed successfully.

View file

@ -5,7 +5,7 @@ Verifies the functionality of "sqlsrv_client_info".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
@ -24,14 +24,7 @@ function clientInfo()
die("Unexpected size for client_info array: ".$count1);
}
$driverName = 'DriverDllName';
$uname = php_uname();
if (isWindows()) {
$driverName = 'DriverDllName';
} else { // other than Windows
$driverName = 'DriverName';
}
$driverName = isWindows() ? 'DriverDllName' : 'DriverName';
showInfo($clientinfo1, 'ExtensionVer');
showInfo($clientinfo1, $driverName);
@ -49,7 +42,6 @@ function showInfo($clientInfo, $infoTag)
trace("$infoTag\t= $info\n");
}
try {
clientInfo();
} catch (Exception $e) {

View file

@ -5,7 +5,7 @@ Verifies the functionality of "sqlsrv_server_info".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');

View file

@ -6,24 +6,22 @@ that resources are invalidated when connection is closed.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ConnectionClose()
function connectionClose()
{
$testName = "Connection - Close";
startTest($testName);
setup();
$noRows = 5;
$conn1 = connect();
$tableName = 'TC24test';
$conn1 = AE\connect();
$tableName = 'TC24test';
createTable($conn1, $tableName);
insertRows($conn1, $tableName, $noRows);
// Insert a couple of random rows
AE\createTestTable($conn1, $tableName);
AE\insertTestRows($conn1, $tableName, 2);
// Close connection twice
for ($i = 0; $i < 2; $i++) {
@ -40,43 +38,32 @@ function ConnectionClose()
}
// Invalid Statement
$conn2 = connect();
$stmt2 = selectFromTable($conn2, $tableName);
$conn2 = AE\connect();
$stmt2 = sqlsrv_query($conn2, "SELECT * FROM [$tableName]");
sqlsrv_close($conn2);
if (sqlsrv_fetch($stmt2)) {
die("Fetch should fail when connection is closed");
}
$conn3 = connect();
dropTable($conn3, $tableName);
sqlsrv_close($conn3);
$conn3 = AE\connect();
dropTable($conn3, $tableName);
sqlsrv_close($conn3);
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
ConnectionClose();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
connectionClose();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECTREGEX--
Warning: sqlsrv_close\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 20
Warning: sqlsrv_close\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 18
Warning: sqlsrv_query\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 27
Warning: sqlsrv_query\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 25
Warning: sqlsrv_fetch\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC24_Close.php on line 36
Warning: sqlsrv_fetch\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC24_Close.php on line 34
Test "Connection - Close" completed successfully.

View file

@ -9,13 +9,13 @@ Basic verification of query statements (via "sqlsrv_query"):
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function SimpleQuery()
function simpleQuery()
{
$testName = "Statement - Simple Query";
startTest($testName);
@ -23,14 +23,14 @@ function SimpleQuery()
setup();
$tableName = 'TC31test';
$conn1 = connect();
$conn1 = AE\connect();
createTable($conn1, $tableName);
// just create an empty table
$stmt1 = sqlsrv_query($conn1, "CREATE TABLE $tableName (dummyColumn int)");
trace("Executing SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM $tableName");
$rows = rowCount($stmt1);
;
sqlsrv_free_stmt($stmt1);
trace(" $rows rows retrieved.\n");
@ -45,22 +45,12 @@ function SimpleQuery()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
SimpleQuery();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
simpleQuery();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Statement - Simple Query" completed successfully.

View file

@ -6,30 +6,31 @@ validates the outcome reported by "sqlsrv_rows_affected".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function DeleteQuery()
function deleteQuery()
{
$testName = "Statement - Delete Query";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
$noRows = 10;
$tableName = 'TC32test';
createTable($conn1, $tableName);
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
AE\createTestTable($conn1, $tableName);
// Insert some random rows
$noRowsInserted = AE\insertTestRows($conn1, $tableName, $noRows);
$row = 1;
$keyValue = "0";
while ($row <= $noRowsInserted) {
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
if (sqlsrv_fetch($stmt1) === false) {
fatalError("Failed to retrieve 1st row of data from test table");
fatalError("Failed to retrieve 1st row of data from test table", true);
}
$keyValue = sqlsrv_get_field($stmt1, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
sqlsrv_free_stmt($stmt1);
@ -37,16 +38,17 @@ function DeleteQuery()
trace("Deleting rows from $tableName ...");
$delRows = 1;
if (strlen($keyValue) == 0) {
$stmt2 = executeQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
$stmt2 = AE\executeQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
$cond = "(top row)";
} else {
$cond = "(c1_int = $keyValue)";
$stmt3 = selectFromTableEx($conn1, $tableName, $cond);
$cond = "(c1_int = ?)";
$params = array($keyValue);
$stmt3 = AE\selectFromTable($conn1, $tableName, $cond, $params);
$delRows = rowCount($stmt3);
sqlsrv_free_stmt($stmt3);
$stmt2 = executeQuery($conn1, "DELETE FROM [$tableName] WHERE $cond");
$stmt2 = AE\executeQuery($conn1, "DELETE FROM [$tableName]", $cond, $params );
}
$numRows1 = sqlsrv_rows_affected($stmt2);
sqlsrv_free_stmt($stmt2);
@ -58,7 +60,7 @@ function DeleteQuery()
$row += $numRows1;
}
$stmt3 = executeQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
$stmt3 = AE\executeQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
$numRows2 = sqlsrv_rows_affected($stmt3);
sqlsrv_free_stmt($stmt3);
@ -73,21 +75,12 @@ function DeleteQuery()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
DeleteQuery();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
deleteQuery();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Statement - Delete Query" completed successfully.

View file

@ -5,85 +5,129 @@ Verifies the behavior of INSERT queries with and without the IDENTITY flag set.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ComplexQuery()
function complexQuery()
{
$testName = "Statement - Complex Query";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
$tableName = 'TC33test';
$dataTypes = "[c1_int] int IDENTITY, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_varchar] varchar(512)";
createTableEx($conn1, $tableName, $dataTypes);
$columns = array(new AE\ColumnMeta('int', 'c1_int', "IDENTITY"),
new AE\ColumnMeta('tinyint', 'c2_tinyint'),
new AE\ColumnMeta('smallint', 'c3_smallint'),
new AE\ColumnMeta('bigint', 'c4_bigint'),
new AE\ColumnMeta('varchar(512)', 'c5_varchar'));
AE\createTable($conn1, $tableName, $columns);
Execute($conn1, true, "SET IDENTITY_INSERT [$tableName] ON;");
Execute($conn1, true, "INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (-204401468, 168, 4787, 1583186637, 'î<ÄäC~zããa.Oa._ߣ*©<u_ßßCÃoa äãäÐßa+OühäobUa:zB_CÖ@~UÄz+ÃîÐ//Z@üo_:r,o¢ÃrßzoZß*ߪªå~ U¢a>£ÃZUÄ/ä_ZãðäåhüCã+/.obî|ößß,ð¢ðð:ÄÐ:*/>+/¢aö.öÄ<ð:>äO~*~ßÄzå¢<ª£ðý.O,>Ü,åbü@böhýC*<<hbÖä*o©¢h¢Ðüa+A/_@b/ÃBýBªß@ã~zÖZýC@äU_ßUßhvU*a@ÃðÄ:ªZAßAb£U_¢ßbãä:üåãorýÃߪ_ãÐÖªzãðåãoaü <ß~zZªaB.+åA¢ãÖ><î:/Ur î¢UßåOaÄ:a|++ª©.r~:/+ä|©ýo++v_@BZ:©©AßCð.©/Ab<,îß>UãÜÜöbb|ßÐߣ:î<<bîöa+,<_aÄ._ª>Ü<|ÖzÃz@>¢ª:a,CÜr__ª.<öÜCã+UÖU¢_üzü bÃ~ßo|, .î,b/U>äýaBZ@Ü£: bÖvýb>Ã/ÜÃ@üÖ/äb¢+r:Zß>ÐÜ|üu©ßZAC:Cßh *.ã£_ýîu|Urå.:aAUv@u>@<Öü.<ãZ böZAÜÖ£oüÐä*,ü:ðä')");
Execute($conn1, true, "SET IDENTITY_INSERT [$tableName] OFF;");
Execute($conn1, false,"INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1264768176, 111, 23449, 1421472052, 'uå©C@bðUOv~,©v,BZÜ*oh>zb_åÐä<@*OOå_Ö<ãuß/oßr <ðãbÜUßÜÃÖÄ~¢~£ bÜ©î.uÜТª:|_ÐüÄBÐbüåßÃv@,<CßOäv~:+,CZîvhC/oßUuößa<å>©/Ub,+AЩî:ÖrýB+~~ßßßãÜ+_<vO@ ßÃüÖîaCzÐîå@:rý.~vh~r.ÃbÃã©å_îCär BÖÜ:BbUväåöZ+|,CîaAöC,aîbb*UÜßßA hCu¢hOb ð|ßC.<C<.aBßvuÃÖå,AÐa>ABðöU/O<ÖãüªOãuߣ~uÖ+ßÄrbî/:ÖÖo /_ÃO:uÃzðUvã£Aã_BÐ/>UCr,Äå aÄÐaãvÖZ@ªr*_::~/+.å~ð©aÄßbz*z<~rU~O+Z|A<_Büß©¢ö ::.Übýüßr/örh¢:ääU äOA~Aîr<¢äv¢Ä+hC/vßoUª+Oãªã*ð¢Bö.Zbh/ä,åä>*öðßUßý>aªbBbvßãÖ/bã|ýÖ u.zý©~äðzÐU.UA*a*.¢>î rß ~Cüßaö+rª~ß@aã/ÐCß*a,ªÄbb<o+v.åu<£B<îBZßåu£/_>*~')");
Execute($conn1, true, "SET IDENTITY_INSERT [$tableName] ON;INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (-411114769, 198, 1378, 140345831, 'Ü@ßaörêA*ÐüßA>_hOüv@|h~O<¢+*ÃÐCbazÜaåZ/Öö:ýãuöÐaz£ÐAh+u+rß:| U*¢ªåßÄÐ_vî@@~ChÐö_å*AAýBö¢B,ßbßå.ÃB+u*CAvÜ,ã>ªßCU<åî©ürz¢@ör¢*Öub¢BåaÜ@ª.äBv¢o~ ßýo oîu/>ÜÐÄ,ð,ðaOÖå>ðC:öZ>ßåð©<ð¢+£r.bO.©,uAßr><ov:,ÄßîåÃ+å./||CUÜÜ_ÖĪh~<ã_å/hbý Ä©uBuß<Ö@boÖýBãCÜA/öÄ:© ßUü*ývuß.Bãååo_übýr_üß>ÐÃÜ£B¢AªvaîvýßCÜUß åvöuª><îÐUC*aÖU©rªhr+>|äýî|oðröУ<ª<Ö|AªohäAî_vu~:~£Ãhü+ÃBuÄð ü@Z+Ä@hÖî¢|@bU£_ü/£ |:¢zb>@Uß© Ãão Ö@ãÐBã_öBOBÄÐhCÜb~Ö>îü rýåüUzuãrbzß/ªîUÐð©uå.ß@£__vBb©/Ür¢Öuåz£ä*å£/*ÃO');SET IDENTITY_INSERT [$tableName] OFF;");
// SET IDENTITY_INSERT ON/OFF only works at execute or run time and not at parse time
// because a prepared statement runs in a separate context
// https://technet.microsoft.com/en-us/library/ms188059(v=sql.110).aspx
$query = "SET IDENTITY_INSERT [$tableName] ON;";
$stmt = sqlsrv_query($conn1, $query);
if (!$stmt) {
die("Unexpected execution outcome for \'$query\'.");
}
// expect this to pass
$inputs = array("c1_int" => -204401468, "c2_tinyint" => 168, "c3_smallint" => 4787, "c4_bigint" =>1583186637, "c5_varchar" => "î<ÄäC~zããa.Oa._ߣ*©<u_ßßCÃoa äãäÐßa+OühäobUa:zB_CÖ@~UÄz+ÃîÐ//Z@üo_:r,o¢ÃrßzoZß*ߪªå~ U¢a>£ÃZUÄ/ä_ZãðäåhüCã+/.obî|ößß,ð¢ðð:ÄÐ:*/>+/¢aö.öÄ<ð:>äO~*~ßÄzå¢<ª£ðý.O,>Ü,åbü@böhýC*<<hbÖä*o©¢h¢Ðüa+A/_@b/ÃBýBªß@ã~zÖZýC@äU_ßUßhvU*a@ÃðÄ:ªZAßAb£U_¢ßbãä:üåãorýÃߪ_ãÐÖªzãðåãoaü <ß~zZªaB.+åA¢ãÖ><î:/Ur î¢UßåOaÄ:a|++ª©.r~:/+ä|©ýo++v_@BZ:©©AßCð.©/Ab<,îß>UãÜÜöbb|ßÐߣ:î<<bîöa+,<_aÄ._ª>Ü<|ÖzÃz@>¢ª:a,CÜr__ª.<öÜCã+UÖU¢_üzü bÃ~ßo|, .î,b/U>äýaBZ@Ü£: bÖvýb>Ã/ÜÃ@üÖ/äb¢+r:Zß>ÐÜ|üu©ßZAC:Cßh *.ã£_ýîu|Urå.:aAUv@u>@<Öü.<ãZ böZAÜÖ£oüÐä*,ü:ðä");
$stmt = insertTest($conn1, $tableName, true, $inputs);
$query = "SET IDENTITY_INSERT [$tableName] OFF;";
$stmt = sqlsrv_query($conn1, $query);
if (!$stmt) {
die("Unexpected execution outcome for \'$query\'.");
}
// expect this to fail
$inputs = array("c1_int" => 1264768176, "c2_tinyint" => 111, "c3_smallint" => 23449, "c4_bigint" =>1421472052, "c5_varchar" => "uå©C@bðUOv~,©v,BZÜ*oh>zb_åÐä<@*OOå_Ö<ãuß/oßr <ðãbÜUßÜÃÖÄ~¢~£ bÜ©î.uÜТª:|_ÐüÄBÐbüåßÃv@,<CßOäv~:+,CZîvhC/oßUuößa<å>©/Ub,+AЩî:ÖrýB+~~ßßßãÜ+_<vO@ ßÃüÖîaCzÐîå@:rý.~vh~r.ÃbÃã©å_îCär BÖÜ:BbUväåöZ+|,CîaAöC,aîbb*UÜßßA hCu¢hOb ð|ßC.<C<.aBßvuÃÖå,AÐa>ABðöU/O<ÖãüªOãuߣ~uÖ+ßÄrbî/:ÖÖo /_ÃO:uÃzðUvã£Aã_BÐ/>UCr,Äå aÄÐaãvÖZ@ªr*_::~/+.å~ð©aÄßbz*z<~rU~O+Z|A<_Büß©¢ö ::.Übýüßr/örh¢:ääU äOA~Aîr<¢äv¢Ä+hC/vßoUª+Oãªã*ð¢Bö.Zbh/ä,åä>*öðßUßý>aªbBbvßãÖ/bã|ýÖ u.zý©~äðzÐU.UA*a*.¢>î rß ~Cüßaö+rª~ß@aã/ÐCß*a,ªÄbb<o+v.åu<£B<îBZßåu£/_>*~");
$stmt = insertTest($conn1, $tableName, false, $inputs);
// expect this to pass
$query = "SET IDENTITY_INSERT [$tableName] ON; SQL; SET IDENTITY_INSERT [$tableName] OFF;";
if (AE\isColEncrypted()){
// When AE is enabled, SQL types must be specified for sqlsrv_query
$inputs = array("c1_int" => array(-411114769, null, null, SQLSRV_SQLTYPE_INT),
"c2_tinyint" => array(198, null, null, SQLSRV_SQLTYPE_TINYINT),
"c3_smallint" => array(1378, null, null, SQLSRV_SQLTYPE_SMALLINT),
"c4_bigint" => array(140345831, null, null, SQLSRV_SQLTYPE_BIGINT),
"c5_varchar" => array("Ü@ßaörêA*ÐüßA>_hOüv@|h~O<¢+*ÃÐCbazÜaåZ/Öö:ýãuöÐaz£ÐAh+u+rß:| U*¢ªåßÄÐ_vî@@~ChÐö_å*AAýBö¢B,ßbßå.ÃB+u*CAvÜ,ã>ªßCU<åî©ürz¢@ör¢*Öub¢BåaÜ@ª.äBv¢o~ ßýo oîu/>ÜÐÄ,ð,ðaOÖå>ðC:öZ>ßåð©<ð¢+£r.bO.©,uAßr><ov:,ÄßîåÃ+å./||CUÜÜ_ÖĪh~<ã_å/hbý Ä©uBuß<Ö@boÖýBãCÜA/öÄ:© ßUü*ývuß.Bãååo_übýr_üß>ÐÃÜ£B¢AªvaîvýßCÜUß åvöuª><îÐUC*aÖU©rªhr+>|äýî|oðröУ<ª<Ö|AªohäAî_vu~:~£Ãhü+ÃBuÄð ü@Z+Ä@hÖî¢|@bU£_ü/£ |:¢zb>@Uß© Ãão Ö@ãÐBã_öBOBÄÐhCÜb~Ö>îü rýåüUzuãrbzß/ªîUÐð©uå.ß@£__vBb©/Ür¢Öuåz£ä*å£/*ÃO", null, null, SQLSRV_SQLTYPE_VARCHAR(512)));
$stmt = insertTest($conn1, $tableName, true, $inputs, $query);
} else {
$inputs = array("c1_int" => -411114769, "c2_tinyint" => 198, "c3_smallint" => 1378, "c4_bigint" => 140345831, "c5_varchar" => "Ü@ßaörêA*ÐüßA>_hOüv@|h~O<¢+*ÃÐCbazÜaåZ/Öö:ýãuöÐaz£ÐAh+u+rß:| U*¢ªåßÄÐ_vî@@~ChÐö_å*AAýBö¢B,ßbßå.ÃB+u*CAvÜ,ã>ªßCU<åî©ürz¢@ör¢*Öub¢BåaÜ@ª.äBv¢o~ ßýo oîu/>ÜÐÄ,ð,ðaOÖå>ðC:öZ>ßåð©<ð¢+£r.bO.©,uAßr><ov:,ÄßîåÃ+å./||CUÜÜ_ÖĪh~<ã_å/hbý Ä©uBuß<Ö@boÖýBãCÜA/öÄ:© ßUü*ývuß.Bãååo_übýr_üß>ÐÃÜ£B¢AªvaîvýßCÜUß åvöuª><îÐUC*aÖU©rªhr+>|äýî|oðröУ<ª<Ö|AªohäAî_vu~:~£Ãhü+ÃBuÄð ü@Z+Ä@hÖî¢|@bU£_ü/£ |:¢zb>@Uß© Ãão Ö@ãÐBã_öBOBÄÐhCÜb~Ö>îü rýåüUzuãrbzß/ªîUÐð©uå.ß@£__vBb©/Ür¢Öuåz£ä*å£/*ÃO");
$stmt = insertTest($conn1, $tableName, true, $inputs, $query);
}
$stmt1 = selectFromTable($conn1, $tableName);
$rowCount = rowCount($stmt1);
sqlsrv_free_stmt($stmt1);
if ($rowCount != 2)
{
if ($rowCount != 2) {
die("Table $tableName has $rowCount rows instead of 2.");
}
dropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
endTest($testName);
}
function Execute($conn, $expectedOutcome, $query)
function insertTest($conn, $tableName, $expectedOutcome, $inputs, $query = null)
{
trace("Executing query ".ltrim(substr($query, 0, 40))." ... ");
$stmt = ExecuteQueryEx($conn, $query, true);
if ($stmt === false)
{
trace("failed.\n");
$actualOutcome = false;
$stmt = null;
if (!AE\isColEncrypted()) {
$insertSql = AE\getInsertSqlComplete($tableName, $inputs);
if (! is_null($query)) {
$sql = str_replace("SQL", $insertSql, $query);
} else {
$sql = $insertSql;
}
$stmt = sqlsrv_query($conn, $sql);
$actualOutcome = ($stmt !== false);
} else {
// must bind parameters
$insertSql = AE\getInsertSqlPlaceholders($tableName, $inputs);
$params = array();
foreach ($inputs as $key => $input) {
array_push($params, $inputs[$key]);
}
if (! is_null($query)) {
// this contains a batch of sql statements,
// with set identity_insert on or off
// thus, sqlsrv_query should be called
$sql = str_replace("SQL", $insertSql, $query);
$stmt = sqlsrv_query($conn, $sql, $params);
$actualOutcome = ($stmt !== false);
} else {
// just a regular insert, so use sqlsrv_prepare
$sql = $insertSql;
$actualOutcome = true;
$stmt = sqlsrv_prepare($conn, $sql, $params);
if ($stmt) {
$result = sqlsrv_execute($stmt);
$actualOutcome = ($result !== false);
}
}
}
else
{
trace("succeeded.\n");
sqlsrv_free_stmt($stmt);
$actualOutcome = true;
}
if ($actualOutcome != $expectedOutcome)
{
die("Unexpected query execution outcome.");
if ($actualOutcome != $expectedOutcome) {
die("Unexpected execution outcome for \'$sql\'.");
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try
{
ComplexQuery();
}
catch (Exception $e)
{
echo $e->getMessage();
}
try {
complexQuery();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Statement - Complex Query" completed successfully.

View file

@ -6,7 +6,7 @@ Validates that a prepared statement can be successfully executed more than once.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
@ -17,19 +17,18 @@ function prepareAndExecute($noPasses)
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
$tableName = 'TC34test';
createTable($conn1, $tableName);
insertRows($conn1, $tableName, 1);
AE\createTestTable($conn1, $tableName);
AE\insertTestRows($conn1, $tableName, 1);
$values = array();
$fieldlVal = "";
// Prepare reference values
trace("Execute a direct SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
$numFields1 = sqlsrv_num_fields($stmt1);
sqlsrv_fetch($stmt1);
for ($i = 0; $i < $numFields1; $i++) {
@ -39,7 +38,7 @@ function prepareAndExecute($noPasses)
$fieldVal = sqlsrv_get_field($stmt1, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
if ($fieldVal === false) {
fatalError("Failed to retrieve field $i");
fatalError("Failed to retrieve field $i", true);
}
$values[$i] = $fieldVal;
}

View file

@ -5,7 +5,7 @@ Verifies that "sqlsrv_cancel" discards any pending data in current result set
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
@ -16,14 +16,14 @@ function cancel()
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
$tableName = 'TC35test';
createTable($conn1, $tableName);
insertRows($conn1, $tableName, 5);
AE\createTestTable($conn1, $tableName);
AE\insertTestRows($conn1, $tableName, 5);
trace("Executing SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
if (sqlsrv_fetch($stmt1) === false) {
fatalError("Failed to retrieve data from test table");
}

View file

@ -12,19 +12,19 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function Close()
function close()
{
$testName = "Statement - Close";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
$tableName = 'TC36test';
createTable($conn1, $tableName);
AE\createTestTable($conn1, $tableName);
trace("Executing SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
trace(" successfull.\n");
sqlsrv_free_stmt($stmt1);
@ -48,21 +48,12 @@ function Close()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
Close();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
close();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECTREGEX--

View file

@ -20,9 +20,9 @@ function queryTimeout()
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
$tableName = 'TC37test';
createTable($conn1, $tableName);
AE\createTestTable($conn1, $tableName);
trace("Executing batch queries requiring 3 seconds with 1 second timeout.\n");
$query = "WAITFOR DELAY '00:00:03'; SELECT * FROM [$tableName]";

View file

@ -16,7 +16,7 @@ function invalidQuery()
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
// Invalid Query
$stmt1 = sqlsrv_query($conn1, "INVALID QUERY");
@ -24,15 +24,15 @@ function invalidQuery()
die("Invalid query should have failed.");
}
$dataType = "[c1] int, [c2] int";
$tableName = 'TC38test';
createTableEx($conn1, $tableName, $dataType);
$columns = array(new AE\ColumnMeta('int', 'c1'),
new AE\ColumnMeta('int', 'c2'));
// Invalid PHPTYPE parameter
$stmt2 = sqlsrv_query(
$conn1,
"INSERT INTO [$tableName] (c1, c2) VALUES (?, ?)",
array(1, array(2, SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN'))
array(1, array(2, SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN'))
);
if ($stmt2) {
die("Insert query with invalid parameter should have failed.");
@ -41,9 +41,7 @@ function invalidQuery()
// Invalid option
$stmt3 = sqlsrv_query(
$conn1,
"INSERT INTO [$tableName] (c1, c2) VALUES (?, ?)",
array(1, 2),
array('doSomething' => 1)
"INSERT INTO [$tableName] (c1, c2) VALUES (?, ?)", array(1, 2), array('doSomething' => 1)
);
if ($stmt3) {
die("Insert query with invalid option should have failed.");
@ -55,7 +53,6 @@ function invalidQuery()
if ($stmt4) {
die("Select query should have failed.");
}
sqlsrv_close($conn1);
endTest($testName);

View file

@ -10,16 +10,16 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function CursorTest($noRows1, $noRows2)
function cursorTest($noRows1, $noRows2)
{
include 'MsSetup.inc';
$testName = "Statement - Cursor Mode";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
$tableName = 'TC39test';
$cursor = "";
for ($k = 0; $k < 4; $k++) {
switch ($k) {
@ -27,9 +27,9 @@ function CursorTest($noRows1, $noRows2)
case 1: $cursor = SQLSRV_CURSOR_STATIC; break;
case 2: $cursor = SQLSRV_CURSOR_DYNAMIC; break;
case 3: $cursor = SQLSRV_CURSOR_KEYSET; break;
default: break;
default: break;
}
ScrollableFetch($conn1, $tableName, $noRows1, $noRows2, $cursor);
scrollableFetch($conn1, $tableName, $noRows1, $noRows2, $cursor);
}
sqlsrv_close($conn1);
@ -37,25 +37,26 @@ function CursorTest($noRows1, $noRows2)
endTest($testName);
}
function ScrollableFetch($conn, $tableName, $noRows1, $noRows2, $cursor)
function scrollableFetch($conn, $tableName, $noRows1, $noRows2, $cursor)
{
$colIndex = "c27_timestamp";
$tableIndex = "TC39index";
createTable($conn, $tableName);
createUniqueIndex($conn, $tableName, $colIndex);
AE\createTestTable($conn, $tableName);
createUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex);
$stmt1 = selectFromTable($conn, $tableName);
$stmt1 = AE\selectFromTable($conn, $tableName);
if (sqlsrv_has_rows($stmt1)) {
die("Table $tableName is expected to be empty...");
}
sqlsrv_free_stmt($stmt1);
$noRows = insertRows($conn, $tableName, $noRows1);
$noRows = AE\insertTestRows($conn, $tableName, $noRows1);
$query = "SELECT * FROM [$tableName] ORDER BY $colIndex";
$options = array('Scrollable' => $cursor);
$stmt2 = selectQueryEx($conn, $query, $options);
$stmt2 = sqlsrv_query($conn, $query, null, $options);
if (!sqlsrv_has_rows($stmt2)) {
die("Table $tableName is not expected to be empty...");
}
@ -71,7 +72,7 @@ function ScrollableFetch($conn, $tableName, $noRows1, $noRows2, $cursor)
$noRows--;
}
if ($noRows2 > 0) {
$extraRows = insertRows($conn, $tableName, $noRows2);
$extraRows = AE\insertTestRows($conn, $tableName, $noRows2);
if ($cursor == SQLSRV_CURSOR_DYNAMIC) {
$noRows += $extraRows;
}
@ -88,22 +89,12 @@ function ScrollableFetch($conn, $tableName, $noRows1, $noRows2, $cursor)
dropTable($conn, $tableName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
CursorTest(10, 5);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
cursorTest(10, 5);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Statement - Cursor Mode" completed successfully.

View file

@ -14,21 +14,19 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function FetchMetadata()
function fetchMetadata()
{
include 'MsSetup.inc';
$testName = "Fetch - Metadata";
startTest($testName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$tableName = 'TC41test';
$conn1 = AE\connect();
AE\createTestTable($conn1, $tableName);
AE\insertTestRows($conn1, $tableName, 1);
insertRow($conn1, $tableName);
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
$numFields = sqlsrv_num_fields($stmt1);
trace("Expecting $numFields fields...\n");
@ -40,11 +38,11 @@ function FetchMetadata()
}
for ($k = 0; $k < $count; $k++) {
trace(" ".($k + 1)."\t");
ShowMetadata($metadata, $k, 'Name');
ShowMetadata($metadata, $k, 'Size');
ShowMetadata($metadata, $k, 'Precision');
ShowMetadata($metadata, $k, 'Scale');
ShowMetadata($metadata, $k, 'Nullable');
showMetadata($metadata, $k, 'Name');
showMetadata($metadata, $k, 'Size');
showMetadata($metadata, $k, 'Precision');
showMetadata($metadata, $k, 'Scale');
showMetadata($metadata, $k, 'Nullable');
trace("\n");
}
@ -57,31 +55,22 @@ function FetchMetadata()
endTest($testName);
}
function ShowMetadata($mdArray, $field, $info)
function showMetadata($mdArray, $field, $info)
{
$mdInfo = $mdArray[$field][$info];
$refInfo = GetMetadata($field + 1, $info);
$refInfo = getMetadata($field + 1, $info);
trace("[$info=$mdInfo]");
if ($mdInfo != $refInfo) {
die("Unexpected metadata value for $info in field ".($field + 1).": $mdInfo instead of $refInfo");
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
FetchMetadata();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
fetchMetadata();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Fetch - Metadata" completed successfully.

View file

@ -11,38 +11,38 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function FetchFields()
function fetchFields()
{
include 'MsSetup.inc';
$testName = "Fetch - Field";
startTest($testName);
setup();
$tableName = 'TC42test';
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn1 = AE\connect(array('CharacterSet'=>'UTF-8'));
} else {
$conn1 = connect();
$conn1 = AE\connect();
}
createTable($conn1, $tableName);
AE\createTestTable($conn1, $tableName);
$noRows = 10;
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
$noRowsInserted = AE\insertTestRows($conn1, $tableName, $noRows);
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
$numFields = sqlsrv_num_fields($stmt1);
trace("Retrieving $noRowsInserted rows with $numFields fields each ...");
for ($i = 0; $i < $noRowsInserted; $i++) {
$row = sqlsrv_fetch($stmt1);
if ($row === false) {
fatalError("Row $i is missing");
fatalError("Row $i is missing", true);
}
for ($j = 0; $j < $numFields; $j++) {
$fld = sqlsrv_get_field($stmt1, $j);
if ($fld === false) {
fatalError("Field $j of Row $i is missing\n");
fatalError("Field $j of Row $i is missing\n", true);
}
}
}
@ -56,21 +56,12 @@ function FetchFields()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
FetchFields();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
fetchFields();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Fetch - Field" completed successfully.

View file

@ -9,23 +9,23 @@ PHPT_EXEC=true
require_once('MsCommon.inc');
function FetchFields()
function fetchFields()
{
include 'MsSetup.inc';
$testName = "Fetch - Field Data";
startTest($testName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$tableName = 'TC43test';
$conn1 = AE\connect();
AE\createTestTable($conn1, $tableName);
$startRow = 1;
$noRows = 20;
insertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
AE\insertTestRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
$query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp";
$stmt1 = selectQuery($conn1, $query);
$stmt1 = AE\executeQuery($conn1, $query);
$numFields = sqlsrv_num_fields($stmt1);
trace("Retrieving $noRows rows with $numFields fields each ...");
@ -34,7 +34,6 @@ function FetchFields()
if ($row === false) {
fatalError("Row $i is missing");
}
$skipCount = 0;
for ($j = 0; $j < $numFields; $j++) {
if (useUTF8Data()) {
$fld = sqlsrv_get_field($stmt1, $j, SQLSRV_PHPTYPE_STRING('UTF-8'));
@ -45,11 +44,13 @@ function FetchFields()
fatalError("Field $j of Row $i is missing");
}
$col = $j + 1;
if (!IsUpdatable($col)) {
$skipCount++;
} else { // should check data even if $fld is null
$data = getInsertData($startRow + $i, $col, $skipCount);
if (!CheckData($col, $fld, $data)) {
$data = AE\getInsertData($startRow + $i, $col);
if (isUpdatable($col)) {
// should check data even if $fld is null
$data = AE\getInsertData($startRow + $i, $col);
if (!checkData($col, $fld, $data)) {
echo("\nData error\nExpected:\n$data\nActual:\n$fld\n");
setUTF8Data(false);
die("Data corruption on row ".($startRow + $i)." column $col");
}
@ -66,19 +67,18 @@ function FetchFields()
endTest($testName);
}
function CheckData($col, $actual, $expected)
function checkData($col, $actual, $expected)
{
$success = true;
if (IsNumeric($col)) {
if (isNumeric($col)) {
if (floatval($actual) != floatval($expected)) {
$success = false;
}
} else {
$actual = trim($actual);
// Do not trim data because the data itself can be some space characters
$len = strlen($expected);
if (IsDateTime($col)) {
if (isDateTime($col)) {
$len = min(strlen("YYYY-MM-DD HH:mm:ss"), $len);
}
if (strncasecmp($actual, $expected, $len) != 0) {
@ -92,25 +92,15 @@ function CheckData($col, $actual, $expected)
return ($success);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
if (! isWindows()) {
setUTF8Data(true);
}
try {
FetchFields();
} catch (Exception $e) {
echo $e->getMessage();
}
setUTF8Data(false);
if (! isWindows()) {
setUTF8Data(true);
}
repro();
try {
fetchFields();
} catch (Exception $e) {
echo $e->getMessage();
}
setUTF8Data(false);
?>
--EXPECT--

View file

@ -16,27 +16,28 @@ function fetchRow($minFetchMode, $maxFetchMode)
$testName = "Fetch - Array";
startTest($testName);
if (!IsMarsSupported()) {
if (!isMarsSupported()) {
endTest($testName);
return;
}
setup();
$tableName = 'TC44test';
if (!isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn1 = AE\connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
$conn1 = AE\connect();
}
$tableName = 'TC44Test';
createTable($conn1, $tableName);
AE\createTestTable($conn1, $tableName);
$noRows = 10;
$numFields = 0;
insertRows($conn1, $tableName, $noRows);
AE\insertTestRows($conn1, $tableName, $noRows);
for ($k = $minFetchMode; $k <= $maxFetchMode; $k++) {
$stmt1 = selectFromTable($conn1, $tableName);
$stmt2 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
$stmt2 = AE\selectFromTable($conn1, $tableName);
if ($numFields == 0) {
$numFields = sqlsrv_num_fields($stmt1);
} else {
@ -122,23 +123,23 @@ function checkData($row, $stmt, $index, $mode)
$success = true;
$col = $index + 1;
$actual = (($mode == SQLSRV_FETCH_ASSOC) ? $row[GetColName($col)] : $row[$index]);
$actual = (($mode == SQLSRV_FETCH_ASSOC) ? $row[getColName($col)] : $row[$index]);
$expected = null;
if (!IsUpdatable($col)) {
if (!isUpdatable($col)) {
// do not check the timestamp
} elseif (IsNumeric($col) || IsDateTime($col)) {
} elseif (isNumeric($col) || isDateTime($col)) {
$expected = sqlsrv_get_field($stmt, $index);
if ($expected != $actual) {
$success = false;
}
} elseif (IsBinary($col)) {
} elseif (isBinary($col)) {
$expected = sqlsrv_get_field($stmt, $index, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
$actual = bin2hex($actual);
if (strcasecmp($actual, $expected) != 0) {
$success = false;
}
} else { // if (IsChar($col))
} else { // if (isChar($col))
if (useUTF8Data()) {
$expected = sqlsrv_get_field($stmt, $index, SQLSRV_PHPTYPE_STRING('UTF-8'));
} else {

View file

@ -19,27 +19,27 @@ class TestClass
function fetchRow($minFetchMode, $maxFetchMode)
{
include 'MsSetup.inc';
$testName = "Fetch - Object";
startTest($testName);
setup();
$tableName = 'TC45test';
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn1 = AE\connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
$conn1 = AE\connect();
}
createTable($conn1, $tableName);
AE\createTestTable($conn1, $tableName);
$noRows = 10;
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
$noRowsInserted = AE\insertTestRows($conn1, $tableName, $noRows);
$actual = null;
$expected = null;
$numFields = 0;
for ($k = $minFetchMode; $k <= $maxFetchMode; $k++) {
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
if ($numFields == 0) {
$numFields = sqlsrv_num_fields($stmt1);
} else {

View file

@ -12,8 +12,6 @@ require_once('MsCommon.inc');
function fetchFields()
{
include 'MsSetup.inc';
$testName = "Fetch - Next Result";
startTest($testName);
@ -23,14 +21,15 @@ function fetchFields()
}
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$tableName = 'TC46test';
$conn1 = AE\connect();
AE\createTestTable($conn1, $tableName);
$noRows = 10;
insertRows($conn1, $tableName, $noRows);
AE\insertTestRows($conn1, $tableName, $noRows);
$stmt1 = selectQuery($conn1, "SELECT * FROM [$tableName]");
$stmt2 = selectQuery($conn1, "SELECT * FROM [$tableName]; SELECT * FROM [$tableName]");
$stmt1 = AE\executeQuery($conn1, "SELECT * FROM [$tableName]");
$stmt2 = AE\executeQuery($conn1, "SELECT * FROM [$tableName]; SELECT * FROM [$tableName]");
if (sqlsrv_next_result($stmt2) === false) {
fatalError("Failed to retrieve next result set");
}
@ -66,10 +65,10 @@ function fetchFields()
}
}
}
if (sqlsrv_next_result($stmt1) ||
sqlsrv_next_result($stmt2)) {
if ($r1 = sqlsrv_next_result($stmt1) ||
$r2 = sqlsrv_next_result($stmt2)) {
setUTF8Data(false);
die("No more results were expected");
fatalError("No more results were expected", true);
}
sqlsrv_free_stmt($stmt1);
sqlsrv_free_stmt($stmt2);

View file

@ -11,27 +11,34 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function ParamQuery($minType, $maxType)
function paramQuery($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Parameterized Query";
startTest($testName);
setup();
$conn1 = connect();
$tableName = 'TC47test';
$conn1 = AE\connect();
for ($k = $minType; $k <= $maxType; $k++) {
$data = GetSampleData($k);
$data = getSampleData($k);
if ($data != null) {
$sqlType = GetSqlType($k);
$phpDriverType = GetDriverType($k, strlen($data));
$dataType = "[c1] int, [c2] $sqlType";
$dataOptions = array($k, array($data, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $phpDriverType));
$sqlType = getSqlType($k);
$phpDriverType = getDriverType($k, strlen($data));
$columns = array(new AE\ColumnMeta('int', 'c1'),
new AE\ColumnMeta($sqlType, 'c2'));
traceData($sqlType, $data);
TraceData($sqlType, $data);
CreateQueryTable($conn1, $tableName, $dataType, "c1, c2", "?, ?", $dataOptions);
CheckData($conn1, $tableName, 2, $data);
$res = null;
AE\createTable($conn1, $tableName, $columns);
AE\insertRow($conn1,
$tableName,
array("c1"=>$k, "c2"=>array($data, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $phpDriverType)),
$res,
AE\INSERT_QUERY_PARAMS
);
checkData($conn1, $tableName, 2, $data);
dropTable($conn1, $tableName);
}
}
@ -41,16 +48,9 @@ function ParamQuery($minType, $maxType)
endTest($testName);
}
function CreateQueryTable($conn, $table, $dataType, $dataCols, $dataValues, $dataOptions)
function checkData($conn, $tableName, $cols, $expectedValue)
{
createTableEx($conn, $table, $dataType);
insertRowEx($conn, $table, $dataCols, $dataValues, $dataOptions);
}
function CheckData($conn, $table, $cols, $expectedValue)
{
$stmt = selectFromTable($conn, $table);
$stmt = AE\selectFromTable($conn, $tableName);
if (!sqlsrv_fetch($stmt)) {
die("Table $tableName was not expected to be empty.");
}
@ -65,21 +65,12 @@ function CheckData($conn, $table, $cols, $expectedValue)
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
ParamQuery(1, 28);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
paramQuery(1, 28);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Parameterized Query" completed successfully.

View file

@ -10,62 +10,65 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function FetchRow($noRows)
function fetchRow($noRows)
{
include 'MsSetup.inc';
$testName = "Fetch - Scrollable";
startTest($testName);
setup();
$tableName = 'TC48test';
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn1 = AE\connect(array('CharacterSet'=>'UTF-8'));
} else {
$conn1 = connect();
$conn1 = AE\connect();
}
createTable($conn1, $tableName);
AE\createTestTable($conn1, $tableName);
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
$noRowsInserted = AE\insertTestRows($conn1, $tableName, $noRows);
$actual = null;
$expected = null;
// fetch array (to retrieve reference values)
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
$numFields = sqlsrv_num_fields($stmt1);
$expected = FetchArray($stmt1, $noRowsInserted, $numFields);
$expected = fetchArray($stmt1, $noRowsInserted, $numFields);
sqlsrv_free_stmt($stmt1);
$query = "SELECT * FROM [$tableName]";
// fetch object - FORWARD cursor
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_NEXT);
$stmt2 = AE\executeQueryEx($conn1, $query, $options);
$actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_NEXT);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
checkData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - STATIC cursor
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_RELATIVE);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
// Always Encrypted feature does not support the following options
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation
if (!AE\isColEncrypted()) {
// fetch object - STATIC cursor
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
$stmt2 = AE\executeQueryEx($conn1, $query, $options);
$actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_RELATIVE);
sqlsrv_free_stmt($stmt2);
checkData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - DYNAMIC cursor
$options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_ABSOLUTE);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - KEYSET cursor
$options = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_PRIOR, 0);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - DYNAMIC cursor
$options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC);
$stmt2 = AE\executeQueryEx($conn1, $query, $options);
$actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_ABSOLUTE);
sqlsrv_free_stmt($stmt2);
checkData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - KEYSET cursor
$options = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
$stmt2 = AE\executeQueryEx($conn1, $query, $options);
$actual = fetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_PRIOR, 0);
sqlsrv_free_stmt($stmt2);
checkData($noRowsInserted, $numFields, $actual, $expected);
}
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
@ -73,8 +76,7 @@ function FetchRow($noRows)
endTest($testName);
}
function FetchArray($stmt, $rows, $fields)
function fetchArray($stmt, $rows, $fields)
{
$values = array();
for ($i = 0; $i < $rows; $i++) {
@ -87,8 +89,7 @@ function FetchArray($stmt, $rows, $fields)
return ($values);
}
function FetchObject($stmt, $rows, $fields, $dir)
function fetchObject($stmt, $rows, $fields, $dir)
{
trace("\tRetrieving $rows objects with $fields fields each ...\n");
$values = array();
@ -118,12 +119,12 @@ function FetchObject($stmt, $rows, $fields, $dir)
return ($values);
}
function CheckData($rows, $fields, $actualValues, $expectedValues)
function checkData($rows, $fields, $actualValues, $expectedValues)
{
if (($actualValues != null) && ($expectedValues != null)) {
for ($i = 0; $i < $rows; $i++) {
for ($j = 0; $j < $fields; $j++) {
$colName = GetColName($j + 1);
$colName = getColName($j + 1);
$actual = $actualValues[$i]->$colName;
$expected = $expectedValues[$i][$colName];
if ($actual != $expected) {
@ -134,22 +135,12 @@ function CheckData($rows, $fields, $actualValues, $expectedValues)
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
FetchRow(10);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
fetchRow(10);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Fetch - Scrollable" completed successfully.

View file

@ -11,25 +11,24 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StreamRead($noRows, $startRow)
function streamRead($noRows, $startRow)
{
include 'MsSetup.inc';
$testName = "Stream - Read";
startTest($testName);
setup();
$tableName = 'TC51test';
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn1 = AE\connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
$conn1 = AE\connect();
}
createTable($conn1, $tableName);
insertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
AE\createTestTable($conn1, $tableName);
AE\insertTestRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
$query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp";
$stmt1 = selectQuery($conn1, $query);
$stmt1 = AE\executeQuery($conn1, $query);
$numFields = sqlsrv_num_fields($stmt1);
for ($row = 1; $row <= $noRows; $row++) {
@ -37,14 +36,12 @@ function StreamRead($noRows, $startRow)
fatalError("Failed to fetch row ".$row);
}
trace("\nStreaming row $row:\n");
$skipCount = 0;
for ($j = 0; $j < $numFields; $j++) {
$col = $j + 1;
if (!IsUpdatable($col)) {
$skipCount++;
}
if (IsStreamable($col)) {
VerifyStream($stmt1, $startRow + $row - 1, $j, $skipCount);
if (isUpdatable($col)) {
if (isStreamable($col)) {
verifyStream($stmt1, $startRow + $row - 1, $j);
}
}
}
}
@ -58,12 +55,12 @@ function StreamRead($noRows, $startRow)
endTest($testName);
}
function VerifyStream($stmt, $row, $colIndex, $skip)
function verifyStream($stmt, $row, $colIndex)
{
$col = $colIndex + 1;
if (IsStreamable($col)) {
$type = GetSqlType($col);
if (IsBinary($col)) {
if (isStreamable($col)) {
$type = getSqlType($col);
if (isBinary($col)) {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
} else {
if (useUTF8Data()) {
@ -81,24 +78,24 @@ function VerifyStream($stmt, $row, $colIndex, $skip)
$value .= fread($stream, 8192);
}
fclose($stream);
$data = getInsertData($row, $col, $skip);
if (!CheckData($col, $value, $data)) {
$data = AE\getInsertData($row, $col);
if (!checkData($col, $value, $data)) {
setUTF8Data(false);
trace("Data corruption on row $row column $col\n");
die("Data corruption on row $row column $col\n");
}
}
TraceData($type, "".strlen($value)." bytes");
traceData($type, "".strlen($value)." bytes");
}
}
}
function CheckData($col, $actual, $expected)
function checkData($col, $actual, $expected)
{
$success = true;
if (IsBinary($col)) {
if (isBinary($col)) {
$actual = bin2hex($actual);
if (strncasecmp($actual, $expected, strlen($expected)) != 0) {
$success = false;
@ -120,27 +117,17 @@ function CheckData($col, $actual, $expected)
return ($success);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
if (! isWindows()) {
setUTF8Data(true);
}
try {
StreamRead(20, 1);
} catch (Exception $e) {
echo $e->getMessage();
}
setUTF8Data(false);
if (! isWindows()) {
setUTF8Data(true);
}
repro();
try {
streamRead(20, 1);
} catch (Exception $e) {
echo $e->getMessage();
}
setUTF8Data(false);
?>
--EXPECT--

View file

@ -13,15 +13,15 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function SendStream($minType, $maxType, $atExec)
function sendStream($minType, $maxType, $atExec)
{
include 'MsSetup.inc';
$testName = "Stream - ".($atExec ? "Send at Execution" : "Send after Execution");
startTest($testName);
setup();
$conn1 = connect();
$tableName = "TC52test";
$fileName = "TC52test.dat";
$conn1 = AE\connect();
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
@ -101,35 +101,58 @@ function SendStream($minType, $maxType, $atExec)
fclose($fname1);
$fname2 = fopen($fileName, "r");
$sqlType = GetSqlType($k);
$phpDriverType = GetDriverType($k, strlen($data));
$dataType = "[c1] int, [c2] $sqlType";
$dataOptions = array($k, array($fname2, SQLSRV_PARAM_IN, null, $phpDriverType));
TraceData($sqlType, $data);
CreateQueryTable($conn1, $tableName, $dataType, "c1, c2", "?, ?", $dataOptions, $atExec);
CheckData($conn1, $tableName, 2, $data);
$sqlType = getSqlType($k);
$phpDriverType = getDriverType($k, strlen($data));
traceData($sqlType, $data);
// create table
$columns = array(new AE\ColumnMeta('int', 'c1'),
new AE\ColumnMeta($sqlType, 'c2'));
AE\createTable($conn1, $tableName, $columns);
// insert data
$params = array($k, array($fname2, SQLSRV_PARAM_IN, null, $phpDriverType));
insertQueryTable($conn1, $tableName, $params, $atExec);
checkData($conn1, $tableName, 2, $data);
fclose($fname2);
}
}
dropTable($conn1, $tableName);
unlink($fileName);
sqlsrv_close($conn1);
endTest($testName);
}
function CreateQueryTable($conn, $table, $dataType, $dataCols, $dataValues, $dataOptions, $execMode)
function insertQueryTable($conn, $tableName, $params, $execMode)
{
createTableEx($conn, $table, $dataType);
insertStream($conn, $table, $dataCols, $dataValues, $dataOptions, $execMode);
$sql = "INSERT INTO $tableName (c1, c2) VALUES (?, ?)";
$flag = $execMode ? 1 : 0;
$options = array('SendStreamParamsAtExec' => $flag);
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $sql, $params, $options);
if (!sqlsrv_execute($stmt)) {
fatalError("Failed to execute query!", true);
}
} else {
$stmt = sqlsrv_query($conn, $sql, $params, $options);
}
if (!$stmt) {
fatalError("Failed to run query!", true);
}
if (!$execMode) {
while (sqlsrv_send_stream_data($stmt)) {
}
}
insertCheck($stmt);
}
function CheckData($conn, $table, $cols, $expectedValue)
function checkData($conn, $table, $cols, $expectedValue)
{
$stmt = selectFromTable($conn, $table);
$stmt = AE\selectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt)) {
fatalError("Table $tableName was not expected to be empty.");
}
@ -144,23 +167,13 @@ function CheckData($conn, $table, $cols, $expectedValue)
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
SendStream(12, 28, true); // send stream at execution
SendStream(12, 28, false); // send stream after execution
} catch (Exception $e) {
echo $e->getMessage();
}
try {
sendStream(12, 28, true); // send stream at execution
sendStream(12, 28, false); // send stream after execution
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Stream - Send at Execution" completed successfully.

View file

@ -14,35 +14,34 @@ require_once('MsCommon.inc');
function CancelStream()
{
include 'MsSetup.inc';
$testName = "Stream - Cancel";
startTest($testName);
setup();
$conn1 = connect();
$tableName = "TC53test";
$conn1 = AE\connect();
$noRows = 5;
createTable($conn1, $tableName);
insertRows($conn1, $tableName, $noRows);
AE\createTestTable($conn1, $tableName);
AE\insertTestRows($conn1, $tableName, $noRows);
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
// Expired stream
$stream1 = GetStream($stmt1);
$stream1 = getStream($stmt1);
sqlsrv_fetch($stmt1);
CheckStream($stream1);
checkStream($stream1);
// Cancelled statement
$stream2 = GetStream($stmt1);
$stream2 = getStream($stmt1);
sqlsrv_cancel($stmt1);
CheckStream($stream2);
checkStream($stream2);
// Closed statement
$stmt2 = selectFromTable($conn1, $tableName);
$stream3 = GetStream($stmt2);
$stmt2 = AE\selectFromTable($conn1, $tableName);
$stream3 = getStream($stmt2);
sqlsrv_free_stmt($stmt2);
CheckStream($stream3);
checkStream($stream3);
dropTable($conn1, $tableName);
@ -51,7 +50,7 @@ function CancelStream()
endTest($testName);
}
function GetStream($stmt)
function getStream($stmt)
{
$stream = null;
@ -60,10 +59,10 @@ function GetStream($stmt)
}
while ($stream == null) {
$col = rand(11, 22); // select a streamable field
if (!IsStreamable($col + 1)) {
if (!isStreamable($col + 1)) {
die("Failed to select a streamable field.");
}
$type = GetSqlType($col + 1);
$type = getSqlType($col + 1);
trace("Selected streamable type: $type ...\n");
$stream = sqlsrv_get_field($stmt, $col, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
@ -75,7 +74,7 @@ function GetStream($stmt)
return ($stream);
}
function CheckStream($stream)
function checkStream($stream)
{
$bytesRead = 0;
try {
@ -90,27 +89,18 @@ function CheckStream($stream)
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
CancelStream();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
CancelStream();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECTREGEX--
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 86
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 84
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 86
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 84
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 86
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 84
Test "Stream - Cancel" completed successfully.

View file

@ -12,15 +12,15 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function SendStream($minType, $maxType)
function sendStream($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Stream - Prepared Send";
startTest($testName);
setup();
$conn1 = connect();
$tableName = "TC54test";
$fileName = "TC53test.dat";
$conn1 = AE\connect();
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
@ -52,30 +52,31 @@ function SendStream($minType, $maxType)
fclose($fname1);
$fname2 = fopen($fileName, "r");
$sqlType = GetSqlType($k);
$phpDriverType = GetDriverType($k, strlen($data));
$sqlType = getSqlType($k);
$phpDriverType = getDriverType($k, strlen($data));
$dataType = "[c1] int, [c2] $sqlType";
$dataOptions = array(array($k, SQLSRV_PARAM_IN),
array(&$fname2, SQLSRV_PARAM_IN, null, $phpDriverType));
TraceData($sqlType, $data);
traceData($sqlType, $data);
createTableEx($conn1, $tableName, $dataType);
InsertData($conn1, $tableName, "c1, c2", "?, ?", $dataOptions);
CheckData($conn1, $tableName, 2, $data);
$columns = array(new AE\ColumnMeta('int', 'c1'),
new AE\ColumnMeta($sqlType, 'c2'));
AE\createTable($conn1, $tableName, $columns);
insertData($conn1, $tableName, "c1, c2", "?, ?", $dataOptions);
checkData($conn1, $tableName, 2, $data);
fclose($fname2);
}
dropTable($conn1, $tableName);
unlink($fileName);
sqlsrv_close($conn1);
endTest($testName);
}
function InsertData($conn, $tableName, $dataCols, $dataValues, $dataOptions)
function insertData($conn, $tableName, $dataCols, $dataValues, $dataOptions)
{
$sql = "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)";
$stmt = sqlsrv_prepare($conn, $sql, $dataOptions);
@ -95,10 +96,9 @@ function InsertData($conn, $tableName, $dataCols, $dataValues, $dataOptions)
}
}
function CheckData($conn, $table, $cols, $expectedValue)
function checkData($conn, $table, $cols, $expectedValue)
{
$stmt = selectFromTable($conn, $table);
$stmt = AE\selectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt)) {
fatalError("Table $tableName was not expected to be empty.");
}
@ -121,7 +121,7 @@ function CheckData($conn, $table, $cols, $expectedValue)
function repro()
{
try {
SendStream(12, 23);
sendStream(12, 23);
} catch (Exception $e) {
echo $e->getMessage();
}

View file

@ -10,53 +10,75 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StreamScroll($noRows, $startRow)
function streamScroll($noRows, $startRow)
{
include 'MsSetup.inc';
$testName = "Stream - Scrollable";
startTest($testName);
setup();
$tableName = "TC55test";
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn1 = AE\connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
$conn1 = AE\connect();
}
createTable($conn1, $tableName);
insertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
AE\createTestTable($conn1, $tableName);
AE\insertTestRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
$query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp";
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
$stmt1 = selectQueryEx($conn1, $query, $options);
$numFields = sqlsrv_num_fields($stmt1);
$row = $noRows;
while ($row >= 1) {
if ($row == $noRows) {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_LAST)) {
fatalError("Failed to fetch row ".$row);
}
} else {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_PRIOR)) {
fatalError("Failed to fetch row ".$row);
}
}
trace("\nStreaming row $row:\n");
$skipCount = 0;
for ($j = 0; $j < $numFields; $j++) {
$col = $j + 1;
if (!IsUpdatable($col)) {
$skipCount++;
}
if (IsStreamable($col)) {
VerifyStream($stmt1, $startRow + $row - 1, $j, $skipCount);
}
}
$row--;
// Always Encrypted feature does not support SQLSRV_CURSOR_STATIC
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation
if (AE\isColEncrypted()) {
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
} else {
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
}
$stmt1 = AE\executeQueryEx($conn1, $query, $options);
$numFields = sqlsrv_num_fields($stmt1);
if (AE\isColEncrypted()) {
$row = $startRow;
while ($row <= $noRows) {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_NEXT)) {
fatalError("Failed to fetch row ".$row);
}
trace("\nStreaming row $row:\n");
for ($j = 0; $j < $numFields; $j++) {
$col = $j + 1;
if (!isUpdatable($col)) {
continue;
}
if (isStreamable($col)) {
verifyStream($stmt1, $startRow + $row - 1, $j);
}
}
$row++;
}
} else {
$row = $noRows;
while ($row >= 1) {
if ($row == $noRows) {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_LAST)) {
fatalError("Failed to fetch row ".$row);
}
} else {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_PRIOR)) {
fatalError("Failed to fetch row ".$row);
}
}
trace("\nStreaming row $row:\n");
for ($j = 0; $j < $numFields; $j++) {
$col = $j + 1;
if (!isUpdatable($col)) {
continue;
}
if (isStreamable($col)) {
verifyStream($stmt1, $startRow + $row - 1, $j);
}
}
$row--;
}
}
sqlsrv_free_stmt($stmt1);
dropTable($conn1, $tableName);
@ -66,12 +88,12 @@ function StreamScroll($noRows, $startRow)
endTest($testName);
}
function VerifyStream($stmt, $row, $colIndex, $skip)
function verifyStream($stmt, $row, $colIndex)
{
$col = $colIndex + 1;
if (IsStreamable($col)) {
$type = GetSqlType($col);
if (IsBinary($col)) {
if (isStreamable($col)) {
$type = getSqlType($col);
if (isBinary($col)) {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
} else {
if (useUTF8Data()) {
@ -89,24 +111,23 @@ function VerifyStream($stmt, $row, $colIndex, $skip)
$value .= fread($stream, 8192);
}
fclose($stream);
$data = getInsertData($row, $col, $skip);
if (!CheckData($col, $value, $data)) {
$data = AE\getInsertData($row, $col);
if (!checkData($col, $value, $data)) {
trace("Data corruption on row $row column $col\n");
setUTF8Data(false);
die("Data corruption on row $row column $col\n");
}
}
TraceData($type, "".strlen($value)." bytes");
traceData($type, "".strlen($value)." bytes");
}
}
}
function CheckData($col, $actual, $expected)
function checkData($col, $actual, $expected)
{
$success = true;
if (IsBinary($col)) {
if (isBinary($col)) {
$actual = bin2hex($actual);
if (strncasecmp($actual, $expected, strlen($expected)) != 0) {
$success = false;
@ -129,25 +150,15 @@ function CheckData($col, $actual, $expected)
return ($success);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
if (! isWindows()) {
setUTF8Data(true);
}
try {
StreamScroll(20, 1);
} catch (Exception $e) {
echo $e->getMessage();
}
setUTF8Data(false);
if (! isWindows()) {
setUTF8Data(true);
}
repro();
try {
streamScroll(20, 1);
} catch (Exception $e) {
echo $e->getMessage();
}
setUTF8Data(false);
?>
--EXPECT--

View file

@ -13,20 +13,19 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function Transaction()
function transaction()
{
include 'MsSetup.inc';
$testName = "Transaction - Execution";
startTest($testName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$tableName = 'TC61test';
$conn1 = AE\connect();
AE\createTestTable($conn1, $tableName);
$noRows = 10;
ExecTransaction($conn1, false, $tableName, $noRows); // rollback
ExecTransaction($conn1, true, $tableName, $noRows); // submit
execTransaction($conn1, false, $tableName, $noRows); // rollback
execTransaction($conn1, true, $tableName, $noRows); // submit
dropTable($conn1, $tableName);
@ -35,8 +34,7 @@ function Transaction()
endTest($testName);
}
function ExecTransaction($conn, $mode, $tableName, $noRows)
function execTransaction($conn, $mode, $tableName, $noRows)
{
if ($mode === true) {
trace("\nSUBMIT sequence:\n\t");
@ -44,7 +42,7 @@ function ExecTransaction($conn, $mode, $tableName, $noRows)
trace("\nROLLBACK sequence:\n\t");
}
sqlsrv_begin_transaction($conn);
$noRowsInserted = insertRows($conn, $tableName, $noRows);
$noRowsInserted = AE\insertTestRows($conn, $tableName, $noRows);
if ($mode === true) {
trace("\tTransaction submit...");
sqlsrv_commit($conn);
@ -54,7 +52,7 @@ function ExecTransaction($conn, $mode, $tableName, $noRows)
}
$rowCount = 0;
$stmt = selectFromTable($conn, $tableName);
$stmt = AE\selectFromTable($conn, $tableName);
while (sqlsrv_fetch($stmt)) {
$rowCount++;
}
@ -72,21 +70,12 @@ function ExecTransaction($conn, $mode, $tableName, $noRows)
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
Transaction();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
transaction();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Transaction - Execution" completed successfully.

View file

@ -11,45 +11,41 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function Transaction()
function transaction()
{
include 'MsSetup.inc';
$testName = "Transaction - Disconnect";
startTest($testName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$tableName = 'TC62test';
$conn1 = AE\connect();
AE\createTestTable($conn1, $tableName);
$noRows = 10;
// Insert rows and disconnect before the transaction is commited (implicit rollback)
trace("\nBegin transaction...\n");
sqlsrv_begin_transaction($conn1);
insertRows($conn1, $tableName, $noRows);
AE\insertTestRows($conn1, $tableName, $noRows);
trace("Disconnect prior to commit...\n\n");
sqlsrv_close($conn1);
// Insert rows and commit the transaction
$conn2 = connect();
$conn2 = AE\connect();
trace("Begin transaction...\n");
sqlsrv_begin_transaction($conn2);
$noRowsInserted = insertRows($conn2, $tableName, $noRows);
$noRowsInserted = AE\insertTestRows($conn2, $tableName, $noRows);
trace("Transaction commit...\n");
sqlsrv_commit($conn2);
$rowCount = 0;
$stmt1 = selectFromTable($conn2, $tableName);
while (sqlsrv_fetch($stmt1))
{
$stmt1 = AE\selectFromTable($conn2, $tableName);
while (sqlsrv_fetch($stmt1)) {
$rowCount++;
}
sqlsrv_free_stmt($stmt1);
trace("\nRows effectively inserted through both transactions: ".$rowCount."\n");
if ($rowCount != $noRowsInserted)
{
if ($rowCount != $noRowsInserted) {
die("An incorrect number of rows was fetched. Expected: ".$noRowsInserted);
}
@ -60,24 +56,12 @@ function Transaction()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try
{
Transaction();
}
catch (Exception $e)
{
echo $e->getMessage();
}
try {
transaction();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Transaction - Disconnect" completed successfully.

View file

@ -15,17 +15,16 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function Transaction($steps)
function transaction($steps)
{
include 'MsSetup.inc';
$testName = "Transaction - Boundaries";
startTest($testName);
setup();
$conn1 = connect();
$conn2 = connect();
createTable($conn1, $tableName);
$tableName = 'TC63test';
$conn1 = AE\connect();
$conn2 = AE\connect();
AE\createTestTable($conn1, $tableName);
$noRows1 = 2; // inserted rows
$noRows2 = 3;
@ -36,8 +35,8 @@ function Transaction($steps)
case 0: // nested commit
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
sqlsrv_commit($conn1);
$noRows += ($noRows1 + $noRows2);
@ -46,8 +45,8 @@ function Transaction($steps)
case 1: // nested rollback
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_rollback($conn2);
sqlsrv_rollback($conn1);
break;
@ -55,8 +54,8 @@ function Transaction($steps)
case 2: // nested commit & rollback
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_rollback($conn2);
sqlsrv_commit($conn1);
$noRows += $noRows1;
@ -64,19 +63,19 @@ function Transaction($steps)
case 3: // interleaved commit
sqlsrv_begin_transaction($conn1);
insertRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn1, $tableName, $noRows1);
sqlsrv_begin_transaction($conn2);
sqlsrv_commit($conn1);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
$noRows += ($noRows1 + $noRows2);
break;
case 4: // interleaved insert
sqlsrv_begin_transaction($conn1);
insertRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn1, $tableName, $noRows1);
sqlsrv_begin_transaction($conn2);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn1);
sqlsrv_commit($conn2);
$noRows += ($noRows1 + $noRows2);
@ -85,18 +84,18 @@ function Transaction($steps)
case 5: // interleaved insert & commit
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
insertRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn1, $tableName, $noRows1);
sqlsrv_commit($conn1);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
$noRows += ($noRows1 + $noRows2);
break;
case 6: // interleaved execution with commit & rollback
sqlsrv_begin_transaction($conn1);
insertRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn1, $tableName, $noRows1);
sqlsrv_begin_transaction($conn2);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
sqlsrv_rollback($conn1);
$noRows += $noRows2;
@ -104,22 +103,22 @@ function Transaction($steps)
case 7: // mixed execution
sqlsrv_begin_transaction($conn1);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn1);
$noRows += ($noRows1 + $noRows2);
break;
default:// no transaction
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
AE\insertTestRows($conn1, $tableName, $noRows1);
AE\insertTestRows($conn2, $tableName, $noRows2);
$noRows += ($noRows1 + $noRows2);
break;
}
}
$rowCount = 0;
$stmt1 = selectFromTable($conn1, $tableName);
$stmt1 = AE\selectFromTable($conn1, $tableName);
while (sqlsrv_fetch($stmt1)) {
$rowCount++;
}
@ -139,21 +138,12 @@ function Transaction($steps)
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
Transaction(9);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
transaction(9);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Transaction - Boundaries" completed successfully.

View file

@ -12,15 +12,15 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function Transaction($minType, $maxType)
function transaction($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Transaction - Stored Proc";
startTest($testName);
setup();
$conn1 = connect();
$tableName = 'TC64test';
$procName = "TC64test_proc";
$conn1 = AE\connect();
$colName = "c1";
for ($k = $minType; $k <= $maxType; $k++) {
@ -31,20 +31,21 @@ function Transaction($minType, $maxType)
$data = null;
break;
default:
$data = GetSampleData($k);
$data = getSampleData($k);
break;
}
if ($data != null) {
$sqlType = GetSqlType($k);
$sqlType = getSqlType($k);
$driverType = getDriverType($k);
createTableEx($conn1, $tableName, "[$colName] $sqlType");
CreateTransactionProc($conn1, $tableName, $colName, $procName, $sqlType);
AE\createTable($conn1, $tableName, array(new AE\ColumnMeta($sqlType, $colName)));
createTransactionProc($conn1, $tableName, $colName, $procName, $sqlType);
$noRows = ExecTransactionProc($conn1, $procName, $data, true);
$noRows = execTransactionProc($conn1, $procName, $data, $driverType, true);
if ($noRows != 1) {
die("$sqlType: Incorrect row count after commit: $noRows");
}
$noRows = ExecTransactionProc($conn1, $procName, $data, false);
$noRows = execTransactionProc($conn1, $procName, $data, $driverType, false);
if ($noRows != 2) {
die("$sqlType: Incorrect row count after rollback: $noRows");
}
@ -52,31 +53,33 @@ function Transaction($minType, $maxType)
if ($noRows != 1) {
die("$sqlType: Incorrect total row count: $noRows");
}
dropProc($conn1, $procName);
dropTable($conn1, $tableName);
}
}
sqlsrv_close($conn1);
endTest($testName);
}
function CreateTransactionProc($conn, $tableName, $colName, $procName, $sqlType)
function createTransactionProc($conn, $tableName, $colName, $procName, $sqlType)
{
$procArgs = "@p1 $sqlType, @p2 INT OUTPUT";
$procCode = "SET NOCOUNT ON; INSERT INTO [$tableName] ($colName) VALUES (@p1) SET @p2 = (SELECT COUNT(*) FROM [$tableName])";
createProc($conn, $procName, $procArgs, $procCode);
}
function ExecTransactionProc($conn, $procName, $data, $commitMode)
function execTransactionProc($conn, $procName, $data, $driverType, $commitMode)
{
// Always Encrypted feature requires SQL Types to be specified for sqlsrv_query
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation
if (AE\isColEncrypted()) {
$inType = $driverType;
} else {
$inType = null;
}
$retValue = -1;
$callArgs = array(array($data, SQLSRV_PARAM_IN), array(&$retValue, SQLSRV_PARAM_OUT));
$callArgs = array(array($data, SQLSRV_PARAM_IN, null, $inType),
array(&$retValue, SQLSRV_PARAM_OUT, null, SQLSRV_SQLTYPE_INT));
sqlsrv_begin_transaction($conn);
$stmt = callProc($conn, $procName, "?, ?", $callArgs);
if ($commitMode === true) { // commit
@ -84,26 +87,15 @@ function ExecTransactionProc($conn, $procName, $data, $commitMode)
} else { // rollback
sqlsrv_rollback($conn);
}
return ($retValue);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
Transaction(1, 28);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
transaction(1, 28);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Transaction - Stored Proc" completed successfully.

View file

@ -10,30 +10,30 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StoredProc()
function storedProc()
{
include 'MsSetup.inc';
$testName = "Stored Proc Call";
$data1 = "Microsoft SQL Server ";
$data2 = "Driver for PHP";
$tableName = 'TC71test';
$procName = "TC71test_proc";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
ExecProc($conn1, $procName, "CHAR", $data1, $data2);
ExecProc($conn1, $procName, "VARCHAR", $data1, $data2);
ExecProc($conn1, $procName, "NCHAR", $data1, $data2);
ExecProc($conn1, $procName, "NVARCHAR", $data1, $data2);
execProc($conn1, $procName, "CHAR", $data1, $data2);
execProc($conn1, $procName, "VARCHAR", $data1, $data2);
execProc($conn1, $procName, "NCHAR", $data1, $data2);
execProc($conn1, $procName, "NVARCHAR", $data1, $data2);
sqlsrv_close($conn1);
endTest($testName);
}
function ExecProc($conn, $procName, $sqlType, $inValue1, $inValue2)
function execProc($conn, $procName, $sqlType, $inValue1, $inValue2)
{
$len1 = strlen($inValue1);
$len2 = strlen($inValue2);
@ -41,40 +41,42 @@ function ExecProc($conn, $procName, $sqlType, $inValue1, $inValue2)
$sqlTypeIn1 = "$sqlType($len1)";
$sqlTypeIn2 = "$sqlType($len2)";
$sqlTypeOut = "$sqlType($len)";
// Always Encrypted feature requires SQL Types to be specified for sqlsrv_query
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation
if (AE\isColEncrypted()) {
$driverTypeIn1 = call_user_func("SQLSRV_SQLTYPE_$sqlType", $len1);
$driverTypeIn2 = call_user_func("SQLSRV_SQLTYPE_$sqlType", $len2);
} else {
$driverTypeIn1 = null;
$driverTypeIn2 = null;
}
$expected = "$inValue1$inValue2";
$actual = "";
$procArgs = "@p1 $sqlTypeOut OUTPUT, @p2 $sqlTypeIn1, @p3 $sqlTypeIn2";
$procCode = "SET @p1 = CONVERT($sqlTypeOut, @p2 + @p3)";
$callArgs = array(array(&$actual, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_CHAR($len)),
array($inValue1, SQLSRV_PARAM_IN),
array($inValue2, SQLSRV_PARAM_IN));
array($inValue1, SQLSRV_PARAM_IN, null, $driverTypeIn1),
array($inValue2, SQLSRV_PARAM_IN, null, $driverTypeIn2));
createProc($conn, $procName, $procArgs, $procCode);
callProc($conn, $procName, "?, ?, ?", $callArgs);
dropProc($conn, $procName);
if (strncmp($actual, $expected, strlen($expected)) != 0) {
var_dump($actual);
die("Data corruption: $expected => $actual.");
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
StoredProc();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
storedProc();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Stored Proc Call" completed successfully.

View file

@ -10,30 +10,30 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StoredFunc()
function storedFunc()
{
include 'MsSetup.inc';
$testName = "Stored Function";
$data1 = "Microsoft SQL Server ";
$data2 = "Driver for PHP";
$tableName = 'TC72test';
$procName = "TC72test_proc";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
ExecFunc($conn1, $procName, "CHAR", $data1, $data2);
ExecFunc($conn1, $procName, "VARCHAR", $data1, $data2);
ExecFunc($conn1, $procName, "NCHAR", $data1, $data2);
ExecFunc($conn1, $procName, "NVARCHAR", $data1, $data2);
execFunc($conn1, $procName, "CHAR", $data1, $data2);
execFunc($conn1, $procName, "VARCHAR", $data1, $data2);
execFunc($conn1, $procName, "NCHAR", $data1, $data2);
execFunc($conn1, $procName, "NVARCHAR", $data1, $data2);
sqlsrv_close($conn1);
endTest($testName);
}
function ExecFunc($conn, $funcName, $sqlType, $inValue1, $inValue2)
function execFunc($conn, $funcName, $sqlType, $inValue1, $inValue2)
{
$len1 = strlen($inValue1);
$len2 = strlen($inValue2);
@ -44,14 +44,23 @@ function ExecFunc($conn, $funcName, $sqlType, $inValue1, $inValue2)
$expected = "$inValue1$inValue2";
$actual = "";
// Always Encrypted feature requires SQL Types to be specified for sqlsrv_query
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation
if (AE\isColEncrypted()) {
$driverTypeIn1 = call_user_func("SQLSRV_SQLTYPE_$sqlType", $len1);
$driverTypeIn2 = call_user_func("SQLSRV_SQLTYPE_$sqlType", $len2);
} else {
$driverTypeIn1 = null;
$driverTypeIn2 = null;
}
$funcArgs = "@p1 $sqlTypeIn1, @p2 $sqlTypeIn2";
$funcCode = "RETURN (CONVERT($sqlTypeOut, @p1 + @p2))";
$callArgs = array(array(&$actual, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_CHAR($len)),
array($inValue1, SQLSRV_PARAM_IN),
array($inValue2, SQLSRV_PARAM_IN));
array($inValue1, SQLSRV_PARAM_IN, null, $driverTypeIn1),
array($inValue2, SQLSRV_PARAM_IN, null, $driverTypeIn2));
CreateFunc($conn, $funcName, $funcArgs, $sqlTypeOut, $funcCode);
createFunc($conn, $funcName, $funcArgs, $sqlTypeOut, $funcCode);
callFunc($conn, $funcName, "?, ?", $callArgs);
dropFunc($conn, $funcName);
@ -60,21 +69,12 @@ function ExecFunc($conn, $funcName, $sqlType, $inValue1, $inValue2)
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
StoredFunc();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
storedFunc();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Stored Function" completed successfully.

View file

@ -10,15 +10,15 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StoredProc()
function storedProc()
{
include 'MsSetup.inc';
$testName = "Stored Proc Call";
startTest($testName);
setup();
$conn1 = connect();
$tableName = 'TC73test';
$procName = "TC73test_proc";
$conn1 = AE\connect();
$step = 0;
$dataStr = "The quick brown fox jumps over the lazy dog.";
@ -26,31 +26,31 @@ function StoredProc()
// Scenario #1: using a null buffer
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 40, 0)) {
if (!execProc1($conn1, $procName, $dataStr, 40, 0)) {
die("Execution failure at step $step.");
}
// Scenario #2: using a pre-allocated buffer
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 25, 1)) {
if (!execProc1($conn1, $procName, $dataStr, 25, 1)) {
die("Execution failure at step $step.");
}
// Scenario #3: specifying an exact return size
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 0, 2)) {
if (!execProc1($conn1, $procName, $dataStr, 0, 2)) {
die("Execution failure at step $step.");
}
// Scenario #4: specifying a larger return size
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 50, 2)) {
if (!execProc1($conn1, $procName, $dataStr, 50, 2)) {
die("Execution failure at step $step.");
}
// Scenario #5: returning a value
$step++;
if (!ExecProc2($conn1, $procName, $dataInt)) {
if (!execProc2($conn1, $procName, $dataInt)) {
die("Execution failure at step $step.");
}
@ -59,7 +59,7 @@ function StoredProc()
endTest($testName);
}
function ExecProc1($conn, $procName, $dataIn, $extraSize, $phpInit)
function execProc1($conn, $procName, $dataIn, $extraSize, $phpInit)
{
$inValue = trim($dataIn);
$outValue = null;
@ -90,12 +90,15 @@ function ExecProc1($conn, $procName, $dataIn, $extraSize, $phpInit)
}
function ExecProc2($conn, $procName, $dataIn)
function execProc2($conn, $procName, $dataIn)
{
$procArgs = "@p1 INT";
$procCode = "SET NOCOUNT ON; SELECT 199 IF @p1 = 0 RETURN 11 ELSE RETURN 22";
$retValue = -1;
$callArgs = array(array(&$retValue, SQLSRV_PARAM_OUT), array($dataIn, SQLSRV_PARAM_IN));
$driverType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
$callArgs = array(array(&$retValue, SQLSRV_PARAM_OUT, null, $driverType),
array($dataIn, SQLSRV_PARAM_IN, null, $driverType));
createProc($conn, $procName, $procArgs, $procCode);
$stmt = callProcEx($conn, $procName, "? = ", "?", $callArgs);
@ -114,21 +117,12 @@ function ExecProc2($conn, $procName, $dataIn)
return (true);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
StoredProc();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
storedProc();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Stored Proc Call" completed successfully.

View file

@ -12,56 +12,56 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function ProcQuery($minType, $maxType)
function procQuery($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Stored Proc Query";
startTest($testName);
setup();
$conn1 = connect();
$tableName = 'TC74test';
$procName = "TC74test_proc";
$conn1 = AE\connect();
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
case 1: // TINYINT
ExecProcQuery($conn1, $procName, "TINYINT", 11, 12, 23);
execprocQuery($conn1, $procName, $k, "TINYINT", 11, 12, 23);
break;
case 2: // SMALLINT
ExecProcQuery($conn1, $procName, "SMALLINT", 4.3, 5.5, 9);
execprocQuery($conn1, $procName, $k, "SMALLINT", 4.3, 5.5, 9);
break;
case 3: // INT
ExecProcQuery($conn1, $procName, "INT", 3.2, 4, 7);
execprocQuery($conn1, $procName, $k, "INT", 3.2, 4, 7);
break;
case 4: // BIGINT
ExecProcQuery($conn1, $procName, "BIGINT", 5.2, 3.7, 8);
execprocQuery($conn1, $procName, $k, "BIGINT", 5.2, 3.7, 8);
break;
case 5: // FLOAT
ExecProcQuery($conn1, $procName, "FLOAT", 2.5, 5.25, 7.75);
execprocQuery($conn1, $procName, $k, "FLOAT", 2.5, 5.25, 7.75);
break;
case 6: // REAL
ExecProcQuery($conn1, $procName, "REAL", 3.4, 6.6, 10);
execprocQuery($conn1, $procName, $k, "REAL", 3.4, 6.6, 10);
break;
case 7: // DECIMAL
ExecProcQuery($conn1, $procName, "DECIMAL", 2.1, 5.3, 7);
execprocQuery($conn1, $procName, $k, "DECIMAL", 2.1, 5.3, 7);
break;
case 8: // NUMERIC
ExecProcQuery($conn1, $procName, "NUMERIC", 2.8, 5.4, 8);
execprocQuery($conn1, $procName, $k, "NUMERIC", 2.8, 5.4, 8);
break;
case 9: // SMALLMONEY
ExecProcQuery($conn1, $procName, "SMALLMONEY", 10, 11.7, 21.7);
execprocQuery($conn1, $procName, $k, "SMALLMONEY", 10, 11.7, 21.7);
break;
case 10:// MONEY
ExecProcQuery($conn1, $procName, "MONEY", 22.3, 16.1, 38.4);
execprocQuery($conn1, $procName, $k, "MONEY", 22.3, 16.1, 38.4);
break;
default:// default
@ -74,7 +74,7 @@ function ProcQuery($minType, $maxType)
endTest($testName);
}
function ExecProcQuery($conn, $procName, $dataType, $inData1, $inData2, $outData)
function execprocQuery($conn, $procName, $type, $dataType, $inData1, $inData2, $outData)
{
$procArgs = "@p1 $dataType, @p2 $dataType, @p3 $dataType OUTPUT";
$procCode = "SELECT @p3 = CONVERT($dataType, @p1 + @p2)";
@ -82,32 +82,42 @@ function ExecProcQuery($conn, $procName, $dataType, $inData1, $inData2, $outData
$callArgs = "?, ?, ?";
$callResult = 0.0;
$callValues = array($inData1, $inData2, array(&$callResult, SQLSRV_PARAM_OUT));
if (!AE\isColEncrypted()) {
$callValues = array($inData1, $inData2, array(&$callResult, SQLSRV_PARAM_OUT));
} else {
if ($type == 7 || $type == 8) {
// DECIMAL or NUMERIC
$driverType = call_user_func("SQLSRV_SQLTYPE_$dataType", 2, 1);
} else {
$driverType = constant("SQLSRV_SQLTYPE_$dataType");
}
if ($type >= 1 && $type < 5) {
// for any kinds of integers convert the inputs to integers first
// AE is stricter with data types
$inData1 = floor($inData1);
$inData2 = floor($inData2);
}
$callValues = array(array($inData1, null, null, $driverType),
array($inData2, null, null, $driverType),
array(&$callResult, SQLSRV_PARAM_OUT, null, $driverType));
}
callProc($conn, $procName, $callArgs, $callValues);
dropProc($conn, $procName);
TraceData($dataType, "".$inData1." + ".$inData2." = ".$callResult);
traceData($dataType, "".$inData1." + ".$inData2." = ".$callResult);
if ($callResult != $outData) {
die("Expected result for ".$dataType." was ".$outData);
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
ProcQuery(1, 10);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
procQuery(1, 10);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Stored Proc Query" completed successfully.

View file

@ -11,22 +11,24 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StoredProcRoundtrip($minType, $maxType)
function storedProcRoundtrip($minType, $maxType)
{
include 'MsSetup.inc';
// include 'MsSetup.inc';
$testName = "Stored Proc Roundtrip";
startTest($testName);
setup();
$conn1 = connect();
$tableName = 'TC75test';
$procName = "TC75test_proc";
$conn1 = AE\connect();
$data = "The quick brown fox jumps over the lazy dog 0123456789";
$dataSize = strlen($data);
for ($i = $minType; $i <= $maxType; $i++) {
$dataTypeIn = GetSqlType($i);
$phpTypeIn = GetDriverType($i, $dataSize);
$dataTypeIn = getSqlType($i);
$phpTypeIn = getDriverType($i, $dataSize);
for ($j = $minType; $j <= $maxType; $j++) {
$k = $j;
@ -45,9 +47,9 @@ function StoredProcRoundtrip($minType, $maxType)
break;
}
$dataTypeOut = GetSqlType($k);
$phpTypeOut = GetDriverType($k, 512);
ExecProcRoundtrip($conn1, $procName, $dataTypeIn, $dataTypeOut, $phpTypeIn, $phpTypeOut, $data);
$dataTypeOut = getSqlType($k);
$phpTypeOut = getDriverType($k, 512);
execProcRoundtrip($conn1, $procName, $dataTypeIn, $dataTypeOut, $phpTypeIn, $phpTypeOut, $data);
}
}
@ -57,7 +59,7 @@ function StoredProcRoundtrip($minType, $maxType)
}
function ExecProcRoundtrip($conn, $procName, $dataTypeIn, $dataTypeOut, $phpTypeIn, $phpTypeOut, $dataIn)
function execProcRoundtrip($conn, $procName, $dataTypeIn, $dataTypeOut, $phpTypeIn, $phpTypeOut, $dataIn)
{
$procArgs = "@p1 $dataTypeIn, @p2 $dataTypeOut OUTPUT";
$procCode = "SELECT @p2 = CONVERT($dataTypeOut, @p1)";
@ -73,26 +75,17 @@ function ExecProcRoundtrip($conn, $procName, $dataTypeIn, $dataTypeOut, $phpType
$dataOut = trim($callResult);
if (strncmp($dataOut, $dataIn, strlen($dataIn)) != 0) {
TraceData($dataTypeIn."=>".$dataTypeOut, "\n In: [".$dataIn."]\nOut: [".$dataOut."]");
traceData($dataTypeIn."=>".$dataTypeOut, "\n In: [".$dataIn."]\nOut: [".$dataOut."]");
die("Unexpected result for ".$dataTypeIn."=>".$dataTypeOut);
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
StoredProcRoundtrip(12, 19);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
storedProcRoundtrip(12, 19);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Stored Proc Roundtrip" completed successfully.

View file

@ -10,29 +10,28 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StoredProc()
function storedProc()
{
include 'MsSetup.inc';
$testName = "Stored Proc - Null Data";
$data1 = "Microsoft SQL Server ";
$data2 = "Driver for PHP";
startTest($testName);
setup();
$conn1 = connect();
$tableName = 'TC76test';
$procName = "TC76test_proc";
$conn1 = AE\connect();
ExecProc($conn1, $procName, "VARCHAR(32)", SQLSRV_SQLTYPE_VARCHAR(32), "ABC");
ExecProc($conn1, $procName, "FLOAT", SQLSRV_SQLTYPE_FLOAT, 3.2);
ExecProc($conn1, $procName, "INT", SQLSRV_SQLTYPE_INT, 5);
execProc($conn1, $procName, "VARCHAR(32)", SQLSRV_SQLTYPE_VARCHAR(32), "ABC");
execProc($conn1, $procName, "FLOAT", SQLSRV_SQLTYPE_FLOAT, 3.2);
execProc($conn1, $procName, "INT", SQLSRV_SQLTYPE_INT, 5);
sqlsrv_close($conn1);
endTest($testName);
}
function ExecProc($conn, $procName, $sqlType, $sqlTypeEx, $initData)
function execProc($conn, $procName, $sqlType, $sqlTypeEx, $initData)
{
$data = $initData;
@ -40,7 +39,6 @@ function ExecProc($conn, $procName, $sqlType, $sqlTypeEx, $initData)
$procCode = "SET @p1 = NULL";
$callArgs = array(array(&$data, SQLSRV_PARAM_OUT, null, $sqlTypeEx));
createProc($conn, $procName, $procArgs, $procCode);
callProc($conn, $procName, "?", $callArgs);
dropProc($conn, $procName);
@ -50,21 +48,12 @@ function ExecProc($conn, $procName, $sqlType, $sqlTypeEx, $initData)
}
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
StoredProc();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
storedProc();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Stored Proc - Null Data" completed successfully.

View file

@ -11,15 +11,13 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function BugRepro()
function bugRepro()
{
include 'MsSetup.inc';
$testName = "Regression VSTS 611146";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
// empty parameter array
$s = sqlsrv_query($conn1, "select ?", array( array() ));
if ($s !== false) {
@ -44,22 +42,12 @@ function BugRepro()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
BugRepro();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
bugRepro();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Parameter array 1 must have at least one value or variable.

View file

@ -11,57 +11,50 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function BugRepro()
function bugRepro()
{
include 'MsSetup.inc';
$testName = "Regression VSTS 846501";
startTest($testName);
setup();
$conn1 = connect();
$conn1 = AE\connect();
// empty parameter array
$s = sqlsrv_query($conn1, "DROP TABLE test_bq");
$s = sqlsrv_query($conn1, "CREATE TABLE test_bq (id INT IDENTITY NOT NULL, test_varchar_max varchar(max))");
$tableName = "test_bq";
dropTable($conn1, $tableName);
$columns = array(new AE\ColumnMeta("int", "id", "IDENTITY NOT NULL"),
new AE\ColumnMeta("varchar(max)", "test_varchar_max"));
$s = AE\createTable($conn1, $tableName, $columns);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query($conn1, "CREATE CLUSTERED INDEX [idx_test_int] ON test_bq (id)");
$s = sqlsrv_query($conn1, "CREATE CLUSTERED INDEX [idx_test_int] ON $tableName (id)");
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query($conn1, "INSERT INTO test_bq (test_varchar_max) VALUES ('ABCD')");
$inputs = array("test_varchar_max" => "ABCD");
$s = AE\insertRow($conn1, $tableName, $inputs);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$tsql = "select test_varchar_max from test_bq";
$result = sqlsrv_query($conn1, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_CLIENT_BUFFERED ));
$tsql = "select test_varchar_max from $tableName";
$result = AE\executeQueryEx($conn1, $tsql, array( "Scrollable" => SQLSRV_CURSOR_CLIENT_BUFFERED ));
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_BOTH)) {
print $row['test_varchar_max']."\n";
}
sqlsrv_query($conn1, "DROP TABLE test_bq");
dropTable($conn1, $tableName);
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
BugRepro();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
bugRepro();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
ABCD

View file

@ -11,7 +11,7 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
function memCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
{
$testName = "Memory Leakage Check";
@ -26,12 +26,12 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
// set the encoding to UTF-8. We can set the UTF-8 option elsewhere
// (in the options for sqlsrv_fetch for example) but it is easier
// to simply call connect(array( 'CharacterSet'=>'UTF-8' )).
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn1 = AE\connect(array( 'CharacterSet'=>'UTF-8' ));
setUTF8Data(true);
$tableName = 'TC81test';
createTable($conn1, $tableName);
$noRowsInserted = insertRows($conn1, $tableName, $noRows1);
AE\createTestTable($conn1, $tableName);
$noRowsInserted = AE\insertTestRows($conn1, $tableName, $noRows1);
// Calibration
// when fetching DateTime in the test, the DateTime PHP extension is used, and memory is allocated when this
@ -39,26 +39,26 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
// appear to be a leak in the testing step.
$date = new DateTime();
unset($date);
$phpLeak = RunTest($noPasses, 0, $tableName, $conn1, false, true, 0);
$phpLeak = runTest($noPasses, 0, $tableName, $conn1, false, true, 0);
trace("\n0. Calibration\t - PHP memory leak: $phpLeak bytes\n");
// Preliminary Execution
trace("\nPreliminary Execution:\n");
$drvLeak = ExecTest(1, $noRows1, $startStep, $endStep, $tableName, $conn1, false, true, $phpLeak);
$drvLeak = execTest(1, $noRows1, $startStep, $endStep, $tableName, $conn1, false, true, $phpLeak);
$totalLeak = 0;
// Connection & Query
$start = Max($startStep, 1);
$end = Min($endStep, 3);
trace("\nConnection & Direct Query Execution:\n");
$leak = ExecTest($noPasses, $noRows1, $start, $end, $tableName, $conn1, false, true, $phpLeak) - $drvLeak;
$leak = execTest($noPasses, $noRows1, $start, $end, $tableName, $conn1, false, true, $phpLeak) - $drvLeak;
if ($leak > $totalLeak) {
$totalLeak = $leak;
}
trace("\nPrepared Query Execution:\n");
$start = Max($startStep, 2);
$leak = ExecTest($noPasses, $noRows1, $start, $end, $tableName, $conn1, true, true, $phpLeak) - $drvLeak;
$leak = execTest($noPasses, $noRows1, $start, $end, $tableName, $conn1, true, true, $phpLeak) - $drvLeak;
if ($leak > $totalLeak) {
$totalLeak = $leak;
}
@ -92,7 +92,7 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
break;
case 4:
insertRows($conn1, $tableName, $noRows2);
AE\insertTestRows($conn1, $tableName, $noRows2);
$noRows = $noRows1 + $noRows2;
$prepared = false;
$release = false;
@ -127,7 +127,7 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
} else {
trace(" without statement release:\n");
}
$leak = ExecTest($noPasses, $noRows, $start, $end, $tableName, $conn1, $prepared, $release, $phpLeak) - $drvLeak;
$leak = execTest($noPasses, $noRows, $start, $end, $tableName, $conn1, $prepared, $release, $phpLeak) - $drvLeak;
if ($leak > $totalLeak) {
$totalLeak = $leak;
}
@ -135,7 +135,7 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
sqlsrv_close($conn1);
$conn2 = connect();
$conn2 = AE\connect();
dropTable($conn2, $tableName);
sqlsrv_close($conn2);
setUTF8Data(false);
@ -147,36 +147,38 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
endTest($testName);
}
function GetConnection()
function getConnection()
{
include 'MsSetup.inc';
$conn = sqlsrv_connect($server, $connectionOptions);
$conn = AE\connect();
return ($conn);
}
function ExecQuery($conn, $tableName, $prepared)
function execQuery($conn, $tableName, $prepared)
{
$selectQuery = "SELECT * FROM [$tableName]";
$stmt = null;
if ($prepared) {
$stmt = sqlsrv_prepare($conn, $selectQuery);
if (AE\isColEncrypted()){
$stmt = AE\executeQuery($conn, $selectQuery);
} else {
$stmt = sqlsrv_query($conn, $selectQuery);
}
if ($stmt === false) {
fatalError("Query execution failed: $selectQuery");
}
if ($prepared) {
if (!sqlsrv_execute($stmt)) {
if ($prepared) {
$stmt = sqlsrv_prepare($conn, $selectQuery);
} else {
$stmt = sqlsrv_query($conn, $selectQuery);
}
if ($stmt === false) {
fatalError("Query execution failed: $selectQuery");
}
if ($prepared) {
if (!sqlsrv_execute($stmt)) {
fatalError("Query execution failed: $selectQuery");
}
}
}
return ($stmt);
}
function ExecTest($noPasses, $noRows, $startStep, $endStep, $tableName, $conn, $prepared, $release, $phpLeak)
function execTest($noPasses, $noRows, $startStep, $endStep, $tableName, $conn, $prepared, $release, $phpLeak)
{
$leak = 0;
@ -214,7 +216,7 @@ function ExecTest($noPasses, $noRows, $startStep, $endStep, $tableName, $conn, $
default:
break;
}
$memLeak = RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $i) - $phpLeak;
$memLeak = runTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $i) - $phpLeak;
trace("Driver memory leak: $memLeak bytes\n");
if ($memLeak > 0) {
if ($leak <= 0) {
@ -227,7 +229,7 @@ function ExecTest($noPasses, $noRows, $startStep, $endStep, $tableName, $conn, $
return ($leak);
}
function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mode)
function runTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mode)
{
$memStart = memory_get_usage();
for ($k = 1; $k <= $noPasses; $k++) {
@ -243,21 +245,21 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
break;
case 1: // no release
$conn2 = GetConnection();
$conn2 = getConnection();
sqlsrv_close($conn2);
break;
case 2: // query with no release
$stmt = ExecQuery($conn, $tableName, $prepared);
$stmt = execQuery($conn, $tableName, $prepared);
break;
case 3: // query with release
$stmt = ExecQuery($conn, $tableName, $prepared);
$stmt = execQuery($conn, $tableName, $prepared);
sqlsrv_free_stmt($stmt);
break;
case 4: // fetch
$stmt = ExecQuery($conn, $tableName, $prepared);
$stmt = execQuery($conn, $tableName, $prepared);
while (sqlsrv_fetch($stmt)) {
$rowCount++;
}
@ -270,7 +272,7 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
break;
case 5: // fetch fields
$stmt = ExecQuery($conn, $tableName, $prepared);
$stmt = execQuery($conn, $tableName, $prepared);
$numFields = sqlsrv_num_fields($stmt);
while (sqlsrv_fetch($stmt)) {
$rowCount++;
@ -291,7 +293,7 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
break;
case 6: // fetch array
$stmt = ExecQuery($conn, $tableName, $prepared);
$stmt = execQuery($conn, $tableName, $prepared);
while (sqlsrv_fetch_array($stmt)) {
$rowCount++;
}
@ -304,7 +306,7 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
break;
case 7: // fetch object
$stmt = ExecQuery($conn, $tableName, $prepared);
$stmt = execQuery($conn, $tableName, $prepared);
while (sqlsrv_fetch_object($stmt)) {
$rowCount++;
}
@ -329,22 +331,12 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
return ($memEnd - $memStart);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
MemCheck(20, 10, 15, 1, 7);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
memCheck(20, 10, 15, 1, 7);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test "Memory Leakage Check" completed successfully.

View file

@ -10,54 +10,79 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function StoredProcCheck()
function storedProcCheck()
{
include 'MsSetup.inc';
$testName = "ResultSet with Stored Proc";
startTest($testName);
setup();
$conn1 = connect();
$tableName = 'TC82test';
$procName = "TC82test_proc";
$conn1 = AE\connect();
$table1 = $tableName."_1";
$table2 = $tableName."_2";
$table3 = $tableName."_3";
$procArgs = "@p1 int, @p2 nchar(32), @p3 nvarchar(64), @p4 nvarchar(max) OUTPUT";
$date = date("Y-m-d H:i:s");
// When AE is enabled, the size must match exactly
$size = AE\isColEncrypted() ? "256" : "max";
$procArgs = "@p1 int, @p2 nchar(32), @p3 nvarchar(64), @p4 datetime, @p5 nvarchar($size) OUTPUT";
$introText="Initial Value";
$callArgs = array(array(1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT),
array('Dummy No', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
array('Dummy ID', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
array( &$introText, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(256)));
$callArgs = array(array(1, SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT),
array('Dummy No', SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(32)),
array('Dummy ID', SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(50)),
array($date, SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_DATETIME),
array(&$introText, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(256)));
$procCode =
"IF (@p3 IS NULL)
BEGIN
INSERT INTO [$table1] (DataID, ExecTime, DataNo) values (@p1, GETDATE(), @p2)
INSERT INTO [$table1] (DataID, ExecTime, DataNo) values (@p1, @p4, @p2)
END
ELSE
BEGIN
INSERT INTO [$table1] (DataID, ExecTime, DataNo, DataRef) values (@p1, GETDATE(), @p2, @p3)
INSERT INTO [$table1] (DataID, ExecTime, DataNo, DataRef) values (@p1, @p4, @p2, @p3)
END
INSERT INTO [$table2] (DataID, DataNo) values (@p1, @p2)
SELECT @p4=(SELECT Intro from [$table3] WHERE DataID=@p1) ";
SELECT @p5=(SELECT Intro from [$table3] WHERE DataID=@p1) ";
$columns1 = array(new AE\ColumnMeta("int", "DataID"),
new AE\ColumnMeta("datetime", "ExecTime"),
new AE\ColumnMeta("nchar(32)", "DataNo"),
new AE\ColumnMeta("nvarchar(64)", "DataRef"));
AE\createTable($conn1, $table1, $columns1);
$columns2 = array(new AE\ColumnMeta("int", "DataID"),
new AE\ColumnMeta("nchar(32)", "DataNo"));
AE\createTable($conn1, $table2, $columns2);
$columns3 = array(new AE\ColumnMeta("int", "DataID"),
new AE\ColumnMeta("nvarchar($size)", "Intro"));
AE\createTable($conn1, $table3, $columns3);
createTableEx($conn1, $table1, "DataID int, ExecTime datetime, DataNo nchar(32), DataRef nvarchar(64)");
createTableEx($conn1, $table2, "DataID int, DataNo nchar(32)");
createTableEx($conn1, $table3, "DataID int, Intro nvarchar(max)");
createProc($conn1, $procName, $procArgs, $procCode);
$stmt1 = sqlsrv_query($conn1, "INSERT INTO [$table3] (DataID, Intro) VALUES (1, 'Test Value 1')");
$r = null;
$stmt1 = AE\insertRow($conn1, $table3, array("DataID" => 1, "Intro" => 'Test Value 1'), $r, AE\INSERT_PREPARE_PARAMS);
insertCheck($stmt1);
$stmt2 = sqlsrv_query($conn1, "INSERT INTO [$table3] (DataID, Intro) VALUES (2, 'Test Value 2')");
$stmt2 = AE\insertRow($conn1, $table3, array("DataID" => 2, "Intro" => 'Test Value 2'), $r, AE\INSERT_PREPARE_PARAMS);
insertCheck($stmt2);
$stmt3 = sqlsrv_query($conn1, "INSERT INTO [$table3] (DataID, Intro) VALUES (3, 'Test Value 3')");
$stmt3 = AE\insertRow($conn1, $table3, array("DataID" => 3, "Intro" => 'Test Value 3'), $r, AE\INSERT_PREPARE_PARAMS);
insertCheck($stmt3);
$stmt4 = callProcEx($conn1, $procName, "", "?, ?, ?, ?", $callArgs);
$stmt4 = callProcEx($conn1, $procName, "", "?, ?, ?, ?, ?", $callArgs);
$result = sqlsrv_next_result($stmt4);
while ($result != null) {
if ($result === false) {
@ -79,22 +104,12 @@ function StoredProcCheck()
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
StoredProcCheck();
} catch (Exception $e) {
echo $e->getMessage();
}
try {
storedProcCheck();
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
Test Value 1

View file

@ -10,7 +10,7 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');
function ComplexInsert($count)
function complexInsert($count)
{
$testName = "Complex Insert Query";
@ -18,7 +18,7 @@ function ComplexInsert($count)
setup();
$conn1 = connect();
$conn1 = AE\connect();
$tableName = 'TC83test';
dropTable($conn1, $tableName);
@ -53,22 +53,12 @@ function ComplexInsert($count)
endTest($testName);
}
//--------------------------------------------------------------------
// repro
//
//--------------------------------------------------------------------
function repro()
{
try {
ComplexInsert(160);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
complexInsert(160);
} catch (Exception $e) {
echo $e->getMessage();
}
repro();
?>
--EXPECT--
160 rows attempted; actual rows created = 160

View file

@ -18,12 +18,12 @@ function insertNullsTest($phptype, $sqltype)
setup();
$conn = connect();
$conn = AE\connect();
$tableName = 'TC86test';
dropTable($conn, $tableName);
createTable($conn, $tableName);
AE\createTestTable($conn, $tableName);
$stmt = sqlsrv_query($conn, "SELECT [TABLE_NAME],[COLUMN_NAME],[IS_NULLABLE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '$tableName'");

View file

@ -12,7 +12,9 @@ require_once('AEData.inc');
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real" );
$conn = AE\connect();
foreach ($dataTypes as $dataType) {
$count = count($dataTypes);
for ($i = 0; $i < $count; $i++) {
$dataType = $dataTypes[$i];
echo "\nTesting $dataType: \n";
// create table
@ -23,7 +25,12 @@ foreach ($dataTypes as $dataType) {
// insert a row
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r);
// convert input values to strings for decimals and numerics
if ($i == 5 || $i == 6) {
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => (string) $inputValues[0], $colMetaArr[1]->colName => (string) $inputValues[1] ), $r);
} else {
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r);
}
if ($r === false) {
is_incompatible_types_error($dataType, "default type");
} else {

View file

@ -8,9 +8,9 @@ PHPT_EXEC=true
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
$conn = connect();
createTable($conn, $tableName);
$conn = AE\connect();
$tableName = 'InvalidKeyTest';
AE\createTestTable($conn, $tableName);
$query = "SELECT * FROM [$tableName]";
//integer keys are invalid
@ -40,7 +40,6 @@ if (!$stmt) {
print_r(sqlsrv_errors());
}
dropTable($conn, $tableName);
sqlsrv_close($conn);