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