Commit a05b61f1 authored by Maciej Sobczak's avatar Maciej Sobczak

Added docs and removed impractical function for metadata queries.

parent 3c3fec62
......@@ -5,6 +5,7 @@
* [Bulk operations](#bulk)
* [Stored procedures](#procedures)
* [Transactions](#transactions)
* [Metadata queries](#metadata)
* [Basic logging support](#logging)
### <a name="preparation"></a> Statement preparation and repeated execution
......@@ -289,6 +290,37 @@ A typical usage pattern for this class might be:
With the above pattern the transaction is committed only when the code successfully reaches the end of block. If some exception is thrown before that, the scope will be left without reaching the final statement and the transaction object will automatically roll back in its destructor.
### <a name="metadata"></a> Metadata queries
It is possible to portably query the database server to obtain basic metadata information.
In order to get the list of table names in the current schema:
std::vector<std::string> names(100);
sql.get_table_names(), into(names);
std::string name;
soci::statement st = (sql.prepare_table_names(), into(name));
while (st.fetch())
// ...
Similarly, to get the description of all columns in the given table:
soci::column_info ci;
soci::statement st = (sql.prepare_column_descriptions(table_name), into(ci));
while (st.fetch())
// ci fields describe each column in turn
### <a name="logging"></a> Basic logging support
The following members of the `session` class support the basic logging functionality:
......@@ -125,14 +125,6 @@ public:
// it makes sense to bind std::string for the output field.
details::prepare_temp_type prepare_table_names();
// Returns once_temp_type for the internally composed query
// for the list of column descriptions.
// Since this query usually returns multiple results (for multiple columns),
// it makes sense to bind std::vector<std::string> for each output field.
// Note: table_name is a non-const reference to prevent temporary objects,
// this argument is bound as a regular "use" element.
details::once_temp_type get_column_descriptions(std::string & table_name);
// Returns prepare_temp_type for the internally composed query
// for the list of column descriptions.
// Since this is intended for use with statement objects, where results are obtained one row after another,
......@@ -238,12 +238,17 @@ public:
// queried in a portable way - backends that are standard compliant
// do not need to override the following methods, which are intended
// to return a proper query for basic metadata statements.
// Returns a parameterless query for the list of table names in the current schema.
virtual std::string get_table_names_query() const
return "select table_name as \"TABLE_NAME\""
" from information_schema.tables"
" where table_schema = 'public'";
// Returns a query with a single parameter (table name) for the list
// of columns and their properties.
virtual std::string get_column_descriptions_query() const
return "select column_name as \"COLUMN_NAME\","
......@@ -369,11 +369,6 @@ details::prepare_temp_type session::prepare_table_names()
return prepare << backEnd_->get_table_names_query();
details::once_temp_type session::get_column_descriptions(std::string & table_name)
return once << backEnd_->get_column_descriptions_query(), use(table_name, "t");
details::prepare_temp_type session::prepare_column_descriptions(std::string & table_name)
return prepare << backEnd_->get_column_descriptions_query(), use(table_name, "t");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment