77#ifndef NANODBC_NANODBC_H
78#define NANODBC_NANODBC_H
93#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
94#define NANODBC_HAS_STD_STRING_VIEW
96#define NANODBC_HAS_STD_OPTIONAL
98#define NANODBC_HAS_STD_VARIANT
100#define NANODBC_HAS_STD_ANY
138#define NANODBC_THROW_NO_SOURCE_LOCATION 1
154#define NANODBC_ASSERT(expression) assert(expression)
161#ifdef NANODBC_ENABLE_UNICODE
162#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
163#define NANODBC_TEXT(s) U##s
164typedef std::u32string
string;
165#ifdef NANODBC_HAS_STD_STRING_VIEW
166typedef std::u32string_view string_view;
170typedef std::wstring
string;
171#ifdef NANODBC_HAS_STD_STRING_VIEW
172typedef std::wstring_view string_view;
174#define NANODBC_TEXT(s) L##s
176typedef std::u16string
string;
177#ifdef NANODBC_HAS_STD_STRING_VIEW
178typedef std::u16string_view string_view;
180#define NANODBC_TEXT(s) u##s
184typedef std::string
string;
185#ifdef NANODBC_HAS_STD_STRING_VIEW
186typedef std::string_view string_view;
188#define NANODBC_TEXT(s) s
191#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
192typedef std::u32string wide_string;
193#ifdef NANODBC_HAS_STD_STRING_VIEW
194typedef std::u32string_view wide_string_view;
198typedef std::wstring wide_string;
199#ifdef NANODBC_HAS_STD_STRING_VIEW
200typedef std::wstring_view wide_string_view;
203typedef std::u16string wide_string;
204#ifdef NANODBC_HAS_STD_STRING_VIEW
205typedef std::u16string_view wide_string_view;
210typedef wide_string::value_type wide_char_t;
215#elif !defined(_WIN64) && defined(__LP64__)
232#define NANODBC_TEXT(s) s
245#define NANODBC_DEPRECATED [[deprecated]]
248#ifndef NANODBC_DISABLE_MSSQL_TVP
249class table_valued_parameter;
290 char const*
what() const noexcept override;
301 char const*
what() const noexcept override;
312 char const*
what() const noexcept override;
325 char const*
what() const noexcept override;
340 char const*
what() const noexcept override;
343 long native() const noexcept;
346 std::
string const& state() const noexcept;
350 std::
string sql_state;
382 : parameter_array_length(-1L)
383 , rowset_size(-1L) {};
388 : parameter_array_length(all_length)
389 , rowset_size(all_length) {};
428#ifdef NANODBC_HAS_STD_VARIANT
443#ifdef NANODBC_ENABLE_UNICODE
444 typedef std::variant<std::vector<uint8_t>,
string, std::string, std::intptr_t, std::uintptr_t>
447 typedef std::variant<std::vector<uint8_t>,
string, std::intptr_t, std::uintptr_t> variant;
459 attribute(
long const&
attribute,
long const& string_length, variant
const& resource)
noexcept;
463 void extractValuePtr();
486 , string_length_(string_length)
487 , value_ptr_((
void*)value_ptr) {};
501 std::is_same<typename std::decay<T>::type, std::string>::value ||
502 std::is_same<typename std::decay<T>::type, wide_string>::value
503#ifdef NANODBC_HAS_STD_STRING_VIEW
504 || std::is_same<typename std::decay<T>::type, std::string_view>::value ||
505 std::is_same<typename std::decay<T>::type, wide_string_view>::value
514 std::is_same<typename std::decay<T>::type, std::string::value_type>::value ||
515 std::is_same<typename std::decay<T>::type, wide_char_t>::value>;
575 void rollback() noexcept;
590 class transaction_impl;
594 std::shared_ptr<transaction_impl> impl_;
609#ifndef NANODBC_DISABLE_MSSQL_TVP
639 void open(
statement& stmt,
short param_index, std::
size_t row_count);
668 void bind(
short param_index, T const* values, std::
size_t batch_size);
673 void bind(
short param_index, T const* values, std::
size_t batch_size, T const* null_sentry);
678 void bind(
short param_index, T const* values, std::
size_t batch_size,
bool const* nulls);
682 void bind(
short param_index, std::vector<std::vector<uint8_t>> const& values);
687 bind(
short param_index, std::vector<std::vector<uint8_t>> const& values,
bool const* nulls);
693 std::vector<std::vector<uint8_t>> const& values,
694 uint8_t const* null_sentry);
724 std::
size_t value_size,
725 std::
size_t batch_size);
734 void bind_strings(
short param_index, std::vector<T> const& values);
739 std::
size_t BatchSize,
740 std::
size_t ValueSize,
743 void bind_strings(
short param_index, T const (&values)[BatchSize][ValueSize])
745 auto param_values =
reinterpret_cast<T const*
>(values);
746 bind_strings(param_index, param_values, ValueSize, BatchSize);
751 template <
class T,
typename = enable_if_
character<T>>
755 std::size_t value_size,
756 std::size_t batch_size,
757 T
const* null_sentry);
761 template <
class T,
typename = enable_if_
string<T>>
764 std::vector<T>
const& values,
765 typename T::value_type
const* null_sentry);
770 std::size_t BatchSize,
771 std::size_t ValueSize,
775 bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize], T
const* null_sentry)
777 auto param_values =
reinterpret_cast<T const*
>(values);
778 bind_strings(param_index, param_values, ValueSize, BatchSize,
nullptr, null_sentry);
783 template <
class T,
typename = enable_if_
character<T>>
787 std::size_t value_size,
788 std::size_t batch_size,
793 template <
class T,
typename = enable_if_
string<T>>
794 void bind_strings(
short param_index, std::vector<T>
const& values,
bool const* nulls);
799 std::size_t BatchSize,
800 std::size_t ValueSize,
803 void bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize],
bool const* nulls)
805 auto param_values =
reinterpret_cast<T const*
>(values);
806 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls);
827 const std::vector<short>& idx,
828 const std::vector<short>& type,
829 const std::vector<unsigned long>& size,
830 const std::vector<short>& scale);
836 unsigned long parameter_size(
short param_index) const;
839 short parameter_scale(
short param_index) const;
842 short parameter_type(
short param_index) const;
845 class table_valued_parameter_impl;
849 std::shared_ptr<table_valued_parameter_impl> impl_;
870 class statement_impl;
872#ifdef NANODBC_HAS_STD_VARIANT
881 long const& string_length,
882 variant
const& resource) noexcept
886 friend class nanodbc::statement::statement_impl;
895 long const& string_length,
896 std::uintptr_t value_ptr) noexcept
900 friend class nanodbc::statement::statement_impl;
962 bool open() const noexcept;
965 bool connected() const noexcept;
974 void* native_statement_handle() const noexcept;
989 void prepare(class
connection& conn,
string const& query,
long timeout = 0);
998 void prepare(
string const& query,
long timeout = 0);
1002 void timeout(
long timeout = 0);
1016 string const& query,
1017 long batch_operations = 1,
1032 string const& query,
1036#if !defined(NANODBC_DISABLE_ASYNC)
1090 string const& query,
1091 long batch_operations = 1,
1111 bool async_execute(
void* event_handle,
long batch_operations = 1,
long timeout = 0);
1126 class result complete_execute(long batch_operations = 1);
1146 string const& query,
1147 long batch_operations = 1,
1194 string const& schema,
1195 string const& procedure,
1196 string const& column);
1211 short parameters() const;
1214 unsigned long parameter_size(
short param_index) const;
1217 short parameter_scale(
short param_index) const;
1220 short parameter_type(
short param_index) const;
1233 bool parameter_is_null(
short param_index, std::
size_t batch_index = 0) const;
1298 std::
size_t batch_size,
1307 std::
size_t batch_size,
1308 T const* null_sentry,
1317 std::
size_t batch_size,
1325 std::vector<std::vector<uint8_t>> const& values,
1332 std::vector<std::vector<uint8_t>> const& values,
1340 std::vector<std::vector<uint8_t>> const& values,
1341 uint8_t const* null_sentry,
1352 bind(
short param_index, std::vector<T> const& values,
param_direction direction = PARAM_IN);
1359 std::vector<T> const& values,
1392 std::
size_t value_size,
1393 std::
size_t batch_size,
1405 std::vector<T> const& values,
1411 std::
size_t BatchSize,
1412 std::
size_t ValueSize,
1417 T const (&values)[BatchSize][ValueSize],
1420 auto param_values =
reinterpret_cast<T const*
>(values);
1421 bind_strings(param_index, param_values, ValueSize, BatchSize, direction);
1426 template <
class T,
typename = enable_if_
character<T>>
1430 std::size_t value_size,
1431 std::size_t batch_size,
1432 T
const* null_sentry,
1437 template <
class T,
typename = enable_if_
string<T>>
1440 std::vector<T>
const& values,
1441 typename T::value_type
const* null_sentry,
1447 std::size_t BatchSize,
1448 std::size_t ValueSize,
1453 T
const (&values)[BatchSize][ValueSize],
1454 T
const* null_sentry,
1457 auto param_values =
reinterpret_cast<T const*
>(values);
1458 bind_strings(param_index, param_values, ValueSize, BatchSize, null_sentry, direction);
1463 template <
class T,
typename = enable_if_
character<T>>
1467 std::size_t value_size,
1468 std::size_t batch_size,
1474 template <
class T,
typename = enable_if_
string<T>>
1477 std::vector<T>
const& values,
1484 std::size_t BatchSize,
1485 std::size_t ValueSize,
1490 T
const (&values)[BatchSize][ValueSize],
1494 auto param_values =
reinterpret_cast<T const*
>(values);
1495 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls, direction);
1511 void bind_null(
short param_index, std::size_t batch_size = 1);
1533 const std::vector<short>& idx,
1534 const std::vector<short>& type,
1535 const std::vector<unsigned long>& size,
1536 const std::vector<short>& scale);
1539 typedef std::function<bool(std::size_t)> null_predicate_type;
1541#ifndef NANODBC_DISABLE_MSSQL_TVP
1542 friend class nanodbc::table_valued_parameter::table_valued_parameter_impl;
1546 std::shared_ptr<statement_impl> impl_;
1566 class connection_impl;
1567 friend class nanodbc::transaction::transaction_impl;
1569#ifdef NANODBC_HAS_STD_VARIANT
1578 long const& string_length,
1579 variant
const& resource) noexcept
1583 friend class nanodbc::connection::connection_impl;
1592 long const& string_length,
1593 std::uintptr_t value_ptr) noexcept
1597 friend class nanodbc::connection::connection_impl;
1626 connection(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1637 explicit connection(
string const& connection_string,
long timeout = 0);
1656 std::list<attribute>
const& attributes);
1667 connection(
string const& connection_string, std::list<attribute>
const& attributes);
1695 void connect(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1702 void connect(
string const& connection_string,
long timeout = 0);
1716 std::list<
attribute> const& attributes);
1724 void connect(
string const& connection_string, std::list<
attribute> const& attributes);
1742 string browse_connect(
string const& connection_string,
bool& more_wanted);
1743#if !defined(NANODBC_DISABLE_ASYNC)
1783 bool async_connect(
string const& connection_string,
void* event_handle,
long timeout = 0);
1799 std::
size_t transactions() const noexcept;
1802 void* native_dbc_handle() const noexcept;
1805 void* native_env_handle() const noexcept;
1811 T get_info(
short info_type) const;
1816 string dbms_name() const;
1821 string dbms_version() const;
1825 string driver_name() const;
1829 string driver_version() const;
1833 string database_name() const;
1837 string catalog_name() const;
1840 std::
size_t ref_transaction() noexcept;
1841 std::
size_t unref_transaction() noexcept;
1842 bool rollback() const noexcept;
1843 void rollback(
bool onoff) noexcept;
1846 std::shared_ptr<connection_impl> impl_;
1862class variant_row_cached_result;
1890 void* native_statement_handle() const noexcept;
1893 long rowset_size() const noexcept;
1897 long affected_rows() const;
1907 bool has_affected_rows() const;
1910 long rows() const noexcept;
1914 short columns() const;
1931#if !defined(NANODBC_DISABLE_ASYNC)
1983 void unbind(
string const& column_name);
2000 void unbind(
short column);
2043 void get_ref(
short column, T const& fallback, T&
result) const;
2054 void get_ref(
string const& column_name, T&
result) const;
2067 void get_ref(
string const& column_name, T const& fallback, T&
result) const;
2083 T get(
short column) const;
2096 T get(
short column, T const& fallback) const;
2098#if defined(NANODBC_HAS_STD_ANY) || defined(NANODBC_HAS_STD_VARIANT)
2119 T get_as(
short column)
const;
2124 T get_as(
string const& column_name)
const;
2135 T
get(
string const& column_name)
const;
2147 T
get(
string const& column_name, T
const& fallback)
const;
2208 short column(
string const& column_name)
const;
2287 explicit operator bool() const noexcept;
2297 friend class nanodbc::variant_row_cached_result;
2301 std::shared_ptr<result_impl> impl_;
2331 throw std::runtime_error(
"result is empty");
2332 return &(operator*());
2340 if (!result_.next())
2360 if (result_ && rhs.result_)
2361 return result_.native_statement_handle() == rhs.result_.native_statement_handle();
2363 return !result_ && !rhs.result_;
2433 auto count() const noexcept ->
short;
2438 auto auto_unique_value(
short record) const ->
bool;
2441 auto base_column_name(
short record) const ->
string;
2444 auto base_table_name(
short record) const ->
string;
2447 auto case_sensitive(
short record) const ->
bool;
2450 auto catalog_name(
short record) const ->
string;
2453 auto concise_type(
short record) const ->
short;
2456 auto display_size(
short record) const -> std::int64_t;
2459 auto fixed_prec_scale(
short record) const ->
short;
2462 auto label(
short record) const ->
string;
2465 auto length(
short record) const -> std::uint64_t;
2468 auto local_type_name(
short record) const ->
string;
2471 auto name(
short record) const ->
string;
2476 auto nullable(
short record) const ->
short;
2479 auto num_prec_radix(
short record) const ->
short;
2482 auto octet_length(
short record) const -> std::int64_t;
2485 auto precision(
short record) const ->
short;
2488 auto rowver(
short record) const ->
short;
2491 auto scale(
short record) const ->
short;
2494 auto schema_name(
short record) const ->
string;
2500 auto searchable(
short record) const ->
short;
2503 auto table_name(
short record) const ->
string;
2506 auto type(
short record) const ->
short;
2509 auto type_name(
short record) const ->
string;
2512 auto unnamed(
short record) const ->
bool;
2515 auto unsigned_(
short record) const ->
bool;
2521 auto updatable(
short record) const ->
short;
2525 struct sql_get_descr_field
2527 sql_get_descr_field(
2530 std::uint16_t field_identifier)
noexcept;
2531 operator std::int64_t()
const;
2532 operator std::uint64_t()
const;
2537 std::uint16_t field_identifier_;
2539 friend sql_get_descr_field;
2541 void initialize_descriptor();
2542 void throw_if_record_is_out_of_range(
short record)
const;
2544 void* statement_handle_{
nullptr};
2545 short statement_columns_count_{0};
2546 void* descriptor_handle_{
nullptr};
2547 short descriptor_records_count_{0};
2747 string const& table =
string(),
2748 string const& type =
string(),
2749 string const& schema =
string(),
2750 string const&
catalog =
string());
2767 string const& table =
string(),
2768 string const& schema =
string());
2780 string const& column =
string(),
2781 string const& table =
string(),
2782 string const& schema =
string(),
2783 string const&
catalog =
string());
2794 string const& table,
2795 string const& schema =
string(),
2796 string const&
catalog =
string());
2809 string const& procedure =
string(),
2810 string const& schema =
string(),
2811 string const&
catalog =
string());
2824 string const& column =
string(),
2825 string const& procedure =
string(),
2826 string const& schema =
string(),
2827 string const&
catalog =
string());
2860#if defined(NANODBC_HAS_STD_ANY) || defined(NANODBC_HAS_STD_VARIANT)
2868struct hold_column_value;
2870#ifdef NANODBC_HAS_STD_ANY
2872struct hold_column_value<std::any>
2874 static std::any from(std::any value) {
return value; }
2878#ifdef NANODBC_HAS_STD_VARIANT
2879template <
class Alternative,
class Variant>
2880inline bool hold_alternative(Variant& variant, std::any
const& value)
2882 if (
auto const* held = std::any_cast<Alternative>(&value))
2890template <
class... Ts>
2891struct hold_column_value<std::variant<Ts...>>
2893 static std::variant<Ts...> from(std::any
const& value)
2895 std::variant<Ts...> variant;
2896 if (!value.has_value())
2900 bool const each[] = {
false, (held = held || hold_alternative<Ts>(variant, value))...};
2906 throw type_incompatible_error();
2916T result::get_as(
short column)
const
2918 return detail::hold_column_value<T>::from(get<std::any>(column));
2922T result::get_as(
string const& column_name)
const
2924 return get_as<T>(this->column(column_name));
2985 string const& query,
2986 long batch_operations = 1,
2994template <
class Row,
class Member,
class Class>
3001template <
class Row,
class Accessor>
3002auto read_field(Row
const& row, Accessor
const& accessor) ->
decltype(accessor(row))
3004 return accessor(row);
3008template <
class Row,
class Accessor>
3011 using type =
typename std::decay<
3012 decltype(
read_field(std::declval<Row const&>(), std::declval<Accessor const&>()))>::type;
3020#ifdef NANODBC_HAS_STD_OPTIONAL
3022struct is_optional<std::optional<T>> : std::true_type
3056template <class T, bool IsOptional = is_optional<T>::value>
3059 using type =
typename std::
3063#ifdef NANODBC_HAS_STD_OPTIONAL
3067 using type =
typename std::conditional<
3074template <
class Rows,
class Accessor>
3079 Accessor
const& accessor,
3082 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3083 std::vector<value_type> column;
3084 column.reserve(rows.size());
3085 for (
auto const& row : rows)
3086 column.push_back(read_field(row, accessor));
3087 stmt.
bind(param_index, column);
3090template <
class Rows,
class Accessor>
3095 Accessor
const& accessor,
3098 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3099 std::vector<value_type> column;
3100 column.reserve(rows.size());
3101 for (
auto const& row : rows)
3102 column.push_back(read_field(row, accessor));
3103 stmt.bind_strings(param_index, column);
3106#ifdef NANODBC_HAS_STD_OPTIONAL
3109template <
class Rows,
class Accessor,
class Column>
3110std::unique_ptr<bool[]> gather_optional(Rows
const& rows, Accessor
const& accessor, Column& column)
3112 std::unique_ptr<bool[]> nulls(
new bool[rows.size()]);
3114 for (
auto const& row : rows)
3116 auto const& value =
read_field(row, accessor);
3117 nulls[i++] = !value.has_value();
3118 column.push_back(value ? *value : typename Column::value_type());
3123template <
class Rows,
class Accessor>
3128 Accessor
const& accessor,
3129 bind_as_optional_value)
3131 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3132 std::vector<typename optional_type::value_type> column;
3133 column.reserve(rows.size());
3134 auto const nulls = gather_optional(rows, accessor, column);
3135 stmt.bind(param_index, column, nulls.get());
3138template <
class Rows,
class Accessor>
3143 Accessor
const& accessor,
3144 bind_as_optional_string)
3146 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3147 std::vector<typename optional_type::value_type> column;
3148 column.reserve(rows.size());
3149 auto const nulls = gather_optional(rows, accessor, column);
3150 stmt.bind_strings(param_index, column, nulls.get());
3154template <
class Rows,
class Accessor>
3155void bind_one(statement& stmt,
short param_index, Rows
const& rows, Accessor
const& accessor)
3157 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3158 bind_column(stmt, param_index, rows, accessor,
typename bind_kind<value_type>::type());
3194template <
class Rows,
class... Accessors>
3197 short param_index = 0;
3200 int const sequence[] = {0, (detail::bind_one(stmt, param_index++, rows, accessors), 0)...};
A class representing a connection or a statement attribute.
Definition nanodbc.h:478
long string_length_
The StringLength argument of the ODBC call.
Definition nanodbc.h:491
void * value_ptr_
The ValuePtr argument of the ODBC call.
Definition nanodbc.h:492
long attribute_
The Attribute argument of the ODBC call.
Definition nanodbc.h:490
attribute(long const &attribute, long const &string_length, std::uintptr_t value_ptr) noexcept
Creates an attribute from the three arguments the ODBC call takes.
Definition nanodbc.h:484
Result set for a list of columns in one or more tables.
Definition nanodbc.h:2593
string remarks() const
Fetch column remarks.
short sql_data_type() const
Fetch column's SQL data type.
string table_catalog() const
Fetch table catalog.
short numeric_precision_radix() const
Fetch numeric precission.
string column_default() const
Fetch column's default.
string table_schema() const
Fetch table schema.
string type_name() const
Fetch column type name.
short sql_datetime_subtype() const
Fetch datetime subtype of column.
bool next()
Move to the next result in the result set.
short nullable() const
True iff column is nullable.
string column_name() const
Fetch column name.
string table_name() const
Fetch table name.
long column_size() const
Fetch column size.
short decimal_digits() const
Fetch decimal digits.
long char_octet_length() const
Fetch char octet length.
long ordinal_position() const
Ordinal position of the column in the table.
string is_nullable() const
Fetch column is-nullable information.
long buffer_length() const
Fetch buffer length.
short data_type() const
Fetch column data type.
Result set for a list of columns that compose the primary key of a single table.
Definition nanodbc.h:2633
bool next()
Move to the next result in the result set.
string column_name() const
Fetch column name.
short column_number() const
Column sequence number in the key (starting with 1).
string table_name() const
Fetch table name.
string primary_key_name() const
Primary key name.
string table_schema() const
Fetch table schema.
string table_catalog() const
Fetch table catalog.
Result set for a list of procedures in the data source.
Definition nanodbc.h:2695
string column_default() const
Fetch column's default.
string type_name() const
Fetch column type name.
long ordinal_position() const
Ordinal position of the column in the table.
bool next()
Move to the next result in the result set.
short decimal_digits() const
Fetch decimal digits.
long column_size() const
Fetch column size.
short sql_datetime_subtype() const
Fetch datetime subtype of column.
string remarks() const
Fetch column remarks.
long char_octet_length() const
Fetch char octet length.
string procedure_schema() const
Fetch procedure schema.
string procedure_catalog() const
Fetch procedure catalog.
short sql_data_type() const
Fetch column's SQL data type.
short column_type() const
Fetch column type.
short numeric_precision_radix() const
Fetch numeric precission.
string is_nullable() const
Fetch column is-nullable information.
long buffer_length() const
Fetch buffer length.
short nullable() const
True iff column is nullable.
string column_name() const
Fetch column name.
string procedure_name() const
Fetch procedure name.
short data_type() const
Fetch column data type.
Result set for a list of procedures in the data source.
Definition nanodbc.h:2678
string procedure_name() const
Fetch procedure name.
short procedure_type() const
Fetch procedure type.
string procedure_schema() const
Fetch procedure schema.
string procedure_catalog() const
Fetch procedure catalog.
string procedure_remarks() const
Fetch procedure remarks.
bool next()
Move to the next result in the result set.
Result set for a list of tables and the privileges associated with each table.
Definition nanodbc.h:2658
string privilege() const
Fetch the table privilege.
string grantor() const
Fetch name of user who granted the privilege.
bool next()
Move to the next result in the result set.
string table_schema() const
Fetch table schema.
string table_catalog() const
Fetch table catalog.
string table_name() const
Fetch table name.
string grantee() const
Fetch name of user whom the privilege was granted.
string is_grantable() const
Fetch indicator whether the grantee is permitted to grant the privilege to other users.
Result set for a list of tables in the data source.
Definition nanodbc.h:2576
string table_name() const
Fetch table name.
string table_catalog() const
Fetch table catalog.
bool next()
Move to the next result in the result set.
string table_remarks() const
Fetch table remarks.
string table_type() const
Fetch table type.
string table_schema() const
Fetch table schema.
A resource for get catalog information from connected data source.
Definition nanodbc.h:2572
std::list< string > list_schemas()
Returns names of all schemas available in connected data source.
std::list< string > list_catalogs()
Returns names of all catalogs (or databases) available in connected data source.
catalog(connection &conn) noexcept
Creates catalog operating on database accessible through the specified connection.
catalog::procedures find_procedures(string const &procedure=string(), string const &schema=string(), string const &catalog=string())
Creates result set with catalog, schema, procedure, and procedure types.
std::list< string > list_table_types()
Returns all available table types in the connected data source.
catalog::table_privileges find_table_privileges(string const &catalog, string const &table=string(), string const &schema=string())
Creates result set with tables and the privileges associated with each table.
catalog::tables find_tables(string const &table=string(), string const &type=string(), string const &schema=string(), string const &catalog=string())
Creates result set with catalogs, schemas, tables, or table types.
catalog::columns find_columns(string const &column=string(), string const &table=string(), string const &schema=string(), string const &catalog=string())
Creates result set with columns in one or more tables.
catalog::primary_keys find_primary_keys(string const &table, string const &schema=string(), string const &catalog=string())
Creates result set with columns that compose the primary key of a single table.
catalog::procedure_columns find_procedure_columns(string const &column=string(), string const &procedure=string(), string const &schema=string(), string const &catalog=string())
Creates result set with columns in one or more procedures.
Definition nanodbc.h:1588
Manages and encapsulates ODBC resources such as the connection and environment handles.
Definition nanodbc.h:1563
~connection() noexcept
Automatically disconnects from the database and frees all associated resources.
connection(string const &dsn, string const &user, string const &pass, std::list< attribute > const &attributes)
Create new connection object, set the connection attributes passed as arguments and connect to the gi...
bool async_connect(string const &connection_string, void *event_handle, long timeout=0)
Initiate an asynchronous connection operation using the given connection string.
connection(const connection &rhs) noexcept
Copy constructor.
bool connected() const noexcept
Returns true if connected to the database.
void async_complete()
Completes a previously initiated asynchronous connection operation.
connection(connection &&rhs) noexcept
Move constructor.
connection(string const &connection_string, std::list< attribute > const &attributes)
Create new connection object, set the connection attributes passed as arguments and connect to the gi...
connection(string const &dsn, string const &user, string const &pass, long timeout=0)
Create new connection object and immediately connect to the given data source.
connection & operator=(connection rhs) noexcept
Assignment.
connection()
Create new connection object, initially not connected.
bool async_connect(string const &dsn, string const &user, string const &pass, void *event_handle, long timeout=0)
Initiate an asynchronous connection operation to the given data source.
void swap(connection &) noexcept
Member swap.
connection(string const &connection_string, long timeout=0)
Create new connection object and immediately connect using the given connection string.
General database error.
Definition nanodbc.h:331
char const * what() const noexcept override
Returns the full message, including the driver's own text.
database_error(void *handle, short handle_type, std::string const &info="")
Creates runtime_error with message about last ODBC error.
Provides access to metadata in the Implementation Row Descriptor (IRD) implicitly allocated for a pre...
Definition nanodbc.h:2411
implementation_row_descriptor(statement const &statement)
Initializes IRD access from prepared or executed statement.
implementation_row_descriptor(result const &result)
Initializes IRD access from statement of executed result set.
auto alloc_type() const -> short
Value of the header field SQL_DESC_ALLOC_AUTO.
Index out of range.
Definition nanodbc.h:307
char const * what() const noexcept override
Returns the message describing the out of range index.
Accessed null data.
Definition nanodbc.h:296
char const * what() const noexcept override
Returns the message describing the null access.
Programming logic error.
Definition nanodbc.h:318
programming_error(std::string const &info)
Creates a programming error with the given message.
char const * what() const noexcept override
Returns the message describing the error.
Single pass input iterator that accesses successive rows in the attached result set.
Definition nanodbc.h:2306
result_iterator()=default
Default iterator; an empty result set.
bool operator!=(result_iterator const &rhs) const noexcept
Iterators are not equal if they have different native statemnt handles.
Definition nanodbc.h:2367
result * pointer
Pointer to iteration values.
Definition nanodbc.h:2310
pointer operator->()
Access through dereference.
Definition nanodbc.h:2328
result value_type
Values returned by iterator access.
Definition nanodbc.h:2309
void operator++(int)
Iteration.
Definition nanodbc.h:2355
bool operator==(result_iterator const &rhs) const noexcept
Iterators are equal if they a tied to the same native statemnt handle, or both empty.
Definition nanodbc.h:2358
result_iterator & operator++()
Iteration.
Definition nanodbc.h:2336
reference operator*() noexcept
Dereference.
Definition nanodbc.h:2325
result & reference
Reference to iteration values.
Definition nanodbc.h:2311
result_iterator(result &r)
Create result iterator for a given result set.
Definition nanodbc.h:2318
std::ptrdiff_t difference_type
Iterator difference.
Definition nanodbc.h:2312
std::input_iterator_tag iterator_category
Category of iterator.
Definition nanodbc.h:2308
A resource for managing result sets from statement execution.
Definition nanodbc.h:1869
int column_datatype(string const &column_name) const
Returns a identifying integer value representing the SQL type of this column by name.
int column_c_datatype(short column) const
Returns a identifying integer value representing the C type of this column.
bool complete_next()
Completes a previously-initiated async fetch for next row in the current result set.
unsigned long position() const
Returns the row position in the current result set.
string column_name(short column) const
Returns the name of the specified column.
int column_c_datatype(string const &column_name) const
Returns a identifying integer value representing the C type of this column by name.
bool move(long row)
Moves to and fetches the specified row in the current result set.
string column_datatype_name(short column) const
Returns data source dependent data type name of this column.
bool is_bound(string const &column_name) const
Returns true if we have bound a buffer to the given column.
bool is_null(short column) const
Returns true if and only if the given column of the current rowset is null.
int column_datatype(short column) const
Returns a identifying integer value representing the SQL type of this column.
bool async_next(void *event_handle)
Initiates an asynchronous fetch of the next row in the current result set.
bool next_result()
Returns the next result, e.g. when stored procedure returns multiple result sets.
int column_decimal_digits(short column) const
Returns the number of decimal digits of the specified column.
bool is_bound(short column) const
Returns true if we have bound a buffer to the given column.
bool column_unsigned(short column) const
SQL_TRUE if the column is unsigned (or not numeric).
bool at_end() const noexcept
Returns true if there are no more results in the current result set.
bool skip(long rows)
Skips a number of rows and then fetches the resulting row in the current result set.
bool column_unsigned(string const &column_name) const
SQL_TRUE if the column is unsigned (or not numeric).
long column_size(string const &column_name) const
Returns the size of the specified column by name.
string column_datatype_name(string const &column_name) const
Returns data source dependent data type name of this column by name.
int column_decimal_digits(string const &column_name) const
Returns the number of decimal digits of the specified column by name.
short column(string const &column_name) const
Returns the column number of the specified column name.
long column_size(short column) const
Returns the size of the specified column.
bool is_null(string const &column_name) const
Returns true if and only if the given column by name of the current rowset is null.
result() noexcept
Empty result set.
bool prior()
Fetches the prior row in the current result set.
Represents a statement on the database.
Definition nanodbc.h:867
statement(class connection &conn, std::list< attribute > const &attributes)
Constructs a statement object and associates it to the given connection, applying the given ODBC stat...
statement & operator=(statement rhs) noexcept
Assignment.
void just_execute_direct(class connection &conn, string const &query, long batch_operations=1, long timeout=0)
Execute the previously prepared query now without constructing result object.
void complete_prepare()
Completes a previously initiated asynchronous query preparation.
param_direction
Provides support for retrieving output/return parameters.
Definition nanodbc.h:908
@ PARAM_OUT
Binding an output parameter.
Definition nanodbc.h:910
@ PARAM_INOUT
Binding an input/output parameter.
Definition nanodbc.h:911
@ PARAM_IN
Binding an input parameter.
Definition nanodbc.h:909
bool async_prepare(string const &query, void *event_handle, long timeout=0)
Prepare the given statement, in asynchronous mode.
short columns() const
Returns the number of columns in a result set.
void disable_async() const
undocumented - for internal use only (used from result_impl)
bool async_execute_direct(class connection &conn, void *event_handle, string const &query, long batch_operations=1, long timeout=0)
Opens, prepares, and executes query directly on the given connection, in async mode.
void describe_parameters(const std::vector< short > &idx, const std::vector< short > &type, const std::vector< unsigned long > &size, const std::vector< short > &scale)
Sets descriptions for parameters in the prepared statement.
statement(statement &&rhs) noexcept
Move constructor.
~statement() noexcept
Closes the statement.
statement(class connection &conn)
Constructs a statement object and associates it to the given connection.
void swap(statement &rhs) noexcept
Member swap.
bool async_execute(void *event_handle, long batch_operations=1, long timeout=0)
Execute the previously prepared query now, in asynchronous mode.
statement()
Creates a new un-prepared statement.
statement(const statement &rhs) noexcept
Copy constructor.
void enable_async(void *event_handle)
undocumented - for internal use only (used from result_impl)
statement(class connection &conn, string const &query, long timeout=0)
Constructs and prepares a statement using the given connection and query.
void reset_parameters() noexcept
Resets all currently bound parameters.
void just_execute(long batch_operations=1, long timeout=0)
Execute the previously prepared query now without constructing result object.
long affected_rows() const
Returns rows affected by the request or -1 if affected rows is not available.
Support for table-valued parameter.
Definition nanodbc.h:612
table_valued_parameter(statement &stmt, short param_index, size_t row_count)
Creates a table-valued parameter and opens it on the given statement.
~table_valued_parameter() noexcept
Closes the parameter, if it is still open.
void bind_null(short param_index)
Binds a null value to the given column of every row.
table_valued_parameter(const table_valued_parameter &rhs) noexcept
Copy constructor.
short parameters() const noexcept
Returns the number of columns in the table valued parameter.
table_valued_parameter(table_valued_parameter &&rhs) noexcept
Move constructor.
table_valued_parameter()
Creates a table-valued parameter that is not yet open.
void describe_parameters(const std::vector< short > &idx, const std::vector< short > &type, const std::vector< unsigned long > &size, const std::vector< short > &scale)
Sets descriptions for columns of the table-valued parameter.
A resource for managing transaction commits and rollbacks.
Definition nanodbc.h:548
~transaction() noexcept
If this transaction has not been committed, it will rollback any modifying ops.
transaction(const class connection &conn)
Begin a transaction on the given connection object.
transaction(transaction &&rhs) noexcept
Move constructor.
transaction(const transaction &rhs) noexcept
Copy constructor.
transaction & operator=(transaction rhs) noexcept
Assignment.
void swap(transaction &rhs) noexcept
Member swap.
Type incompatible.
Definition nanodbc.h:285
char const * what() const noexcept override
Returns the message describing the incompatibility.
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple string values.
Definition nanodbc.h:1488
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls)
Binds multiple string values.
Definition nanodbc.h:803
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, T const *null_sentry)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, bool const *nulls)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, typename T::value_type const *null_sentry)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], T const *null_sentry)
Binds multiple string values.
Definition nanodbc.h:775
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, T const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, bool const *nulls)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, typename T::value_type const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], T const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple string values.
Definition nanodbc.h:1451
void bind_null(short param_index, std::size_t batch_size=1)
Binds null values to the parameter placeholder number in the prepared statement.
void bind(short param_index, T const *value, param_direction direction=PARAM_IN)
Binds given value to given parameter placeholder number in the prepared statement.
result_iterator end(result &) noexcept
Returns an iterator to the end of a result set.
Definition nanodbc.h:2385
result_iterator begin(result &r)
Returns an iterator to the beginning of the given result set.
Definition nanodbc.h:2374
void prepare(statement &stmt, string const &query, long timeout=0)
Prepares the given statement to execute on it associated connection.
void bind_rows(statement &stmt, Rows const &rows, Accessors const &... accessors)
Binds a range of rows, a parameter at a time.
Definition nanodbc.h:3195
result execute(connection &conn, string const &query, long batch_operations=1, long timeout=0)
Immediately opens, prepares, and executes the given query directly on the given connection.
void just_transact(statement &stmt, long batch_operations)
Execute the previously prepared query now and without creating result object.
result transact(statement &stmt, long batch_operations)
Execute the previously prepared query now.
std::list< driver > list_drivers()
Returns a list of ODBC drivers on your system.
std::list< datasource > list_datasources()
Returns a list of ODBC data sources on your system.
void just_execute(connection &conn, string const &query, long batch_operations=1, long timeout=0)
Opens, prepares, and executes query directly without creating result object.
T get(string const &column_name) const
Gets data from the given column by name of the current rowset.
T get(string const &column_name, T const &fallback) const
Gets data from the given column by name of the current rowset.
typename std::enable_if< is_string< T >::value >::type enable_if_string
Enables an overload only for the string types nanodbc binds as strings.
Definition nanodbc.h:519
typename std::enable_if< is_character< T >::value >::type enable_if_character
Enables an overload only for the character types nanodbc binds as strings.
Definition nanodbc.h:523
std::integral_constant< bool, std::is_same< typename std::decay< T >::type, std::string >::value||std::is_same< typename std::decay< T >::type, wide_string >::value > is_string
A type trait for testing if a type is a std::basic_string compatible with the current nanodbc configu...
Definition nanodbc.h:507
std::integral_constant< bool, std::is_same< typename std::decay< T >::type, std::string::value_type >::value||std::is_same< typename std::decay< T >::type, wide_char_t >::value > is_character
A type trait for testing if a type is a character compatible with the current nanodbc configuration.
Definition nanodbc.h:515
Member const & read_field(Row const &row, Member Class::*field)
Reads a member through a pointer to it.
Definition nanodbc.h:2995
The entirety of nanodbc can be found within this one namespace.
Definition nanodbc.h:110
unspecified type string
string will be std::u16string or std::32string if NANODBC_ENABLE_UNICODE defined.
Definition nanodbc.h:238
unspecified type null_type
null_type will be int64_t for 64-bit compilations, otherwise long.
Definition nanodbc.h:240
A type capturing parameter array length as well as number of rows in a rowset of a result.
Definition nanodbc.h:376
batch_ops() noexcept
Creates lengths of -1, meaning neither has been chosen.
Definition nanodbc.h:381
batch_ops(const long all_length) noexcept
Creates both lengths with the same value.
Definition nanodbc.h:387
long rowset_size
Number of rows fetched into a rowset at a time.
Definition nanodbc.h:378
long parameter_array_length
Number of parameter values bound per execution.
Definition nanodbc.h:377
A data source name registered with the driver manager.
Definition nanodbc.h:2952
nanodbc::string driver
Driver description.
Definition nanodbc.h:2954
nanodbc::string name
DSN name.
Definition nanodbc.h:2953
A type for representing date data.
Definition nanodbc.h:394
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:396
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:397
std::int16_t year
Year [0-inf).
Definition nanodbc.h:395
Definition nanodbc.h:3053
Definition nanodbc.h:3050
Definition nanodbc.h:3047
Definition nanodbc.h:3044
Definition nanodbc.h:3058
The type an accessor yields for a row, stripped of reference and const.
Definition nanodbc.h:3010
Definition nanodbc.h:3029
Definition nanodbc.h:3017
Driver attributes.
Definition nanodbc.h:2941
nanodbc::string keyword
Driver keyword attribute.
Definition nanodbc.h:2942
nanodbc::string value
Driver attribute value.
Definition nanodbc.h:2943
Information on a configured ODBC driver.
Definition nanodbc.h:2938
nanodbc::string name
Driver name.
Definition nanodbc.h:2946
std::list< attribute > attributes
List of driver attributes.
Definition nanodbc.h:2947
A type for representing time data.
Definition nanodbc.h:402
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:403
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:404
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:405
A type for representing timestamp data.
Definition nanodbc.h:410
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:414
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:416
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:413
std::int16_t year
Year [0-inf).
Definition nanodbc.h:411
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:415
std::int32_t fract
Fractional seconds.
Definition nanodbc.h:417
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:412
A type for representing timestamp+offset data.
Definition nanodbc.h:422
std::int16_t offset_minute
Minutes part of time zome offset.
Definition nanodbc.h:425
timestamp stamp
Date and time, in the offset's local terms.
Definition nanodbc.h:423
std::int16_t offset_hour
Whole hour part of time zone offset.
Definition nanodbc.h:424