sqldata/sqlmysqlapi.cpp
// Get the list of available tables
Get the list of available tables
Get the list of available tables
int SqlMysqlApi::GetAvailableTables(std::string &table_template, std::string & , 
									std::list<std::string> &tables)
{
	std::string condition;
	GetSelectionCriteria(table_template.c_str(), "table_schema", "table_name", condition, _db.c_str(), false);
	std::string query = "SELECT table_schema, table_name FROM information_schema.tables";
	query += " WHERE table_type='BASE TABLE'";
	query += " AND table_schema NOT IN ('information_schema', 'mysql', 'performance_schema')";
	if(condition.empty() == false)
	{
		query += " AND ";
		query += condition;
	}
	int rc = _mysql_query(&_mysql, query.c_str());
	if(rc != 0)
	{
		SetError();
		return -1;
	}
	MYSQL_RES *res = _mysql_use_result(&_mysql);
	if(res == NULL)
		return -1;
	bool more = true;
	while(more)
	{
		MYSQL_ROW row = _mysql_fetch_row(res);
		if(row == NULL)
		{
			more = false;
			break;
		}
		std::string tab;
		if(row[0] != NULL)
		{
			tab += row[0];
			tab += ".";
		}
		if(row[1] != NULL)
			tab += row[1];
		tables.push_back(tab);
	}
	_mysql_free_result(res);
	return 0;
}
int SqlMysqlApi :: GetAvailableTables ( std :: string & table_template , std :: string & , std :: list < std :: string > & tables ) { std :: string condition ; GetSelectionCriteria ( table_template . c_str ( ) , " " , " " , condition , _db . c_str ( ) , false ) ; std :: string query = " " ; query += " " ; query += " " ; if ( condition . empty ( ) == false ) { query += " " ; query += condition ; } int rc = _mysql_query ( & _mysql , query . c_str ( ) ) ; if ( rc != 0 ) { SetError ( ) ; return -1 ; } MYSQL_RES * res = _mysql_use_result ( & _mysql ) ; if ( res == NULL ) return -1 ; bool more = true ; while ( more ) { MYSQL_ROW row = _mysql_fetch_row ( res ) ; if ( row == NULL ) { more = false ; break ; } std :: string tab ; if ( row [ 0 ] != NULL ) { tab += row [ 0 ] ; tab += " " ; } if ( row [ 1 ] != NULL ) tab += row [ 1 ] ; tables . push_back ( tab ) ; } _mysql_free_result ( res ) ; return 0 ; }
Get the list of available tables
Get the list of available tables
/*exclude*/ // Get a condition to select objects from the catalog // MySQL contains the database name in "table_schema" column // Build the query // Add filter // Execute the query // Error raised // Fetch the row // We must fetch all rows to avoid "out of sync" errors // Schema name // Table name