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
136#define NANODBC_THROW_NO_SOURCE_LOCATION 1
152#define NANODBC_ASSERT(expression) assert(expression)
159#ifdef NANODBC_ENABLE_UNICODE
160#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
161#define NANODBC_TEXT(s) U##s
162typedef std::u32string
string;
163#ifdef NANODBC_HAS_STD_STRING_VIEW
164typedef std::u32string_view string_view;
168typedef std::wstring
string;
169#ifdef NANODBC_HAS_STD_STRING_VIEW
170typedef std::wstring_view string_view;
172#define NANODBC_TEXT(s) L##s
174typedef std::u16string
string;
175#ifdef NANODBC_HAS_STD_STRING_VIEW
176typedef std::u16string_view string_view;
178#define NANODBC_TEXT(s) u##s
182typedef std::string
string;
183#ifdef NANODBC_HAS_STD_STRING_VIEW
184typedef std::string_view string_view;
186#define NANODBC_TEXT(s) s
189#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
190typedef std::u32string wide_string;
191#ifdef NANODBC_HAS_STD_STRING_VIEW
192typedef std::u32string_view wide_string_view;
196typedef std::wstring wide_string;
197#ifdef NANODBC_HAS_STD_STRING_VIEW
198typedef std::wstring_view wide_string_view;
201typedef std::u16string wide_string;
202#ifdef NANODBC_HAS_STD_STRING_VIEW
203typedef std::u16string_view wide_string_view;
208typedef wide_string::value_type wide_char_t;
213#elif !defined(_WIN64) && defined(__LP64__)
230#define NANODBC_TEXT(s) s
243#define NANODBC_DEPRECATED [[deprecated]]
246#ifndef NANODBC_DISABLE_MSSQL_TVP
247class table_valued_parameter;
288 char const*
what() const noexcept override;
299 char const*
what() const noexcept override;
310 char const*
what() const noexcept override;
323 char const*
what() const noexcept override;
338 char const*
what() const noexcept override;
341 long native() const noexcept;
344 std::
string const& state() const noexcept;
348 std::
string sql_state;
380 : parameter_array_length(-1L)
381 , rowset_size(-1L) {};
386 : parameter_array_length(all_length)
387 , rowset_size(all_length) {};
426#ifdef NANODBC_HAS_STD_VARIANT
441#ifdef NANODBC_ENABLE_UNICODE
442 typedef std::variant<std::vector<uint8_t>,
string, std::string, std::intptr_t, std::uintptr_t>
445 typedef std::variant<std::vector<uint8_t>,
string, std::intptr_t, std::uintptr_t> variant;
457 attribute(
long const&
attribute,
long const& string_length, variant
const& resource)
noexcept;
461 void extractValuePtr();
484 , string_length_(string_length)
485 , value_ptr_((
void*)value_ptr) {};
499 std::is_same<typename std::decay<T>::type, std::string>::value ||
500 std::is_same<typename std::decay<T>::type, wide_string>::value
501#ifdef NANODBC_HAS_STD_STRING_VIEW
502 || std::is_same<typename std::decay<T>::type, std::string_view>::value ||
503 std::is_same<typename std::decay<T>::type, wide_string_view>::value
512 std::is_same<typename std::decay<T>::type, std::string::value_type>::value ||
513 std::is_same<typename std::decay<T>::type, wide_char_t>::value>;
573 void rollback() noexcept;
588 class transaction_impl;
592 std::shared_ptr<transaction_impl> impl_;
607#ifndef NANODBC_DISABLE_MSSQL_TVP
637 void open(
statement& stmt,
short param_index, std::
size_t row_count);
666 void bind(
short param_index, T const* values, std::
size_t batch_size);
671 void bind(
short param_index, T const* values, std::
size_t batch_size, T const* null_sentry);
676 void bind(
short param_index, T const* values, std::
size_t batch_size,
bool const* nulls);
680 void bind(
short param_index, std::vector<std::vector<uint8_t>> const& values);
685 bind(
short param_index, std::vector<std::vector<uint8_t>> const& values,
bool const* nulls);
691 std::vector<std::vector<uint8_t>> const& values,
692 uint8_t const* null_sentry);
722 std::
size_t value_size,
723 std::
size_t batch_size);
732 void bind_strings(
short param_index, std::vector<T> const& values);
737 std::
size_t BatchSize,
738 std::
size_t ValueSize,
741 void bind_strings(
short param_index, T const (&values)[BatchSize][ValueSize])
743 auto param_values =
reinterpret_cast<T const*
>(values);
744 bind_strings(param_index, param_values, ValueSize, BatchSize);
749 template <
class T,
typename = enable_if_
character<T>>
753 std::size_t value_size,
754 std::size_t batch_size,
755 T
const* null_sentry);
759 template <
class T,
typename = enable_if_
string<T>>
762 std::vector<T>
const& values,
763 typename T::value_type
const* null_sentry);
768 std::size_t BatchSize,
769 std::size_t ValueSize,
773 bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize], T
const* null_sentry)
775 auto param_values =
reinterpret_cast<T const*
>(values);
776 bind_strings(param_index, param_values, ValueSize, BatchSize,
nullptr, null_sentry);
781 template <
class T,
typename = enable_if_
character<T>>
785 std::size_t value_size,
786 std::size_t batch_size,
791 template <
class T,
typename = enable_if_
string<T>>
792 void bind_strings(
short param_index, std::vector<T>
const& values,
bool const* nulls);
797 std::size_t BatchSize,
798 std::size_t ValueSize,
801 void bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize],
bool const* nulls)
803 auto param_values =
reinterpret_cast<T const*
>(values);
804 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls);
825 const std::vector<short>& idx,
826 const std::vector<short>& type,
827 const std::vector<unsigned long>& size,
828 const std::vector<short>& scale);
834 unsigned long parameter_size(
short param_index) const;
837 short parameter_scale(
short param_index) const;
840 short parameter_type(
short param_index) const;
843 class table_valued_parameter_impl;
847 std::shared_ptr<table_valued_parameter_impl> impl_;
868 class statement_impl;
870#ifdef NANODBC_HAS_STD_VARIANT
879 long const& string_length,
880 variant
const& resource) noexcept
884 friend class nanodbc::statement::statement_impl;
893 long const& string_length,
894 std::uintptr_t value_ptr) noexcept
898 friend class nanodbc::statement::statement_impl;
960 bool open() const noexcept;
963 bool connected() const noexcept;
972 void* native_statement_handle() const noexcept;
987 void prepare(class
connection& conn,
string const& query,
long timeout = 0);
996 void prepare(
string const& query,
long timeout = 0);
1000 void timeout(
long timeout = 0);
1014 string const& query,
1015 long batch_operations = 1,
1030 string const& query,
1034#if !defined(NANODBC_DISABLE_ASYNC)
1088 string const& query,
1089 long batch_operations = 1,
1109 bool async_execute(
void* event_handle,
long batch_operations = 1,
long timeout = 0);
1124 class result complete_execute(long batch_operations = 1);
1144 string const& query,
1145 long batch_operations = 1,
1192 string const& schema,
1193 string const& procedure,
1194 string const& column);
1209 short parameters() const;
1212 unsigned long parameter_size(
short param_index) const;
1215 short parameter_scale(
short param_index) const;
1218 short parameter_type(
short param_index) const;
1283 std::
size_t batch_size,
1292 std::
size_t batch_size,
1293 T const* null_sentry,
1302 std::
size_t batch_size,
1310 std::vector<std::vector<uint8_t>> const& values,
1317 std::vector<std::vector<uint8_t>> const& values,
1325 std::vector<std::vector<uint8_t>> const& values,
1326 uint8_t const* null_sentry,
1337 bind(
short param_index, std::vector<T> const& values,
param_direction direction = PARAM_IN);
1344 std::vector<T> const& values,
1377 std::
size_t value_size,
1378 std::
size_t batch_size,
1390 std::vector<T> const& values,
1396 std::
size_t BatchSize,
1397 std::
size_t ValueSize,
1402 T const (&values)[BatchSize][ValueSize],
1405 auto param_values =
reinterpret_cast<T const*
>(values);
1406 bind_strings(param_index, param_values, ValueSize, BatchSize, direction);
1411 template <
class T,
typename = enable_if_
character<T>>
1415 std::size_t value_size,
1416 std::size_t batch_size,
1417 T
const* null_sentry,
1422 template <
class T,
typename = enable_if_
string<T>>
1425 std::vector<T>
const& values,
1426 typename T::value_type
const* null_sentry,
1432 std::size_t BatchSize,
1433 std::size_t ValueSize,
1438 T
const (&values)[BatchSize][ValueSize],
1439 T
const* null_sentry,
1442 auto param_values =
reinterpret_cast<T const*
>(values);
1443 bind_strings(param_index, param_values, ValueSize, BatchSize, null_sentry, direction);
1448 template <
class T,
typename = enable_if_
character<T>>
1452 std::size_t value_size,
1453 std::size_t batch_size,
1459 template <
class T,
typename = enable_if_
string<T>>
1462 std::vector<T>
const& values,
1469 std::size_t BatchSize,
1470 std::size_t ValueSize,
1475 T
const (&values)[BatchSize][ValueSize],
1479 auto param_values =
reinterpret_cast<T const*
>(values);
1480 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls, direction);
1496 void bind_null(
short param_index, std::size_t batch_size = 1);
1518 const std::vector<short>& idx,
1519 const std::vector<short>& type,
1520 const std::vector<unsigned long>& size,
1521 const std::vector<short>& scale);
1524 typedef std::function<bool(std::size_t)> null_predicate_type;
1526#ifndef NANODBC_DISABLE_MSSQL_TVP
1527 friend class nanodbc::table_valued_parameter::table_valued_parameter_impl;
1531 std::shared_ptr<statement_impl> impl_;
1551 class connection_impl;
1552 friend class nanodbc::transaction::transaction_impl;
1554#ifdef NANODBC_HAS_STD_VARIANT
1563 long const& string_length,
1564 variant
const& resource) noexcept
1568 friend class nanodbc::connection::connection_impl;
1577 long const& string_length,
1578 std::uintptr_t value_ptr) noexcept
1582 friend class nanodbc::connection::connection_impl;
1611 connection(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1622 explicit connection(
string const& connection_string,
long timeout = 0);
1641 std::list<attribute>
const& attributes);
1652 connection(
string const& connection_string, std::list<attribute>
const& attributes);
1680 void connect(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1687 void connect(
string const& connection_string,
long timeout = 0);
1701 std::list<
attribute> const& attributes);
1709 void connect(
string const& connection_string, std::list<
attribute> const& attributes);
1710#if !defined(NANODBC_DISABLE_ASYNC)
1750 bool async_connect(
string const& connection_string,
void* event_handle,
long timeout = 0);
1766 std::
size_t transactions() const noexcept;
1769 void* native_dbc_handle() const noexcept;
1772 void* native_env_handle() const noexcept;
1778 T get_info(
short info_type) const;
1783 string dbms_name() const;
1788 string dbms_version() const;
1792 string driver_name() const;
1796 string driver_version() const;
1800 string database_name() const;
1804 string catalog_name() const;
1807 std::
size_t ref_transaction() noexcept;
1808 std::
size_t unref_transaction() noexcept;
1809 bool rollback() const noexcept;
1810 void rollback(
bool onoff) noexcept;
1813 std::shared_ptr<connection_impl> impl_;
1829class variant_row_cached_result;
1857 void* native_statement_handle() const noexcept;
1860 long rowset_size() const noexcept;
1864 long affected_rows() const;
1874 bool has_affected_rows() const;
1877 long rows() const noexcept;
1881 short columns() const;
1898#if !defined(NANODBC_DISABLE_ASYNC)
1950 void unbind(
string const& column_name);
1967 void unbind(
short column);
2010 void get_ref(
short column, T const& fallback, T&
result) const;
2021 void get_ref(
string const& column_name, T&
result) const;
2034 void get_ref(
string const& column_name, T const& fallback, T&
result) const;
2045 T get(
short column) const;
2058 T get(
short column, T const& fallback) const;
2068 T get(
string const& column_name) const;
2080 T get(
string const& column_name, T const& fallback) const;
2105 bool is_null(
short column) const;
2114 bool is_null(
string const& column_name) const;
2126 bool is_bound(
short column) const;
2134 bool is_bound(
string const& column_name) const;
2141 short column(
string const& column_name) const;
2148 string column_name(
short column) const;
2155 long column_size(
short column) const;
2158 long column_size(
string const& column_name) const;
2168 int column_decimal_digits(
short column) const;
2171 int column_decimal_digits(
string const& column_name) const;
2174 int column_datatype(
short column) const;
2177 int column_datatype(
string const& column_name) const;
2186 string column_datatype_name(
short column) const;
2195 string column_datatype_name(
string const& column_name) const;
2198 int column_c_datatype(
short column) const;
2201 int column_c_datatype(
string const& column_name) const;
2210 bool column_unsigned(
short column) const;
2214 bool column_unsigned(
string const& column_name) const;
2220 explicit operator
bool() const noexcept;
2230 friend class nanodbc::variant_row_cached_result;
2234 std::shared_ptr<result_impl> impl_;
2264 throw std::runtime_error(
"result is empty");
2265 return &(operator*());
2273 if (!result_.next())
2293 if (result_ && rhs.result_)
2294 return result_.native_statement_handle() == rhs.result_.native_statement_handle();
2296 return !result_ && !rhs.result_;
2366 auto count() const noexcept ->
short;
2371 auto auto_unique_value(
short record) const ->
bool;
2374 auto base_column_name(
short record) const ->
string;
2377 auto base_table_name(
short record) const ->
string;
2380 auto case_sensitive(
short record) const ->
bool;
2383 auto catalog_name(
short record) const ->
string;
2386 auto concise_type(
short record) const ->
short;
2389 auto display_size(
short record) const -> std::int64_t;
2392 auto fixed_prec_scale(
short record) const ->
short;
2395 auto label(
short record) const ->
string;
2398 auto length(
short record) const -> std::uint64_t;
2401 auto local_type_name(
short record) const ->
string;
2404 auto name(
short record) const ->
string;
2409 auto nullable(
short record) const ->
short;
2412 auto num_prec_radix(
short record) const ->
short;
2415 auto octet_length(
short record) const -> std::int64_t;
2418 auto precision(
short record) const ->
short;
2421 auto rowver(
short record) const ->
short;
2424 auto scale(
short record) const ->
short;
2427 auto schema_name(
short record) const ->
string;
2433 auto searchable(
short record) const ->
short;
2436 auto table_name(
short record) const ->
string;
2439 auto type(
short record) const ->
short;
2442 auto type_name(
short record) const ->
string;
2445 auto unnamed(
short record) const ->
bool;
2448 auto unsigned_(
short record) const ->
bool;
2454 auto updatable(
short record) const ->
short;
2458 struct sql_get_descr_field
2460 sql_get_descr_field(
2463 std::uint16_t field_identifier)
noexcept;
2464 operator std::int64_t()
const;
2465 operator std::uint64_t()
const;
2470 std::uint16_t field_identifier_;
2472 friend sql_get_descr_field;
2474 void initialize_descriptor();
2475 void throw_if_record_is_out_of_range(
short record)
const;
2477 void* statement_handle_{
nullptr};
2478 short statement_columns_count_{0};
2479 void* descriptor_handle_{
nullptr};
2480 short descriptor_records_count_{0};
2680 string const& table =
string(),
2681 string const& type =
string(),
2682 string const& schema =
string(),
2683 string const&
catalog =
string());
2700 string const& table =
string(),
2701 string const& schema =
string());
2713 string const& column =
string(),
2714 string const& table =
string(),
2715 string const& schema =
string(),
2716 string const&
catalog =
string());
2727 string const& table,
2728 string const& schema =
string(),
2729 string const&
catalog =
string());
2742 string const& procedure =
string(),
2743 string const& schema =
string(),
2744 string const&
catalog =
string());
2757 string const& column =
string(),
2758 string const& procedure =
string(),
2759 string const& schema =
string(),
2760 string const&
catalog =
string());
2850 string const& query,
2851 long batch_operations = 1,
2859template <
class Row,
class Member,
class Class>
2866template <
class Row,
class Accessor>
2867auto read_field(Row
const& row, Accessor
const& accessor) ->
decltype(accessor(row))
2869 return accessor(row);
2873template <
class Row,
class Accessor>
2876 using type =
typename std::decay<
2877 decltype(
read_field(std::declval<Row const&>(), std::declval<Accessor const&>()))>::type;
2885#ifdef NANODBC_HAS_STD_OPTIONAL
2887struct is_optional<std::optional<T>> : std::true_type
2921template <class T, bool IsOptional = is_optional<T>::value>
2924 using type =
typename std::
2928#ifdef NANODBC_HAS_STD_OPTIONAL
2932 using type =
typename std::conditional<
2939template <
class Rows,
class Accessor>
2944 Accessor
const& accessor,
2947 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
2948 std::vector<value_type> column;
2949 column.reserve(rows.size());
2950 for (
auto const& row : rows)
2951 column.push_back(read_field(row, accessor));
2952 stmt.
bind(param_index, column);
2955template <
class Rows,
class Accessor>
2960 Accessor
const& accessor,
2963 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
2964 std::vector<value_type> column;
2965 column.reserve(rows.size());
2966 for (
auto const& row : rows)
2967 column.push_back(read_field(row, accessor));
2968 stmt.bind_strings(param_index, column);
2971#ifdef NANODBC_HAS_STD_OPTIONAL
2974template <
class Rows,
class Accessor,
class Column>
2975std::unique_ptr<bool[]> gather_optional(Rows
const& rows, Accessor
const& accessor, Column& column)
2977 std::unique_ptr<bool[]> nulls(
new bool[rows.size()]);
2979 for (
auto const& row : rows)
2981 auto const& value =
read_field(row, accessor);
2982 nulls[i++] = !value.has_value();
2983 column.push_back(value ? *value : typename Column::value_type());
2988template <
class Rows,
class Accessor>
2993 Accessor
const& accessor,
2994 bind_as_optional_value)
2996 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
2997 std::vector<typename optional_type::value_type> column;
2998 column.reserve(rows.size());
2999 auto const nulls = gather_optional(rows, accessor, column);
3000 stmt.bind(param_index, column, nulls.get());
3003template <
class Rows,
class Accessor>
3008 Accessor
const& accessor,
3009 bind_as_optional_string)
3011 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3012 std::vector<typename optional_type::value_type> column;
3013 column.reserve(rows.size());
3014 auto const nulls = gather_optional(rows, accessor, column);
3015 stmt.bind_strings(param_index, column, nulls.get());
3019template <
class Rows,
class Accessor>
3020void bind_one(statement& stmt,
short param_index, Rows
const& rows, Accessor
const& accessor)
3022 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3023 bind_column(stmt, param_index, rows, accessor,
typename bind_kind<value_type>::type());
3059template <
class Rows,
class... Accessors>
3062 short param_index = 0;
3065 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:476
long string_length_
The StringLength argument of the ODBC call.
Definition nanodbc.h:489
void * value_ptr_
The ValuePtr argument of the ODBC call.
Definition nanodbc.h:490
long attribute_
The Attribute argument of the ODBC call.
Definition nanodbc.h:488
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:482
Result set for a list of columns in one or more tables.
Definition nanodbc.h:2526
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:2566
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:2628
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:2611
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:2591
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:2509
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:2505
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:1573
Manages and encapsulates ODBC resources such as the connection and environment handles.
Definition nanodbc.h:1548
~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:329
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:2344
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:305
char const * what() const noexcept override
Returns the message describing the out of range index.
Accessed null data.
Definition nanodbc.h:294
char const * what() const noexcept override
Returns the message describing the null access.
Programming logic error.
Definition nanodbc.h:316
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:2239
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:2300
result * pointer
Pointer to iteration values.
Definition nanodbc.h:2243
pointer operator->()
Access through dereference.
Definition nanodbc.h:2261
result value_type
Values returned by iterator access.
Definition nanodbc.h:2242
void operator++(int)
Iteration.
Definition nanodbc.h:2288
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:2291
result_iterator & operator++()
Iteration.
Definition nanodbc.h:2269
reference operator*() noexcept
Dereference.
Definition nanodbc.h:2258
result & reference
Reference to iteration values.
Definition nanodbc.h:2244
result_iterator(result &r)
Create result iterator for a given result set.
Definition nanodbc.h:2251
std::ptrdiff_t difference_type
Iterator difference.
Definition nanodbc.h:2245
std::input_iterator_tag iterator_category
Category of iterator.
Definition nanodbc.h:2241
A resource for managing result sets from statement execution.
Definition nanodbc.h:1836
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.
bool move(long row)
Moves to and fetches the specified row in the current result set.
bool async_next(void *event_handle)
Initiates an asynchronous fetch of the next row in the current result set.
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.
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:865
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:906
@ PARAM_OUT
Binding an output parameter.
Definition nanodbc.h:908
@ PARAM_INOUT
Binding an input/output parameter.
Definition nanodbc.h:909
@ PARAM_IN
Binding an input parameter.
Definition nanodbc.h:907
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:610
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:546
~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:283
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:1473
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls)
Binds multiple string values.
Definition nanodbc.h:801
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:773
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:1436
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:2318
result_iterator begin(result &r)
Returns an iterator to the beginning of the given result set.
Definition nanodbc.h:2307
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:3060
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.
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:517
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:521
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:505
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:513
Member const & read_field(Row const &row, Member Class::*field)
Reads a member through a pointer to it.
Definition nanodbc.h:2860
The entirety of nanodbc can be found within this one namespace.
Definition nanodbc.h:108
unspecified type string
string will be std::u16string or std::32string if NANODBC_ENABLE_UNICODE defined.
Definition nanodbc.h:236
unspecified type null_type
null_type will be int64_t for 64-bit compilations, otherwise long.
Definition nanodbc.h:238
A type capturing parameter array length as well as number of rows in a rowset of a result.
Definition nanodbc.h:374
batch_ops() noexcept
Creates lengths of -1, meaning neither has been chosen.
Definition nanodbc.h:379
batch_ops(const long all_length) noexcept
Creates both lengths with the same value.
Definition nanodbc.h:385
long rowset_size
Number of rows fetched into a rowset at a time.
Definition nanodbc.h:376
long parameter_array_length
Number of parameter values bound per execution.
Definition nanodbc.h:375
A data source name registered with the driver manager.
Definition nanodbc.h:2817
nanodbc::string driver
Driver description.
Definition nanodbc.h:2819
nanodbc::string name
DSN name.
Definition nanodbc.h:2818
A type for representing date data.
Definition nanodbc.h:392
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:394
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:395
std::int16_t year
Year [0-inf).
Definition nanodbc.h:393
Definition nanodbc.h:2918
Definition nanodbc.h:2915
Definition nanodbc.h:2912
Definition nanodbc.h:2909
Definition nanodbc.h:2923
The type an accessor yields for a row, stripped of reference and const.
Definition nanodbc.h:2875
Definition nanodbc.h:2894
Definition nanodbc.h:2882
Driver attributes.
Definition nanodbc.h:2806
nanodbc::string keyword
Driver keyword attribute.
Definition nanodbc.h:2807
nanodbc::string value
Driver attribute value.
Definition nanodbc.h:2808
Information on a configured ODBC driver.
Definition nanodbc.h:2803
nanodbc::string name
Driver name.
Definition nanodbc.h:2811
std::list< attribute > attributes
List of driver attributes.
Definition nanodbc.h:2812
A type for representing time data.
Definition nanodbc.h:400
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:401
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:402
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:403
A type for representing timestamp data.
Definition nanodbc.h:408
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:412
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:414
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:411
std::int16_t year
Year [0-inf).
Definition nanodbc.h:409
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:413
std::int32_t fract
Fractional seconds.
Definition nanodbc.h:415
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:410
A type for representing timestamp+offset data.
Definition nanodbc.h:420
std::int16_t offset_minute
Minutes part of time zome offset.
Definition nanodbc.h:423
timestamp stamp
Date and time, in the offset's local terms.
Definition nanodbc.h:421
std::int16_t offset_hour
Whole hour part of time zone offset.
Definition nanodbc.h:422