Fixed coding style to comply with standard
This commit is contained in:
parent
f8af52bf26
commit
a69daf2beb
|
@ -50,7 +50,7 @@ function CompareDateTime($datetimetype, $returnStrings, &$expectedDateTime, $ret
|
|||
|
||||
// Split each element of the testing date/time into
|
||||
// [0]:date, [1]:time, and possibly [2]:timezone offset
|
||||
for ($i=0; $i<sizeof($expectedDateTime); ++$i) {
|
||||
for ($i = 0; $i < sizeof($expectedDateTime); ++$i) {
|
||||
$expected_date_time[] = explode(" ", $expectedDateTime[$i]);
|
||||
}
|
||||
|
||||
|
@ -128,8 +128,7 @@ function CompareDateTime($datetimetype, $returnStrings, &$expectedDateTime, $ret
|
|||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Combine the retrieved date and time.
|
||||
if (sizeof($retrieved_date_time)>1) {
|
||||
$date_time_only = $retrieved_date_time[0]." ".$retrieved_date_time[1];
|
||||
|
@ -195,7 +194,8 @@ function InsertDatesAndOrTimes($conn, $datetimetype, &$formats_array, $array_siz
|
|||
}
|
||||
|
||||
$insertSql = "INSERT INTO [$tableName] (id, [c1_$datetimetype]) VALUES (?, ?)";
|
||||
for ($i=0; $i<$array_size; $i++) {
|
||||
|
||||
for ($i = 0; $i < $array_size; $i++) {
|
||||
$stmt = sqlsrv_prepare($conn, $insertSql, array($i, array($formats_array[$i], SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), $SQLSRV_SQLTYPE_CONST)));
|
||||
ExecutePreparedStmt($stmt);
|
||||
$stmt = sqlsrv_prepare($conn, $insertSql, array($i, $formats_array[$i]));
|
||||
|
@ -274,8 +274,7 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$expectedDateTime, $returnD
|
|||
}
|
||||
|
||||
CompareDateTime($datetimetype, $returnDatesAsStrings, $expectedDateTime, $datetime);
|
||||
}
|
||||
else { // ReturnsDatesAsStrings is false
|
||||
} else { // ReturnsDatesAsStrings is false
|
||||
if (!($datetime instanceof DateTime)) {
|
||||
fatalError("DateTime object expected, not a DateTime");
|
||||
}
|
||||
|
@ -303,8 +302,7 @@ function FetchDatesAndOrTimes($conn, $datetimetype, &$expectedDateTime, $returnD
|
|||
}
|
||||
|
||||
CompareDateTime($datetimetype, $returnDatesAsStrings, $expectedDateTime, $row[1]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!($row[1] instanceof DateTime)) {
|
||||
fatalError("DateTime object expected, not a DateTime");
|
||||
}
|
||||
|
@ -416,8 +414,7 @@ for ($i=0; $i<$SZ_DATE_all; $i++)
|
|||
$datetimeoffset_formats_all[] = $date_formats_all[$i]." ".$time_formats_all[$j].$tz_correction;
|
||||
if (str_replace(".".$frac.$frac2, "", $date_formats_all[$i]." ".$time_formats_all[$j]) == ($date_formats_all[$i]." ".$time_formats_all[$j])) {
|
||||
$datetimesmall_formats_all[] = str_replace(".".$frac, "", $date_formats_all[$i]." ".$time_formats_all[$j]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$datetimesmall_formats_all[] = str_replace(".".$frac.$frac2, "", $date_formats_all[$i]." ".$time_formats_all[$j]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
--TEST--
|
||||
Test insert various data types and fetch as strings
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
@ -16,7 +18,7 @@ function FormulateSetupQuery($tableName, &$dataTypes, &$columns, &$insertQuery,
|
|||
$valuesString = "VALUES (";
|
||||
$numTypes = sizeof($dataTypes);
|
||||
|
||||
for ($i=0; $i<$numTypes; ++$i) {
|
||||
for ($i = 0; $i < $numTypes; ++$i) {
|
||||
// Replace parentheses for column names
|
||||
$colname = str_replace("($strsize)", "_$strsize", $dataTypes[$i]);
|
||||
$colname = str_replace("($strsize2)", "_$strsize2", $colname);
|
||||
|
@ -87,12 +89,11 @@ if (!$stmt) {
|
|||
}
|
||||
|
||||
// The data we test against is in values.php
|
||||
for ($v=0; $v<sizeof($values);++$v)
|
||||
for ($v = 0; $v < sizeof($values);++$v)
|
||||
{
|
||||
// Each value must be inserted twice because the AE and non-AE column are side by side.
|
||||
$testValues = array();
|
||||
for ($i=0; $i<sizeof($values[$v]); ++$i)
|
||||
{
|
||||
for ($i=0; $i<sizeof($values[$v]); ++$i) {
|
||||
$testValues[] = $values[$v][$i];
|
||||
$testValues[] = $values[$v][$i];
|
||||
}
|
||||
|
@ -105,7 +106,7 @@ for ($v=0; $v<sizeof($values);++$v)
|
|||
fatalError("sqlsrv_prepare failed\n");
|
||||
}
|
||||
|
||||
for ($i=0; $i<sizeof($SQLSRV_PHPTYPE_CONST); ++$i) {
|
||||
for ($i = 0; $i < sizeof($SQLSRV_PHPTYPE_CONST); ++$i) {
|
||||
if (sqlsrv_execute($stmt) == false) {
|
||||
print_r(sqlsrv_errors());
|
||||
fatalError("sqlsrv_execute failed\n");
|
||||
|
@ -131,16 +132,14 @@ for ($v=0; $v<sizeof($values);++$v)
|
|||
$metadata = sqlsrv_field_metadata($stmt);
|
||||
$numFields = count($metadata);
|
||||
|
||||
$i=0;
|
||||
$i = 0;
|
||||
$valueAE = null;
|
||||
$valueArrayAE = null;
|
||||
|
||||
while ($result = sqlsrv_fetch($stmt))
|
||||
{
|
||||
while ($result = sqlsrv_fetch($stmt)) {
|
||||
$dataArray = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_NUMERIC);
|
||||
|
||||
for ($j = 0; $j < $numFields; $j++)
|
||||
{
|
||||
for ($j = 0; $j < $numFields; $j++) {
|
||||
$value = sqlsrv_get_field($stmt, $j, $SQLSRV_PHPTYPE_CONST[$i]);
|
||||
$valueArray = $dataArray[$j];
|
||||
|
||||
|
@ -149,13 +148,10 @@ for ($v=0; $v<sizeof($values);++$v)
|
|||
|
||||
// For each type, the AE values come first and non-AE values second
|
||||
// So let's do the comparison every second field
|
||||
if ($j%2 == 0)
|
||||
{
|
||||
if ($j%2 == 0) {
|
||||
$valueAE = $value;
|
||||
$valueArrayAE = $valueArray;
|
||||
}
|
||||
else if ($j%2 == 1)
|
||||
{
|
||||
} elseif ($j%2 == 1) {
|
||||
// If returning a DateTime PHP type from a date only SQL type,
|
||||
// PHP adds the current timestamp to make a DateTime object,
|
||||
// and in this case the AE and non-AE times may be off by a
|
||||
|
@ -163,20 +159,18 @@ for ($v=0; $v<sizeof($values);++$v)
|
|||
// different times. This not a test-failing discrepancy, so
|
||||
// below the DateTime objects are made equal again for the next if
|
||||
// block.
|
||||
if ($value instanceof DateTime)
|
||||
{
|
||||
if ($value instanceof DateTime) {
|
||||
// date_diff returns a DateInterval object, and f is
|
||||
// the difference expressed as a fraction of a second
|
||||
$datediff = date_diff($value, $valueAE);
|
||||
$diff = $datediff->f;
|
||||
|
||||
if ($diff < 1.0 and $diff > -1.0)
|
||||
{
|
||||
if ($diff < 1.0 and $diff > -1.0) {
|
||||
$value = $valueAE;
|
||||
}
|
||||
}
|
||||
if ($valueAE != $value or $valueArrayAE != $valueArray)
|
||||
{
|
||||
|
||||
if ($valueAE != $value or $valueArrayAE != $valueArray) {
|
||||
echo "Values do not match! PHPType $i Field $j\n";
|
||||
print_r($valueAE);echo "\n";
|
||||
print_r($value);echo "\n";
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
--TEST--
|
||||
Test insert various data types and fetch as strings
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
@ -15,7 +17,7 @@ function FormulateSetupQuery($tableName, &$dataTypes, &$columns, &$insertQuery,
|
|||
$valuesString = "VALUES (";
|
||||
$numTypes = sizeof($dataTypes);
|
||||
|
||||
for ($i=0; $i<$numTypes; ++$i) {
|
||||
for ($i = 0; $i < $numTypes; ++$i) {
|
||||
// Replace parentheses for column names
|
||||
$colname = str_replace("($strsize)", "_$strsize", $dataTypes[$i]);
|
||||
$colname = str_replace("($strsize2)", "_$strsize2", $colname);
|
||||
|
@ -44,11 +46,9 @@ function FormulateSelectQuery($tableName, &$selectQuery, &$selectQueryAE, &$data
|
|||
{
|
||||
$numTypes = sizeof($dataTypes);
|
||||
|
||||
for ($i=0; $i<$numTypes; ++$i)
|
||||
{
|
||||
for ($i = 0; $i < $numTypes; ++$i) {
|
||||
$selectQuery[] = array();
|
||||
for ($j=0; $j<sizeof($dataTypes); ++$j)
|
||||
{
|
||||
for ($j = 0; $j < sizeof($dataTypes); ++$j) {
|
||||
$colnamei = str_replace("($strsize)", "_$strsize", $dataTypes[$i]);
|
||||
$colnamei = str_replace("($strsize2)", "_$strsize2", $colnamei);
|
||||
$colnamei = str_replace("(max)", "_max", $colnamei);
|
||||
|
@ -188,12 +188,11 @@ if (!$stmt) {
|
|||
}
|
||||
|
||||
// The data we test against is in values.php
|
||||
for ($v=0; $v<sizeof($values); ++$v)
|
||||
for ($v = 0; $v < sizeof($values); ++$v)
|
||||
{
|
||||
// Each value must be inserted twice because the AE and non-AE column are side by side.
|
||||
$testValues = array();
|
||||
for ($i=0; $i<sizeof($values[$v]); ++$i)
|
||||
{
|
||||
for ($i = 0; $i < sizeof($values[$v]); ++$i) {
|
||||
$testValues[] = $values[$v][$i];
|
||||
$testValues[] = $values[$v][$i];
|
||||
}
|
||||
|
@ -217,14 +216,11 @@ for ($v=0; $v<sizeof($values); ++$v)
|
|||
$selectQueryAE = array();
|
||||
FormulateSelectQuery($tableName, $selectQuery, $selectQueryAE, $dataTypes, $strsize, $strsize2);
|
||||
|
||||
for ($i=0; $i<sizeof($dataTypes); ++$i)
|
||||
{
|
||||
for ($j=0; $j<sizeof($dataTypes); ++$j)
|
||||
{
|
||||
for ($i = 0; $i < sizeof($dataTypes); ++$i) {
|
||||
for ($j = 0; $j < sizeof($dataTypes); ++$j) {
|
||||
$stmt = sqlsrv_query($conn, $selectQuery[$i][$j]);
|
||||
|
||||
if ($stmt == false)
|
||||
{
|
||||
if ($stmt == false) {
|
||||
$convError = sqlsrv_errors();
|
||||
|
||||
// These are the errors we expect to see if a conversion fails.
|
||||
|
@ -236,8 +232,7 @@ for ($v=0; $v<sizeof($values); ++$v)
|
|||
$convError[0][1] != '6234' and
|
||||
$convError[0][1] != '6522' and
|
||||
$convError[0][1] != '8114' and
|
||||
$convError[0][1] != '8169')
|
||||
{
|
||||
$convError[0][1] != '8169') {
|
||||
print_r($convError);
|
||||
fatalError("Conversion failed with unexpected error message. i=$i, j=$j\n");
|
||||
}
|
||||
|
@ -248,54 +243,41 @@ for ($v=0; $v<sizeof($values); ++$v)
|
|||
// if the non-AE conversion fails, certainly the AE conversion
|
||||
// should fail but only with error 22018.
|
||||
if ($stmtAE != false) fatalError("AE conversion should have failed. i=$i, j=$j\n\n");
|
||||
if ($convError[0][0] != '22018')
|
||||
{
|
||||
if ($convError[0][0] != '22018') {
|
||||
print_r($convError);
|
||||
fatalError("AE conversion failed with unexpected error message. i=$i, j=$j\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($conversionMatrix[$i][$j] == 'x') fatalError("Conversion succeeded, should have failed. i=$i, j=$j\n");
|
||||
$stmtAE = sqlsrv_query($conn, $selectQueryAE[$i][$j]);
|
||||
|
||||
// Check every combination of statement value and conversion.
|
||||
// The last else if block covers the case where the select
|
||||
// query worked and the retrieved values are compared.
|
||||
if ($stmtAE == false and $conversionMatrixAE[$i][$j] == 'x')
|
||||
{
|
||||
if ($stmtAE == false and $conversionMatrixAE[$i][$j] == 'x') {
|
||||
$convError = sqlsrv_errors();
|
||||
if ($convError[0][0] != '22018')
|
||||
{
|
||||
if ($convError[0][0] != '22018') {
|
||||
print_r($convError);
|
||||
fatalError("AE conversion failed with unexpected error message. i=$i, j=$j\n");
|
||||
}
|
||||
}
|
||||
else if ($stmtAE == false and $conversionMatrixAE[$i][$j] == 'y')
|
||||
{
|
||||
} elseif ($stmtAE == false and $conversionMatrixAE[$i][$j] == 'y') {
|
||||
print_r(sqlsrv_errors());
|
||||
fatalError("AE conversion failed, should have succeeded. i=$i, j=$j\n");
|
||||
}
|
||||
else if ($stmtAE != false and $conversionMatrixAE[$i][$j] == 'x')
|
||||
{
|
||||
} elseif ($stmtAE != false and $conversionMatrixAE[$i][$j] == 'x') {
|
||||
fatalError("AE conversion succeeded, should have failed. i=$i, j=$j\n");
|
||||
}
|
||||
else if ($stmtAE != false and $conversionMatrixAE[$i][$j] == 'y')
|
||||
{
|
||||
} elseif ($stmtAE != false and $conversionMatrixAE[$i][$j] == 'y') {
|
||||
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
|
||||
$rowAE = sqlsrv_fetch_array($stmtAE, SQLSRV_FETCH_NUMERIC);
|
||||
|
||||
// rtrim strips whitespace from the end of the string, which
|
||||
// takes care of a bug where some conversions lead to extraneous
|
||||
// whitespace padding the end of the string
|
||||
if (is_string($row[0]))
|
||||
{
|
||||
if (is_string($row[0])) {
|
||||
$row[0] = rtrim($row[0]);
|
||||
$rowAE[0] = rtrim($rowAE[0]);
|
||||
}
|
||||
|
||||
if ($row[0] != $rowAE[0])
|
||||
{
|
||||
if ($row[0] != $rowAE[0]) {
|
||||
echo "Values do not match! i=$i, j=$j\n";
|
||||
print_r($row[0]);
|
||||
print_r($rowAE[0]);
|
||||
|
@ -310,8 +292,7 @@ for ($v=0; $v<sizeof($values); ++$v)
|
|||
|
||||
$deleteQuery = "DELETE FROM $tableName";
|
||||
$stmt = sqlsrv_query($conn, $deleteQuery);
|
||||
if ($stmt == false)
|
||||
{
|
||||
if ($stmt == false) {
|
||||
print_r(sqlsrv_errors());
|
||||
fatalError("Delete statement failed");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue