Skip to content
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

Conversion is unnecessary for numeric parameters #1136

Merged
merged 9 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
542 changes: 276 additions & 266 deletions source/shared/core_stmt.cpp

Large diffs are not rendered by default.

35 changes: 31 additions & 4 deletions test/functional/pdo_sqlsrv/pdo_ae_insert_decimal.phpt
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
--TEST--
Test for inserting into and retrieving from decimal columns of different scale
--DESCRIPTION--
This test is similar to sqlsrv_ae_insert_decimal.phpt but it requires enabling column encryption in order
to test the rounding of decimal numbers
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");

$num = array("-10.0", "13.33", "-191.78464696202265", "833.33", "-850.00000000000006", "851.64835164835168", "-316053.16053160531", "505505.5055055055055055055", "-1535020.0615", "7501300.675013006750130067501300675", "-7540010.067540010067540010067540010067", "7540450.0675404500675404500675404500", "-820012820012820.01282001282001282001282", "1122551511225515.1122", "-1234567892112345678912.3456", "123456789012346261234567890123.4629", "-13775323913775323913775323913775323913");
$frac = array("-0.000", "0.100", "-0.1333", "0.019178464696202265", "-0.083333", "0.085000000000000006", "-0.085164835164835168", "0.0000316", "-0.00005", "0.0000153502", "-0.0000075013", "0.00000754001", "-0.00000754045", "0.000000000008200", "-0.00000000000000112255", "0.00000000000000000000123456789", "-0.00000000000000000000000123456789012346", "0.00000000000000000000000000000001377532");
$num = array("-10.0", "13.33", "-191.78464696202265", "833.33", "-850.00000000000006", "851.64835164835168", "-316053.16053160531", "505505.5055055055055055055", "-1535020.0615", "7501300.675013006750130067501300675", "-7540010.067540010067540010067540010067", "7540450.0675404500675404500675404500", "-820012820012820.01282001282001282001282", "1122551511225515.1122", "-1234567892112345678912.3456", "123456789012346261234567890123.4629", "-13775323913775323913775323913775323913", "7654");
$frac = array("-0.000", "0.100", "-0.1333", "0.019178464696202265", "-0.083333", "0.085000000000000006", "-0.085164835164835168", "0.0000316", "-0.00005", "0.0000153502", "-0.0000075013", "0.00000754001", "-0.00000754045", "0.000000000008200", "-0.00000000000000112255", "0.00000000000000000000123456789", "-0.00000000000000000000000123456789012346", "0.00000000000000000000000000000001377532", "0.88");
$numSets = array("Testing numbers greater than 1 or less than -1:" => $num,
"Testing numbers between 1 and -1:" => $frac);
$scalesToTest = array(0, 1, 2, 3, 4, 5, 7, 9, 19, 28, 38);

