Go to the documentation of this file.
7 #include <dballe/core/error.h>
8 #include <dballe/fwd.h>
23 #define TRACE(...) fprintf(stderr, __VA_ARGS__)
24 #define IFTRACE if (1)
27 #define TRACE(...) do { } while (0)
29 #define IFTRACE if (0)
49 const char* format_server_type(ServerType type);
69 const std::string& get_url()
const {
return url; }
77 virtual std::unique_ptr<Transaction>
transaction(
bool readonly=
false) = 0;
80 virtual bool has_table(
const std::string& name) = 0;
87 virtual std::string
get_setting(
const std::string& key) = 0;
94 virtual void set_setting(
const std::string& key,
const std::string& value) = 0;
103 virtual void execute(
const std::string& query) = 0;
106 virtual void explain(
const std::string& query, FILE* out) = 0;
130 virtual void commit() = 0;
140 virtual void lock_table(
const char* name) = 0;
A RAII transaction interface for SQL transactions.
Definition: sql.h:121
virtual bool has_table(const std::string &name)=0
Check if the database contains a table.
virtual void rollback()=0
Roll back this transaction.
ServerType server_type
Type of SQL server we are connected to.
Definition: sql.h:64
virtual std::unique_ptr< Transaction > transaction(bool readonly=false)=0
Begin a transaction.
virtual void set_setting(const std::string &key, const std::string &value)=0
Set a value in the settings table.
ServerType
Supported SQL servers.
Definition: sql.h:40
virtual void drop_settings()=0
Drop the settings table.
Options controlling how to connect to a database.
Definition: db.h:17
virtual void lock_table(const char *name)=0
Get an exclusive lock on the given table until the end of the transaction.
virtual void add_datetime(Querybuf &qb, const Datetime &dt) const
Format a datetime and add it to the querybuf.
static std::unique_ptr< Connection > create(const DBConnectOptions &options)
Create a new connection from a URL.
virtual void rollback_nothrow() noexcept=0
Roll back this transaction.
virtual void explain(const std::string &query, FILE *out)=0
Format and print the EXPLAIN output for the query to the given file.
virtual std::string get_setting(const std::string &key)=0
Get a value from the settings table.
Date and time.
Definition: types.h:164
String buffer for composing database queries.
Definition: querybuf.h:15
virtual void commit()=0
Commit this transaction.
virtual void execute(const std::string &query)=0
Execute a query without reading its results.