1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include <ndb_global.h>
24
static int g_diskbased = 0;
25
static const char* g_tsname = 0;
28
g_create_hook(Ndb* ndb, NdbDictionary::Table& tab, int when, void* arg)
32
for (int i = 0; i < tab.getNoOfColumns(); i++) {
33
NdbDictionary::Column* col = tab.getColumn(i);
34
if (! col->getPrimaryKey()) {
35
col->setStorageType(NdbDictionary::Column::StorageTypeDisk);
39
if (g_tsname != NULL) {
40
tab.setTablespaceName(g_tsname);
46
int main(int argc, const char** argv){
53
const char* _connectstr = NULL;
55
const char* _tsname = NULL;
57
struct getargs args[] = {
58
{ "all", 'a', arg_flag, &_all, "Create/print all tables", 0 },
59
{ "print", 'p', arg_flag, &_print, "Print table(s) instead of creating it", 0},
60
{ "temp", 't', arg_flag, &_temp, "Temporary table", 0 },
61
{ "connstr", 'c', arg_string, &_connectstr, "Connect string", "cs" },
62
{ "diskbased", 0, arg_flag, &_diskbased, "Store attrs on disk if possible", 0 },
63
{ "tsname", 0, arg_string, &_tsname, "Tablespace name", "ts" },
64
{ "usage", '?', arg_flag, &_help, "Print help", "" }
66
int num_args = sizeof(args) / sizeof(args[0]);
70
"This program will create one table in Ndb.\n"\
71
"The tables may be selected from a fixed list of tables\n"\
72
"defined in NDBT_Tables class\n";
74
if(getarg(args, num_args, argc, argv, &optind) || _help){
75
arg_printusage(args, num_args, argv[0], desc);
76
return NDBT_ProgramExit(NDBT_WRONGARGS);
79
if(argv[optind] == NULL && !_all){
80
arg_printusage(args, num_args, argv[0], desc);
81
return NDBT_ProgramExit(NDBT_WRONGARGS);
84
g_diskbased = _diskbased;
90
* Print instead of creating
93
for(int i = optind; i<argc; i++){
94
NDBT_Tables::print(argv[i]);
97
NDBT_Tables::printAll();
105
Ndb_cluster_connection con(_connectstr);
106
if(con.connect(12, 5, 1) != 0)
108
return NDBT_ProgramExit(NDBT_FAILED);
110
Ndb MyNdb(&con, "TEST_DB" );
112
if(MyNdb.init() != 0){
113
ERR(MyNdb.getNdbError());
114
return NDBT_ProgramExit(NDBT_FAILED);
117
while(MyNdb.waitUntilReady() != 0)
118
ndbout << "Waiting for ndb to become ready..." << endl;
121
res = NDBT_Tables::createAllTables(&MyNdb, _temp);
124
for(int i = optind; i<argc; i++){
125
ndbout << "Trying to create " << argv[i] << endl;
126
if((tmp = NDBT_Tables::createTable(&MyNdb, argv[i], _temp, false,
127
g_create_hook)) != 0)
134
return NDBT_ProgramExit(NDBT_FAILED);
136
return NDBT_ProgramExit(NDBT_OK);