MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
testNDBT.cpp
1 /*
2  Copyright (C) 2008 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <NDBT.hpp>
20 #include <NDBT_Test.hpp>
21 #include <DbUtil.hpp>
22 #include <AtrtClient.hpp>
23 
24 
25 int runTestAtrtClient(NDBT_Context* ctx, NDBT_Step* step){
26  AtrtClient atrt;
27 
28  SqlResultSet clusters;
29  if (!atrt.getClusters(clusters))
30  return NDBT_FAILED;
31 
32  int i= 0;
33  while(clusters.next())
34  {
35  ndbout << clusters.column("name") << endl;
36  if (i++ == 1){
37  ndbout << "removing: " << clusters.column("name") << endl;
38  clusters.remove();
39  }
40  }
41 
42  clusters.reset();
43  while(clusters.next())
44  {
45  ndbout << clusters.column("name") << endl;
46  }
47 
48  return NDBT_OK;
49 }
50 
51 
52 int runTestDbUtil(NDBT_Context* ctx, NDBT_Step* step){
53  DbUtil sql("test");
54 
55  {
56  // Select all rows from mysql.user
57  SqlResultSet result;
58  if (!sql.doQuery("SELECT * FROM mysql.user", result))
59  return NDBT_FAILED;
60  // result.print();
61 
62  while(result.next())
63  {
64  ndbout << result.column("host") << ", "
65  << result.column("uSer") << ", "
66  << result.columnAsInt("max_updates") << ", "
67  << endl;
68  }
69 
70  result.reset();
71  while(result.next())
72  {
73  ndbout << result.column("host") << endl;
74  }
75  }
76 
77  {
78  // No column name, query should fail
79  Properties args;
80  SqlResultSet result;
81  if (sql.doQuery("SELECT * FROM mysql.user WHERE name=?", args, result))
82  return NDBT_FAILED;
83  result.print();
84  }
85 
86  {
87  // Select nonexisiting rows from mysql.user
88  Properties args;
89  SqlResultSet result;
90  args.put("0", "no_such_host");
91  if (!sql.doQuery("SELECT * FROM mysql.user WHERE host=?", args, result))
92  return NDBT_FAILED;
93  ndbout << "no rows" << endl;
94  result.print();
95 
96  // Change args to an find one row
97  args.clear();
98  args.put("0", "localhost");
99  if (!sql.doQuery("SELECT host, user FROM mysql.user WHERE host=?",
100  args, result))
101  return NDBT_FAILED;
102  result.print();
103  }
104 
105  {
106  if (!sql.doQuery("DROP TABLE IF EXISTS sql_client_test"))
107  return NDBT_FAILED;
108 
109  if (!sql.doQuery("CREATE TABLE sql_client_test"
110  "(a int, b varchar(255), c bigint)"))
111  return NDBT_FAILED;
112 
113  if (!sql.doQuery("INSERT INTO sql_client_test VALUES"
114  "(1, 'hello', 456456456789),"
115  "(2, 'bye', 9000000000)"))
116  return NDBT_FAILED;
117 
118  // Select all rows from sql_client_test
119  SqlResultSet result;
120  if (!sql.doQuery("SELECT * FROM sql_client_test", result))
121  return NDBT_FAILED;
122  // result.print();
123 
124  while(result.next())
125  {
126  }
127 
128  // Select second row from sql_client_test
129  Properties args;
130  args.put("0", 2);
131  if (!sql.doQuery("SELECT * FROM sql_client_test WHERE a=?", args,result))
132  return NDBT_FAILED;
133  result.print();
134 
135  result.reset();
136  while(result.next())
137  {
138  ndbout << "a: " << result.columnAsInt("a") << endl
139  << "b: " << result.column("b") << endl
140  << "c: " << result.columnAsLong("c") << endl;
141  if (result.columnAsInt("a") != 2){
142  ndbout << "hepp1" << endl;
143  return NDBT_FAILED;
144  }
145 
146  if (strcmp(result.column("b"), "bye")){
147  ndbout << "hepp2" << endl;
148  return NDBT_FAILED;
149  }
150 
151  if (result.columnAsLong("c") != 9000000000ULL){
152  ndbout << "hepp3" << endl;
153  return NDBT_FAILED;
154  }
155 
156  }
157 
158  if (sql.selectCountTable("sql_client_test") != 2)
159  {
160  ndbout << "Got wrong count" << endl;
161  return NDBT_FAILED;
162  }
163 
164 
165  if (!sql.doQuery("DROP TABLE sql_client_test"))
166  return NDBT_FAILED;
167 
168  }
169 
170  return NDBT_OK;
171 }
172 
173 NDBT_TESTSUITE(testNDBT);
174 TESTCASE("AtrtClient",
175  "Test AtrtClient class"){
176  INITIALIZER(runTestAtrtClient);
177 }
178 TESTCASE("DbUtil",
179  "Test DbUtil class"){
180  INITIALIZER(runTestDbUtil);
181 }
182 NDBT_TESTSUITE_END(testNDBT);
183 
184 int main(int argc, const char** argv){
185  ndb_init();
186  NDBT_TESTSUITE_INSTANCE(testNDBT);
187  return testNDBT.execute(argc, argv);
188 }
189