Loading configure.in +18 −1 Original line number Diff line number Diff line Loading @@ -1770,6 +1770,7 @@ examine config.log for possible errors. If you want to report this, use 'scripts/mysqlbug' and include at least the last 20 rows from config.log!]) fi AC_CHECK_SIZEOF(char*, 4) AC_CHECK_SIZEOF(short, 2) AC_CHECK_SIZEOF(int, 4) if test "$ac_cv_sizeof_int" -eq 0 then Loading Loading @@ -2723,11 +2724,26 @@ then fi AC_SUBST([ndb_bin_am_ldflags]) AC_SUBST([ndb_opt_subdirs]) NDB_SIZEOF_CHARP="$ac_cv_sizeof_charp" NDB_SIZEOF_CHAR="$ac_cv_sizeof_char" NDB_SIZEOF_SHORT="$ac_cv_sizeof_short" NDB_SIZEOF_INT="$ac_cv_sizeof_int" NDB_SIZEOF_LONG="$ac_cv_sizeof_long" NDB_SIZEOF_LONG_LONG="$ac_cv_sizeof_long_long" AC_SUBST([NDB_SIZEOF_CHARP]) AC_SUBST([NDB_SIZEOF_CHAR]) AC_SUBST([NDB_SIZEOF_SHORT]) AC_SUBST([NDB_SIZEOF_INT]) AC_SUBST([NDB_SIZEOF_LONG]) AC_SUBST([NDB_SIZEOF_LONG_LONG]) AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl ndb/src/Makefile ndb/src/common/Makefile dnl ndb/docs/Makefile dnl ndb/tools/Makefile dnl ndb/src/common/debugger/Makefile ndb/src/common/debugger/signaldata/Makefile dnl ndb/src/common/debugger/Makefile dnl ndb/src/common/debugger/signaldata/Makefile dnl ndb/src/common/portlib/Makefile dnl ndb/src/common/util/Makefile dnl ndb/src/common/logger/Makefile dnl Loading Loading @@ -2766,6 +2782,7 @@ AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl ndb/test/tools/Makefile dnl ndb/test/run-test/Makefile mysql-test/ndb/Makefile dnl ndb/include/ndb_version.h ndb/include/ndb_global.h dnl ndb/include/ndb_types.h dnl ) fi Loading ndb/examples/ndbapi_async_example/Makefile +12 −23 Original line number Diff line number Diff line -include .defs.mk #NDB_OS = OS_YOU_ARE_RUNNING_ON #NDB_OS = LINUX #You need to set the NDB_OS variable here (LINUX, SOLARIS, MACOSX) TARGET = ndbapi_async SRCS = ndbapi_async.cpp OBJS = ndbapi_async.o CC = g++ CFLAGS = -c -Wall -fno-rtti -D$(NDB_OS) SRCS = $(TARGET).cpp OBJS = $(TARGET).o CXX = g++ CFLAGS = -g -c -Wall -fno-rtti -fno-exceptions CXXFLAGS = -g DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include LIB_DIR = ../../lib ifeq ($(NDB_OS), SOLARIS) # Here is the definition of system libraries necessary for Solaris 7 SYS_LIB = -lpthread -lsocket -lnsl -lrt endif ifeq ($(NDB_OS), LINUX) # Here is the definition of system libraries necessary for Linux 2.4 SYS_LIB = -lpthread endif ifeq ($(NDB_OS), MACOSX) # Here is the definition of system libraries necessary for Mac OS X TOP_SRCDIR = ../../.. INCLUDE_DIR = $(TOP_SRCDIR) LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ -L$(TOP_SRCDIR)/mysys SYS_LIB = endif $(TARGET): $(OBJS) $(CC) $(LFLAGS) -L$(LIB_DIR) -lNDB_API $(OBJS) $(SYS_LIB) -o $(TARGET) $(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lz $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CC) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR)/include -I$(INCLUDE_DIR)/extra -I$(INCLUDE_DIR)/ndb/include -I$(INCLUDE_DIR)/ndb/include/ndbapi $(SRCS) clean: rm -f *.o $(TARGET) ndb/examples/ndbapi_async_example/ndbapi_async.cpp +76 −95 Original line number Diff line number Diff line Loading @@ -24,10 +24,12 @@ * * Classes and methods in NDBAPI used in this example: * * Ndb_cluster_connection * connect() * wait_until_ready() * * Ndb * init() * waitUntilRead() * getDictionary() * startTransaction() * closeTransaction() * sendPollNdb() Loading @@ -38,23 +40,6 @@ * executeAsynchPrepare() * getNdbError() * * NdbDictionary::Dictionary * getTable() * dropTable() * createTable() * getNdbError() * * NdbDictionary::Column * setName() * setType() * setLength() * setPrimaryKey() * setNullable() * * NdbDictionary::Table * setName() * addColumn() * * NdbOperation * insertTuple() * equal() Loading @@ -63,10 +48,10 @@ */ #include <ndb_global.h> #include <mysql.h> #include <mysqld_error.h> #include <NdbApi.hpp> #include <NdbScanFilter.hpp> #include <iostream> // Used for cout /** Loading @@ -85,11 +70,16 @@ milliSleep(int milliseconds){ /** * error printout macro */ #define APIERROR(error) \ { std::cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \ << error.code << ", msg: " << error.message << "." << std::endl; \ #define PRINT_ERROR(code,msg) \ std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \ << ", code: " << code \ << ", msg: " << msg << "." << std::endl #define MYSQLERROR(mysql) { \ PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \ exit(-1); } #define APIERROR(error) { \ PRINT_ERROR(error.code,error.message); \ exit(-1); } #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** Loading @@ -106,10 +96,10 @@ typedef struct { } async_callback_t; /** * Structure used in "free list" to a NdbConnection * Structure used in "free list" to a NdbTransaction */ typedef struct { NdbConnection* conn; NdbTransaction* conn; int used; } transaction_t; Loading @@ -132,7 +122,7 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData); /** * Error handler. */ bool asynchErrorHandler(NdbConnection * trans, Ndb* ndb); bool asynchErrorHandler(NdbTransaction * trans, Ndb* ndb); /** * Exit function Loading Loading @@ -171,7 +161,7 @@ closeTransaction(Ndb * ndb , async_callback_t * cb) * Callback executed when transaction has return from NDB */ static void callback(int result, NdbConnection* trans, void* aObject) callback(int result, NdbTransaction* trans, void* aObject) { async_callback_t * cbData = (async_callback_t *)aObject; if (result<0) Loading Loading @@ -207,61 +197,26 @@ callback(int result, NdbConnection* trans, void* aObject) /** * Create table "GARAGE" */ int create_table(Ndb * myNdb) int create_table(MYSQL &mysql) { NdbDictionary::Table myTable; NdbDictionary::Column myColumn; NdbDictionary::Dictionary* myDict = myNdb->getDictionary(); /********************************************************* * Create a table named GARAGE if it does not exist * *********************************************************/ if (myDict->getTable("GARAGE") != NULL) while (mysql_query(&mysql, "CREATE TABLE" " GARAGE" " (REG_NO INT UNSIGNED NOT NULL," " BRAND CHAR(20) NOT NULL," " COLOR CHAR(20) NOT NULL," " PRIMARY KEY USING HASH (REG_NO))" " ENGINE=NDB")) { std::cout << "NDB already has example table: GARAGE. " if (mysql_errno(&mysql) != ER_TABLE_EXISTS_ERROR) MYSQLERROR(mysql); std::cout << "MySQL Cluster already has example table: GARAGE. " << "Dropping it..." << std::endl; if(myDict->dropTable("GARAGE") == -1) { std::cout << "Failed to drop: GARAGE." << std::endl; exit(1); } } myTable.setName("GARAGE"); /** * Column REG_NO */ myColumn.setName("REG_NO"); myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setLength(1); myColumn.setPrimaryKey(true); myColumn.setNullable(false); myTable.addColumn(myColumn); /** * Column BRAND */ myColumn.setName("BRAND"); myColumn.setType(NdbDictionary::Column::Char); myColumn.setLength(20); myColumn.setPrimaryKey(false); myColumn.setNullable(false); myTable.addColumn(myColumn); /** * Column COLOR */ myColumn.setName("COLOR"); myColumn.setType(NdbDictionary::Column::Char); myColumn.setLength(20); myColumn.setPrimaryKey(false); myColumn.setNullable(false); myTable.addColumn(myColumn); if (myDict->createTable(myTable) == -1) { APIERROR(myDict->getNdbError()); /************** * Drop table * **************/ if (mysql_query(&mysql, "DROP TABLE GARAGE")) MYSQLERROR(mysql); } return 1; } Loading @@ -276,7 +231,7 @@ void asynchExitHandler(Ndb * m_ndb) /* returns true if is recoverable (temporary), * false if it is an error that is permanent. */ bool asynchErrorHandler(NdbConnection * trans, Ndb* ndb) bool asynchErrorHandler(NdbTransaction * trans, Ndb* ndb) { NdbError error = trans->getNdbError(); switch(error.status) Loading Loading @@ -455,21 +410,47 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) int main() { ndb_init(); Ndb* myNdb = new Ndb( "TEST_DB" ); // Object representing the database MYSQL mysql; /******************************************* * Initialize NDB and wait until its ready * *******************************************/ if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions APIERROR(myNdb->getNdbError()); /************************************************************** * Connect to mysql server and create table * **************************************************************/ { if ( !mysql_init(&mysql) ) { std::cout << "mysql_init failed\n"; exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", 3306, "/tmp/mysql.sock", 0) ) MYSQLERROR(mysql); mysql_query(&mysql, "CREATE DATABASE TEST_DB"); if (mysql_query(&mysql, "USE TEST_DB") != 0) MYSQLERROR(mysql); if (myNdb->waitUntilReady(30) != 0) { std::cout << "NDB was not ready within 30 secs." << std::endl; create_table(mysql); } /************************************************************** * Connect to ndb cluster * **************************************************************/ Ndb_cluster_connection cluster_connection; if (cluster_connection.connect(4, 5, 1)) { std::cout << "Unable to connect to cluster within 30 secs." << std::endl; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster_connection.wait_until_ready(30,0) < 0) { std::cout << "Cluster was not ready within 30 secs.\n"; exit(-1); } create_table(myNdb); Ndb* myNdb = new Ndb( &cluster_connection, "TEST_DB" ); // Object representing the database if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions APIERROR(myNdb->getNdbError()); } /** * Initialise transaction array Loading ndb/examples/ndbapi_example1/ndbapi_example1.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -141,8 +141,8 @@ static void create_table(MYSQL &mysql) if (mysql_query(&mysql, "CREATE TABLE" " MYTABLENAME" " (ATTR1 INT UNSIGNED PRIMARY KEY," " ATTR2 INT UNSIGNED)" " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY," " ATTR2 INT UNSIGNED NOT NULL)" " ENGINE=NDB")) MYSQLERROR(mysql); } Loading Loading @@ -234,7 +234,7 @@ static void do_read(Ndb &myNdb) NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->readTuple(); myOperation->readTuple(NdbOperation::LM_Read); myOperation->equal("ATTR1", i); NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL); Loading ndb/examples/ndbapi_example4/Makefile +10 −8 Original line number Diff line number Diff line TARGET = ndbapi_example4 SRCS = ndbapi_example4.cpp OBJS = ndbapi_example4.o SRCS = $(TARGET).cpp OBJS = $(TARGET).o CXX = g++ CFLAGS = -c -Wall -fno-rtti -fno-exceptions CXXFLAGS = DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include LIB_DIR = -L../../src/.libs \ -L../../../libmysql_r/.libs \ -L../../../mysys TOP_SRCDIR = ../../.. INCLUDE_DIR = $(TOP_SRCDIR) LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ -L$(TOP_SRCDIR)/mysys SYS_LIB = $(TARGET): $(OBJS) $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lz $(SYS_LIB) -o $(TARGET) $(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lz $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR)/include -I$(INCLUDE_DIR)/ndb/include -I$(INCLUDE_DIR)/ndb/include/ndbapi $(SRCS) clean: rm -f *.o $(TARGET) Loading
configure.in +18 −1 Original line number Diff line number Diff line Loading @@ -1770,6 +1770,7 @@ examine config.log for possible errors. If you want to report this, use 'scripts/mysqlbug' and include at least the last 20 rows from config.log!]) fi AC_CHECK_SIZEOF(char*, 4) AC_CHECK_SIZEOF(short, 2) AC_CHECK_SIZEOF(int, 4) if test "$ac_cv_sizeof_int" -eq 0 then Loading Loading @@ -2723,11 +2724,26 @@ then fi AC_SUBST([ndb_bin_am_ldflags]) AC_SUBST([ndb_opt_subdirs]) NDB_SIZEOF_CHARP="$ac_cv_sizeof_charp" NDB_SIZEOF_CHAR="$ac_cv_sizeof_char" NDB_SIZEOF_SHORT="$ac_cv_sizeof_short" NDB_SIZEOF_INT="$ac_cv_sizeof_int" NDB_SIZEOF_LONG="$ac_cv_sizeof_long" NDB_SIZEOF_LONG_LONG="$ac_cv_sizeof_long_long" AC_SUBST([NDB_SIZEOF_CHARP]) AC_SUBST([NDB_SIZEOF_CHAR]) AC_SUBST([NDB_SIZEOF_SHORT]) AC_SUBST([NDB_SIZEOF_INT]) AC_SUBST([NDB_SIZEOF_LONG]) AC_SUBST([NDB_SIZEOF_LONG_LONG]) AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl ndb/src/Makefile ndb/src/common/Makefile dnl ndb/docs/Makefile dnl ndb/tools/Makefile dnl ndb/src/common/debugger/Makefile ndb/src/common/debugger/signaldata/Makefile dnl ndb/src/common/debugger/Makefile dnl ndb/src/common/debugger/signaldata/Makefile dnl ndb/src/common/portlib/Makefile dnl ndb/src/common/util/Makefile dnl ndb/src/common/logger/Makefile dnl Loading Loading @@ -2766,6 +2782,7 @@ AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl ndb/test/tools/Makefile dnl ndb/test/run-test/Makefile mysql-test/ndb/Makefile dnl ndb/include/ndb_version.h ndb/include/ndb_global.h dnl ndb/include/ndb_types.h dnl ) fi Loading
ndb/examples/ndbapi_async_example/Makefile +12 −23 Original line number Diff line number Diff line -include .defs.mk #NDB_OS = OS_YOU_ARE_RUNNING_ON #NDB_OS = LINUX #You need to set the NDB_OS variable here (LINUX, SOLARIS, MACOSX) TARGET = ndbapi_async SRCS = ndbapi_async.cpp OBJS = ndbapi_async.o CC = g++ CFLAGS = -c -Wall -fno-rtti -D$(NDB_OS) SRCS = $(TARGET).cpp OBJS = $(TARGET).o CXX = g++ CFLAGS = -g -c -Wall -fno-rtti -fno-exceptions CXXFLAGS = -g DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include LIB_DIR = ../../lib ifeq ($(NDB_OS), SOLARIS) # Here is the definition of system libraries necessary for Solaris 7 SYS_LIB = -lpthread -lsocket -lnsl -lrt endif ifeq ($(NDB_OS), LINUX) # Here is the definition of system libraries necessary for Linux 2.4 SYS_LIB = -lpthread endif ifeq ($(NDB_OS), MACOSX) # Here is the definition of system libraries necessary for Mac OS X TOP_SRCDIR = ../../.. INCLUDE_DIR = $(TOP_SRCDIR) LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ -L$(TOP_SRCDIR)/mysys SYS_LIB = endif $(TARGET): $(OBJS) $(CC) $(LFLAGS) -L$(LIB_DIR) -lNDB_API $(OBJS) $(SYS_LIB) -o $(TARGET) $(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lz $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CC) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR)/include -I$(INCLUDE_DIR)/extra -I$(INCLUDE_DIR)/ndb/include -I$(INCLUDE_DIR)/ndb/include/ndbapi $(SRCS) clean: rm -f *.o $(TARGET)
ndb/examples/ndbapi_async_example/ndbapi_async.cpp +76 −95 Original line number Diff line number Diff line Loading @@ -24,10 +24,12 @@ * * Classes and methods in NDBAPI used in this example: * * Ndb_cluster_connection * connect() * wait_until_ready() * * Ndb * init() * waitUntilRead() * getDictionary() * startTransaction() * closeTransaction() * sendPollNdb() Loading @@ -38,23 +40,6 @@ * executeAsynchPrepare() * getNdbError() * * NdbDictionary::Dictionary * getTable() * dropTable() * createTable() * getNdbError() * * NdbDictionary::Column * setName() * setType() * setLength() * setPrimaryKey() * setNullable() * * NdbDictionary::Table * setName() * addColumn() * * NdbOperation * insertTuple() * equal() Loading @@ -63,10 +48,10 @@ */ #include <ndb_global.h> #include <mysql.h> #include <mysqld_error.h> #include <NdbApi.hpp> #include <NdbScanFilter.hpp> #include <iostream> // Used for cout /** Loading @@ -85,11 +70,16 @@ milliSleep(int milliseconds){ /** * error printout macro */ #define APIERROR(error) \ { std::cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \ << error.code << ", msg: " << error.message << "." << std::endl; \ #define PRINT_ERROR(code,msg) \ std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \ << ", code: " << code \ << ", msg: " << msg << "." << std::endl #define MYSQLERROR(mysql) { \ PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \ exit(-1); } #define APIERROR(error) { \ PRINT_ERROR(error.code,error.message); \ exit(-1); } #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** Loading @@ -106,10 +96,10 @@ typedef struct { } async_callback_t; /** * Structure used in "free list" to a NdbConnection * Structure used in "free list" to a NdbTransaction */ typedef struct { NdbConnection* conn; NdbTransaction* conn; int used; } transaction_t; Loading @@ -132,7 +122,7 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData); /** * Error handler. */ bool asynchErrorHandler(NdbConnection * trans, Ndb* ndb); bool asynchErrorHandler(NdbTransaction * trans, Ndb* ndb); /** * Exit function Loading Loading @@ -171,7 +161,7 @@ closeTransaction(Ndb * ndb , async_callback_t * cb) * Callback executed when transaction has return from NDB */ static void callback(int result, NdbConnection* trans, void* aObject) callback(int result, NdbTransaction* trans, void* aObject) { async_callback_t * cbData = (async_callback_t *)aObject; if (result<0) Loading Loading @@ -207,61 +197,26 @@ callback(int result, NdbConnection* trans, void* aObject) /** * Create table "GARAGE" */ int create_table(Ndb * myNdb) int create_table(MYSQL &mysql) { NdbDictionary::Table myTable; NdbDictionary::Column myColumn; NdbDictionary::Dictionary* myDict = myNdb->getDictionary(); /********************************************************* * Create a table named GARAGE if it does not exist * *********************************************************/ if (myDict->getTable("GARAGE") != NULL) while (mysql_query(&mysql, "CREATE TABLE" " GARAGE" " (REG_NO INT UNSIGNED NOT NULL," " BRAND CHAR(20) NOT NULL," " COLOR CHAR(20) NOT NULL," " PRIMARY KEY USING HASH (REG_NO))" " ENGINE=NDB")) { std::cout << "NDB already has example table: GARAGE. " if (mysql_errno(&mysql) != ER_TABLE_EXISTS_ERROR) MYSQLERROR(mysql); std::cout << "MySQL Cluster already has example table: GARAGE. " << "Dropping it..." << std::endl; if(myDict->dropTable("GARAGE") == -1) { std::cout << "Failed to drop: GARAGE." << std::endl; exit(1); } } myTable.setName("GARAGE"); /** * Column REG_NO */ myColumn.setName("REG_NO"); myColumn.setType(NdbDictionary::Column::Unsigned); myColumn.setLength(1); myColumn.setPrimaryKey(true); myColumn.setNullable(false); myTable.addColumn(myColumn); /** * Column BRAND */ myColumn.setName("BRAND"); myColumn.setType(NdbDictionary::Column::Char); myColumn.setLength(20); myColumn.setPrimaryKey(false); myColumn.setNullable(false); myTable.addColumn(myColumn); /** * Column COLOR */ myColumn.setName("COLOR"); myColumn.setType(NdbDictionary::Column::Char); myColumn.setLength(20); myColumn.setPrimaryKey(false); myColumn.setNullable(false); myTable.addColumn(myColumn); if (myDict->createTable(myTable) == -1) { APIERROR(myDict->getNdbError()); /************** * Drop table * **************/ if (mysql_query(&mysql, "DROP TABLE GARAGE")) MYSQLERROR(mysql); } return 1; } Loading @@ -276,7 +231,7 @@ void asynchExitHandler(Ndb * m_ndb) /* returns true if is recoverable (temporary), * false if it is an error that is permanent. */ bool asynchErrorHandler(NdbConnection * trans, Ndb* ndb) bool asynchErrorHandler(NdbTransaction * trans, Ndb* ndb) { NdbError error = trans->getNdbError(); switch(error.status) Loading Loading @@ -455,21 +410,47 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) int main() { ndb_init(); Ndb* myNdb = new Ndb( "TEST_DB" ); // Object representing the database MYSQL mysql; /******************************************* * Initialize NDB and wait until its ready * *******************************************/ if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions APIERROR(myNdb->getNdbError()); /************************************************************** * Connect to mysql server and create table * **************************************************************/ { if ( !mysql_init(&mysql) ) { std::cout << "mysql_init failed\n"; exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", 3306, "/tmp/mysql.sock", 0) ) MYSQLERROR(mysql); mysql_query(&mysql, "CREATE DATABASE TEST_DB"); if (mysql_query(&mysql, "USE TEST_DB") != 0) MYSQLERROR(mysql); if (myNdb->waitUntilReady(30) != 0) { std::cout << "NDB was not ready within 30 secs." << std::endl; create_table(mysql); } /************************************************************** * Connect to ndb cluster * **************************************************************/ Ndb_cluster_connection cluster_connection; if (cluster_connection.connect(4, 5, 1)) { std::cout << "Unable to connect to cluster within 30 secs." << std::endl; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster_connection.wait_until_ready(30,0) < 0) { std::cout << "Cluster was not ready within 30 secs.\n"; exit(-1); } create_table(myNdb); Ndb* myNdb = new Ndb( &cluster_connection, "TEST_DB" ); // Object representing the database if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions APIERROR(myNdb->getNdbError()); } /** * Initialise transaction array Loading
ndb/examples/ndbapi_example1/ndbapi_example1.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -141,8 +141,8 @@ static void create_table(MYSQL &mysql) if (mysql_query(&mysql, "CREATE TABLE" " MYTABLENAME" " (ATTR1 INT UNSIGNED PRIMARY KEY," " ATTR2 INT UNSIGNED)" " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY," " ATTR2 INT UNSIGNED NOT NULL)" " ENGINE=NDB")) MYSQLERROR(mysql); } Loading Loading @@ -234,7 +234,7 @@ static void do_read(Ndb &myNdb) NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); myOperation->readTuple(); myOperation->readTuple(NdbOperation::LM_Read); myOperation->equal("ATTR1", i); NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL); Loading
ndb/examples/ndbapi_example4/Makefile +10 −8 Original line number Diff line number Diff line TARGET = ndbapi_example4 SRCS = ndbapi_example4.cpp OBJS = ndbapi_example4.o SRCS = $(TARGET).cpp OBJS = $(TARGET).o CXX = g++ CFLAGS = -c -Wall -fno-rtti -fno-exceptions CXXFLAGS = DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include LIB_DIR = -L../../src/.libs \ -L../../../libmysql_r/.libs \ -L../../../mysys TOP_SRCDIR = ../../.. INCLUDE_DIR = $(TOP_SRCDIR) LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ -L$(TOP_SRCDIR)/mysys SYS_LIB = $(TARGET): $(OBJS) $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lz $(SYS_LIB) -o $(TARGET) $(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lz $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR)/include -I$(INCLUDE_DIR)/ndb/include -I$(INCLUDE_DIR)/ndb/include/ndbapi $(SRCS) clean: rm -f *.o $(TARGET)