2
2
This test verifies that GitHub issue #378 is fixed.
3
3
--DESCRIPTION--
4
4
GitHub issue #378 - output parameters appends garbage info when variable is initialized with different data type
5
- steps to reproduce the issue:
5
+ Steps to reproduce the issue:
6
6
1- create a store procedure with print and output parameter
7
7
2- initialize output parameters to a different data type other than the type declared in sp.
8
8
3- set the WarningsReturnAsErrors to true
9
9
4- call sp.
10
+ Also check error conditions by passing output parameters NOT by reference.
11
+ --ENV--
12
+ PHPT_EXEC=true
10
13
--SKIPIF--
11
14
<?php require ('skipif_versions_old.inc ' ); ?>
12
15
--FILE--
@@ -19,11 +22,8 @@ $conn = AE\connect();
19
22
$ procName = 'test_378 ' ;
20
23
createSP ($ conn , $ procName );
21
24
22
- sqlsrv_configure ('WarningsReturnAsErrors ' , true );
23
- executeSP ($ conn , $ procName );
24
-
25
- sqlsrv_configure ('WarningsReturnAsErrors ' , false );
26
- executeSP ($ conn , $ procName );
25
+ runTests ($ conn , $ procName , true );
26
+ runTests ($ conn , $ procName , false );
27
27
28
28
dropProc ($ conn , $ procName );
29
29
echo "Done \n" ;
@@ -46,22 +46,79 @@ function createSP($conn, $procName)
46
46
}
47
47
}
48
48
49
- function executeSP ($ conn , $ procName )
49
+ //-------------------functions-------------------
50
+ function runTests ($ conn , $ procName , $ warningAsErrors )
51
+ {
52
+ sqlsrv_configure ('WarningsReturnAsErrors ' , $ warningAsErrors );
53
+
54
+ trace ("\nWarningsReturnAsErrors: $ warningAsErrors \n" );
55
+
56
+ executeSP ($ conn , $ procName , true , false );
57
+ executeSP ($ conn , $ procName , true , true );
58
+ executeSP ($ conn , $ procName , false , false );
59
+ executeSP ($ conn , $ procName , false , true );
60
+ }
61
+
62
+ function compareErrors ()
63
+ {
64
+ $ message = 'Variable parameter 3 not passed by reference (prefaced with an &). Output or bidirectional variable parameters (SQLSRV_PARAM_OUT and SQLSRV_PARAM_INOUT) passed to sqlsrv_prepare or sqlsrv_query should be passed by reference, not by value. ' ;
65
+
66
+ $ error = sqlsrv_errors ()[0 ]['message ' ];
67
+
68
+ if ($ error !== $ message ) {
69
+ print_r (sqlsrv_errors (), true );
70
+ return ;
71
+ }
72
+
73
+ trace ("Comparing errors: matched! \n" );
74
+ }
75
+
76
+ function executeSP ($ conn , $ procName , $ noRef , $ prepare )
50
77
{
51
78
$ expected = 3 ;
52
79
$ v1 = 1 ;
53
80
$ v2 = 2 ;
54
81
$ v3 = 'str ' ;
55
82
56
83
$ res = true ;
57
- if (AE \isColEncrypted ()) {
58
- $ stmt = sqlsrv_prepare ($ conn , "{call $ procName( ?, ?, ?)} " , array ($ v1 , $ v2 , array (&$ v3 , SQLSRV_PARAM_OUT )));
84
+ $ tsql = "{call $ procName( ?, ?, ?)} " ;
85
+
86
+ if ($ noRef ) {
87
+ $ params = array ($ v1 , $ v2 , array ($ v3 , SQLSRV_PARAM_OUT ));
88
+ } else {
89
+ $ params = array ($ v1 , $ v2 , array (&$ v3 , SQLSRV_PARAM_OUT ));
90
+ }
91
+
92
+ trace ("No reference: $ noRef \n" );
93
+ trace ("Use prepared stmt: $ prepare \n" );
94
+
95
+ if (AE \isColEncrypted () || $ prepare ) {
96
+ $ stmt = sqlsrv_prepare ($ conn , $ tsql , $ params );
59
97
if ($ stmt ) {
60
98
$ res = sqlsrv_execute ($ stmt );
99
+ } else {
100
+ fatalError ("executeSP: failed in preparing statement with reference( $ noRef) " );
61
101
}
102
+ if ($ noRef ) {
103
+ if ($ res !== false ) {
104
+ echo "Expect this to fail! \n" ;
105
+ }
106
+ compareErrors ();
107
+ return ;
108
+ }
62
109
} else {
63
- $ stmt = sqlsrv_query ($ conn , "{call $ procName( ?, ?, ?)} " , array ($ v1 , $ v2 , array (&$ v3 , SQLSRV_PARAM_OUT )));
110
+ $ stmt = sqlsrv_query ($ conn , $ tsql , $ params );
111
+ if ($ noRef ) {
112
+ if ($ stmt !== false ) {
113
+ echo "Expect this to fail! \n" ;
114
+ }
115
+ compareErrors ();
116
+ return ;
117
+ }
64
118
}
119
+
120
+ trace ("No errors: $ v3 and $ expected \n" );
121
+ // No errors expected
65
122
if ($ stmt === false || !$ res ) {
66
123
print_r (sqlsrv_errors (), true );
67
124
}
0 commit comments