Skip to content

Commit f798c85

Browse files
committed
Bug#35861516 Ndb : DbUtil test class only supports prepared statements
Follow up fix for problem with AtrtClient which attempted to read a number which had been saved only as a string. Improve test case to check that both prepared and basic protcol returns same values and that they are save in same format where expected. In general the basic protocol returns all values as strings which differs against the prepared statement protocol, thus the mappings are not always identical but it seems like the basic protocol currently have a more resilient implementation. Change-Id: Idf36139e4cf82d93cc9215a63ad516b8ffd76887
1 parent 9a07b6e commit f798c85

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

storage/ndb/test/include/SqlClient.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class SqlResultSet : public Properties {
5050
void clear();
5151

5252
SqlResultSet();
53+
SqlResultSet(SqlResultSet &) = delete;
54+
SqlResultSet(SqlResultSet &&) = delete;
5355
~SqlResultSet();
5456

5557
const char *column(const char *col_name);

storage/ndb/test/ndbapi/testNDBT.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -155,32 +155,46 @@ int runTestSqlClient(NDBT_Context *ctx, NDBT_Step *step) {
155155
while (result.next()) {
156156
}
157157

158-
// Select second row from sql_client_test
159-
Properties args;
160-
args.put("0", 2);
161-
if (!sql.doQuery("SELECT * FROM sql_client_test WHERE a=?", args, result))
162-
return NDBT_FAILED;
163-
result.print();
164-
165-
result.reset();
166-
while (result.next()) {
167-
ndbout << "a: " << result.columnAsInt("a") << endl
168-
<< "b: " << result.column("b") << endl
169-
<< "c: " << result.columnAsLong("c") << endl;
170-
if (result.columnAsInt("a") != 2) {
171-
ndbout << "hepp1" << endl;
172-
return NDBT_FAILED;
173-
}
174-
175-
if (strcmp(result.column("b"), "bye")) {
176-
ndbout << "hepp2" << endl;
158+
{
159+
auto check_result = [](SqlResultSet &result) {
160+
result.reset();
161+
while (result.next()) {
162+
ndbout << "a: " << result.columnAsInt("a") << endl
163+
<< "b: " << result.column("b") << endl
164+
<< "c: " << result.columnAsLong("c") << endl;
165+
if (result.columnAsInt("a") != 2) {
166+
ndbout << "Unexpected value for a" << endl;
167+
return false;
168+
}
169+
170+
if (strcmp(result.column("b"), "bye")) {
171+
ndbout << "Unexpected value for b" << endl;
172+
return false;
173+
}
174+
175+
if (result.columnAsLong("c") != 9000000000ULL) {
176+
ndbout << "Unexpected value for c" << endl;
177+
return false;
178+
}
179+
}
180+
return true;
181+
};
182+
183+
// Select second row from sql_client_test using placeholders and check
184+
// expected result, this will use prepared statement behind the scenes
185+
Properties args;
186+
args.put("0", 2);
187+
if (!sql.doQuery("SELECT * FROM sql_client_test WHERE a=?", args, result))
177188
return NDBT_FAILED;
178-
}
189+
result.print();
190+
if (!check_result(result)) return NDBT_FAILED;
179191

180-
if (result.columnAsLong("c") != 9000000000ULL) {
181-
ndbout << "hepp3" << endl;
192+
// Select second row from sql_client_test without placeholders and check
193+
// expected result
194+
if (!sql.doQuery("SELECT * FROM sql_client_test WHERE a=2", result))
182195
return NDBT_FAILED;
183-
}
196+
result.print();
197+
if (!check_result(result)) return NDBT_FAILED;
184198
}
185199

186200
if (sql.selectCountTable("sql_client_test") != 2) {

storage/ndb/test/src/SqlClient.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,15 @@ bool SqlClient::runQueryBasic(const char *sql, SqlResultSet &rows) {
433433
// Save as Uint64 in result
434434
curr.put64(fields[i].name, std::stoull(field_data));
435435
break;
436+
437+
case MYSQL_TYPE_TINY:
438+
case MYSQL_TYPE_SHORT:
439+
case MYSQL_TYPE_INT24:
440+
case MYSQL_TYPE_LONG:
441+
// Save as Uint32 in result
442+
curr.put(fields[i].name, std::stoul(field_data));
443+
break;
444+
436445
default:
437446
// Save as string in result
438447
curr.put(fields[i].name, field_data);

0 commit comments

Comments
 (0)