Commit d3b643d7 authored by mskold@mysql.com's avatar mskold@mysql.com

Merge mskold@bk-internal.mysql.com:/home/bk/mysql-5.0-ndb

into mysql.com:/usr/local/home/marty/MySQL/test/mysql-5.0-ndb
parents 43514808 9d267f4d
...@@ -1770,6 +1770,7 @@ examine config.log for possible errors. If you want to report this, use ...@@ -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!]) 'scripts/mysqlbug' and include at least the last 20 rows from config.log!])
fi fi
AC_CHECK_SIZEOF(char*, 4) AC_CHECK_SIZEOF(char*, 4)
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(int, 4) AC_CHECK_SIZEOF(int, 4)
if test "$ac_cv_sizeof_int" -eq 0 if test "$ac_cv_sizeof_int" -eq 0
then then
...@@ -2723,11 +2724,26 @@ then ...@@ -2723,11 +2724,26 @@ then
fi fi
AC_SUBST([ndb_bin_am_ldflags]) AC_SUBST([ndb_bin_am_ldflags])
AC_SUBST([ndb_opt_subdirs]) 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 AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl
ndb/src/Makefile ndb/src/common/Makefile dnl ndb/src/Makefile ndb/src/common/Makefile dnl
ndb/docs/Makefile dnl ndb/docs/Makefile dnl
ndb/tools/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/portlib/Makefile dnl
ndb/src/common/util/Makefile dnl ndb/src/common/util/Makefile dnl
ndb/src/common/logger/Makefile dnl ndb/src/common/logger/Makefile dnl
...@@ -2766,6 +2782,7 @@ AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl ...@@ -2766,6 +2782,7 @@ AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl
ndb/test/tools/Makefile dnl ndb/test/tools/Makefile dnl
ndb/test/run-test/Makefile mysql-test/ndb/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_version.h ndb/include/ndb_global.h dnl
ndb/include/ndb_types.h dnl
) )
fi fi
......
-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 TARGET = ndbapi_async
SRCS = ndbapi_async.cpp SRCS = $(TARGET).cpp
OBJS = ndbapi_async.o OBJS = $(TARGET).o
CC = g++ CXX = g++
CFLAGS = -c -Wall -fno-rtti -D$(NDB_OS) CFLAGS = -g -c -Wall -fno-rtti -fno-exceptions
CXXFLAGS = -g
DEBUG = DEBUG =
LFLAGS = -Wall LFLAGS = -Wall
INCLUDE_DIR = ../../include TOP_SRCDIR = ../../..
LIB_DIR = ../../lib INCLUDE_DIR = $(TOP_SRCDIR)
ifeq ($(NDB_OS), SOLARIS) LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \
# Here is the definition of system libraries necessary for Solaris 7 -L$(TOP_SRCDIR)/libmysql_r/.libs \
SYS_LIB = -lpthread -lsocket -lnsl -lrt -L$(TOP_SRCDIR)/mysys
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
SYS_LIB = SYS_LIB =
endif
$(TARGET): $(OBJS) $(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) $(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: clean:
rm -f *.o $(TARGET) rm -f *.o $(TARGET)
...@@ -24,10 +24,12 @@ ...@@ -24,10 +24,12 @@
* *
* Classes and methods in NDBAPI used in this example: * Classes and methods in NDBAPI used in this example:
* *
* Ndb_cluster_connection
* connect()
* wait_until_ready()
*
* Ndb * Ndb
* init() * init()
* waitUntilRead()
* getDictionary()
* startTransaction() * startTransaction()
* closeTransaction() * closeTransaction()
* sendPollNdb() * sendPollNdb()
...@@ -38,23 +40,6 @@ ...@@ -38,23 +40,6 @@
* executeAsynchPrepare() * executeAsynchPrepare()
* getNdbError() * getNdbError()
* *
* NdbDictionary::Dictionary
* getTable()
* dropTable()
* createTable()
* getNdbError()
*
* NdbDictionary::Column
* setName()
* setType()
* setLength()
* setPrimaryKey()
* setNullable()
*
* NdbDictionary::Table
* setName()
* addColumn()
*
* NdbOperation * NdbOperation
* insertTuple() * insertTuple()
* equal() * equal()
...@@ -63,10 +48,10 @@ ...@@ -63,10 +48,10 @@
*/ */
#include <ndb_global.h> #include <mysql.h>
#include <mysqld_error.h>
#include <NdbApi.hpp> #include <NdbApi.hpp>
#include <NdbScanFilter.hpp>
#include <iostream> // Used for cout #include <iostream> // Used for cout
/** /**
...@@ -85,11 +70,16 @@ milliSleep(int milliseconds){ ...@@ -85,11 +70,16 @@ milliSleep(int milliseconds){
/** /**
* error printout macro * error printout macro
*/ */
#define APIERROR(error) \ #define PRINT_ERROR(code,msg) \
{ std::cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \ std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \
<< error.code << ", msg: " << error.message << "." << std::endl; \ << ", code: " << code \
exit(-1); } << ", 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 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
/** /**
...@@ -106,10 +96,10 @@ typedef struct { ...@@ -106,10 +96,10 @@ typedef struct {
} async_callback_t; } async_callback_t;
/** /**
* Structure used in "free list" to a NdbConnection * Structure used in "free list" to a NdbTransaction
*/ */
typedef struct { typedef struct {
NdbConnection* conn; NdbTransaction* conn;
int used; int used;
} transaction_t; } transaction_t;
...@@ -132,7 +122,7 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData); ...@@ -132,7 +122,7 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData);
/** /**
* Error handler. * Error handler.
*/ */
bool asynchErrorHandler(NdbConnection * trans, Ndb* ndb); bool asynchErrorHandler(NdbTransaction * trans, Ndb* ndb);
/** /**
* Exit function * Exit function
...@@ -171,7 +161,7 @@ closeTransaction(Ndb * ndb , async_callback_t * cb) ...@@ -171,7 +161,7 @@ closeTransaction(Ndb * ndb , async_callback_t * cb)
* Callback executed when transaction has return from NDB * Callback executed when transaction has return from NDB
*/ */
static void static void
callback(int result, NdbConnection* trans, void* aObject) callback(int result, NdbTransaction* trans, void* aObject)
{ {
async_callback_t * cbData = (async_callback_t *)aObject; async_callback_t * cbData = (async_callback_t *)aObject;
if (result<0) if (result<0)
...@@ -207,61 +197,26 @@ callback(int result, NdbConnection* trans, void* aObject) ...@@ -207,61 +197,26 @@ callback(int result, NdbConnection* trans, void* aObject)
/** /**
* Create table "GARAGE" * Create table "GARAGE"
*/ */
int create_table(Ndb * myNdb) int create_table(MYSQL &mysql)
{ {
NdbDictionary::Table myTable; while (mysql_query(&mysql,
NdbDictionary::Column myColumn; "CREATE TABLE"
" GARAGE"
NdbDictionary::Dictionary* myDict = myNdb->getDictionary(); " (REG_NO INT UNSIGNED NOT NULL,"
" BRAND CHAR(20) NOT NULL,"
/********************************************************* " COLOR CHAR(20) NOT NULL,"
* Create a table named GARAGE if it does not exist * " PRIMARY KEY USING HASH (REG_NO))"
*********************************************************/ " ENGINE=NDB"))
if (myDict->getTable("GARAGE") != NULL)
{ {
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; << "Dropping it..." << std::endl;
if(myDict->dropTable("GARAGE") == -1) /**************
{ * Drop table *
std::cout << "Failed to drop: GARAGE." << std::endl; **************/
exit(1); if (mysql_query(&mysql, "DROP TABLE GARAGE"))
} MYSQLERROR(mysql);
}
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());
} }
return 1; return 1;
} }
...@@ -276,7 +231,7 @@ void asynchExitHandler(Ndb * m_ndb) ...@@ -276,7 +231,7 @@ void asynchExitHandler(Ndb * m_ndb)
/* returns true if is recoverable (temporary), /* returns true if is recoverable (temporary),
* false if it is an error that is permanent. * 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(); NdbError error = trans->getNdbError();
switch(error.status) switch(error.status)
...@@ -455,22 +410,48 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) ...@@ -455,22 +410,48 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData)
int main() int main()
{ {
ndb_init(); ndb_init();
Ndb* myNdb = new Ndb( "TEST_DB" ); // Object representing the database MYSQL mysql;
/******************************************* /**************************************************************
* Initialize NDB and wait until its ready * * Connect to mysql server and create table *
*******************************************/ **************************************************************/
if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions {
APIERROR(myNdb->getNdbError()); 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);
create_table(mysql);
} }
if (myNdb->waitUntilReady(30) != 0) { /**************************************************************
std::cout << "NDB was not ready within 30 secs." << std::endl; * 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); 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 * Initialise transaction array
*/ */
......
...@@ -141,8 +141,8 @@ static void create_table(MYSQL &mysql) ...@@ -141,8 +141,8 @@ static void create_table(MYSQL &mysql)
if (mysql_query(&mysql, if (mysql_query(&mysql,
"CREATE TABLE" "CREATE TABLE"
" MYTABLENAME" " MYTABLENAME"
" (ATTR1 INT UNSIGNED PRIMARY KEY," " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY,"
" ATTR2 INT UNSIGNED)" " ATTR2 INT UNSIGNED NOT NULL)"
" ENGINE=NDB")) " ENGINE=NDB"))
MYSQLERROR(mysql); MYSQLERROR(mysql);
} }
...@@ -234,7 +234,7 @@ static void do_read(Ndb &myNdb) ...@@ -234,7 +234,7 @@ static void do_read(Ndb &myNdb)
NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME"); NdbOperation *myOperation= myTransaction->getNdbOperation("MYTABLENAME");
if (myOperation == NULL) APIERROR(myTransaction->getNdbError()); if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->readTuple(); myOperation->readTuple(NdbOperation::LM_Read);
myOperation->equal("ATTR1", i); myOperation->equal("ATTR1", i);
NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL); NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL);
......
TARGET = ndbapi_example4 TARGET = ndbapi_example4
SRCS = ndbapi_example4.cpp SRCS = $(TARGET).cpp
OBJS = ndbapi_example4.o OBJS = $(TARGET).o
CXX = g++ CXX = g++
CFLAGS = -c -Wall -fno-rtti -fno-exceptions CFLAGS = -c -Wall -fno-rtti -fno-exceptions
CXXFLAGS =
DEBUG = DEBUG =
LFLAGS = -Wall LFLAGS = -Wall
INCLUDE_DIR = ../../include TOP_SRCDIR = ../../..
LIB_DIR = -L../../src/.libs \ INCLUDE_DIR = $(TOP_SRCDIR)
-L../../../libmysql_r/.libs \ LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \
-L../../../mysys -L$(TOP_SRCDIR)/libmysql_r/.libs \
-L$(TOP_SRCDIR)/mysys
SYS_LIB = SYS_LIB =
$(TARGET): $(OBJS) $(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) $(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: clean:
rm -f *.o $(TARGET) rm -f *.o $(TARGET)
TARGET = ndbapi_scan TARGET = ndbapi_scan
SRCS = ndbapi_scan.cpp SRCS = $(TARGET).cpp
OBJS = ndbapi_scan.o OBJS = $(TARGET).o
CXX = g++ CXX = g++
CFLAGS = -c -Wall -fno-rtti -fno-exceptions CFLAGS = -g -c -Wall -fno-rtti -fno-exceptions
CXXFLAGS = CXXFLAGS = -g
DEBUG = DEBUG =
LFLAGS = -Wall LFLAGS = -Wall
TOP_SRCDIR = ../../.. TOP_SRCDIR = ../../..
INCLUDE_DIR = $(TOP_SRCDIR)/ndb/include INCLUDE_DIR = $(TOP_SRCDIR)
LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \ LIB_DIR = -L$(TOP_SRCDIR)/ndb/src/.libs \
-L$(TOP_SRCDIR)/libmysql_r/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \
-L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/mysys
...@@ -17,7 +17,7 @@ $(TARGET): $(OBJS) ...@@ -17,7 +17,7 @@ $(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $(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) $(TARGET).o: $(SRCS)
$(CXX) $(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: clean:
rm -f *.o $(TARGET) rm -f *.o $(TARGET)
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
* getNdbScanOperation() * getNdbScanOperation()
* execute() * execute()
* *
* NdbResultSet
*
* NdbScanOperation * NdbScanOperation
* getValue() * getValue()
* readTuples() * readTuples()
...@@ -47,21 +45,14 @@ ...@@ -47,21 +45,14 @@
* deleteCurrentTuple() * deleteCurrentTuple()
* updateCurrentTuple() * updateCurrentTuple()
* *
* NdbDictionary::Dictionary * const NdbDictionary::Dictionary
* getTable() * getTable()
* dropTable()
* createTable()
* *
* NdbDictionary::Column * const NdbDictionary::Table
* setName() * getColumn()
* setType()
* setLength()
* setPrimaryKey()
* setNullable()
* *
* NdbDictionary::Table * const NdbDictionary::Column
* setName() * getLength()
* addColumn()
* *
* NdbOperation * NdbOperation
* insertTuple() * insertTuple()
...@@ -76,6 +67,8 @@ ...@@ -76,6 +67,8 @@
*/ */
#include <mysql.h>
#include <mysqld_error.h>
#include <NdbApi.hpp> #include <NdbApi.hpp>
// Used for cout // Used for cout
#include <iostream> #include <iostream>
...@@ -97,10 +90,16 @@ milliSleep(int milliseconds){ ...@@ -97,10 +90,16 @@ milliSleep(int milliseconds){
/** /**
* Helper sleep function * Helper sleep function
*/ */
#define APIERROR(error) \ #define PRINT_ERROR(code,msg) \
{ std::cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \ std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \
<< error.code << ", msg: " << error.message << "." << std::endl; \ << ", code: " << code \
exit(-1); } << ", 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); }
struct Car struct Car
{ {
...@@ -112,55 +111,26 @@ struct Car ...@@ -112,55 +111,26 @@ struct Car
/** /**
* Function to create table * Function to create table
*/ */
int create_table(Ndb * myNdb) int create_table(MYSQL &mysql)
{ {
NdbDictionary::Table myTable; while (mysql_query(&mysql,
NdbDictionary::Column myColumn; "CREATE TABLE"
" GARAGE"
NdbDictionary::Dictionary* myDict = myNdb->getDictionary(); " (REG_NO INT UNSIGNED NOT NULL,"
" BRAND CHAR(20) NOT NULL,"
/********************************************************* " COLOR CHAR(20) NOT NULL,"
* Create a table named GARAGE if it does not exist * " PRIMARY KEY USING HASH (REG_NO))"
*********************************************************/ " ENGINE=NDB"))
if (myDict->getTable("GARAGE") != NULL) { {
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; << "Dropping it..." << std::endl;
if(myDict->dropTable("GARAGE") == -1) /**************
{ * Drop table *
std::cout << "Failed to drop: GARAGE." << std::endl; **************/
exit(1); if (mysql_query(&mysql, "DROP TABLE GARAGE"))
} MYSQLERROR(mysql);
}
Car car;
myTable.setName("GARAGE");
myColumn.setName("REG_NO");
myColumn.setType(NdbDictionary::Column::Unsigned);
myColumn.setLength(1);
myColumn.setPrimaryKey(true);
myColumn.setNullable(false);
myTable.addColumn(myColumn);
myColumn.setName("BRAND");
myColumn.setType(NdbDictionary::Column::Char);
myColumn.setLength(sizeof(car.brand));
myColumn.setPrimaryKey(false);
myColumn.setNullable(false);
myTable.addColumn(myColumn);
myColumn.setName("COLOR");
myColumn.setType(NdbDictionary::Column::Char);
myColumn.setLength(sizeof(car.color));
myColumn.setPrimaryKey(false);
myColumn.setNullable(false);
myTable.addColumn(myColumn);
if (myDict->createTable(myTable) == -1) {
APIERROR(myDict->getNdbError());
return -1;
} }
return 1; return 1;
} }
...@@ -460,7 +430,7 @@ int scan_update(Ndb* myNdb, ...@@ -460,7 +430,7 @@ int scan_update(Ndb* myNdb,
/** /**
* Define a result set for the scan. * Define a result set for the scan.
*/ */
if( myScanOp->readTuplesExclusive(NdbOperation::LM_Exclusive) ) if( myScanOp->readTuples(NdbOperation::LM_Exclusive) )
{ {
std::cout << myTrans->getNdbError().message << std::endl; std::cout << myTrans->getNdbError().message << std::endl;
myNdb->closeTransaction(myTrans); myNdb->closeTransaction(myTrans);
...@@ -726,36 +696,67 @@ int scan_print(Ndb * myNdb) ...@@ -726,36 +696,67 @@ int scan_print(Ndb * myNdb)
int main() int main()
{ {
ndb_init(); ndb_init();
MYSQL mysql;
Ndb_cluster_connection cluster_connection; /**************************************************************
* 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 (cluster_connection.connect(12, 5, 1)) 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; std::cout << "Unable to connect to cluster within 30 secs." << std::endl;
exit(-1); exit(-1);
} }
// Optionally connect and wait for the storage nodes (ndbd's)
if (cluster_connection.wait_until_ready(30,30)) if (cluster_connection.wait_until_ready(30,0) < 0)
{ {
std::cout << "Cluster was not ready within 30 secs." << std::endl; std::cout << "Cluster was not ready within 30 secs.\n";
exit(-1); exit(-1);
} }
Ndb myNdb(&cluster_connection,"TEST_DB" ); Ndb myNdb(&cluster_connection,"TEST_DB");
if (myNdb.init(1024) == -1) { // Set max 1024 parallel transactions
/*******************************************
* Initialize NDB and wait until its ready *
*******************************************/
if (myNdb.init(1024) == -1) { // Set max 1024 parallel transactions
APIERROR(myNdb.getNdbError()); APIERROR(myNdb.getNdbError());
exit(-1); exit(-1);
} }
create_table(&myNdb); /*******************************************
* Check table definition *
NdbDictionary::Dictionary* myDict = myNdb.getDictionary(); *******************************************/
int column_color = myDict->getTable("GARAGE")->getColumn("COLOR")->getColumnNo(); int column_color;
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *t= myDict->getTable("GARAGE");
Car car;
if (t->getColumn("COLOR")->getLength() != sizeof(car.color) ||
t->getColumn("BRAND")->getLength() != sizeof(car.brand))
{
std::cout << "Wrong table definition" << std::endl;
exit(-1);
}
column_color= t->getColumn("COLOR")->getColumnNo();
}
if(populate(&myNdb) > 0) if(populate(&myNdb) > 0)
std::cout << "populate: Success!" << std::endl; std::cout << "populate: Success!" << std::endl;
...@@ -789,4 +790,6 @@ int main() ...@@ -789,4 +790,6 @@ int main()
} }
if(scan_print(&myNdb) > 0) if(scan_print(&myNdb) > 0)
std::cout << "scan_print: Success!" << std::endl << std::endl; std::cout << "scan_print: Success!" << std::endl << std::endl;
return 0;
} }
-include .defs.mk
#NDB_OS = OS_YOU_ARE_RUNNING_ON
#You need to set the NDB_OS variable here
TARGET = select_all
SRCS = select_all.cpp
OBJS = select_all.o
CXX = g++
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
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)
$(TARGET).o: $(SRCS)
$(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS)
clean:
rm -f *.o $(TARGET)
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
//
// select_all.cpp: Prints all rows of a table
//
// Usage: select_all <table_name>+
#include <NdbApi.hpp>
// Used for cout
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#define APIERROR(error) \
{ cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \
<< error.code << ", msg: " << error.message << "." << endl; \
exit(-1); }
void usage(const char* prg) {
cout << "Usage: " << prg << " <table name>" << endl;
cout << "Prints all rows of table named <table name>" << endl;
exit(0);
}
/*****************************************************************************
*************************** Result Set Container ****************************
*****************************************************************************/
/*
* Container of NdbRecAttr objects.
* (NdbRecAttr objects are database rows read by a scan operation.)
*/
class ResultSetContainer {
public:
/**
* Initialize ResultSetContainer object for table named <tableName>
* - Allocates memory
* - Fetches attribute names from NDB Cluster
*/
void init(NdbDictionary::Dictionary* dict, const char* tableName);
/**
* Get no of attributes for stored NdbRecAttr objects
*/
int getNoOfAttributes() const;
/**
* Get NdbRecAttr object no i
*/
NdbRecAttr* & getAttrStore(int i);
/**
* Get attribute name of attribute no i
*/
const char* getAttrName(int i) const;
/**
* Print header of rows
*/
void header() const;
private:
int m_cols; // No of attributes for stored NdbRecAttr objects
char **m_names; // Names of attributes
NdbRecAttr **m_data; // The actual stored NdbRecAttr objects
};
void ResultSetContainer::init(NdbDictionary::Dictionary * dict,
const char* tableName)
{
// Get Table object from NDB (this contains metadata about all tables)
const NdbDictionary::Table * tab = dict->getTable(tableName);
// Get table id of the table we are interested in
if (tab == 0) APIERROR(dict->getNdbError()); // E.g. table didn't exist
// Get no of attributes and allocate memory
m_cols = tab->getNoOfColumns();
m_names = new char* [m_cols];
m_data = new NdbRecAttr* [m_cols];
// Store all attribute names for the table
for (int i = 0; i < m_cols; i++) {
m_names[i] = new char[255];
BaseString::snprintf(m_names[i], 255, "%s", tab->getColumn(i)->getName());
}
}
int ResultSetContainer::getNoOfAttributes() const {return m_cols;}
NdbRecAttr*& ResultSetContainer::getAttrStore(int i) {return m_data[i];}
const char* ResultSetContainer::getAttrName(int i) const {return m_names[i];}
/*****************************************************************************
********************************** MAIN ***********************************
*****************************************************************************/
int main(int argc, const char** argv)
{
ndb_init();
Ndb* myNdb = new Ndb("ndbapi_example4"); // Object representing the database
NdbConnection* myNdbConnection; // For transactions
NdbOperation* myNdbOperation; // For operations
int check;
if (argc != 2) {
usage(argv[0]);
exit(0);
}
const char* tableName = argv[1];
/*******************************************
* Initialize NDB and wait until its ready *
*******************************************/
if (myNdb->init() == -1) {
APIERROR(myNdb->getNdbError());
exit(-1);
}
if (myNdb->waitUntilReady(30) != 0) {
cout << "NDB was not ready within 30 secs." << endl;
exit(-1);
}
/***************************
* Define and execute scan *
***************************/
cout << "Select * from " << tableName << endl;
ResultSetContainer * container = new ResultSetContainer;
container->init(myNdb->getDictionary(), tableName);
myNdbConnection = myNdb->startTransaction();
if (myNdbConnection == NULL) APIERROR(myNdb->getNdbError());
myNdbOperation = myNdbConnection->getNdbOperation(tableName);
if (myNdbOperation == NULL) APIERROR(myNdbConnection->getNdbError());
// Define the operation to be an 'openScanRead' operation.
check = myNdbOperation->openScanRead(1);
if (check == -1) APIERROR(myNdbConnection->getNdbError());
// Set interpreted program to just be the single instruction
// 'interpret_exit_ok'. (This approves all rows of the table.)
if (myNdbOperation->interpret_exit_ok() == -1)
APIERROR(myNdbConnection->getNdbError());
// Get all attribute values of the row
for(int i = 0; i < container->getNoOfAttributes(); i++){
if((container->getAttrStore(i) =
myNdbOperation->getValue(container->getAttrName(i))) == 0)
APIERROR(myNdbConnection->getNdbError());
}
// Execute scan operation
check = myNdbConnection->executeScan();
if (check == -1) APIERROR(myNdbConnection->getNdbError());
/****************
* Print header *
****************/
for (int i = 0; i < container->getNoOfAttributes(); i++)
cout << container->getAttrName(i) << "\t";
cout << endl;
for (int i = 0; i < container->getNoOfAttributes(); i++) {
for (int j = strlen(container->getAttrName(i)); j > 0; j--)
cout << "-";
cout << "\t";
}
cout << "\n";
/**************
* Scan table *
**************/
int eof;
int rows = 0;
// Print all rows of table
while ((eof = myNdbConnection->nextScanResult()) == 0) {
rows++;
for (int i = 0; i < container->getNoOfAttributes(); i++) {
if (container->getAttrStore(i)->isNULL()) {
cout << "NULL";
} else {
// Element size of value (No of bits per element in attribute value)
const int size = container->getAttrStore(i)->attrSize();
// No of elements in an array attribute (Is 1 if non-array attribute)
const int aSize = container->getAttrStore(i)->arraySize();
switch(container->getAttrStore(i)->attrType()){
case UnSigned:
switch(size) {
case 8: cout << container->getAttrStore(i)->u_64_value(); break;
case 4: cout << container->getAttrStore(i)->u_32_value(); break;
case 2: cout << container->getAttrStore(i)->u_short_value(); break;
case 1: cout << (unsigned) container->getAttrStore(i)->u_char_value();
break;
default: cout << "Unknown size" << endl;
}
break;
case Signed:
switch(size) {
case 8: cout << container->getAttrStore(i)->int64_value(); break;
case 4: cout << container->getAttrStore(i)->int32_value(); break;
case 2: cout << container->getAttrStore(i)->short_value(); break;
case 1: cout << (int) container->getAttrStore(i)->char_value(); break;
default: cout << "Unknown size" << endl;
}
break;
case String:
{
char* buf = new char[aSize+1];
memcpy(buf, container->getAttrStore(i)->aRef(), aSize);
buf[aSize] = 0;
cout << buf;
delete [] buf;
}
break;
case Float:
cout << container->getAttrStore(i)->float_value();
break;
default:
cout << "Unknown";
break;
}
}
cout << "\t";
}
cout << endl;
}
if (eof == -1) APIERROR(myNdbConnection->getNdbError());
myNdb->closeTransaction(myNdbConnection);
cout << "Selected " << rows << " rows." << endl;
}
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef NDBGLOBAL_H #ifndef NDB_GLOBAL_H
#define NDBGLOBAL_H #define NDB_GLOBAL_H
#include <ndb_types.h> #include <ndb_types.h>
...@@ -31,45 +31,22 @@ ...@@ -31,45 +31,22 @@
#define HAVE_STRCASECMP #define HAVE_STRCASECMP
#define strcasecmp _strcmpi #define strcasecmp _strcmpi
#pragma warning(disable: 4503 4786) #pragma warning(disable: 4503 4786)
typedef unsigned __int64 Uint64;
typedef signed __int64 Int64;
#else #else
#undef NDB_WIN32 #undef NDB_WIN32
#define DIR_SEPARATOR "/" #define DIR_SEPARATOR "/"
typedef unsigned long long Uint64;
typedef signed long long Int64;
#endif #endif
#include <my_global.h> #include <my_global.h>
typedef signed char Int8; #if ! (NDB_SIZEOF_CHAR == SIZEOF_CHAR)
typedef unsigned char Uint8;
typedef signed short Int16;
typedef unsigned short Uint16;
typedef signed int Int32;
typedef unsigned int Uint32;
typedef unsigned int UintR;
#ifdef __SIZE_TYPE__
typedef __SIZE_TYPE__ UintPtr;
#elif SIZEOF_CHARP == 4
typedef Uint32 UintPtr;
#elif SIZEOF_CHARP == 8
typedef Uint64 UintPtr;
#else
#error "Unknown size of (char *)"
#endif
#if ! (SIZEOF_CHAR == 1)
#error "Invalid define for Uint8" #error "Invalid define for Uint8"
#endif #endif
#if ! (SIZEOF_INT == 4) #if ! (NDB_SIZEOF_INT == SIZEOF_INT)
#error "Invalid define for Uint32" #error "Invalid define for Uint32"
#endif #endif
#if ! (SIZEOF_LONG_LONG == 8) #if ! (NDB_SIZEOF_LONG_LONG == SIZEOF_LONG_LONG)
#error "Invalid define for Uint64" #error "Invalid define for Uint64"
#endif #endif
......
...@@ -21,7 +21,61 @@ ...@@ -21,7 +21,61 @@
#ifndef NDB_TYPES_H #ifndef NDB_TYPES_H
#define NDB_TYPES_H #define NDB_TYPES_H
#include "ndb_global.h" #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64)
#define NDB_SIZEOF_CHARP SIZEOF_CHARP
#define NDB_SIZEOF_CHAR SIZEOF_CHAR
#define NDB_SIZEOF_SHORT 2
#define NDB_SIZEOF_INT SIZEOF_INT
#define NDB_SIZEOF_LONG SIZEOF_LONG
#define NDB_SIZEOF_LONG_LONG SIZEOF_LONG_LONG
typedef unsigned __int64 Uint64;
typedef signed __int64 Int64;
#else
#define NDB_SIZEOF_CHARP @NDB_SIZEOF_CHARP@
#define NDB_SIZEOF_CHAR @NDB_SIZEOF_CHAR@
#define NDB_SIZEOF_INT @NDB_SIZEOF_INT@
#define NDB_SIZEOF_SHORT @NDB_SIZEOF_SHORT@
#define NDB_SIZEOF_LONG @NDB_SIZEOF_LONG@
#define NDB_SIZEOF_LONG_LONG @NDB_SIZEOF_LONG_LONG@
typedef unsigned long long Uint64;
typedef signed long long Int64;
#endif
typedef signed char Int8;
typedef unsigned char Uint8;
typedef signed short Int16;
typedef unsigned short Uint16;
typedef signed int Int32;
typedef unsigned int Uint32;
typedef unsigned int UintR;
#ifdef __SIZE_TYPE__
typedef __SIZE_TYPE__ UintPtr;
#elif NDB_SIZEOF_CHARP == 4
typedef Uint32 UintPtr;
#elif NDB_SIZEOF_CHARP == 8
typedef Uint64 UintPtr;
#else
#error "Unknown size of (char *)"
#endif
#if ! (NDB_SIZEOF_CHAR == 1)
#error "Invalid define for Uint8"
#endif
#if ! (NDB_SIZEOF_SHORT == 2)
#error "Invalid define for Uint16"
#endif
#if ! (NDB_SIZEOF_INT == 4)
#error "Invalid define for Uint32"
#endif
#if ! (NDB_SIZEOF_LONG_LONG == 8)
#error "Invalid define for Uint64"
#endif
#include "ndb_constants.h" #include "ndb_constants.h"
#endif #endif
...@@ -1023,7 +1023,7 @@ public: ...@@ -1023,7 +1023,7 @@ public:
* @param name Name of table to get * @param name Name of table to get
* @return table if successful otherwise NULL. * @return table if successful otherwise NULL.
*/ */
const Table * getTable(const char * name); const Table * getTable(const char * name) const;
/** /**
* Get index with given name, NULL if undefined * Get index with given name, NULL if undefined
...@@ -1032,7 +1032,7 @@ public: ...@@ -1032,7 +1032,7 @@ public:
* @return index if successful, otherwise 0. * @return index if successful, otherwise 0.
*/ */
const Index * getIndex(const char * indexName, const Index * getIndex(const char * indexName,
const char * tableName); const char * tableName) const;
/** /**
* Fetch list of indexes of given table. * Fetch list of indexes of given table.
...@@ -1173,10 +1173,10 @@ public: ...@@ -1173,10 +1173,10 @@ public:
class NdbDictionaryImpl & m_impl; class NdbDictionaryImpl & m_impl;
Dictionary(NdbDictionaryImpl&); Dictionary(NdbDictionaryImpl&);
const Table * getIndexTable(const char * indexName, const Table * getIndexTable(const char * indexName,
const char * tableName); const char * tableName) const;
public: public:
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
const Table * getTable(const char * name, void **data); const Table * getTable(const char * name, void **data) const;
void set_local_table_data_size(unsigned sz); void set_local_table_data_size(unsigned sz);
#endif #endif
}; };
......
...@@ -706,7 +706,8 @@ NdbDictionary::Dictionary::alterTable(const Table & t){ ...@@ -706,7 +706,8 @@ NdbDictionary::Dictionary::alterTable(const Table & t){
} }
const NdbDictionary::Table * const NdbDictionary::Table *
NdbDictionary::Dictionary::getTable(const char * name, void **data){ NdbDictionary::Dictionary::getTable(const char * name, void **data) const
{
NdbTableImpl * t = m_impl.getTable(name, data); NdbTableImpl * t = m_impl.getTable(name, data);
if(t) if(t)
return t->m_facade; return t->m_facade;
...@@ -719,7 +720,8 @@ void NdbDictionary::Dictionary::set_local_table_data_size(unsigned sz) ...@@ -719,7 +720,8 @@ void NdbDictionary::Dictionary::set_local_table_data_size(unsigned sz)
} }
const NdbDictionary::Table * const NdbDictionary::Table *
NdbDictionary::Dictionary::getTable(const char * name){ NdbDictionary::Dictionary::getTable(const char * name) const
{
return getTable(name, 0); return getTable(name, 0);
} }
...@@ -752,7 +754,7 @@ NdbDictionary::Dictionary::dropIndex(const char * indexName, ...@@ -752,7 +754,7 @@ NdbDictionary::Dictionary::dropIndex(const char * indexName,
const NdbDictionary::Index * const NdbDictionary::Index *
NdbDictionary::Dictionary::getIndex(const char * indexName, NdbDictionary::Dictionary::getIndex(const char * indexName,
const char * tableName) const char * tableName) const
{ {
NdbIndexImpl * i = m_impl.getIndex(indexName, tableName); NdbIndexImpl * i = m_impl.getIndex(indexName, tableName);
if(i) if(i)
...@@ -782,7 +784,7 @@ NdbDictionary::Dictionary::removeCachedIndex(const char * indexName, ...@@ -782,7 +784,7 @@ NdbDictionary::Dictionary::removeCachedIndex(const char * indexName,
const NdbDictionary::Table * const NdbDictionary::Table *
NdbDictionary::Dictionary::getIndexTable(const char * indexName, NdbDictionary::Dictionary::getIndexTable(const char * indexName,
const char * tableName) const char * tableName) const
{ {
NdbIndexImpl * i = m_impl.getIndex(indexName, tableName); NdbIndexImpl * i = m_impl.getIndex(indexName, tableName);
NdbTableImpl * t = m_impl.getTable(tableName); NdbTableImpl * t = m_impl.getTable(tableName);
......
...@@ -119,7 +119,7 @@ int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism) ...@@ -119,7 +119,7 @@ int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism)
const int retryMax = 10; const int retryMax = 10;
int deletedRows = 0; int deletedRows = 0;
int check; int check;
NdbConnection *pTrans; NdbTransaction *pTrans;
NdbScanOperation *pOp; NdbScanOperation *pOp;
NdbError err; NdbError err;
......
...@@ -21,7 +21,7 @@ extern FilteredNdbOut err; ...@@ -21,7 +21,7 @@ extern FilteredNdbOut err;
extern FilteredNdbOut info; extern FilteredNdbOut info;
extern FilteredNdbOut debug; extern FilteredNdbOut debug;
static void callback(int, NdbConnection*, void*); static void callback(int, NdbTransaction*, void*);
extern const char * g_connect_string; extern const char * g_connect_string;
bool bool
...@@ -492,7 +492,7 @@ BackupRestore::logEntry(const LogEntry & tup) ...@@ -492,7 +492,7 @@ BackupRestore::logEntry(const LogEntry & tup)
if (!m_restore) if (!m_restore)
return; return;
NdbConnection * trans = m_ndb->startTransaction(); NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL) if (trans == NULL)
{ {
// Deep shit, TODO: handle the error // Deep shit, TODO: handle the error
...@@ -584,12 +584,12 @@ BackupRestore::endOfLogEntrys() ...@@ -584,12 +584,12 @@ BackupRestore::endOfLogEntrys()
* *
* (This function must have three arguments: * (This function must have three arguments:
* - The result of the transaction, * - The result of the transaction,
* - The NdbConnection object, and * - The NdbTransaction object, and
* - A pointer to an arbitrary object.) * - A pointer to an arbitrary object.)
*/ */
static void static void
callback(int result, NdbConnection* trans, void* aObject) callback(int result, NdbTransaction* trans, void* aObject)
{ {
restore_callback_t *cb = (restore_callback_t *)aObject; restore_callback_t *cb = (restore_callback_t *)aObject;
(cb->restore)->cback(result, cb); (cb->restore)->cback(result, cb);
...@@ -603,7 +603,7 @@ BackupRestore::tuple(const TupleS & tup) ...@@ -603,7 +603,7 @@ BackupRestore::tuple(const TupleS & tup)
return; return;
while (1) while (1)
{ {
NdbConnection * trans = m_ndb->startTransaction(); NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL) if (trans == NULL)
{ {
// Deep shit, TODO: handle the error // Deep shit, TODO: handle the error
......
...@@ -21,8 +21,8 @@ extern FilteredNdbOut err; ...@@ -21,8 +21,8 @@ extern FilteredNdbOut err;
extern FilteredNdbOut info; extern FilteredNdbOut info;
extern FilteredNdbOut debug; extern FilteredNdbOut debug;
static bool asynchErrorHandler(NdbConnection * trans, Ndb * ndb); static bool asynchErrorHandler(NdbTransaction * trans, Ndb * ndb);
static void callback(int result, NdbConnection* trans, void* aObject); static void callback(int result, NdbTransaction* trans, void* aObject);
bool bool
BackupRestore::init() BackupRestore::init()
...@@ -371,7 +371,7 @@ BackupRestore::tuple(const TupleS & tup) ...@@ -371,7 +371,7 @@ BackupRestore::tuple(const TupleS & tup)
return; return;
while (1) while (1)
{ {
NdbConnection * trans = m_ndb->startTransaction(); NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL) if (trans == NULL)
{ {
// Deep shit, TODO: handle the error // Deep shit, TODO: handle the error
...@@ -460,7 +460,7 @@ BackupRestore::logEntry(const LogEntry & tup) ...@@ -460,7 +460,7 @@ BackupRestore::logEntry(const LogEntry & tup)
if (!m_restore) if (!m_restore)
return; return;
NdbConnection * trans = m_ndb->startTransaction(); NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL) if (trans == NULL)
{ {
// Deep shit, TODO: handle the error // Deep shit, TODO: handle the error
...@@ -551,7 +551,7 @@ BackupRestore::endOfLogEntrys() ...@@ -551,7 +551,7 @@ BackupRestore::endOfLogEntrys()
* *
******************************************/ ******************************************/
static void restoreCallback(int result, // Result for transaction static void restoreCallback(int result, // Result for transaction
NdbConnection *object, // Transaction object NdbTransaction *object, // Transaction object
void *anything) // Not used void *anything) // Not used
{ {
static Uint32 counter = 0; static Uint32 counter = 0;
...@@ -593,12 +593,12 @@ static void restoreCallback(int result, // Result for transaction ...@@ -593,12 +593,12 @@ static void restoreCallback(int result, // Result for transaction
* *
* (This function must have three arguments: * (This function must have three arguments:
* - The result of the transaction, * - The result of the transaction,
* - The NdbConnection object, and * - The NdbTransaction object, and
* - A pointer to an arbitrary object.) * - A pointer to an arbitrary object.)
*/ */
static void static void
callback(int result, NdbConnection* trans, void* aObject) callback(int result, NdbTransaction* trans, void* aObject)
{ {
restore_callback_t *cb = (restore_callback_t *)aObject; restore_callback_t *cb = (restore_callback_t *)aObject;
(cb->restore)->cback(result, cb); (cb->restore)->cback(result, cb);
...@@ -610,7 +610,7 @@ callback(int result, NdbConnection* trans, void* aObject) ...@@ -610,7 +610,7 @@ callback(int result, NdbConnection* trans, void* aObject)
* false if it is an error that generates an abort. * false if it is an error that generates an abort.
*/ */
static static
bool asynchErrorHandler(NdbConnection * trans, Ndb* ndb) bool asynchErrorHandler(NdbTransaction * trans, Ndb* ndb)
{ {
NdbError error = trans->getNdbError(); NdbError error = trans->getNdbError();
ndb->closeTransaction(trans); ndb->closeTransaction(trans);
......
...@@ -194,7 +194,7 @@ int scanReadRecords(Ndb* pNdb, ...@@ -194,7 +194,7 @@ int scanReadRecords(Ndb* pNdb,
int retryAttempt = 0; int retryAttempt = 0;
const int retryMax = 100; const int retryMax = 100;
int check; int check;
NdbConnection *pTrans; NdbTransaction *pTrans;
NdbScanOperation *pOp; NdbScanOperation *pOp;
NdbIndexScanOperation * pIOp= 0; NdbIndexScanOperation * pIOp= 0;
......
...@@ -141,7 +141,7 @@ select_count(Ndb* pNdb, const NdbDictionary::Table* pTab, ...@@ -141,7 +141,7 @@ select_count(Ndb* pNdb, const NdbDictionary::Table* pTab,
int retryAttempt = 0; int retryAttempt = 0;
const int retryMax = 100; const int retryMax = 100;
int check; int check;
NdbConnection *pTrans; NdbTransaction *pTrans;
NdbScanOperation *pOp; NdbScanOperation *pOp;
while (true){ while (true){
......
...@@ -154,7 +154,7 @@ static int ndb_to_mysql_error(const NdbError *err) ...@@ -154,7 +154,7 @@ static int ndb_to_mysql_error(const NdbError *err)
inline inline
int execute_no_commit(ha_ndbcluster *h, NdbConnection *trans) int execute_no_commit(ha_ndbcluster *h, NdbTransaction *trans)
{ {
int m_batch_execute= 0; int m_batch_execute= 0;
#ifdef NOT_USED #ifdef NOT_USED
...@@ -165,7 +165,7 @@ int execute_no_commit(ha_ndbcluster *h, NdbConnection *trans) ...@@ -165,7 +165,7 @@ int execute_no_commit(ha_ndbcluster *h, NdbConnection *trans)
} }
inline inline
int execute_commit(ha_ndbcluster *h, NdbConnection *trans) int execute_commit(ha_ndbcluster *h, NdbTransaction *trans)
{ {
int m_batch_execute= 0; int m_batch_execute= 0;
#ifdef NOT_USED #ifdef NOT_USED
...@@ -176,7 +176,7 @@ int execute_commit(ha_ndbcluster *h, NdbConnection *trans) ...@@ -176,7 +176,7 @@ int execute_commit(ha_ndbcluster *h, NdbConnection *trans)
} }
inline inline
int execute_commit(THD *thd, NdbConnection *trans) int execute_commit(THD *thd, NdbTransaction *trans)
{ {
int m_batch_execute= 0; int m_batch_execute= 0;
#ifdef NOT_USED #ifdef NOT_USED
...@@ -187,7 +187,7 @@ int execute_commit(THD *thd, NdbConnection *trans) ...@@ -187,7 +187,7 @@ int execute_commit(THD *thd, NdbConnection *trans)
} }
inline inline
int execute_no_commit_ie(ha_ndbcluster *h, NdbConnection *trans) int execute_no_commit_ie(ha_ndbcluster *h, NdbTransaction *trans)
{ {
int m_batch_execute= 0; int m_batch_execute= 0;
#ifdef NOT_USED #ifdef NOT_USED
...@@ -532,7 +532,7 @@ void ha_ndbcluster::no_uncommitted_rows_reset(THD *thd) ...@@ -532,7 +532,7 @@ void ha_ndbcluster::no_uncommitted_rows_reset(THD *thd)
*/ */
int ha_ndbcluster::ndb_err(NdbConnection *trans) int ha_ndbcluster::ndb_err(NdbTransaction *trans)
{ {
int res; int res;
const NdbError err= trans->getNdbError(); const NdbError err= trans->getNdbError();
...@@ -1293,7 +1293,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf) ...@@ -1293,7 +1293,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf)
DBUG_PRINT("enter", ("key_len: %u", key_len)); DBUG_PRINT("enter", ("key_len: %u", key_len));
DBUG_DUMP("key", (char*)key, key_len); DBUG_DUMP("key", (char*)key, key_len);
uint no_fields= table->fields, i; uint no_fields= table->fields, i;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbOperation *op; NdbOperation *op;
THD *thd= current_thd; THD *thd= current_thd;
...@@ -1343,7 +1343,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf) ...@@ -1343,7 +1343,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf)
int ha_ndbcluster::complemented_pk_read(const byte *old_data, byte *new_data) int ha_ndbcluster::complemented_pk_read(const byte *old_data, byte *new_data)
{ {
uint no_fields= table->fields, i; uint no_fields= table->fields, i;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbOperation *op; NdbOperation *op;
THD *thd= current_thd; THD *thd= current_thd;
DBUG_ENTER("complemented_pk_read"); DBUG_ENTER("complemented_pk_read");
...@@ -1406,7 +1406,7 @@ int ha_ndbcluster::complemented_pk_read(const byte *old_data, byte *new_data) ...@@ -1406,7 +1406,7 @@ int ha_ndbcluster::complemented_pk_read(const byte *old_data, byte *new_data)
int ha_ndbcluster::peek_row() int ha_ndbcluster::peek_row()
{ {
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbOperation *op; NdbOperation *op;
THD *thd= current_thd; THD *thd= current_thd;
DBUG_ENTER("peek_row"); DBUG_ENTER("peek_row");
...@@ -1437,7 +1437,7 @@ int ha_ndbcluster::unique_index_read(const byte *key, ...@@ -1437,7 +1437,7 @@ int ha_ndbcluster::unique_index_read(const byte *key,
uint key_len, byte *buf) uint key_len, byte *buf)
{ {
int res; int res;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbIndexOperation *op; NdbIndexOperation *op;
DBUG_ENTER("ha_ndbcluster::unique_index_read"); DBUG_ENTER("ha_ndbcluster::unique_index_read");
DBUG_PRINT("enter", ("key_len: %u, index: %u", key_len, active_index)); DBUG_PRINT("enter", ("key_len: %u, index: %u", key_len, active_index));
...@@ -1473,7 +1473,7 @@ inline int ha_ndbcluster::fetch_next(NdbScanOperation* cursor) ...@@ -1473,7 +1473,7 @@ inline int ha_ndbcluster::fetch_next(NdbScanOperation* cursor)
{ {
DBUG_ENTER("fetch_next"); DBUG_ENTER("fetch_next");
int check; int check;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
bool contact_ndb= m_lock.type < TL_WRITE_ALLOW_WRITE; bool contact_ndb= m_lock.type < TL_WRITE_ALLOW_WRITE;
do { do {
...@@ -1753,7 +1753,7 @@ int ha_ndbcluster::define_read_attrs(byte* buf, NdbOperation* op) ...@@ -1753,7 +1753,7 @@ int ha_ndbcluster::define_read_attrs(byte* buf, NdbOperation* op)
{ {
uint i; uint i;
THD *thd= current_thd; THD *thd= current_thd;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
DBUG_ENTER("define_read_attrs"); DBUG_ENTER("define_read_attrs");
...@@ -1800,7 +1800,7 @@ int ha_ndbcluster::ordered_index_scan(const key_range *start_key, ...@@ -1800,7 +1800,7 @@ int ha_ndbcluster::ordered_index_scan(const key_range *start_key,
{ {
int res; int res;
bool restart; bool restart;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbIndexScanOperation *op; NdbIndexScanOperation *op;
DBUG_ENTER("ha_ndbcluster::ordered_index_scan"); DBUG_ENTER("ha_ndbcluster::ordered_index_scan");
...@@ -1870,7 +1870,7 @@ int ha_ndbcluster::filtered_scan(const byte *key, uint key_len, ...@@ -1870,7 +1870,7 @@ int ha_ndbcluster::filtered_scan(const byte *key, uint key_len,
enum ha_rkey_function find_flag) enum ha_rkey_function find_flag)
{ {
int res; int res;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbScanOperation *op; NdbScanOperation *op;
DBUG_ENTER("filtered_scan"); DBUG_ENTER("filtered_scan");
...@@ -1950,7 +1950,7 @@ int ha_ndbcluster::full_table_scan(byte *buf) ...@@ -1950,7 +1950,7 @@ int ha_ndbcluster::full_table_scan(byte *buf)
uint i; uint i;
int res; int res;
NdbScanOperation *op; NdbScanOperation *op;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
DBUG_ENTER("full_table_scan"); DBUG_ENTER("full_table_scan");
DBUG_PRINT("enter", ("Starting new scan on %s", m_tabname)); DBUG_PRINT("enter", ("Starting new scan on %s", m_tabname));
...@@ -1978,7 +1978,7 @@ int ha_ndbcluster::write_row(byte *record) ...@@ -1978,7 +1978,7 @@ int ha_ndbcluster::write_row(byte *record)
{ {
bool has_auto_increment; bool has_auto_increment;
uint i; uint i;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbOperation *op; NdbOperation *op;
int res; int res;
THD *thd= current_thd; THD *thd= current_thd;
...@@ -2147,7 +2147,7 @@ int ha_ndbcluster::key_cmp(uint keynr, const byte * old_row, ...@@ -2147,7 +2147,7 @@ int ha_ndbcluster::key_cmp(uint keynr, const byte * old_row,
int ha_ndbcluster::update_row(const byte *old_data, byte *new_data) int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
{ {
THD *thd= current_thd; THD *thd= current_thd;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbScanOperation* cursor= m_active_cursor; NdbScanOperation* cursor= m_active_cursor;
NdbOperation *op; NdbOperation *op;
uint i; uint i;
...@@ -2265,7 +2265,7 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data) ...@@ -2265,7 +2265,7 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
int ha_ndbcluster::delete_row(const byte *record) int ha_ndbcluster::delete_row(const byte *record)
{ {
THD *thd= current_thd; THD *thd= current_thd;
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
NdbScanOperation* cursor= m_active_cursor; NdbScanOperation* cursor= m_active_cursor;
NdbOperation *op; NdbOperation *op;
DBUG_ENTER("delete_row"); DBUG_ENTER("delete_row");
...@@ -2837,7 +2837,7 @@ int ha_ndbcluster::rnd_init(bool scan) ...@@ -2837,7 +2837,7 @@ int ha_ndbcluster::rnd_init(bool scan)
int ha_ndbcluster::close_scan() int ha_ndbcluster::close_scan()
{ {
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
DBUG_ENTER("close_scan"); DBUG_ENTER("close_scan");
m_multi_cursor= 0; m_multi_cursor= 0;
...@@ -3187,7 +3187,7 @@ int ha_ndbcluster::end_bulk_insert() ...@@ -3187,7 +3187,7 @@ int ha_ndbcluster::end_bulk_insert()
// Check if last inserts need to be flushed // Check if last inserts need to be flushed
if (m_bulk_insert_not_flushed) if (m_bulk_insert_not_flushed)
{ {
NdbConnection *trans= m_active_trans; NdbTransaction *trans= m_active_trans;
// Send rows to NDB // Send rows to NDB
DBUG_PRINT("info", ("Sending inserts to NDB, "\ DBUG_PRINT("info", ("Sending inserts to NDB, "\
"rows_inserted:%d, bulk_insert_rows: %d", "rows_inserted:%d, bulk_insert_rows: %d",
...@@ -3298,7 +3298,7 @@ THR_LOCK_DATA **ha_ndbcluster::store_lock(THD *thd, ...@@ -3298,7 +3298,7 @@ THR_LOCK_DATA **ha_ndbcluster::store_lock(THD *thd,
int ha_ndbcluster::external_lock(THD *thd, int lock_type) int ha_ndbcluster::external_lock(THD *thd, int lock_type)
{ {
int error=0; int error=0;
NdbConnection* trans= NULL; NdbTransaction* trans= NULL;
DBUG_ENTER("external_lock"); DBUG_ENTER("external_lock");
/* /*
...@@ -3385,8 +3385,8 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) ...@@ -3385,8 +3385,8 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
// m_use_local_query_cache= thd->variables.ndb_use_local_query_cache; // m_use_local_query_cache= thd->variables.ndb_use_local_query_cache;
m_active_trans= thd->transaction.all.ndb_tid ? m_active_trans= thd->transaction.all.ndb_tid ?
(NdbConnection*)thd->transaction.all.ndb_tid: (NdbTransaction*)thd->transaction.all.ndb_tid:
(NdbConnection*)thd->transaction.stmt.ndb_tid; (NdbTransaction*)thd->transaction.stmt.ndb_tid;
DBUG_ASSERT(m_active_trans); DBUG_ASSERT(m_active_trans);
// Start of transaction // Start of transaction
m_retrieve_all_fields= FALSE; m_retrieve_all_fields= FALSE;
...@@ -3468,13 +3468,13 @@ int ha_ndbcluster::start_stmt(THD *thd) ...@@ -3468,13 +3468,13 @@ int ha_ndbcluster::start_stmt(THD *thd)
DBUG_ENTER("start_stmt"); DBUG_ENTER("start_stmt");
PRINT_OPTION_FLAGS(thd); PRINT_OPTION_FLAGS(thd);
NdbConnection *trans= (NdbConnection*)thd->transaction.stmt.ndb_tid; NdbTransaction *trans= (NdbTransaction*)thd->transaction.stmt.ndb_tid;
if (!trans){ if (!trans){
Ndb *ndb= ((Thd_ndb*)thd->transaction.thd_ndb)->ndb; Ndb *ndb= ((Thd_ndb*)thd->transaction.thd_ndb)->ndb;
DBUG_PRINT("trans",("Starting transaction stmt")); DBUG_PRINT("trans",("Starting transaction stmt"));
NdbConnection *tablock_trans= NdbTransaction *tablock_trans=
(NdbConnection*)thd->transaction.all.ndb_tid; (NdbTransaction*)thd->transaction.all.ndb_tid;
DBUG_PRINT("info", ("tablock_trans: %x", (uint)tablock_trans)); DBUG_PRINT("info", ("tablock_trans: %x", (uint)tablock_trans));
DBUG_ASSERT(tablock_trans); DBUG_ASSERT(tablock_trans);
// trans= ndb->hupp(tablock_trans); // trans= ndb->hupp(tablock_trans);
...@@ -3503,7 +3503,7 @@ int ndbcluster_commit(THD *thd, void *ndb_transaction) ...@@ -3503,7 +3503,7 @@ int ndbcluster_commit(THD *thd, void *ndb_transaction)
{ {
int res= 0; int res= 0;
Ndb *ndb= ((Thd_ndb*)thd->transaction.thd_ndb)->ndb; Ndb *ndb= ((Thd_ndb*)thd->transaction.thd_ndb)->ndb;
NdbConnection *trans= (NdbConnection*)ndb_transaction; NdbTransaction *trans= (NdbTransaction*)ndb_transaction;
DBUG_ENTER("ndbcluster_commit"); DBUG_ENTER("ndbcluster_commit");
DBUG_PRINT("transaction",("%s", DBUG_PRINT("transaction",("%s",
...@@ -3533,7 +3533,7 @@ int ndbcluster_rollback(THD *thd, void *ndb_transaction) ...@@ -3533,7 +3533,7 @@ int ndbcluster_rollback(THD *thd, void *ndb_transaction)
{ {
int res= 0; int res= 0;
Ndb *ndb= ((Thd_ndb*)thd->transaction.thd_ndb)->ndb; Ndb *ndb= ((Thd_ndb*)thd->transaction.thd_ndb)->ndb;
NdbConnection *trans= (NdbConnection*)ndb_transaction; NdbTransaction *trans= (NdbTransaction*)ndb_transaction;
DBUG_ENTER("ndbcluster_rollback"); DBUG_ENTER("ndbcluster_rollback");
DBUG_PRINT("transaction",("%s", DBUG_PRINT("transaction",("%s",
...@@ -5043,7 +5043,7 @@ ndb_get_table_statistics(Ndb* ndb, const char * table, ...@@ -5043,7 +5043,7 @@ ndb_get_table_statistics(Ndb* ndb, const char * table,
{ {
DBUG_ENTER("ndb_get_table_statistics"); DBUG_ENTER("ndb_get_table_statistics");
DBUG_PRINT("enter", ("table: %s", table)); DBUG_PRINT("enter", ("table: %s", table));
NdbConnection* pTrans= ndb->startTransaction(); NdbTransaction* pTrans= ndb->startTransaction();
do do
{ {
if (pTrans == NULL) if (pTrans == NULL)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment