1 /* Copyright (c) 2003-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #include <ndb_global.h>
20 #include <NDBT_Tables.hpp>
24 #include <NdbDictionary.hpp>
26 //extern NdbOut g_info;
28 int main(int argc
, const char** argv
)
34 const char* _tableName
= NULL
;
36 struct getargs args
[] = {
38 arg_integer
, &_row
, "The row number", "row" },
40 arg_integer
, &_primaryKey
, "The primary key", "primarykey" },
42 arg_flag
, &_hex
, "Print hex", "hex" }
45 int num_args
= sizeof(args
) / sizeof(args
[0]);
48 if(getarg(args
, num_args
, argc
, argv
, &optind
) || argv
[optind
] == NULL
) {
49 arg_printusage(args
, num_args
, argv
[0], "table name\n");
50 return NDBT_WRONGARGS
;
52 // Check if table name is supplied
53 if (argv
[optind
] != NULL
)
54 _tableName
= argv
[optind
];
57 const NdbDictionary::Table
* table
= NDBT_Tables::getTable(_tableName
);
58 // const NDBT_Attribute* attribute = table->getAttribute(_column);
60 g_info
<< "Table " << _tableName
<< endl
61 << "Row: " << _row
<< ", PrimaryKey: " << _primaryKey
64 Ndb_cluster_connection con
;
65 if(con
.connect(12, 5, 1) != 0)
67 return NDBT_ProgramExit(NDBT_FAILED
);
69 Ndb
* ndb
= new Ndb(&con
, "TEST_DB");
70 if (ndb
->init() == 0 && ndb
->waitUntilReady(30) == 0)
72 NdbConnection
* conn
= ndb
->startTransaction();
75 g_info
<< "ERROR: " << ndb
->getNdbError() << endl
;
79 NdbOperation
* op
= conn
->getNdbOperation(_tableName
);
82 g_info
<< "ERROR: " << conn
->getNdbError() << endl
;
87 NdbRecAttr
** data
= new NdbRecAttr
*[table
->getNoOfColumns()];
88 for (i
= 0; i
< table
->getNoOfColumns(); i
++)
90 const NdbDictionary::Column
* c
= table
->getColumn(i
);
91 if (c
->getPrimaryKey())
93 op
->equal(c
->getName(), _primaryKey
);
94 data
[i
] = op
->getValue(c
->getName(), NULL
);
98 data
[i
] = op
->getValue(c
->getName(), NULL
);
101 if (conn
->execute(Commit
) == 0)
103 // Print column names
104 for (i
= 0; i
< table
->getNoOfColumns(); i
++)
106 const NdbDictionary::Column
* c
= table
->getColumn(i
);
110 << "[" << c
->getType() << "] ";
118 for (i
= 0; i
< table
->getNoOfColumns(); i
++)
120 NdbRecAttr
* a
= data
[i
];
121 ndbout
<< (* a
) << " ";
127 g_info
<< "Failed to commit read transaction... "
128 << conn
->getNdbError()
129 << ", commitStatus = " << conn
->commitStatus()
135 ndb
->closeTransaction(conn
);
139 g_info
<< "ERROR: Unable to connect to NDB, "
140 << ndb
->getNdbError() << endl
;