Applied review comments

This commit is contained in:
Jenny Tam 2017-11-08 11:28:15 -08:00
parent 6a14325f37
commit 47c5512cf1
5 changed files with 23 additions and 44 deletions

View file

@ -17,8 +17,13 @@ this test is very similar to test_scrollable.phpt... might consider removing thi
$columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('char(10)', 'value'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table for the test]n");
}
sqlsrv_free_stmt($stmt);
// Always Encrypted feature only supports SQLSRV_CURSOR_FORWARD or
// SQLSRV_CURSOR_CLIENT_BUFFERED
$query = "SELECT * FROM $tableName";
if (AE\isColEncrypted()) {
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);

View file

@ -74,7 +74,7 @@ class ColumnMeta
if (stripos($this->options, "identity") !== false) {
$this->encryptable = false;
} elseif (in_array($this->dataType, $unsupported)) {
} elseif (in_array(strtolower($this->dataType), $unsupported)) {
$this->encryptable = false;
} else {
$this->encryptable = true;
@ -381,36 +381,6 @@ function createTable($conn, $tbname, $columnMetaArr)
return sqlsrv_query($conn, $createSql);
}
/**
* Create a table with options for sqlsrv_prepare()
* @param resource $conn : sqlsrv connection resource
* @param string $tbname : name of the table to be created
* @param array $columnMetaArr : array of ColumnMeta objects, which contain metadata for one column
* @param array $options : array of options for sqlsrv_prepare()
* @return resource sqlsrv statement resource
*/
function createTableEx($conn, $tbname, $columnMetaArr, $options)
{
require_once("MsCommon.inc");
dropTable($conn, $tbname);
$colDef = "";
foreach ($columnMetaArr as $meta) {
$colDef = $colDef . $meta->getColDef() . ", ";
}
$colDef = rtrim($colDef, ", ");
$createSql = "CREATE TABLE $tbname ( $colDef )";
$stmt = sqlsrv_prepare($conn, $createSql, array(), $options);
if ($stmt) {
$res = sqlsrv_execute($stmt);
if ($res == false) {
fatalError("createTableEx: failed to execute the query to create table\n");
}
} else {
fatalError("createTableEx: failed to prepare the statement to create table\n");
}
return $stmt;
}
/**
* Insert a row into a table
* @param resource $conn : sqlsrv connection resource
@ -435,7 +405,7 @@ function insertRow($conn, $tbname, $inputs, &$r = null, $api = INSERT_QUERY)
$stmt = sqlsrv_prepare($conn, $insertSql);
if ($stmt) {
$r = sqlsrv_execute($stmt);
}
}
break;
}
} else {
@ -462,6 +432,7 @@ function insertRow($conn, $tbname, $inputs, &$r = null, $api = INSERT_QUERY)
$stmt = sqlsrv_query($conn, $insertSql, $params);
}
}
return $stmt;
}
@ -681,7 +652,6 @@ function insertTestRow($conn, $tbname, $index)
echo("Invalid row index $index for test data!\n");
return false;
}
// get array of input values
$inputArray = getInsertArray($index);
if (empty($inputArray)) {

View file

@ -19,12 +19,7 @@ function insertOneRow($conn, $tableName)
"Field7" => "This is field 7.");
$query = AE\getInsertSqlPlaceholders($tableName, $data);
// form the array of parameters
$params = array();
foreach ($data as $key => $input) {
array_push($params, $input);
}
$stmt = sqlsrv_prepare($conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, array_values($data), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
} else {
$query = "INSERT INTO $tableName ([Field2], [Field3], [Field4], [Field5], [Field6], [Field7]) VALUES ('This is field 2.', 0x010203, 'This is field 4.', 0x040506, 'This is field 6.', 'This is field 7.' )";
$stmt = sqlsrv_prepare($conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
@ -75,7 +70,10 @@ $columns = array(new AE\ColumnMeta('int', 'Id', 'NOT NULL Identity (100,2) PRIMA
new AE\ColumnMeta('varchar(max)', 'Field6'),
new AE\ColumnMeta('nvarchar(max)', 'Field7'));
AE\createTableEx($conn, $tableName, $columns, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table for the test\n");
}
$stmt = insertOneRow($conn, $tableName);
$f2 = fopen('php://memory', 'a');

View file

@ -5,7 +5,7 @@ sqlsrv_fetch_object() into a class with Unicode column name
--FILE--
<?php
// Define the Product classes
// Define the Product class
class Product
{
public function __construct($ID, $UID)

View file

@ -47,11 +47,17 @@ AE\createTable($conn, $tableName, $columns);
$res = null;
$params = array($sample, $sample1, $sample2, $sample3, $sample4, $sample5, 0, 0, 0);
$data = getInputData($params);
AE\insertRow($conn, $tableName, $data, $res, AE\INSERT_QUERY_PARAMS);
$stmt = AE\insertRow($conn, $tableName, $data, $res, AE\INSERT_QUERY_PARAMS);
if (!$stmt) {
fatalError("Failed to insert into $tableName!");
}
$params = array($sample4, $sample5, 100000, -1234567, $sample, $sample1, 0, 0, 0);
$data = getInputData($params);
AE\insertRow($conn, $tableName, $data, $res, AE\INSERT_QUERY_PARAMS);
$stmt = AE\insertRow($conn, $tableName, $data, $res, AE\INSERT_QUERY_PARAMS);
if (!$stmt) {
fatalError("Failed to insert into $tableName!");
}
$query = "SELECT TOP 2 * FROM $tableName";
$stmt = AE\executeQueryEx($conn, $query, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));