About Store Forum Documentation Contact



Post Reply 
SQL - Getting all tables
Author Message
PsychoBoy Offline
Member

Post: #1
SQL - Getting all tables
Hello, SQL class is missing function allowing to get all table names, smth like:
Code:
Memc<Str>& getTables(); //returns container with table names
Useful when user doesn't know table name but know what data it contains

Best regards, PsychoBoy
05-06-2012 06:47 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: SQL - Getting all tables
if you know how to achieve this in MySQL, MS SQL and SQLite and you can supply the codes or links to sample code then I can integrate them.
05-07-2012 03:05 PM
Find all posts by this user Quote this message in a reply
PsychoBoy Offline
Member

Post: #3
RE: SQL - Getting all tables
in MYSQL:
We can send Query to get tables from selected db, eg:
Code:
show tables from db_name

Or we can get all tables from all db:
Code:
show tables

Query will return 1 column, in C++ (omitting details) it's something like:
Code:
MYSQL_ROW row;
Memc<Str> *tables = new Memc<Str>;
while(row = mysql_fetch_row(result))
{
    tables->add(row);
}

in MSSQL:
I never used it, but this query is probably correct:
Code:
select name from sys.tables;
Then fetch rows the same way as in mysql.

And finally in SQLITE, query:
Code:
SELECT name FROM sqlite_master WHERE type = 'table';

For MySQL and SQLite i've tested it.

In ODBC (never used) after connecting and executing query it could be something like:
Code:
Memc<Str> *tables = new Memc<Str>;
char name[MAX_TABLE_SIZE];
while(SQLFetch(sqlstatementhandle)==SQL_SUCCESS)
{
    SQLGetData(sqlstatementhandle, 1, SQL_C_CHAR, name, MAX_TABLE_SIZE, NULL);
    tables->add(name);
}
(This post was last modified: 05-08-2012 01:10 AM by PsychoBoy.)
05-08-2012 01:08 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: SQL - Getting all tables
Thank you! I will check this out along with other piece of code Zervox has sent me, and I will add this for next SDK.
05-08-2012 05:59 AM
Find all posts by this user Quote this message in a reply
Post Reply