From 52722f1b433a9c6406693ad26e79e9c10b574c34 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 3 Jan 2005 11:31:05 +0100 Subject: [PATCH] updated ndbapi examples --- ndb/examples/Makefile | 11 +--- ndb/examples/ndbapi_example1/Makefile | 20 ++------ .../ndbapi_example1/ndbapi_example1.cpp | 25 ++++++--- ndb/examples/ndbapi_example2/Makefile | 20 ++------ .../ndbapi_example2/ndbapi_example2.cpp | 17 ++++++- ndb/examples/ndbapi_example3/Makefile | 20 ++------ .../ndbapi_example3/ndbapi_example3.cpp | 17 ++++++- ndb/examples/ndbapi_example4/Makefile | 20 ++------ .../ndbapi_example4/ndbapi_example4.cpp | 17 ++++++- ndb/examples/ndbapi_example5/Makefile | 24 +++------ .../ndbapi_example5/ndbapi_example5.cpp | 51 ++++++++++--------- ndb/examples/ndbapi_scan_example/Makefile | 34 ++++--------- 12 files changed, 128 insertions(+), 148 deletions(-) diff --git a/ndb/examples/Makefile b/ndb/examples/Makefile index 0294632e23d..b5832d1dd2c 100644 --- a/ndb/examples/Makefile +++ b/ndb/examples/Makefile @@ -1,12 +1,6 @@ --include .defs.mk - -#ifneq ($(C++),) -#OPTS = CC=$(CC) CXX=$(C++) -#endif - -# XXX ndbapi_example4 commented out until fixed +# XXX ndbapi_example4, select_all commented out until fixed BIN_DIRS := ndbapi_example1 ndbapi_example2 ndbapi_example3 $(ndbapi_example4) \ - ndbapi_example5 select_all + ndbapi_example5 $(select_all) ndbapi_scan_example bins: $(patsubst %, _bins_%, $(BIN_DIRS)) @@ -24,4 +18,3 @@ clean_dep: clean cleanall: clean tidy: clean distclean: clean - diff --git a/ndb/examples/ndbapi_example1/Makefile b/ndb/examples/ndbapi_example1/Makefile index eb0142ce673..90719423233 100644 --- a/ndb/examples/ndbapi_example1/Makefile +++ b/ndb/examples/ndbapi_example1/Makefile @@ -1,6 +1,3 @@ --include .defs.mk -#NDB_OS = OS_YOU_ARE_RUNNING_ON -#You need to set the NDB_OS variable here TARGET = ndbapi_example1 SRCS = ndbapi_example1.cpp OBJS = ndbapi_example1.o @@ -9,22 +6,13 @@ CFLAGS = -c -Wall -fno-rtti -fno-exceptions DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include -LIB_DIR = ../../lib -ifeq ($(NDB_OS), SOLARIS) -# Here is the definition of system libraries necessary for Solaris 7 +LIB_DIR = -L../../src/.libs \ + -L../../../libmysql/.libs \ + -L../../../mysys SYS_LIB = -endif -ifeq ($(NDB_OS), LINUX) -# Here is the definition of system libraries necessary for Linux 2.4 -SYS_LIB = -endif -ifeq ($(NDB_OS), MACOSX) -# Here is the definition of system libraries necessary for Mac OS X -SYS_LIB = -endif $(TARGET): $(OBJS) - $(CXX) $(LFLAGS) -L$(LIB_DIR) $(OBJS) -lNDB_API $(SYS_LIB) -o $(TARGET) + $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient -lmysys $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) diff --git a/ndb/examples/ndbapi_example1/ndbapi_example1.cpp b/ndb/examples/ndbapi_example1/ndbapi_example1.cpp index 03a84aa249b..25fb69d8690 100644 --- a/ndb/examples/ndbapi_example1/ndbapi_example1.cpp +++ b/ndb/examples/ndbapi_example1/ndbapi_example1.cpp @@ -45,7 +45,18 @@ int main() { ndb_init(); - Ndb* myNdb = new Ndb( "TEST_DB_1" ); // Object representing the database + + Ndb_cluster_connection *cluster_connection= + new Ndb_cluster_connection(); // Object representing the cluster + + if (cluster_connection->wait_until_ready(30,30)) + { + std::cout << "Cluster was not ready within 30 secs." << std::endl; + exit(-1); + } + + Ndb* myNdb = new Ndb( cluster_connection, + "TEST_DB_1" ); // Object representing the database NdbDictionary::Table myTable; NdbDictionary::Column myColumn; @@ -56,16 +67,11 @@ int main() /******************************************** * Initialize NDB and wait until it's ready * ********************************************/ - if (myNdb->init() == -1) { + if (myNdb->init()) { APIERROR(myNdb->getNdbError()); exit(-1); } - if (myNdb->waitUntilReady(30) != 0) { - std::cout << "NDB was not ready within 30 secs." << std::endl; - exit(-1); - } - NdbDictionary::Dictionary* myDict = myNdb->getDictionary(); /********************************************************* @@ -190,5 +196,10 @@ int main() } myNdb->closeTransaction(myConnection); } + delete myNdb; + delete cluster_connection; + + ndb_end(0); + return 0; } diff --git a/ndb/examples/ndbapi_example2/Makefile b/ndb/examples/ndbapi_example2/Makefile index 17b2b1528fc..d8fdad2c50c 100644 --- a/ndb/examples/ndbapi_example2/Makefile +++ b/ndb/examples/ndbapi_example2/Makefile @@ -1,6 +1,3 @@ --include .defs.mk -#NDB_OS = OS_YOU_ARE_RUNNING_ON -#You need to set the NDB_OS variable here TARGET = ndbapi_example2 SRCS = ndbapi_example2.cpp OBJS = ndbapi_example2.o @@ -9,22 +6,13 @@ CFLAGS = -c -Wall -fno-rtti -fno-exceptions DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include -LIB_DIR = ../../lib -ifeq ($(NDB_OS), SOLARIS) -# Here is the definition of system libraries necessary for Solaris 7 +LIB_DIR = -L../../src/.libs \ + -L../../../libmysql/.libs \ + -L../../../mysys SYS_LIB = -endif -ifeq ($(NDB_OS), LINUX) -# Here is the definition of system libraries necessary for Linux 2.4 -SYS_LIB = -endif -ifeq ($(NDB_OS), MACOSX) -# Here is the definition of system libraries necessary for Mac OS X -SYS_LIB = -endif $(TARGET): $(OBJS) - $(CXX) $(LFLAGS) -L$(LIB_DIR) $(OBJS) -lNDB_API $(SYS_LIB) -o $(TARGET) + $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient -lmysys $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) diff --git a/ndb/examples/ndbapi_example2/ndbapi_example2.cpp b/ndb/examples/ndbapi_example2/ndbapi_example2.cpp index 95a7bae66b8..d8c5b5f48a8 100644 --- a/ndb/examples/ndbapi_example2/ndbapi_example2.cpp +++ b/ndb/examples/ndbapi_example2/ndbapi_example2.cpp @@ -40,7 +40,18 @@ static void callback(int result, NdbConnection* NdbObject, void* aObject); int main() { ndb_init(); - Ndb* myNdb = new Ndb( "TEST_DB_2" ); // Object representing the database + + Ndb_cluster_connection *cluster_connection= + new Ndb_cluster_connection(); // Object representing the cluster + + if (cluster_connection->wait_until_ready(30,30)) + { + std::cout << "Cluster was not ready within 30 secs." << std::endl; + exit(-1); + } + + Ndb* myNdb = new Ndb( cluster_connection, + "TEST_DB_2" ); // Object representing the database NdbConnection* myNdbConnection[2]; // For transactions NdbOperation* myNdbOperation; // For operations @@ -88,6 +99,10 @@ int main() myNdb->closeTransaction(myNdbConnection[i]); delete myNdb; + delete cluster_connection; + + ndb_end(0); + return 0; } /* diff --git a/ndb/examples/ndbapi_example3/Makefile b/ndb/examples/ndbapi_example3/Makefile index bd6f0182aa4..178282c67ad 100644 --- a/ndb/examples/ndbapi_example3/Makefile +++ b/ndb/examples/ndbapi_example3/Makefile @@ -1,6 +1,3 @@ --include .defs.mk -#NDB_OS = OS_YOU_ARE_RUNNING_ON -#You need to set the NDB_OS variable here TARGET = ndbapi_example3 SRCS = ndbapi_example3.cpp OBJS = ndbapi_example3.o @@ -9,22 +6,13 @@ CFLAGS = -c -Wall -fno-rtti -fno-exceptions DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include -LIB_DIR = ../../lib -ifeq ($(NDB_OS), SOLARIS) -# Here is the definition of system libraries necessary for Solaris 7 +LIB_DIR = -L../../src/.libs \ + -L../../../libmysql/.libs \ + -L../../../mysys SYS_LIB = -endif -ifeq ($(NDB_OS), LINUX) -# Here is the definition of system libraries necessary for Linux 2.4 -SYS_LIB = -endif -ifeq ($(NDB_OS), MACOSX) -# Here is the definition of system libraries necessary for Mac OS X -SYS_LIB = -endif $(TARGET): $(OBJS) - $(CXX) $(LFLAGS) -L$(LIB_DIR) $(OBJS) -lNDB_API $(SYS_LIB) -o $(TARGET) + $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient -lmysys $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) diff --git a/ndb/examples/ndbapi_example3/ndbapi_example3.cpp b/ndb/examples/ndbapi_example3/ndbapi_example3.cpp index 91d9ff122ba..fa061f8f9cb 100644 --- a/ndb/examples/ndbapi_example3/ndbapi_example3.cpp +++ b/ndb/examples/ndbapi_example3/ndbapi_example3.cpp @@ -177,7 +177,18 @@ int executeInsertTransaction(int transactionId, Ndb* myNdb) { int main() { ndb_init(); - Ndb* myNdb = new Ndb( "TEST_DB_1" ); // Object representing the database + + Ndb_cluster_connection *cluster_connection= + new Ndb_cluster_connection(); // Object representing the cluster + + if (cluster_connection->wait_until_ready(30,30)) + { + std::cout << "Cluster was not ready within 30 secs." << std::endl; + exit(-1); + } + + Ndb* myNdb = new Ndb( cluster_connection, + "TEST_DB_1" ); // Object representing the database /******************************************* * Initialize NDB and wait until its ready * @@ -200,4 +211,8 @@ int main() } delete myNdb; + delete cluster_connection; + + ndb_end(0); + return 0; } diff --git a/ndb/examples/ndbapi_example4/Makefile b/ndb/examples/ndbapi_example4/Makefile index b0ce852d347..29cc52e549d 100644 --- a/ndb/examples/ndbapi_example4/Makefile +++ b/ndb/examples/ndbapi_example4/Makefile @@ -1,6 +1,3 @@ --include .defs.mk -#NDB_OS = OS_YOU_ARE_RUNNING_ON -#You need to set the NDB_OS variable here TARGET = ndbapi_example4 SRCS = ndbapi_example4.cpp OBJS = ndbapi_example4.o @@ -9,22 +6,13 @@ CFLAGS = -c -Wall -fno-rtti -fno-exceptions DEBUG = LFLAGS = -Wall INCLUDE_DIR = ../../include -LIB_DIR = ../../lib -ifeq ($(NDB_OS), SOLARIS) -# Here is the definition of system libraries necessary for Solaris 7 +LIB_DIR = -L../../src/.libs \ + -L../../../libmysql/.libs \ + -L../../../mysys SYS_LIB = -endif -ifeq ($(NDB_OS), LINUX) -# Here is the definition of system libraries necessary for Linux 2.4 -SYS_LIB = -endif -ifeq ($(NDB_OS), MACOSX) -# Here is the definition of system libraries necessary for Mac OS X -SYS_LIB = -endif $(TARGET): $(OBJS) - $(CXX) $(LFLAGS) -L$(LIB_DIR) $(OBJS) -lNDB_API $(SYS_LIB) -o $(TARGET) + $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient -lmysys $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) diff --git a/ndb/examples/ndbapi_example4/ndbapi_example4.cpp b/ndb/examples/ndbapi_example4/ndbapi_example4.cpp index fcb770d49e9..c4a7905c1fe 100644 --- a/ndb/examples/ndbapi_example4/ndbapi_example4.cpp +++ b/ndb/examples/ndbapi_example4/ndbapi_example4.cpp @@ -45,7 +45,18 @@ int main() { ndb_init(); - Ndb* myNdb = new Ndb( "TEST_DB_1" ); // Object representing the database + + Ndb_cluster_connection *cluster_connection= + new Ndb_cluster_connection(); // Object representing the cluster + + if (cluster_connection->wait_until_ready(30,30)) + { + std::cout << "Cluster was not ready within 30 secs." << std::endl; + exit(-1); + } + + Ndb* myNdb = new Ndb( cluster_connection, + "TEST_DB_1" ); // Object representing the database NdbDictionary::Table myTable; NdbDictionary::Column myColumn; NdbDictionary::Index myIndex; @@ -250,4 +261,8 @@ int main() APIERROR(myDict->getNdbError()); delete myNdb; + delete cluster_connection; + + ndb_end(0); + return 0; } diff --git a/ndb/examples/ndbapi_example5/Makefile b/ndb/examples/ndbapi_example5/Makefile index e2e3f06374a..5d44fb3933d 100644 --- a/ndb/examples/ndbapi_example5/Makefile +++ b/ndb/examples/ndbapi_example5/Makefile @@ -1,30 +1,20 @@ --include .defs.mk -#NDB_OS = OS_YOU_ARE_RUNNING_ON -#You need to set the NDB_OS variable here TARGET = ndbapi_example5 SRCS = ndbapi_example5.cpp OBJS = ndbapi_example5.o CXX = g++ CFLAGS = -c -Wall -fno-rtti -fno-exceptions +CXXFLAGS = DEBUG = LFLAGS = -Wall -INCLUDE_DIR = ../../include -LIB_DIR = ../../lib -ifeq ($(NDB_OS), SOLARIS) -# Here is the definition of system libraries necessary for Solaris 7 +TOP_SRCDIR = ../../.. +INCLUDE_DIR = $(TOP_SRCDIR)/ndb/include +LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \ + -L$(TOP_SRCDIR)/libmysql/.libs \ + -L$(TOP_SRCDIR)/mysys SYS_LIB = -endif -ifeq ($(NDB_OS), LINUX) -# Here is the definition of system libraries necessary for Linux 2.4 -SYS_LIB = -endif -ifeq ($(NDB_OS), MACOSX) -# Here is the definition of system libraries necessary for Mac OS X -SYS_LIB = -endif $(TARGET): $(OBJS) - $(CXX) $(LFLAGS) -L$(LIB_DIR) $(OBJS) -lNDB_API $(SYS_LIB) -o $(TARGET) + $(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient -lmysys $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) diff --git a/ndb/examples/ndbapi_example5/ndbapi_example5.cpp b/ndb/examples/ndbapi_example5/ndbapi_example5.cpp index 77f74e7bb63..d1a8d03555e 100644 --- a/ndb/examples/ndbapi_example5/ndbapi_example5.cpp +++ b/ndb/examples/ndbapi_example5/ndbapi_example5.cpp @@ -56,7 +56,6 @@ << error.code << ", msg: " << error.message << "." << std::endl; \ exit(-1); } -Ndb* myCreateNdb(); int myCreateEvent(Ndb* myNdb, const char *eventName, const char *eventTableName, @@ -66,12 +65,29 @@ int myCreateEvent(Ndb* myNdb, int main() { ndb_init(); - Ndb* myNdb = myCreateNdb(); + + Ndb_cluster_connection *cluster_connection= + new Ndb_cluster_connection(); // Object representing the cluster + + if (cluster_connection->wait_until_ready(30,30)) + { + std::cout << "Cluster was not ready within 30 secs." << std::endl; + exit(-1); + } + + Ndb* myNdb= new Ndb(cluster_connection, + "TEST_DB"); // Object representing the database + + if (myNdb->init() == -1) { + APIERROR(myNdb->getNdbError()); + exit(-1); + } + NdbDictionary::Dictionary *myDict; - const char *eventName = "CHNG_IN_TAB0"; - const char *eventTableName = "TAB0"; - const int noEventColumnName = 3; + const char *eventName= "CHNG_IN_TAB0"; + const char *eventTableName= "TAB0"; + const int noEventColumnName= 3; const char *eventColumnName[noEventColumnName] = {"COL0", "COL1", @@ -134,6 +150,8 @@ int main() case NdbDictionary::Event::TE_UPDATE: printf("%u UPDATE: ", i); break; + default: + abort(); // should not happen } printf("overrun %u pk %u: ", overrun, recAttr[0]->u_32_value()); for (int i = 1; i < noEventColumnName; i++) { @@ -166,26 +184,9 @@ int main() myDict->dropEvent(eventName); // remove event from database delete myNdb; -} - -Ndb* myCreateNdb() -{ - Ndb* myNdb = new Ndb("TEST_DB"); - - /******************************************** - * Initialize NDB and wait until it's ready * - ********************************************/ - if (myNdb->init() == -1) { - APIERROR(myNdb->getNdbError()); - exit(-1); - } - - if (myNdb->waitUntilReady(30) != 0) { - std::cout << "NDB was not ready within 30 secs." << std::endl; - exit(-1); - } - - return myNdb; + delete cluster_connection; + ndb_end(0); + return 0; } int myCreateEvent(Ndb* myNdb, diff --git a/ndb/examples/ndbapi_scan_example/Makefile b/ndb/examples/ndbapi_scan_example/Makefile index d7f08af4647..56bca839e17 100644 --- a/ndb/examples/ndbapi_scan_example/Makefile +++ b/ndb/examples/ndbapi_scan_example/Makefile @@ -1,35 +1,23 @@ --include .defs.mk -#NDB_OS = OS_YOU_ARE_RUNNING_ON -#You need to set the NDB_OS variable here (LINUX, SOLARIS, MACOSX) -#NDB_OS = LINUX - TARGET = ndbapi_scan -SRCS = ndbapi_scan.cpp +SRCS = ndbapi_scan.cpp OBJS = ndbapi_scan.o -CC = g++ -CFLAGS = -c -Wall -fno-rtti +CXX = g++ +CFLAGS = -c -Wall -fno-rtti -fno-exceptions +CXXFLAGS = 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)/ndb/include +LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \ + -L$(TOP_SRCDIR)/libmysql/.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 -lmysys $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) - $(CC) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) + $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) clean: rm -f *.o $(TARGET)