28 #include <mysqld_error.h>
35 #define PRINT_ERROR(code,msg) \
36 std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \
37 << ", code: " << code \
38 << ", msg: " << msg << "." << std::endl
39 #define MYSQLERROR(mysql) { \
40 PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \
42 #define APIERROR(error) \
43 { std::cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \
44 << error.code << ", msg: " << error.message << "." << std::endl; \
48 static void drop_table(
MYSQL &);
49 static void callback(
int result,
NdbTransaction* NdbObject,
void* aObject);
51 int main(
int argc,
char** argv)
55 std::cout <<
"Arguments are <socket mysqld> <connect_string cluster>.\n";
58 char * mysqld_sock = argv[1];
59 const char *connectstring = argv[2];
65 int r= cluster_connection->
connect(5 ,
71 <<
"Cluster connect failed, possibly resolved with more retries.\n";
77 <<
"Cluster connect failed.\n";
83 std::cout <<
"Cluster was not ready within 30 secs." << std::endl;
89 if ( !mysql_init(&mysql) ) {
90 std::cout <<
"mysql_init failed\n";
93 if ( !mysql_real_connect(&mysql,
"localhost",
"root",
"",
"",
100 mysql_query(&mysql,
"CREATE DATABASE ndb_examples");
101 if (mysql_query(&mysql,
"USE ndb_examples") != 0) MYSQLERROR(mysql);
104 Ndb* myNdb =
new Ndb( cluster_connection,
110 if (myNdb->
init(2) == -1) {
122 for (
int i = 0;
i < 2;
i++) {
124 if (myNdbTransaction[
i] == NULL) APIERROR(myNdb->
getNdbError());
127 if (myNdbOperation == NULL) APIERROR(myNdbTransaction[
i]->getNdbError());
129 myNdbOperation->insertTuple();
130 myNdbOperation->equal(
"ATTR1", 20 +
i);
131 myNdbOperation->setValue(
"ATTR2", 20 +
i);
145 for (
int i = 0;
i < 2;
i++)
149 delete cluster_connection;
160 while(mysql_query(&mysql,
161 "CREATE TABLE api_async1"
162 " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY,"
163 " ATTR2 INT UNSIGNED NOT NULL)"
166 if (mysql_errno(&mysql) == ER_TABLE_EXISTS_ERROR)
168 std::cout <<
"MySQL Cluster already has example table: api_scan. "
169 <<
"Dropping it..." << std::endl;
172 else MYSQLERROR(mysql);
179 static void drop_table(
MYSQL &mysql)
181 if (mysql_query(&mysql,
201 std::cout <<
"Poll error: " << std::endl;
204 std::cout <<
"Successful insert." << std::endl;