~mysql/myodbc/5.2

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