To enable the technician to produce a list of table names for a specific MySQL database the following method satisfies the requirement.
Initally we would need an array to hold the table names. Our description is depicted below.
[codesyntax lang=”cpp”]
string fna[120];
[/codesyntax]
The definition for the method is as follows.
[codesyntax lang=”cpp”]
void getTableNames(std::string db);
[/codesyntax]
To invoke our method the calling sequence is below.
[codesyntax lang=”cpp”]
getTableNames("YourDatabaseName");
[/codesyntax]
Our method is depicted below.
[codesyntax lang=”cpp”]
void cloneuFrame::getTableNames(string db){ ut.dbc.catalog = db; string buf; int ii = 1; ut.dbc.driver = get_driver_instance(); ut.dbc.con = ut.dbc.driver->connect(ut.dbc.server, ut.dbc.user, ut.dbc.pwd); ut.dbc.con->setSchema(ut.dbc.catalog); ut.dbc.stmt = ut.dbc.con->createStatement(); string cmd; cmd = "SELECT table_name FROM information_schema.tables WHERE table_schema = '" + ut.dbc.catalog + "'"; ut.dbc.res = ut.dbc.stmt->executeQuery(cmd.c_str()); if (ut.dbc.res->rowsCount() < 120) { while (ut.dbc.res->next()) { buf = ut.dbc.res->getString(1); ut.fna[ii] = buf; ii++; buf = buf; } } delete ut.dbc.res; delete ut.dbc.stmt; delete ut.dbc.con; }
[/codesyntax]
We now have an array of string that contains all the table names for the specified database.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.