Used sqlsrv_query() instead
This commit is contained in:
parent
1daa4f0623
commit
094e32dc19
|
@ -372,7 +372,6 @@ function connect($options = array(), $disableCE = false)
|
|||
$connectionOptions = array_merge($connectionOptions, array("ColumnEncryption" => "Enabled"));
|
||||
}
|
||||
if ($keystore == "ksp") {
|
||||
// require('AE_Ksp.inc');
|
||||
$ksp_path = getKSPPath();
|
||||
$ksp_options = array("CEKeystoreProvider"=>$ksp_path,
|
||||
"CEKeystoreName"=>KSP_NAME,
|
||||
|
@ -481,7 +480,7 @@ function selectFromTable($conn, $tbname, $conds = null, $values = null)
|
|||
* @param resource $conn : connection resource
|
||||
* @param string $sql : T-SQL query
|
||||
* @param string $conds : string of condition(s) possibly with placeholders, null by default
|
||||
* @param array $values : array of parameters, null by default
|
||||
* @param array $values : array of parameters for placeholders in $conds, null by default
|
||||
* @param array $options : array of query options, null by default
|
||||
* @return resource sqlsrv statement upon success or false otherwise
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,7 @@ $stmt = AE\insertRow($conn, $tableName, array('ID' => 'Aå_Ð×Æ×Ø_B'));
|
|||
|
||||
// Fetch data
|
||||
$query = "SELECT * FROM $tableName";
|
||||
$stmt = AE\executeQueryEx($conn, $query, array("Scrollable"=>"buffered"));
|
||||
$stmt = sqlsrv_query($conn, $query, [], array("Scrollable"=>"buffered"));
|
||||
|
||||
// Fetch
|
||||
$row = sqlsrv_fetch_array($stmt);
|
||||
|
|
|
@ -91,21 +91,51 @@ $columns = array(new AE\ColumnMeta('CHAR(4)', 'ID'),
|
|||
AE\createTable($conn, $tableName1, $columns);
|
||||
|
||||
// Insert data
|
||||
$params = array('P001', 'Pencil 2B', '102', '24', '0.24', '2016-02-01', 'Red');
|
||||
$data = getInputData1($params);
|
||||
AE\insertRow($conn, $tableName1, $data);
|
||||
|
||||
$params = array('P002', 'Notepad', '102', '12', '3.87', '2016-02-21', null);
|
||||
$data = getInputData1($params);
|
||||
AE\insertRow($conn, $tableName1, $data);
|
||||
|
||||
$params = array('P001', 'Mirror 2\"', '652', '3', '15.99', '2016-02-01', null);
|
||||
$data = getInputData1($params);
|
||||
AE\insertRow($conn, $tableName1, $data);
|
||||
|
||||
$params = array('P003', 'USB connector', '1652', '31', '9.99', '2016-02-01', null);
|
||||
$data = getInputData1($params);
|
||||
AE\insertRow($conn, $tableName1, $data);
|
||||
if (AE\isColEncrypted()) {
|
||||
$sql = "INSERT INTO $tableName1 VALUES
|
||||
(?, ?, ?, ?, ?, ?, ?),
|
||||
(?, ?, ?, ?, ?, ?, ?),
|
||||
(?, ?, ?, ?, ?, ?, ?),
|
||||
(?, ?, ?, ?, ?, ?, ?)";
|
||||
$stmt = sqlsrv_query($conn, $sql, array(array('P001', null, null, SQLSRV_SQLTYPE_CHAR(4)),
|
||||
array('Pencil 2B', null, null, SQLSRV_SQLTYPE_VARCHAR(128)),
|
||||
array('102', null, null, SQLSRV_SQLTYPE_SMALLINT),
|
||||
array('24', null, null, SQLSRV_SQLTYPE_INT),
|
||||
array('0.24', null, null, SQLSRV_SQLTYPE_FLOAT),
|
||||
array('2016-02-01', null, null, SQLSRV_SQLTYPE_DATETIME),
|
||||
array('Red', null, null, SQLSRV_SQLTYPE_VARCHAR(20)),
|
||||
array('P002', null, null, SQLSRV_SQLTYPE_CHAR(4)),
|
||||
array('Notepad', null, null, SQLSRV_SQLTYPE_VARCHAR(128)),
|
||||
array('102', null, null, SQLSRV_SQLTYPE_SMALLINT),
|
||||
array('12', null, null, SQLSRV_SQLTYPE_INT),
|
||||
array('3.87', null, null, SQLSRV_SQLTYPE_FLOAT),
|
||||
array('2016-02-21', null, null, SQLSRV_SQLTYPE_DATETIME),
|
||||
array(null, null, null, SQLSRV_SQLTYPE_VARCHAR(20)),
|
||||
array('P001', null, null, SQLSRV_SQLTYPE_CHAR(4)),
|
||||
array('Mirror 2\"', null, null, SQLSRV_SQLTYPE_VARCHAR(128)),
|
||||
array('652', null, null, SQLSRV_SQLTYPE_SMALLINT),
|
||||
array('3', null, null, SQLSRV_SQLTYPE_INT),
|
||||
array('15.99', null, null, SQLSRV_SQLTYPE_FLOAT),
|
||||
array('2016-02-01', null, null, SQLSRV_SQLTYPE_DATETIME),
|
||||
array(null, null, null, SQLSRV_SQLTYPE_VARCHAR(20)),
|
||||
array('P003', null, null, SQLSRV_SQLTYPE_CHAR(4)),
|
||||
array('USB connector', null, null, SQLSRV_SQLTYPE_VARCHAR(128)),
|
||||
array('1652', null, null, SQLSRV_SQLTYPE_SMALLINT),
|
||||
array('31', null, null, SQLSRV_SQLTYPE_INT),
|
||||
array('9.99', null, null, SQLSRV_SQLTYPE_FLOAT),
|
||||
array('2016-02-01', null, null, SQLSRV_SQLTYPE_DATETIME),
|
||||
array(null, null, null, SQLSRV_SQLTYPE_VARCHAR(20))));
|
||||
} else {
|
||||
$sql = "INSERT INTO $tableName1 VALUES
|
||||
('P001', 'Pencil 2B', '102', '24', '0.24', '2016-02-01', 'Red'),
|
||||
('P002', 'Notepad', '102', '12', '3.87', '2016-02-21', Null),
|
||||
('P001', 'Mirror 2\"', '652', '3', '15.99', '2016-02-01', NULL),
|
||||
('P003', 'USB connector', '1652', '31', '9.99', '2016-02-01', NULL)";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
}
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to insert test data into $tableName1\n");
|
||||
}
|
||||
|
||||
// Create table Country
|
||||
$columns = array(new AE\ColumnMeta('CHAR(4)', 'SerialNumber'),
|
||||
|
@ -113,17 +143,21 @@ $columns = array(new AE\ColumnMeta('CHAR(4)', 'SerialNumber'),
|
|||
AE\createTable($conn, $tableName2, $columns);
|
||||
|
||||
// Insert data
|
||||
$params = array('P001', 'FR');
|
||||
$data = getInputData2($params);
|
||||
AE\insertRow($conn, $tableName2, $data);
|
||||
|
||||
$params = array('P002', 'UK');
|
||||
$data = getInputData2($params);
|
||||
AE\insertRow($conn, $tableName2, $data);
|
||||
|
||||
$params = array('P003', 'DE');
|
||||
$data = getInputData2($params);
|
||||
AE\insertRow($conn, $tableName2, $data);
|
||||
if (AE\isColEncrypted()) {
|
||||
$sql = "INSERT INTO $tableName2 VALUES (?, ?), (?, ?), (?, ?)";
|
||||
$stmt = sqlsrv_query($conn, $sql, array(array('P001', null, null, SQLSRV_SQLTYPE_CHAR(4)),
|
||||
array('FR', null, null, SQLSRV_SQLTYPE_VARCHAR(2)),
|
||||
array('P002', null, null, SQLSRV_SQLTYPE_CHAR(4)),
|
||||
array('UK', null, null, SQLSRV_SQLTYPE_VARCHAR(2)),
|
||||
array('P003', null, null, SQLSRV_SQLTYPE_CHAR(4)),
|
||||
array('DE', null, null, SQLSRV_SQLTYPE_VARCHAR(2))));
|
||||
} else {
|
||||
$sql = "INSERT INTO $tableName2 VALUES ('P001', 'FR'), ('P002', 'UK'), ('P003', 'DE')";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
}
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to insert test data into $tableName2\n");
|
||||
}
|
||||
|
||||
// With AE enabled, we cannot do comparisons with encrypted columns
|
||||
// Also, only forward cursor or client buffer is supported
|
||||
|
|
|
@ -9,7 +9,7 @@ Test sqlsrv_num_rows method.
|
|||
|
||||
require_once('MsCommon.inc');
|
||||
$conn = AE\connect();
|
||||
$tableName = 'utf16invalid';
|
||||
$tableName = 'testNumRows';
|
||||
|
||||
$columns = array(new AE\ColumnMeta('int', 'id', 'identity'),
|
||||
new AE\ColumnMeta('nvarchar(100)', 'c1'));
|
||||
|
@ -24,7 +24,7 @@ Test sqlsrv_num_rows method.
|
|||
} else {
|
||||
$options = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
|
||||
}
|
||||
$stmt = AE\executeQueryEx($conn, "SELECT * FROM $tableName", $options);
|
||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName", array(), $options);
|
||||
$row_nums = sqlsrv_num_rows($stmt);
|
||||
|
||||
echo $row_nums;
|
||||
|
|
|
@ -40,7 +40,7 @@ if (sqlsrv_has_rows($stmt)) {
|
|||
}
|
||||
|
||||
// Fetch data using a scrollable cursor
|
||||
$stmt = AE\executeQueryEx($conn, $query, array("Scrollable"=>"buffered"));
|
||||
$stmt = sqlsrv_query($conn, $query, [], array("Scrollable"=>"buffered"));
|
||||
|
||||
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
|
||||
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
|
||||
|
|
|
@ -60,7 +60,7 @@ if (!$stmt) {
|
|||
}
|
||||
|
||||
$query = "SELECT TOP 2 * FROM $tableName";
|
||||
$stmt = AE\executeQueryEx($conn, $query, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
|
||||
$stmt = sqlsrv_query($conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
|
||||
|
||||
$array = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
|
||||
var_dump($array);
|
||||
|
|
|
@ -73,14 +73,15 @@ for ($i = 1; $i <= $numRows; $i++) {
|
|||
// https://github.com/Microsoft/msphpsql/wiki/Features#aelimitation
|
||||
$query = "SELECT * FROM $tableName";
|
||||
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
|
||||
$stmt = AE\executeQueryEx($conn, $query, $options);
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
|
||||
hasRows($stmt, false);
|
||||
countRows($stmt, $numRows, 'forward only');
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
if (! AE\isColEncrypted()) {
|
||||
$options = array('Scrollable' => 'static');
|
||||
$stmt = AE\executeQueryEx($conn, $query, $options);
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
|
||||
$result = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, 4);
|
||||
if($result !== null) {
|
||||
|
@ -128,13 +129,14 @@ if (! AE\isColEncrypted()) {
|
|||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$options = array('Scrollable' => 'static');
|
||||
$stmt = AE\executeQueryEx($conn, $query, $options);
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
|
||||
hasRows($stmt, false);
|
||||
countRows($stmt, $numRows, 'static');
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$options = array('Scrollable' => 'dynamic');
|
||||
$stmt = AE\executeQueryEx($conn, $query, $options);
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
|
||||
sqlsrv_fetch($stmt);
|
||||
sqlsrv_fetch($stmt);
|
||||
|
@ -148,7 +150,8 @@ if (! AE\isColEncrypted()) {
|
|||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
|
||||
$stmt = AE\executeQueryEx($conn, $query, $options);
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
|
||||
$row_count = sqlsrv_num_rows($stmt);
|
||||
if($row_count != $numRows) {
|
||||
die("sqlsrv_num_rows should have returned 6 rows in the static cursor\n");
|
||||
|
@ -164,7 +167,7 @@ if (! AE\isColEncrypted()) {
|
|||
}
|
||||
|
||||
$options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC);
|
||||
$stmt = AE\executeQueryEx($conn, $query, $options);
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
|
||||
$result = sqlsrv_num_rows($stmt);
|
||||
if($result !== false) {
|
||||
|
|
Loading…
Reference in a new issue