Line data Source code
1 : #include "common.h"
2 :
3 : /* Test for {?=call store(?,123,'foo')} syntax and run */
4 :
5 10 : TEST_MAIN()
6 : {
7 : SQLINTEGER input, output;
8 : SQLINTEGER out1;
9 : SQLLEN ind, ind2, ind3;
10 : const char *sql;
11 :
12 10 : odbc_connect();
13 :
14 10 : if (odbc_command_with_result(odbc_stmt, "drop proc const_param") != SQL_SUCCESS)
15 10 : printf("Unable to execute statement\n");
16 :
17 10 : odbc_command("create proc const_param @in1 int, @in2 int, @in3 datetime, @in4 varchar(10), @out int output as\n"
18 : "begin\n"
19 : " set nocount on\n"
20 : " select @out = 7654321\n"
21 : " if (@in1 <> @in2 and @in2 is not null) or @in3 <> convert(datetime, '2004-10-15 12:09:08') or @in4 <> 'foo'\n"
22 : " select @out = 1234567\n"
23 : " return 24680\n"
24 : "end");
25 :
26 10 : CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &input, 0, &ind, "S");
27 10 : CHKBindParameter(2, SQL_PARAM_OUTPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &out1, 0, &ind2, "S");
28 :
29 : /* TODO use {ts ...} for date */
30 10 : CHKPrepare(T("{call const_param(?, 13579, '2004-10-15 12:09:08', 'foo', ?)}"), SQL_NTS, "S");
31 :
32 10 : input = 13579;
33 10 : ind = sizeof(input);
34 10 : out1 = output = 0xdeadbeef;
35 10 : CHKExecute("S");
36 :
37 10 : if (out1 != 7654321) {
38 0 : fprintf(stderr, "Invalid output %d (0x%x)\n", (int) out1, (int) out1);
39 0 : return 1;
40 : }
41 :
42 : /* just to reset some possible buffers */
43 10 : odbc_command("DECLARE @i INT");
44 :
45 : /* MS ODBC don't support empty parameters altough documented so avoid this test */
46 10 : if (odbc_driver_is_freetds()) {
47 :
48 10 : CHKBindParameter(1, SQL_PARAM_OUTPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &output, 0, &ind, "S");
49 10 : CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &input, 0, &ind2, "S");
50 10 : CHKBindParameter(3, SQL_PARAM_OUTPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &out1, 0, &ind3, "S");
51 :
52 : /* TODO use {ts ...} for date */
53 10 : CHKPrepare(T("{?=call const_param(?, , '2004-10-15 12:09:08', 'foo', ?)}"), SQL_NTS, "S");
54 :
55 10 : input = 13579;
56 10 : ind2 = sizeof(input);
57 10 : out1 = output = 0xdeadbeef;
58 10 : CHKExecute("S");
59 :
60 10 : if (out1 != 7654321) {
61 0 : fprintf(stderr, "Invalid output %d (0x%x)\n", (int) out1, (int) out1);
62 0 : return 1;
63 : }
64 :
65 10 : if (output != 24680) {
66 0 : fprintf(stderr, "Invalid result %d (0x%x) expected 24680\n", (int) output, (int) output);
67 0 : return 1;
68 : }
69 : }
70 :
71 10 : odbc_command("IF OBJECT_ID('const_param') IS NOT NULL DROP PROC const_param");
72 :
73 10 : odbc_command("create proc const_param @in1 float, @in2 varbinary(100) as\n"
74 : "begin\n"
75 : " if @in1 <> 12.5 or @in2 <> 0x0102030405060708\n"
76 : " return 12345\n"
77 : " return 54321\n"
78 : "end");
79 :
80 10 : CHKBindParameter(1, SQL_PARAM_OUTPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &output, 0, &ind, "S");
81 :
82 10 : CHKPrepare(T("{?=call const_param(12.5, 0x0102030405060708)}"), SQL_NTS, "S");
83 :
84 10 : output = 0xdeadbeef;
85 10 : CHKExecute("S");
86 :
87 10 : if (output != 54321) {
88 0 : fprintf(stderr, "Invalid result %d (0x%x) expected 54321\n", (int) output, (int) output);
89 0 : return 1;
90 : }
91 :
92 10 : odbc_command("drop proc const_param");
93 :
94 10 : odbc_command("create proc const_param @in varchar(20) as\n"
95 : "begin\n"
96 : " if @in = 'value' select 8421\n"
97 : " select 1248\n"
98 : "end");
99 :
100 : /* catch problem reported by Peter Deacon */
101 10 : output = 0xdeadbeef;
102 10 : odbc_command("{CALL const_param('value')}");
103 10 : CHKBindCol(1, SQL_C_SLONG, &output, 0, &ind, "S");
104 10 : SQLFetch(odbc_stmt);
105 :
106 10 : if (output != 8421) {
107 0 : fprintf(stderr, "Invalid result %d (0x%x)\n", (int) output, (int) output);
108 0 : return 1;
109 : }
110 :
111 10 : odbc_reset_statement();
112 :
113 10 : odbc_command("drop proc const_param");
114 :
115 10 : sql = "create proc const_param @in1 bigint as\n"
116 : "begin\n"
117 : " if @in1 <> 1000000000000 select 0 else select 1\n"
118 : "end";
119 10 : if (odbc_command_with_result(odbc_stmt, sql) == SQL_SUCCESS) {
120 10 : output = 0xdeadbeef;
121 10 : odbc_command("{CALL const_param(1000000000000)}");
122 10 : CHKBindCol(1, SQL_C_SLONG, &output, 0, &ind, "S");
123 10 : SQLFetch(odbc_stmt);
124 :
125 10 : if (output != 1) {
126 0 : fprintf(stderr, "Invalid result %d (0x%x)\n", (int) output, (int) output);
127 0 : return 1;
128 : }
129 :
130 10 : odbc_reset_statement();
131 :
132 10 : odbc_command("drop proc const_param");
133 : }
134 :
135 10 : odbc_disconnect();
136 :
137 10 : printf("Done.\n");
138 10 : return 0;
139 : }
|