try {
$conn = connect();
$conn = connect("ColumnEncryption=Enabled;");
$tbname = "decimalTable";

foreach ($numSets as $testName => $numSet) {
echo "\n$testName\n";
foreach ($numSet as $input) {
Expand All @@ -35,7 +39,9 @@ try {
foreach ($decimalTypes as $key => $value) {
$insertValues = array_merge($insertValues, array($key => $input));
}
insertRow($conn, $tbname, $insertValues);

// Use prepare / execute to bind parameters
insertRow($conn, $tbname, $insertValues, "prepareBindParam");

$stmt = $conn->query("SELECT * FROM $tbname");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
Expand All @@ -47,6 +53,7 @@ try {
$conn->exec("TRUNCATE TABLE $tbname");
}
}

dropTable($conn, $tbname);
unset($conn);
} catch (PDOException $e) {
Expand Down Expand Up @@ -211,6 +218,16 @@ c4: 123456789012346261234567890123.4629
c5: 123456789012346261234567890123.46290
c7: 123456789012346261234567890123.4629000
c0: -13775323913775323913775323913775323913
c0: 7654
c1: 7654.0
c2: 7654.00
c3: 7654.000
c4: 7654.0000
c5: 7654.00000
c7: 7654.0000000
c9: 7654.000000000
c19: 7654.0000000000000000000
c28: 7654.0000000000000000000000000000

Testing numbers between 1 and -1:
c1: .1
Expand Down Expand Up @@ -306,3 +323,13 @@ c38: .00000000000000000000123456789000000000
c28: -.0000000000000000000000012346
c38: -.00000000000000000000000123456789012346
c38: .00000000000000000000000000000001377532
c0: 1
c1: .9
c2: .88
c3: .880
c4: .8800
c5: .88000
c7: .8800000
c9: .880000000
c19: .8800000000000000000
c28: .8800000000000000000000000000
117 changes: 97 additions & 20 deletions test/functional/pdo_sqlsrv/pdo_ae_insert_scientificNot.phpt
Original file line number Diff line number Diff line change
@@ -1,19 +1,80 @@
--TEST--
Test for inserting into and retrieving from decimal columns of different scale
--DESCRIPTION--
This test is similar to sqlsrv_ae_insert_scientificNot.phpt but it requires enabling column encryption in order
to test the parsing of decimal numbers in scientific notation
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");

$posExp = array(-0.00e+01, 10.0E+00, -1.333e+1, 1.9178464696202265E+2, -8.3333e+2, 8.5000000000000006E+2, -8.5164835164835168E+2, 3.16E+05, -5E+05, 1.53502e+006, -7.5013e+006, 7.54001e+006, -7.54045e+006, 820.0E+10, -1.12255E+7, 1.23456789E+9, -1.23456789012346E+7, 1.377532E+10);
$negExp = array(0.00e-01, -10.0E-00, 1.333e-1, -1.9178464696202265E-2, 8.3333e-2, -8.5000000000000006E-2, 8.5164835164835168E-2, -3.16E-01, 5E-03, -1.53502e-004, 7.5013e-004, -7.54001e-004, 7.54045e-004, -820.0E-1, 1.12255E-4, -1.23456789E-3, 1.23456789012346E-4, -1.377532E-1);
$posExp = array("-0.00e+01", "10.0E+00", "-1.333e+1", "1.9178464696202265E+2", "-8.3333e+2", "8.5000000000000006E+2", "-8.5164835164835168E+2", "3.16E+05", "-5E+05", "1.53502e+006", "-7.5013e+006", "7.54001e+006", "-7.54045e+006", "820.0E+10", "-1.12255E+7", "1.23456789E+9", "-1.23456789012346E+7", "1.377532E+10", "+.9999E3");
$negExp = array("+0.00e-01", "-10.0E-00", "1.333e-1", "-1.9178464696202265E-2", "8.3333e-2", "-8.5000000000000006E-2", "8.5164835164835168E-2", "-3.16E-01", "5E-03", "-1.53502e-004", "7.5013e-004", "-7.54001e-004", "7.54045e-004", "-820.0E-1", "1.12255E-4", "-1.23456789E-3", "1.23456789012346E-4", "-1.377532E-1", " .9999e-3");

$numSets = array("Testing numbers greater than 1 or less than -1:" => $posExp,
"Testing numbers between 1 and -1:" => $negExp);
$scalesToTest = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19);

function testErrorCases($conn)
{
// Create a dummy table
$tableName = "pdo_sci_not";
createTable($conn, $tableName, array("Column1" => "decimal(38, 1)"));

$expected = '*Invalid character value for cast specification';

$tsql = "INSERT INTO $tableName (Column1) VALUES (?)";
$input = ".1e-0+1.";

$stmt = $conn->prepare($tsql);
$stmt->bindParam(1, $input);
try {
$stmt->execute();
echo "Expect $input to fail";
} catch (PDOException $e) {
if (!fnmatch($expected, $e->GetMessage())) {
echo $e->getMessage();
}
}

$input = "10E+0.1.";
try {
$stmt->execute();
echo "Expect $input to fail";
} catch (PDOException $e) {
if (!fnmatch($expected, $e->GetMessage())) {
echo $e->getMessage();
}
}

$input = "-9E0+2";
try {
$stmt->execute();
echo "Expect $input to fail";
} catch (PDOException $e) {
if (!fnmatch($expected, $e->GetMessage())) {
echo $e->getMessage();
}
}
$input = "1234.1234.1234";
$expected = "*String data, right truncation";
try {
$stmt->execute();
echo "Expect $input to fail";
} catch (PDOException $e) {
if (!fnmatch($expected, $e->GetMessage())) {
echo $e->getMessage();
}
}
dropTable($conn, $tableName);
}

try {
$conn = connect();
$conn = connect("ColumnEncryption=Enabled;");

testErrorCases($conn);

$tbname = "decimalTable";

foreach ($numSets as $testName => $numSet) {
Expand All @@ -33,12 +94,9 @@ try {

$insertValues = array();
foreach ($decimalTypes as $key => $value) {
if (isColEncrypted()) {
$insertValues = array_merge($insertValues, array($key => strval($input)));
} else {
$insertValues = array_merge($insertValues, array($key => $input));
}
$insertValues = array_merge($insertValues, array($key => $input));
}

insertRow($conn, $tbname, $insertValues, "prepareBindParam");

$stmt = $conn->query("SELECT * FROM $tbname");
Expand Down Expand Up @@ -93,7 +151,7 @@ c6: 191.784647
c7: 191.7846470
c8: 191.78464696
c9: 191.784646962
c19: 191.7846469620200000000
c19: 191.7846469620226500000
c0: -833
c1: -833.3
c2: -833.33
Expand All @@ -115,7 +173,7 @@ c6: 850.000000
c7: 850.0000000
c8: 850.00000000
c9: 850.000000000
c19: 850.0000000000000000000
c19: 850.0000000000000600000
c0: -852
c1: -851.6
c2: -851.65
Expand All @@ -126,7 +184,7 @@ c6: -851.648352
c7: -851.6483516
c8: -851.64835165
c9: -851.648351648
c19: -851.6483516483500000000
c19: -851.6483516483516800000
c0: 316000
c1: 316000.0
c2: 316000.00
Expand Down Expand Up @@ -231,12 +289,12 @@ c1: -12345678.9
c2: -12345678.90
c3: -12345678.901
c4: -12345678.9012
c5: -12345678.90124
c5: -12345678.90123
c6: -12345678.901235
c7: -12345678.9012350
c8: -12345678.90123500
c9: -12345678.901235000
c19: -12345678.9012350000000000000
c7: -12345678.9012346
c8: -12345678.90123460
c9: -12345678.901234600
c19: -12345678.9012346000000000000
c0: 13775320000
c1: 13775320000.0
c2: 13775320000.00
Expand All @@ -248,6 +306,17 @@ c7: 13775320000.0000000
c8: 13775320000.00000000
c9: 13775320000.000000000
c19: 13775320000.0000000000000000000
c0: 1000
c1: 999.9
c2: 999.90
c3: 999.900
c4: 999.9000
c5: 999.90000
c6: 999.900000
c7: 999.9000000
c8: 999.90000000
c9: 999.900000000
c19: 999.9000000000000000000

Testing numbers between 1 and -1:
c0: -10
Expand Down Expand Up @@ -279,7 +348,7 @@ c6: -.019178
c7: -.0191785
c8: -.01917846
c9: -.019178465
c19: -.0191784646962020000
c19: -.0191784646962022650
c1: .1
c2: .08
c3: .083
Expand All @@ -299,7 +368,7 @@ c6: -.085000
c7: -.0850000
c8: -.08500000
c9: -.085000000
c19: -.0850000000000000000
c19: -.0850000000000000060
c1: .1
c2: .09
c3: .085
Expand All @@ -309,7 +378,7 @@ c6: .085165
c7: .0851648
c8: .08516484
c9: .085164835
c19: .0851648351648350000
c19: .0851648351648351680
c1: -.3
c2: -.32
c3: -.316
Expand Down Expand Up @@ -392,7 +461,7 @@ c6: .000123
c7: .0001235
c8: .00012346
c9: .000123457
c19: .0001234567890123500
c19: .0001234567890123460
c1: -.1
c2: -.14
c3: -.138
Expand All @@ -403,3 +472,11 @@ c7: -.1377532
c8: -.13775320
c9: -.137753200
c19: -.1377532000000000000
c3: .001
c4: .0010
c5: .00100
c6: .001000
c7: .0009999
c8: .00099990
c9: .000999900
c19: .0009999000000000000
18 changes: 12 additions & 6 deletions test/functional/pdo_sqlsrv/pdo_fetch_fetchinto_query_args.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
fetch columns using fetch mode and different ways of binding columns
--DESCRIPTION--
This test should not use temporary table as it might occasionally cause deadlocked transactions.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
Expand Down Expand Up @@ -27,19 +29,22 @@ function FetchInto_Query_Args()
include("MsSetup.inc");

set_time_limit(0);
$tableName = GetTempTableName();
$tableName = 'fetchinto_query_args';

$conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_nchar] nchar(512), [c16_nvarchar] nvarchar(512), [c17_nvarchar_max] nvarchar(max), [c18_text] text, [c19_ntext] ntext, [c20_binary] binary(512), [c21_varbinary] varbinary(512), [c22_varbinary_max] varbinary(max), [c23_image] image, [c24_uniqueidentifier] uniqueidentifier, [c25_datetime] datetime, [c26_smalldatetime] smalldatetime, [c27_timestamp] timestamp, [c28_xml] xml, [c29_time] time, [c30_date] date, [c31_datetime2] datetime2, [c32_datetimeoffset] datetimeoffset)");
dropTable($conn, $tableName);
$conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_nchar] nchar(512), [c16_nvarchar] nvarchar(512), [c17_nvarchar_max] nvarchar(max), [c18_text] text, [c19_ntext] ntext, [c20_binary] binary(512), [c21_varbinary] varbinary(512), [c22_varbinary_max] varbinary(max), [c23_image] image, [c24_uniqueidentifier] uniqueidentifier, [c25_datetime] datetime, [c26_smalldatetime] smalldatetime, [c27_timestamp] timestamp, [c28_xml] xml, [c29_time] time, [c30_date] date, [c31_datetime2] datetime2, [c32_datetimeoffset] datetimeoffset)");

$numRows = 0;
$query = GetQuery($tableName, ++$numRows);
$stmt = $conn->query($query);
unset($stmt);

$query = GetQuery($tableName, ++$numRows);
$stmt = $conn->query($query);
$stmt = null;
unset($stmt);

$sql = "SELECT * FROM $tableName ORDER BY c27_timestamp";
$obj1 = new PdoTestClass();
Expand All @@ -51,10 +56,11 @@ function FetchInto_Query_Args()
$stmt2->setFetchMode(PDO::FETCH_INTO, $obj2);

VerifyResults($stmt1, $stmt2, $tableName);
dropTable($conn, $tableName);

$stmt1 = null;
$stmt2 = null;
$conn = null;
unset($stmt1);
unset($stmt2);
unset($conn);
}

function VerifyResults($stmt1, $stmt2, $tableName)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/pdo_sqlsrv/pdo_insert_fetch_utf8text.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function runInOutProcWithErrors($conn, $utf8_2)

function runIntDoubleProcWithErrors($conn)
{
$sql = "{call pdoIntDoubleProc(?)}";
$sql = "{call pdoUTF8InOutProc(?)}";
$val = pack('H*', 'ffffffff');

try {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/sqlsrv/0065.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,12 @@ if ($t !== $u) {
die("Round trip failed.");
}

// $t is an invalid utf-8 string, expect the procedure to fail
$t = pack('H*', 'ffffffff');

$sqlType =
$params = array(array(&$t, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')));
$query = "{call IntDoubleProc(?)}";
$query = "{call Utf8InOutProc(?)}";
$s = AE\executeQueryParams($c, $query, $params, true, "no error from an invalid utf-8 string");

dropTable($c, $tableName);
Expand Down
Loading