Skip to content

Added select type conversion test #783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2018
Merged

Added select type conversion test #783

merged 2 commits into from
May 28, 2018

Conversation

david-puglielli
Copy link
Contributor

@david-puglielli david-puglielli commented May 26, 2018

This change is Reviewable

@david-puglielli david-puglielli requested a review from yitam May 26, 2018 04:55
@coveralls
Copy link

coveralls commented May 26, 2018

Coverage Status

Coverage remained the same at 74.697% when pulling c348aad on david-puglielli:type-conversion-for-ae into 45f422a on Microsoft:dev.

@codecov-io
Copy link

codecov-io commented May 26, 2018

Codecov Report

Merging #783 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     #783   +/-   ##
=======================================
  Coverage   80.06%   80.06%           
=======================================
  Files          25       25           
  Lines        7323     7323           
=======================================
  Hits         5863     5863           
  Misses       1460     1460
Impacted Files Coverage Δ
...php-7.1.18-src/ext/pdo_sqlsrv/shared/core_sqlsrv.h 81.52% <0%> (ø) ⬆️
...x86/php-7.1.18-src/ext/sqlsrv/shared/core_sqlsrv.h 85.38% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45f422a...c348aad. Read the comment docs.

Copy link
Contributor

@yitam yitam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please summarize what you have changed in values.php.

@@ -174,7 +174,7 @@ const int SQL_SERVER_MAX_PRECISION = 38;
const int SQL_SERVER_MAX_TYPE_SIZE = 0;
const int SQL_SERVER_MAX_PARAMS = 2100;
// increase the maximum message length to accommodate for the long error returned for operand type clash
const int SQL_MAX_ERROR_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH * 7;
const int SQL_MAX_ERROR_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH * 8;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extend the comment above to explain why the error message length can be very long

@@ -0,0 +1,302 @@
--TEST--
Test fetching data by conversion with CAST in the SELECT statement
--SKIPIF--
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a DESCRIPTION section to give some examples of what this test is about


for ($i = 0; $i < $numTypes; ++$i) {
$selectQuery[] = array();
$colnamei = str_replace(array("(", ",", ")"), array("_", "_", ""), $dataTypes[$i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to show an example of a typical $dataTypes[$i] and what $colnamei will end up to be


// Conversion matrix for SQL types, based on the conversion chart
// at https://www.microsoft.com/en-us/download/details.aspx?id=35834
// i = implicit conversion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the reference page(s) that justify(ies) why some casting work and some don't?
Please add this link to the DESCRIPTION section as well

// @ = not applicable
// c = explicit CAST required
// m = misc
$conversionMatrix = array(array('@','i','i','i','i','i','i','i','i','i','i','e','e','e','e','i','i','x','x','i','i','i','i','i','i','i','i','i','i','i','e','e','e','i','i'),//binary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does misc mean in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specialised xml conversions, no longer in the matrix in this test so I've removed it.

if ($stmt == false) {
print_r(sqlsrv_errors());
fatalError("sqlsrv_prepare failed\n");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember fatalError() will also print sqlsrv errors, so to print them before calling fatalError() is redundant...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I recall, it prints only the message itself and not the code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need the error codes?

$convError = sqlsrv_errors();

// if the non-AE conversion fails, certainly the AE conversion
// should fail but only with error 22018.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend the comment to include the meaning of 22018 - Conversion not allowed - such that we don't need to scroll all the way up to know what it means

} elseif ($stmtAE != false and $conversionMatrixAE[$i][$j] == 'x') {
fatalError("AE conversion succeeded, should have failed. i=$i, j=$j, v=$v\n");
} elseif ($stmtAE != false and $conversionMatrixAE[$i][$j] == 'y') {
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: rearrange the above if...else block such that:

if (!$stmtAE) {
   if ($conversionMatrixAE[$i][$j] == 'x') {
      ...
   } else { // ($conversionMatrixAE[$i][$j] == 'y') 
      ...
   }
} else { // query succeeded
   if ($conversionMatrixAE[$i][$j] == 'x') {
      ...
   } elseif ($conversionMatrixAE[$i][$j] == 'y') {
      ...
   }
}

print_r($row[0]);
print_r($rowAE[0]);
fatalError("Test failed, values do not match\n");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion not to call fatalError() here when a test case failed. Perhaps printing what fail is enough such that the rest of test cases will continue.

}

$deleteQuery = "DELETE FROM $tableName";
$stmt = sqlsrv_query($conn, $deleteQuery);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use TRUNCATE $tableName instead
From DOCS: "Removes all rows from a table or specified partitions of a table, without logging the individual row deletions. TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources."

Copy link
Contributor

@yitam yitam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@david-puglielli david-puglielli merged commit 13144d9 into microsoft:dev May 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants