1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/*
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
MySQL Connectors. There are special exceptions to the terms and
conditions of the GPLv2 as it is applied to this software, see the
FLOSS License Exception
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "odbctap.h"
SQLINTEGER my_max_rows= 100;
/* making use of mysql_use_result */
DECLARE_TEST(t_use_result)
{
SQLINTEGER i, row_count= 0;
SQLCHAR ch[]= "MySQL AB";
SQLRETURN rc;
ok_sql(hstmt, "DROP TABLE IF EXISTS t_use_result");
ok_sql(hstmt, "CREATE TABLE t_use_result (id INT, name CHAR(10))");
ok_stmt(hstmt, SQLPrepare(hstmt, (SQLCHAR *)
"INSERT INTO t_use_result VALUES (?,?)", SQL_NTS));
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG,
SQL_INTEGER, 0, 0, &i, 0, NULL));
ok_stmt(hstmt, SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_CHAR, 0, 0, ch, sizeof(ch), NULL));
for (i= 1; i <= my_max_rows; i++)
ok_stmt(hstmt, SQLExecute(hstmt));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "SELECT * FROM t_use_result");
rc= SQLFetch(hstmt);
while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)
{
row_count++;
rc= SQLFetch(hstmt);
}
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
is_num(row_count, my_max_rows);
ok_sql(hstmt, "DROP TABLE IF EXISTS t_use_result");
return OK;
}
/**
Bug #4657: "Don't Cache Results" crashes when using catalog functions
*/
DECLARE_TEST(t_bug4657)
{
SQLCHAR name[10];
SQLSMALLINT column_count;
SQLLEN name_length;
ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE,
(SQLPOINTER)SQL_CURSOR_FORWARD_ONLY, 0));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug4657");
ok_sql(hstmt, "CREATE TABLE t_bug4657 (a INT)");
ok_stmt(hstmt, SQLTables(hstmt, (SQLCHAR *)"", SQL_NTS,
(SQLCHAR *)"", SQL_NTS,
(SQLCHAR *)"", SQL_NTS,
(SQLCHAR *)"UNKNOWN", SQL_NTS));
ok_stmt(hstmt, SQLNumResultCols(hstmt, &column_count));
is_num(column_count, 5);
ok_stmt(hstmt, SQLBindCol(hstmt, 3, SQL_C_CHAR, name, sizeof(name),
&name_length));
expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug4657");
return OK;
}
/**
Bug #39878: No error signaled if timeout during fetching data.
*/
DECLARE_TEST(t_bug39878)
{
int i;
SQLINTEGER row_count= 0;
SQLRETURN rc;
ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE,
(SQLPOINTER)SQL_CURSOR_FORWARD_ONLY, 0));
printMessage("Creating table t_bug39878");
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug39878");
ok_sql(hstmt, "CREATE TABLE t_bug39878 (a INT)");
// Fill table with data
printMessage("Filling table with data...");
ok_sql(hstmt, "INSERT INTO t_bug39878 VALUES (0), (1)");
ok_stmt(hstmt, SQLPrepare(hstmt, (SQLCHAR *)
"INSERT INTO t_bug39878 SELECT a+? FROM t_bug39878", SQL_NTS));
ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG,
SQL_INTEGER, 0, 0, &row_count, 0, NULL));
for (i=1, row_count= 2; i < 14; ++i, row_count *= 2)
ok_stmt(hstmt, SQLExecute(hstmt));
printMessage("inserted %d rows.", row_count);
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
printMessage("Setting net_write_timeout to 1");
ok_sql(hstmt, "SET net_write_timeout=1");
// Table scan
ok_sql(hstmt, "SELECT * FROM t_bug39878");
printMessage("Started table scan, sleeping 3sec ...");
sleep(3);
printMessage("Fetching rows...");
while (SQL_SUCCEEDED(rc= SQLFetch(hstmt)))
{
row_count--;
}
print_diag(rc, SQL_HANDLE_STMT, hstmt, "SQLFetch()", __FILE__, __LINE__);
printMessage("Scan interrupted, %d rows left in the table.", row_count);
{
char *rc_name;
switch(rc)
{
case SQL_SUCCESS: rc_name= "SQL_SUCCESS"; break;
case SQL_SUCCESS_WITH_INFO: rc_name= "SQL_SUCCESS_WITH_INFO"; break;
case SQL_NO_DATA: rc_name= "SQL_NO_DATA"; break;
case SQL_STILL_EXECUTING: rc_name= "SQL_STILL_EXECUTING"; break;
case SQL_ERROR: rc_name= "SQL_ERROR"; break;
case SQL_INVALID_HANDLE: rc_name= "SQL_INVALID_HANDLE"; break;
default: rc_name= "<unknown>"; break;
}
printMessage("Last SQLFetch() returned: %s", rc_name);
}
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
is(row_count == 0 || rc == SQL_ERROR);
// We re-connect to drop the table (as connection might be broken)
free_basic_handles(&henv, &hdbc, &hstmt);
alloc_basic_handles(&henv, &hdbc, &hstmt);
ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug39878");
return OK;
}
BEGIN_TESTS
ADD_TEST(t_use_result)
ADD_TEST(t_bug4657)
ADD_TEST(t_bug39878)
END_TESTS
SET_DSN_OPTION(1048576);
RUN_TESTS
|