some invalid scenarios
This commit is contained in:
parent
e8f565daae
commit
4cacc6c770
142
test/sqlsrv/sqlsrv_fetch_invalid_types.phpt
Normal file
142
test/sqlsrv/sqlsrv_fetch_invalid_types.phpt
Normal file
File diff suppressed because one or more lines are too long
120
test/sqlsrv/sqlsrv_param_query_errors.phpt
Normal file
120
test/sqlsrv/sqlsrv_param_query_errors.phpt
Normal file
|
@ -0,0 +1,120 @@
|
|||
--TEST--
|
||||
Test various Katmai types, like geography, geometry, hierarchy, sparse, etc. and fetch them back as strings
|
||||
--FILE--
|
||||
<?php
|
||||
include 'tools.inc';
|
||||
|
||||
function ParamQueryError_PhpType_Mismatch($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array(1.5, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, SQLSRV_SQLTYPE_VARCHAR('max'))));
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
|
||||
$result = sqlsrv_fetch($stmt);
|
||||
if (! $result)
|
||||
{
|
||||
echo "Fetch should succeed\n";
|
||||
}
|
||||
$value = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||
var_dump($value);
|
||||
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
||||
var_dump($value);
|
||||
}
|
||||
|
||||
function ParamQueryError_Dir_Invalid($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", 32, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
|
||||
|
||||
print handle_errors() . "\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", 'SQLSRV_PARAM_INTERNAL', SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
|
||||
|
||||
print handle_errors() . "\n";
|
||||
}
|
||||
|
||||
function ParamQueryError_PhpType_Encoding($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('SQLSRV_ENC_UNKNOWN'), null)));
|
||||
print handle_errors() . "\n";
|
||||
}
|
||||
|
||||
function ParamQueryError_PhpType_Invalid($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN', SQLSRV_SQLTYPE_VARCHAR('max'))));
|
||||
print handle_errors() . "\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, 6, SQLSRV_SQLTYPE_VARCHAR('max'))));
|
||||
print handle_errors() . "\n";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
StartTest("sqlsrv_param_query_errors");
|
||||
try
|
||||
{
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
require_once("autonomous_setup.php");
|
||||
$database = "tempdb";
|
||||
|
||||
// Connect
|
||||
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
|
||||
$conn = sqlsrv_connect($serverName, $connectionInfo);
|
||||
if( !$conn ) { FatalError("Could not connect.\n"); }
|
||||
|
||||
ParamQueryError_PhpType_Mismatch($conn);
|
||||
ParamQueryError_Dir_Invalid($conn);
|
||||
ParamQueryError_PhpType_Encoding($conn);
|
||||
ParamQueryError_PhpType_Invalid($conn);
|
||||
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
EndTest("sqlsrv_param_query_errors");
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
...Starting 'sqlsrv_param_query_errors' test...
|
||||
string(1) "1"
|
||||
string(3) "1.5"
|
||||
An invalid direction for parameter 2 was specified. SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, and SQLSRV_PARAM_INOUT are valid values.
|
||||
An invalid direction for parameter 2 was specified. SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, and SQLSRV_PARAM_INOUT are valid values.
|
||||
An invalid PHP type for parameter 2 was specified.
|
||||
An invalid PHP type for parameter 2 was specified.
|
||||
An invalid PHP type for parameter 2 was specified.
|
||||
|
||||
Done
|
||||
...Test 'sqlsrv_param_query_errors' completed successfully.
|
97
test/sqlsrv/sqlsrv_param_query_invalid_inputs.phpt
Normal file
97
test/sqlsrv/sqlsrv_param_query_invalid_inputs.phpt
Normal file
|
@ -0,0 +1,97 @@
|
|||
--TEST--
|
||||
Test various Katmai types, like geography, geometry, hierarchy, sparse, etc. and fetch them back as strings
|
||||
--FILE--
|
||||
<?php
|
||||
include 'tools.inc';
|
||||
|
||||
function ParamQueryError_MinMaxScale($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_decimal] decimal(28,4), [c3_numeric] numeric(32,4))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(28, 34))));
|
||||
print handle_errors() . "\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(32, -1))));
|
||||
print handle_errors() . "\n";
|
||||
}
|
||||
|
||||
function ParamQueryError_MinMaxSize($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(0))));
|
||||
print handle_errors() . "\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(9000))));
|
||||
print handle_errors() . "\n";
|
||||
}
|
||||
|
||||
function ParamQueryError_MinMaxPrecision($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_decimal] decimal(28,4), [c3_numeric] numeric(32,4))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(40, 0))));
|
||||
print handle_errors() . "\n";
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(-1, 0))));
|
||||
print handle_errors() . "\n";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
StartTest("sqlsrv_param_query_invalid_inputs");
|
||||
try
|
||||
{
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
require_once("autonomous_setup.php");
|
||||
$database = "tempdb";
|
||||
|
||||
// Connect
|
||||
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
|
||||
$conn = sqlsrv_connect($serverName, $connectionInfo);
|
||||
if( !$conn ) { FatalError("Could not connect.\n"); }
|
||||
|
||||
ParamQueryError_MinMaxScale($conn);
|
||||
ParamQueryError_MinMaxSize($conn);
|
||||
ParamQueryError_MinMaxPrecision($conn);
|
||||
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
EndTest("sqlsrv_param_query_invalid_inputs");
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
...Starting 'sqlsrv_param_query_invalid_inputs' test...
|
||||
An invalid size or precision for parameter 2 was specified.
|
||||
An invalid size or precision for parameter 2 was specified.
|
||||
An invalid size or precision for parameter 2 was specified.
|
||||
An invalid size or precision for parameter 2 was specified.
|
||||
An invalid size or precision for parameter 2 was specified.
|
||||
An invalid size or precision for parameter 2 was specified.
|
||||
|
||||
Done
|
||||
...Test 'sqlsrv_param_query_invalid_inputs' completed successfully.
|
Loading…
Reference in a new issue