2012-06-18 07:49:19 +00:00
|
|
|
#include <DB/IO/ReadBufferFromString.h>
|
|
|
|
|
|
|
|
#include <DB/Parsers/ASTShowTablesQuery.h>
|
2013-02-20 13:14:12 +00:00
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
#include <DB/Interpreters/executeQuery.h>
|
|
|
|
#include <DB/Interpreters/InterpreterShowTablesQuery.h>
|
|
|
|
|
|
|
|
#include <mysqlxx/Manip.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
InterpreterShowTablesQuery::InterpreterShowTablesQuery(ASTPtr query_ptr_, Context & context_)
|
|
|
|
: query_ptr(query_ptr_), context(context_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String InterpreterShowTablesQuery::getRewrittenQuery()
|
|
|
|
{
|
2014-06-26 00:58:14 +00:00
|
|
|
const ASTShowTablesQuery & query = typeid_cast<const ASTShowTablesQuery &>(*query_ptr);
|
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
String format_or_nothing;
|
|
|
|
if (query.format)
|
2014-06-26 00:58:14 +00:00
|
|
|
format_or_nothing = " FORMAT " + typeid_cast<const ASTIdentifier &>(*query.format).name;
|
|
|
|
|
2012-06-18 07:49:19 +00:00
|
|
|
/// SHOW DATABASES
|
|
|
|
if (query.databases)
|
2013-02-20 13:14:12 +00:00
|
|
|
return "SELECT name FROM system.databases" + format_or_nothing;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2012-08-02 17:33:31 +00:00
|
|
|
String database = query.from.empty() ? context.getCurrentDatabase() : query.from;
|
2012-06-18 07:49:19 +00:00
|
|
|
context.assertDatabaseExists(database);
|
|
|
|
|
|
|
|
std::stringstream rewritten_query;
|
|
|
|
rewritten_query << "SELECT name FROM system.tables WHERE database = " << mysqlxx::quote << database;
|
|
|
|
|
|
|
|
if (!query.like.empty())
|
2013-03-11 11:28:36 +00:00
|
|
|
rewritten_query << " AND name " << (query.not_like ? "NOT " : "") << "LIKE " << mysqlxx::quote << query.like;
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2013-02-20 13:14:12 +00:00
|
|
|
rewritten_query << format_or_nothing;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
return rewritten_query.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockIO InterpreterShowTablesQuery::execute()
|
|
|
|
{
|
2013-09-03 23:58:05 +00:00
|
|
|
return executeQuery(getRewrittenQuery(), context, true);
|
2012-06-18 07:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|