Fixed tests with money or binary types

This commit is contained in:
Jenny Tam 2017-10-26 12:46:45 -07:00
parent 4d364e1a5b
commit 786bd507d2
4 changed files with 29 additions and 11 deletions

View file

@ -121,10 +121,9 @@ class BindParamOption
}
/**
* @param mix $var : variable to bind to the SQL statement parameter
* @return array needed to bind parameter in sqlsrv_prepare
*/
public function bindParamArr($var)
public function bindParamArr()
{
// get the constant values of direction, phpType, and sqlType
$direction = null;
@ -182,7 +181,7 @@ class BindParamOption
echo $e->getMessage();
}
}
return array($var, $direction, $phpType, $sqlType);
return array($this->value, $direction, $phpType, $sqlType);
}
}
@ -417,19 +416,19 @@ 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());
} 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);
if ($stmt) {
$r = sqlsrv_execute($stmt);
} else {
fatalError("insertRow: failed to prepare insert query!");
fatalError("insertRow: failed to prepare insert query!");
}
} else {
$stmt = sqlsrv_query($conn, $insertSql, $params);

View file

@ -25,8 +25,15 @@ function paramQuery($minType, $maxType)
if ($data != null) {
$sqlType = getSqlType($k);
$phpDriverType = getSqlsrvSqlType($k, strlen($data));
if ($k == 10 || $k == 11) {
// do not encrypt money type -- ODBC restrictions
$noEncrypt = true;
} else {
$noEncrypt = false;
}
$columns = array(new AE\ColumnMeta('int', 'c1'),
new AE\ColumnMeta($sqlType, 'c2'));
new AE\ColumnMeta($sqlType, 'c2', null, true, $noEncrypt));
traceData($sqlType, $data);
$res = null;

View file

@ -39,7 +39,15 @@ function transaction($minType, $maxType)
$sqlType = getSqlType($k);
$driverType = getSqlsrvSqlType($k, $dataSize);
AE\createTable($conn1, $tableName, array(new AE\ColumnMeta($sqlType, $colName)));
if ($k == 10 || $k == 11) {
// do not encrypt money type -- ODBC restrictions
$noEncrypt = true;
} else {
$noEncrypt = false;
}
$columns = array(new AE\ColumnMeta($sqlType, $colName, null, true, $noEncrypt));
AE\createTable($conn1, $tableName, $columns);
createTransactionProc($conn1, $tableName, $colName, $procName, $sqlType);
$noRows = execTransactionProc($conn1, $procName, $data, $driverType, true);

View file

@ -55,8 +55,7 @@ function main($minType, $maxType)
$sqlType = getSqlType($k);
// for each data type create a table with two columns, 1: dataType id 2: data type
$dataType = "[$columnNames[0]] int, [$columnNames[1]] $sqlType";
// createTableEx($conn, $tableName, $dataType);
// $dataType = "[$columnNames[0]] int, [$columnNames[1]] $sqlType";
if ($k == 10 || $k == 11) {
// do not encrypt money type -- ODBC restrictions
$noEncrypt = true;
@ -239,7 +238,12 @@ function getData($k, $initData)
}
try {
main(1, 22);
if (AE\isColEncrypted()) {
// TODO: fix this test to work with binary types when enabling AE
main(1, 17);
} else {
main(1, 22);
}
} catch (Exception $e) {
echo $e->getMessage();
}