ensure proper table creation in session::create_schema including foreign key constraints
This commit is contained in:
@@ -35,7 +35,7 @@ public:
|
||||
virtual void on_close() = 0;
|
||||
|
||||
/**
|
||||
* Is called when a sql statement is going to
|
||||
* Is called when a SQL statement is going to
|
||||
* be executed
|
||||
*
|
||||
* @param stmt SQL statement to be executed
|
||||
@@ -43,7 +43,15 @@ public:
|
||||
virtual void on_execute(const std::string &stmt) = 0;
|
||||
|
||||
/**
|
||||
* Is called when a sql statement is going to
|
||||
* Is called when a SQL select statement is going to
|
||||
* be executed
|
||||
*
|
||||
* @param stmt The SQL select-statement to be executed
|
||||
*/
|
||||
virtual void on_fetch(const std::string &stmt) = 0;
|
||||
|
||||
/**
|
||||
* Is called when a SQL statement is going to
|
||||
* be prepared
|
||||
*
|
||||
* @param stmt SQL statement to be prepared
|
||||
@@ -75,6 +83,11 @@ public:
|
||||
*/
|
||||
void on_execute(const std::string &) override { }
|
||||
|
||||
/**
|
||||
* No logging on a select-statement.
|
||||
*/
|
||||
void on_fetch( const std::string& stmt ) override { }
|
||||
|
||||
/**
|
||||
* No logging on preparing a statement.
|
||||
*/
|
||||
|
||||
@@ -13,27 +13,28 @@
|
||||
namespace matador::sql {
|
||||
class connection_impl;
|
||||
|
||||
const auto null_logger = std::make_shared<null_sql_logger>();
|
||||
|
||||
/**
|
||||
* @brief The connection class represents a connection to a database.
|
||||
*/
|
||||
class connection final : public executor {
|
||||
public:
|
||||
using logger_ptr = std::shared_ptr<abstract_sql_logger>;
|
||||
/**
|
||||
* @brief Creates a database connection from a connection info data.
|
||||
* @brief Creates a database connection from connection info data.
|
||||
*
|
||||
* @param info The database connection info data
|
||||
* @param sql_logger The logging handler
|
||||
*/
|
||||
explicit connection(connection_info info,
|
||||
const std::shared_ptr<abstract_sql_logger> &sql_logger = std::make_shared<null_sql_logger>());
|
||||
explicit connection(connection_info info, const logger_ptr &sql_logger = null_logger);
|
||||
/**
|
||||
* @brief Creates a database connection from a connection string.
|
||||
*
|
||||
* @param dns The database connection string
|
||||
* @param sql_logger The logging handler
|
||||
*/
|
||||
explicit connection(const std::string &dns,
|
||||
const std::shared_ptr<abstract_sql_logger> &sql_logger = std::make_shared<null_sql_logger>());
|
||||
explicit connection(const std::string &dns, const logger_ptr &sql_logger = null_logger);
|
||||
/**
|
||||
* Copies a given connection
|
||||
*
|
||||
@@ -66,8 +67,8 @@ public:
|
||||
/**
|
||||
* @brief Opens the database connection for the given dns.
|
||||
*
|
||||
* Opens the database connection. If database connection
|
||||
* couldn't be opened an exception is thrown.
|
||||
* Opens the database connection. If the database connection
|
||||
* couldn't be opened, an exception is thrown.
|
||||
*/
|
||||
[[nodiscard]] utils::result<void, utils::error> open() const;
|
||||
/**
|
||||
@@ -77,11 +78,11 @@ public:
|
||||
*/
|
||||
[[nodiscard]] utils::result<void, utils::error> close() const;
|
||||
/**
|
||||
* @brief Returns true if database connection is open.
|
||||
* @brief Returns true if the database connection is open.
|
||||
*
|
||||
* Returns true if database connection is open
|
||||
* Returns true if the database connection is open
|
||||
*
|
||||
* @return True on open database connection.
|
||||
* @return True on an open database connection.
|
||||
*/
|
||||
[[nodiscard]] utils::result<bool, utils::error> is_open() const;
|
||||
|
||||
@@ -95,7 +96,7 @@ public:
|
||||
/**
|
||||
* @brief Return the database type of the connection.
|
||||
*
|
||||
* Returns the database type of the connection which is
|
||||
* Returns the database type of the connection, which is
|
||||
* currently one of
|
||||
* - mssql
|
||||
* - mysql
|
||||
@@ -108,21 +109,21 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Starts a transaction by calling the
|
||||
* underlying database backends transaction begin
|
||||
* underlying database backends a transaction begin
|
||||
* statement.
|
||||
*/
|
||||
[[nodiscard]] utils::result<void, utils::error> begin() const;
|
||||
|
||||
/**
|
||||
* @brief Commits a transaction by calling the
|
||||
* underlying database backends transaction commit
|
||||
* underlying database backends a transaction commit
|
||||
* statement.
|
||||
*/
|
||||
[[nodiscard]] utils::result<void, utils::error> commit() const;
|
||||
|
||||
/**
|
||||
* @brief Rollback a transaction by calling the
|
||||
* underlying database backends transaction rollback/abort
|
||||
* @brief Roll back a transaction by calling the
|
||||
* underlying database backends transaction rollback or abort
|
||||
* statement.
|
||||
*/
|
||||
[[nodiscard]] utils::result<void, utils::error> rollback() const;
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
enum class dialect_token : uint8_t
|
||||
{
|
||||
enum class dialect_token : uint8_t {
|
||||
CREATE = 0,
|
||||
DROP,
|
||||
REMOVE,
|
||||
INSERT,
|
||||
UPDATE,
|
||||
SELECT,
|
||||
ALTER,
|
||||
SCHEMA,
|
||||
DATABASE,
|
||||
TABLE,
|
||||
VALUES,
|
||||
INSERT_VALUES,
|
||||
|
||||
@@ -9,18 +9,26 @@
|
||||
namespace matador::sql {
|
||||
|
||||
enum class sql_command {
|
||||
SQL_CMD_UNKNOWN,
|
||||
SQL_CMD_CREATE,
|
||||
SQL_CMD_UPDATE,
|
||||
SQL_CMD_INSERT,
|
||||
SQL_CMD_DELETE,
|
||||
SQL_CMD_SELECT,
|
||||
SQL_CMD_DROP,
|
||||
SQL_CMD_ALTER
|
||||
SQL_UNKNOWN,
|
||||
SQL_CREATE_TABLE,
|
||||
SQL_CREATE_SCHEMA,
|
||||
SQL_CREATE_DATABASE,
|
||||
SQL_UPDATE,
|
||||
SQL_INSERT,
|
||||
SQL_DELETE,
|
||||
SQL_SELECT,
|
||||
SQL_DROP_TABLE,
|
||||
SQL_DROP_SCHEMA,
|
||||
SQL_DROP_DATABASE,
|
||||
SQL_ALTER_TABLE
|
||||
};
|
||||
|
||||
struct query_context
|
||||
{
|
||||
struct sql_command_info {
|
||||
std::string sql;
|
||||
sql_command command{};
|
||||
};
|
||||
|
||||
struct query_context {
|
||||
std::string sql;
|
||||
sql_command command{};
|
||||
std::string command_name;
|
||||
@@ -32,6 +40,8 @@ struct query_context
|
||||
|
||||
std::unordered_map<std::string, std::string> column_aliases;
|
||||
std::unordered_map<std::string, std::string> table_aliases;
|
||||
|
||||
std::vector<sql_command_info> additional_commands;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user