2016-03-26 03:03:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <Databases/IDatabase.h>
|
2016-03-26 03:03:50 +00:00
|
|
|
|
2017-05-23 18:33:48 +00:00
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/// General functionality for several different database engines.
|
2016-03-26 03:03:50 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-23 18:33:48 +00:00
|
|
|
class Context;
|
|
|
|
|
2016-03-26 03:03:50 +00:00
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/** Get the row with the table definition based on the CREATE query.
|
|
|
|
* It is an ATTACH query that you can execute to create a table from the correspondent database.
|
|
|
|
* See the implementation.
|
2016-03-26 03:03:50 +00:00
|
|
|
*/
|
|
|
|
String getTableDefinitionFromCreateQuery(const ASTPtr & query);
|
|
|
|
|
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/** Create a table by its definition, without using InterpreterCreateQuery.
|
|
|
|
* (InterpreterCreateQuery has more complex functionality, and it can not be used if the database has not been created yet)
|
|
|
|
* Returns the table name and the table itself.
|
2016-03-26 03:03:50 +00:00
|
|
|
*/
|
|
|
|
std::pair<String, StoragePtr> createTableFromDefinition(
|
2017-04-01 07:20:54 +00:00
|
|
|
const String & definition,
|
|
|
|
const String & database_name,
|
|
|
|
const String & database_data_path,
|
|
|
|
Context & context,
|
|
|
|
bool has_force_restore_data_flag,
|
|
|
|
const String & description_for_error_message);
|
2016-03-26 03:03:50 +00:00
|
|
|
|
|
|
|
|
2016-10-25 13:49:07 +00:00
|
|
|
/// Copies list of tables and iterates through such snapshot.
|
|
|
|
class DatabaseSnaphotIterator : public IDatabaseIterator
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Tables tables;
|
|
|
|
Tables::iterator it;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
DatabaseSnaphotIterator(Tables & tables_)
|
|
|
|
: tables(tables_), it(tables.begin()) {}
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void next() override
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool isValid() const override
|
|
|
|
{
|
|
|
|
return it != tables.end();
|
|
|
|
}
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const String & name() const override
|
|
|
|
{
|
|
|
|
return it->first;
|
|
|
|
}
|
2016-10-25 13:49:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
StoragePtr & table() const override
|
|
|
|
{
|
|
|
|
return it->second;
|
|
|
|
}
|
2016-10-25 13:49:07 +00:00
|
|
|
};
|
|
|
|
|
2016-03-26 03:03:50 +00:00
|
|
|
}
|