2012-06-18 07:49:19 +00:00
|
|
|
#include <DB/Columns/ColumnString.h>
|
|
|
|
#include <DB/DataTypes/DataTypeString.h>
|
|
|
|
#include <DB/DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <DB/Storages/StorageSystemDatabases.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
StorageSystemDatabases::StorageSystemDatabases(const std::string & name_, const Context & context_)
|
|
|
|
: name(name_), context(context_)
|
|
|
|
{
|
|
|
|
columns.push_back(NameAndTypePair("name", new DataTypeString));
|
|
|
|
}
|
|
|
|
|
2013-02-06 11:26:35 +00:00
|
|
|
StoragePtr StorageSystemDatabases::create(const std::string & name_, const Context & context_)
|
|
|
|
{
|
|
|
|
return (new StorageSystemDatabases(name_, context_))->thisPtr();
|
|
|
|
}
|
|
|
|
|
2012-06-18 07:49:19 +00:00
|
|
|
|
|
|
|
BlockInputStreams StorageSystemDatabases::read(
|
2013-02-01 19:02:04 +00:00
|
|
|
const Names & column_names, ASTPtr query, const Settings & settings,
|
|
|
|
QueryProcessingStage::Enum & processed_stage, size_t max_block_size, unsigned threads)
|
2012-06-18 07:49:19 +00:00
|
|
|
{
|
|
|
|
check(column_names);
|
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
|
|
|
|
|
|
|
Block block;
|
|
|
|
|
|
|
|
ColumnWithNameAndType col_name;
|
|
|
|
col_name.name = "name";
|
|
|
|
col_name.type = new DataTypeString;
|
|
|
|
col_name.column = new ColumnString;
|
|
|
|
block.insert(col_name);
|
|
|
|
|
2012-08-02 17:33:31 +00:00
|
|
|
Poco::ScopedLock<Poco::Mutex> lock(context.getMutex());
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2012-08-02 17:33:31 +00:00
|
|
|
for (Databases::const_iterator it = context.getDatabases().begin(); it != context.getDatabases().end(); ++it)
|
2012-06-18 07:49:19 +00:00
|
|
|
col_name.column->insert(it->first);
|
|
|
|
|
|
|
|
return BlockInputStreams(1, new OneBlockInputStream(block));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|