77#ifndef NANODBC_NANODBC_H
78#define NANODBC_NANODBC_H
100#define NANODBC_HAS_STD_STRING_VIEW
101#define NANODBC_HAS_STD_OPTIONAL
102#define NANODBC_HAS_STD_VARIANT
103#define NANODBC_HAS_STD_ANY
140#define NANODBC_THROW_NO_SOURCE_LOCATION 1
156#define NANODBC_ASSERT(expression) assert(expression)
163#if defined(NANODBC_ENABLE_UNICODE) && defined(NANODBC_ENABLE_UTF8)
164#error "NANODBC_ENABLE_UNICODE and NANODBC_ENABLE_UTF8 are alternatives; define one"
167#ifdef NANODBC_ENABLE_UNICODE
168#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
169#define NANODBC_TEXT(s) U##s
170using string = std::u32string;
171using string_view = std::u32string_view;
174using string = std::wstring;
175using string_view = std::wstring_view;
176#define NANODBC_TEXT(s) L##s
178using string = std::u16string;
179using string_view = std::u16string_view;
180#define NANODBC_TEXT(s) u##s
184using string = std::string;
185using string_view = std::string_view;
186#define NANODBC_TEXT(s) s
189#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
190using wide_string = std::u32string;
191using wide_string_view = std::u32string_view;
194using wide_string = std::wstring;
195using wide_string_view = std::wstring_view;
197using wide_string = std::u16string;
198using wide_string_view = std::u16string_view;
202using wide_char_t = wide_string::value_type;
207#elif !defined(_WIN64) && defined(__LP64__)
224#define NANODBC_TEXT(s) s
237#define NANODBC_DEPRECATED [[deprecated]]
240#ifndef NANODBC_DISABLE_MSSQL_TVP
241class table_valued_parameter;
282 char const*
what() const noexcept override;
293 char const*
what() const noexcept override;
304 char const*
what() const noexcept override;
317 char const*
what() const noexcept override;
332 char const*
what() const noexcept override;
335 long native() const noexcept;
338 std::
string const& state() const noexcept;
342 std::
string sql_state;
369 long parameter_array_length{-1};
370 long rowset_size{-1};
378 : parameter_array_length(all_length)
379 , rowset_size(all_length) {};
432#ifdef NANODBC_ENABLE_UNICODE
434 std::variant<std::vector<uint8_t>,
string, std::string, std::intptr_t, std::uintptr_t>;
436 using variant = std::variant<std::vector<uint8_t>,
string, std::intptr_t, std::uintptr_t>;
467 std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, wide_string> ||
468 std::is_same_v<std::decay_t<T>, std::string_view> ||
469 std::is_same_v<std::decay_t<T>, wide_string_view>>;
481 std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, wide_string>>;
491 std::is_same_v<std::decay_t<T>, std::string::value_type> ||
492 std::is_same_v<std::decay_t<T>, wide_char_t>>;
518std::unique_ptr<bool[]>
519split_optional(std::vector<std::optional<T>>
const& values, std::vector<T>& column)
521 auto nulls = std::make_unique<bool[]>(values.size());
522 column.reserve(values.size());
524 for (
auto const& value : values)
526 nulls[i++] = !value.has_value();
527 column.push_back(value ? *value : T());
590 class transaction_impl;
594 std::shared_ptr<transaction_impl> impl_;
609#ifndef NANODBC_DISABLE_MSSQL_TVP
664 void bind(
short param_index, T
const* values, std::size_t batch_size);
669 void bind(
short param_index, T
const* values, std::size_t batch_size, T
const* null_sentry);
674 void bind(
short param_index, T
const* values, std::size_t batch_size,
bool const* nulls);
678 void bind(
short param_index, std::vector<std::vector<uint8_t>>
const& values);
683 bind(
short param_index, std::vector<std::vector<uint8_t>>
const& values,
bool const* nulls);
694 std::vector<std::vector<uint8_t>>
const& values,
695 uint8_t
const* null_sentry);
701 std::vector<std::vector<uint8_t>>
const& values,
702 std::vector<uint8_t>
const& null_sentry);
728 template <
class T,
typename = enable_if_
character<T>>
732 std::size_t value_size,
733 std::size_t batch_size);
741 template <
class T,
typename = enable_if_
string<T>>
747 std::size_t BatchSize,
748 std::size_t ValueSize,
751 void bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize])
753 auto param_values =
reinterpret_cast<T const*
>(values);
754 bind_strings(param_index, param_values, ValueSize, BatchSize);
759 template <
class T,
typename = enable_if_
character<T>>
763 std::size_t value_size,
764 std::size_t batch_size,
765 T
const* null_sentry);
769 template <
class T,
typename = enable_if_
string<T>>
772 std::vector<T>
const& values,
773 typename T::value_type
const* null_sentry);
778 std::size_t BatchSize,
779 std::size_t ValueSize,
783 bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize], T
const* null_sentry)
785 auto param_values =
reinterpret_cast<T const*
>(values);
786 bind_strings(param_index, param_values, ValueSize, BatchSize,
nullptr, null_sentry);
791 template <
class T,
typename = enable_if_
character<T>>
795 std::size_t value_size,
796 std::size_t batch_size,
801 template <
class T,
typename = enable_if_
string<T>>
802 void bind_strings(
short param_index, std::vector<T>
const& values,
bool const* nulls);
807 std::size_t BatchSize,
808 std::size_t ValueSize,
811 void bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize],
bool const* nulls)
813 auto param_values =
reinterpret_cast<T const*
>(values);
814 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls);
835 const std::vector<short>& idx,
836 const std::vector<short>& type,
837 const std::vector<unsigned long>& size,
838 const std::vector<short>& scale);
844 unsigned long parameter_size(
short param_index) const;
847 short parameter_scale(
short param_index) const;
850 short parameter_type(
short param_index) const;
853 class table_valued_parameter_impl;
857 std::shared_ptr<table_valued_parameter_impl> impl_;
878 class statement_impl;
886 long const& string_length,
887 variant
const& resource) noexcept
891 friend class nanodbc::statement::statement_impl;
941 [[nodiscard]]
bool open() const noexcept;
944 [[nodiscard]]
bool connected() const noexcept;
953 [[nodiscard]]
void* native_statement_handle() const noexcept;
968 void prepare(class
connection& conn,
string const& query,
long timeout = 0);
977 void prepare(
string const& query,
long timeout = 0);
981 void timeout(
long timeout = 0);
996 long batch_operations = 1,
1011 string const& query,
1015#if !defined(NANODBC_DISABLE_ASYNC)
1069 string const& query,
1070 long batch_operations = 1,
1090 bool async_execute(
void* event_handle,
long batch_operations = 1,
long timeout = 0);
1105 class result complete_execute(long batch_operations = 1);
1125 string const& query,
1126 long batch_operations = 1,
1173 string const& schema,
1174 string const& procedure,
1175 string const& column);
1190 short parameters() const;
1193 unsigned long parameter_size(
short param_index) const;
1196 short parameter_scale(
short param_index) const;
1199 short parameter_type(
short param_index) const;
1212 bool parameter_is_null(
short param_index, std::
size_t batch_index = 0) const;
1270 bind(
short param_index, std::optional<T> const& value,
param_direction direction = PARAM_IN)
1272 if (!value.has_value())
1274 bind_null(param_index, 1);
1277 if constexpr (is_owning_string_v<T>)
1278 bind(param_index, value->c_str(), direction);
1280 bind(param_index, &*value, direction);
1308 std::size_t batch_size,
1317 std::size_t batch_size,
1318 T
const* null_sentry,
1327 std::size_t batch_size,
1335 std::vector<std::vector<uint8_t>>
const& values,
1342 std::vector<std::vector<uint8_t>>
const& values,
1355 std::vector<std::vector<uint8_t>>
const& values,
1356 uint8_t
const* null_sentry,
1363 std::vector<std::vector<uint8_t>>
const& values,
1364 std::vector<uint8_t>
const& null_sentry,
1382 std::vector<T>
const& values,
1405 std::vector<std::optional<T>>
const& values,
1408 std::vector<T> column;
1409 auto const nulls = detail::split_optional(values, column);
1410 bind(param_index, column, nulls.get(), direction);
1438 template <
class T,
typename = enable_if_
character<T>>
1442 std::size_t value_size,
1443 std::size_t batch_size,
1452 template <
class T,
typename = enable_if_
string<T>>
1455 std::vector<T>
const& values,
1461 std::size_t BatchSize,
1462 std::size_t ValueSize,
1467 T
const (&values)[BatchSize][ValueSize],
1470 auto param_values =
reinterpret_cast<T const*
>(values);
1471 bind_strings(param_index, param_values, ValueSize, BatchSize, direction);
1476 template <
class T,
typename = enable_if_
character<T>>
1480 std::size_t value_size,
1481 std::size_t batch_size,
1482 T
const* null_sentry,
1487 template <
class T,
typename = enable_if_
string<T>>
1490 std::vector<T>
const& values,
1491 typename T::value_type
const* null_sentry,
1497 std::size_t BatchSize,
1498 std::size_t ValueSize,
1503 T
const (&values)[BatchSize][ValueSize],
1504 T
const* null_sentry,
1507 auto param_values =
reinterpret_cast<T const*
>(values);
1508 bind_strings(param_index, param_values, ValueSize, BatchSize, null_sentry, direction);
1513 template <
class T,
typename = enable_if_
character<T>>
1517 std::size_t value_size,
1518 std::size_t batch_size,
1524 template <
class T,
typename = enable_if_
string<T>>
1527 std::vector<T>
const& values,
1534 std::size_t BatchSize,
1535 std::size_t ValueSize,
1540 T
const (&values)[BatchSize][ValueSize],
1544 auto param_values =
reinterpret_cast<T const*
>(values);
1545 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls, direction);
1565 template <
class T,
typename = enable_if_
string<T>>
1568 std::vector<std::optional<T>>
const& values,
1571 std::vector<T> column;
1572 auto const nulls = detail::split_optional(values, column);
1573 bind_strings(param_index, column, nulls.get(), direction);
1589 void bind_null(
short param_index, std::size_t batch_size = 1);
1611 const std::vector<short>& idx,
1612 const std::vector<short>& type,
1613 const std::vector<unsigned long>& size,
1614 const std::vector<short>& scale);
1617 using null_predicate_type = std::function<bool(std::size_t)>;
1619#ifndef NANODBC_DISABLE_MSSQL_TVP
1620 friend class nanodbc::table_valued_parameter::table_valued_parameter_impl;
1624 std::shared_ptr<statement_impl> impl_;
1644 class connection_impl;
1645 friend class nanodbc::transaction::transaction_impl;
1653 long const& string_length,
1654 variant
const& resource) noexcept
1658 friend class nanodbc::connection::connection_impl;
1678 connection(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1689 explicit connection(
string const& connection_string,
long timeout = 0);
1708 std::list<attribute>
const& attributes);
1719 connection(
string const& connection_string, std::list<attribute>
const& attributes);
1742 void connect(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1749 void connect(
string const& connection_string,
long timeout = 0);
1763 std::list<attribute>
const& attributes);
1771 void connect(
string const& connection_string, std::list<attribute>
const& attributes);
1790#if !defined(NANODBC_DISABLE_ASYNC)
1830 bool async_connect(
string const& connection_string,
void* event_handle,
long timeout = 0);
1850 [[nodiscard]] std::
size_t transactions() const noexcept;
1853 [[nodiscard]]
void* native_dbc_handle() const noexcept;
1856 [[nodiscard]]
void* native_env_handle() const noexcept;
1862 T get_info(
short info_type) const;
1867 string dbms_name() const;
1872 string dbms_version() const;
1876 string driver_name() const;
1880 string driver_version() const;
1884 string database_name() const;
1888 string catalog_name() const;
1891 std::
size_t ref_transaction() noexcept;
1892 std::
size_t unref_transaction() noexcept;
1893 bool rollback() const noexcept;
1894 void rollback(
bool onoff) noexcept;
1895 bool restore_autocommit() const noexcept;
1896 void restore_autocommit(
bool onoff) noexcept;
1899 std::shared_ptr<connection_impl> impl_;
1915class variant_row_cached_result;
1934 [[nodiscard]]
long rowset_size() const noexcept;
1938 [[nodiscard]]
long affected_rows() const;
1948 bool has_affected_rows() const;
1951 [[nodiscard]]
long rows() const noexcept;
1955 [[nodiscard]]
short columns() const;
1960 [[nodiscard]]
bool first();
1965 [[nodiscard]]
bool last();
1970 [[nodiscard]]
bool next();
1972#if !defined(NANODBC_DISABLE_ASYNC)
2002 [[nodiscard]]
bool skip(
long rows);
2024 void unbind(
string const& column_name);
2041 void unbind(
short column);
2084 void get_ref(
short column, T const& fallback, T&
result) const;
2095 void get_ref(
string const& column_name, T&
result) const;
2108 void get_ref(
string const& column_name, T const& fallback, T&
result) const;
2123 [[nodiscard]] T get(
short column) const;
2136 [[nodiscard]] T get(
short column, T const& fallback) const;
2158 [[nodiscard]] T get_as(
short column) const;
2163 [[nodiscard]] T get_as(
string const& column_name) const;
2173 [[nodiscard]] T get(
string const& column_name) const;
2185 [[nodiscard]] T get(
string const& column_name, T const& fallback) const;
2209 std::function<
void(T const&)> const& callback,
2210 std::
size_t chunk_size = 65536) const;
2216 string const& column_name,
2217 std::function<
void(T const&)> const& callback,
2218 std::
size_t chunk_size = 65536) const;
2241 [[nodiscard]]
bool is_null(
short column) const;
2250 [[nodiscard]]
bool is_null(
string const& column_name) const;
2262 bool is_bound(
short column) const;
2270 bool is_bound(
string const& column_name) const;
2277 [[nodiscard]]
short column(
string const& column_name) const;
2284 [[nodiscard]]
string column_name(
short column) const;
2291 [[nodiscard]]
long column_size(
short column) const;
2294 [[nodiscard]]
long column_size(
string const& column_name) const;
2304 int column_decimal_digits(
short column) const;
2307 int column_decimal_digits(
string const& column_name) const;
2310 [[nodiscard]]
int column_datatype(
short column) const;
2313 [[nodiscard]]
int column_datatype(
string const& column_name) const;
2322 string column_datatype_name(
short column) const;
2331 string column_datatype_name(
string const& column_name) const;
2334 int column_c_datatype(
short column) const;
2337 int column_c_datatype(
string const& column_name) const;
2346 bool column_unsigned(
short column) const;
2350 bool column_unsigned(
string const& column_name) const;
2356 [[nodiscard]] explicit operator
bool() const noexcept;
2365 friend class nanodbc::variant_row_cached_result;
2369 std::shared_ptr<result_impl> impl_;
2399 throw std::runtime_error(
"result is empty");
2400 return &operator*();
2408 if (!result_.next())
2428 if (result_ && rhs.result_)
2429 return result_.native_statement_handle() == rhs.result_.native_statement_handle();
2431 return !result_ && !rhs.result_;
2501 auto count() const noexcept ->
short;
2506 auto auto_unique_value(
short record) const ->
bool;
2509 auto base_column_name(
short record) const ->
string;
2512 auto base_table_name(
short record) const ->
string;
2515 auto case_sensitive(
short record) const ->
bool;
2518 auto catalog_name(
short record) const ->
string;
2521 auto concise_type(
short record) const ->
short;
2524 auto display_size(
short record) const -> std::int64_t;
2527 auto fixed_prec_scale(
short record) const ->
short;
2530 auto label(
short record) const ->
string;
2533 auto length(
short record) const -> std::uint64_t;
2536 auto local_type_name(
short record) const ->
string;
2539 auto name(
short record) const ->
string;
2544 auto nullable(
short record) const ->
short;
2547 auto num_prec_radix(
short record) const ->
short;
2550 auto octet_length(
short record) const -> std::int64_t;
2553 auto precision(
short record) const ->
short;
2556 auto rowver(
short record) const ->
short;
2559 auto scale(
short record) const ->
short;
2562 auto schema_name(
short record) const ->
string;
2568 auto searchable(
short record) const ->
short;
2571 auto table_name(
short record) const ->
string;
2574 auto type(
short record) const ->
short;
2577 auto type_name(
short record) const ->
string;
2580 auto unnamed(
short record) const ->
bool;
2583 auto unsigned_(
short record) const ->
bool;
2589 auto updatable(
short record) const ->
short;
2593 struct sql_get_descr_field
2595 sql_get_descr_field(
2598 std::uint16_t field_identifier)
noexcept;
2599 operator std::int64_t()
const;
2600 operator std::uint64_t()
const;
2605 std::uint16_t field_identifier_;
2607 friend sql_get_descr_field;
2609 void initialize_descriptor();
2610 void throw_if_record_is_out_of_range(
short record)
const;
2612 void* statement_handle_{
nullptr};
2613 short statement_columns_count_{0};
2614 void* descriptor_handle_{
nullptr};
2615 short descriptor_records_count_{0};
2815 string const& table = {},
2816 string const& type = {},
2817 string const& schema = {},
2818 string const& catalog = {});
2835 string const& table = {},
2836 string const& schema = {});
2848 string const& column = {},
2849 string const& table = {},
2850 string const& schema = {},
2851 string const& catalog = {});
2861 catalog::primary_keys
2875 string const& procedure = {},
2876 string const& schema = {},
2877 string const& catalog = {});
2890 string const& column = {},
2891 string const& procedure = {},
2892 string const& schema = {},
2893 string const& catalog = {});
2933struct hold_column_value;
2936struct hold_column_value<std::any>
2938 static std::any from(std::any value)
noexcept {
return value; }
2941template <
class Alternative,
class Variant>
2942inline bool hold_alternative(Variant& variant, std::any
const& value)
2944 if (
auto const* held = std::any_cast<Alternative>(&value))
2952template <
class... Ts>
2953struct hold_column_value<std::variant<Ts...>>
2955 static std::variant<Ts...> from(std::any
const& value)
2957 std::variant<Ts...> variant;
2958 if (!value.has_value())
2962 bool const held = (hold_alternative<Ts>(variant, value) || ...);
2967 throw type_incompatible_error();
2976T result::get_as(
short column)
const
2978 return detail::hold_column_value<T>::from(get<std::any>(column));
2982T result::get_as(
string const& column_name)
const
2984 return get_as<T>(this->column(column_name));
3044 string const& query,
3045 long batch_operations = 1,
3053template <
class Row,
class Member,
class Class>
3060template <
class Row,
class Accessor>
3061auto read_field(Row
const& row, Accessor
const& accessor) ->
decltype(accessor(row))
3063 return accessor(row);
3067template <
class Row,
class Accessor>
3070 using type = std::decay_t<
3071 decltype(
read_field(std::declval<Row const&>(), std::declval<Accessor const&>()))>;
3101template <
class T,
bool IsOptional = is_optional_v<T>>
3110 using type = std::conditional_t<
3111 is_owning_string_v<typename T::value_type>,
3116template <
class Rows,
class Accessor>
3121 Accessor
const& accessor,
3124 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3125 std::vector<value_type> column;
3126 column.reserve(rows.size());
3127 for (
auto const& row : rows)
3129 stmt.
bind(param_index, column);
3132template <
class Rows,
class Accessor>
3137 Accessor
const& accessor,
3140 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3141 std::vector<value_type> column;
3142 column.reserve(rows.size());
3143 for (
auto const& row : rows)
3144 column.push_back(read_field(row, accessor));
3150template <
class Rows,
class Accessor,
class Column>
3151std::unique_ptr<bool[]> gather_optional(Rows
const& rows, Accessor
const& accessor, Column& column)
3153 auto nulls = std::make_unique<bool[]>(rows.size());
3155 for (
auto const& row : rows)
3157 auto const& value = read_field(row, accessor);
3158 nulls[i++] = !value.has_value();
3159 column.push_back(value ? *value : typename Column::value_type());
3164template <
class Rows,
class Accessor>
3169 Accessor
const& accessor,
3170 bind_as_optional_value)
3172 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3173 std::vector<typename optional_type::value_type> column;
3174 column.reserve(rows.size());
3175 auto const nulls = gather_optional(rows, accessor, column);
3176 stmt.bind(param_index, column, nulls.get());
3179template <
class Rows,
class Accessor>
3184 Accessor
const& accessor,
3185 bind_as_optional_string)
3187 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3188 std::vector<typename optional_type::value_type> column;
3189 column.reserve(rows.size());
3190 auto const nulls = gather_optional(rows, accessor, column);
3191 stmt.bind_strings(param_index, column, nulls.get());
3194template <
class Rows,
class Accessor>
3195void bind_one(statement& stmt,
short param_index, Rows
const& rows, Accessor
const& accessor)
3197 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3198 bind_column(stmt, param_index, rows, accessor,
typename bind_kind<value_type>::type());
3233template <
class Rows,
class... Accessors>
3236 short param_index = 0;
3239 (detail::bind_one(stmt, param_index++, rows, accessors), ...);
A class representing a connection or a statement attribute.
Definition nanodbc.h:430
attribute(attribute const &other) noexcept
Copy constructor.
void extractValuePtr() noexcept
Points value_ptr_ at the resource, according to which type it holds.
attribute(long const &attribute, long const &string_length, variant resource) noexcept
Creates an attribute from the three arguments the ODBC call takes.
Result set for a list of columns in one or more tables.
Definition nanodbc.h:2661
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:2701
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:2763
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:2746
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:2726
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:2644
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:2640
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::columns find_columns(string const &column={}, string const &table={}, string const &schema={}, string const &catalog={})
Creates result set with columns in one or more tables.
std::list< string > list_table_types()
Returns all available table types in the connected data source.
catalog::procedure_columns find_procedure_columns(string const &column={}, string const &procedure={}, string const &schema={}, string const &catalog={})
Creates result set with columns in one or more procedures.
catalog::procedures find_procedures(string const &procedure={}, string const &schema={}, string const &catalog={})
Creates result set with catalog, schema, procedure, and procedure types.
catalog::tables find_tables(string const &table={}, string const &type={}, string const &schema={}, string const &catalog={})
Creates result set with catalogs, schemas, tables, or table types.
catalog::primary_keys find_primary_keys(string const &table, string const &schema={}, string const &catalog={})
Creates result set with columns that compose the primary key of a single table.
catalog::table_privileges find_table_privileges(string const &catalog, string const &table={}, string const &schema={})
Creates result set with tables and the privileges associated with each table.
Definition nanodbc.h:1649
Manages and encapsulates ODBC resources such as the connection and environment handles.
Definition nanodbc.h:1641
void connect(string const &connection_string, std::list< attribute > const &attributes)
Set the connection attributes passed by the user, and connect to the given connection string.
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.
bool connected() const noexcept
Returns true if connected to the database.
void async_complete()
Completes a previously initiated asynchronous connection operation.
void connect(string const &dsn, string const &user, string const &pass, std::list< attribute > const &attributes)
Set the connection attributes passed by the user, and connect to the given data source.
void deallocate()
Release environment and connection handles.
void connect(string const &connection_string, long timeout=0)
Connect using the given connection string.
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()
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.
string browse_connect(string const &connection_string, bool &more_wanted)
Asks the driver what it needs in order to connect.
void swap(connection &) noexcept
Member swap.
void allocate()
Allocate environment and connection handles.
void connect(string const &dsn, string const &user, string const &pass, long timeout=0)
Connect to the given data source.
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:323
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:2479
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:299
char const * what() const noexcept override
Returns the message describing the out of range index.
Accessed null data.
Definition nanodbc.h:288
char const * what() const noexcept override
Returns the message describing the null access.
Programming logic error.
Definition nanodbc.h:310
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:2374
reference operator*() const noexcept
Dereference.
Definition nanodbc.h:2393
pointer operator->() const
Access through dereference.
Definition nanodbc.h:2396
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:2435
std::ptrdiff_t difference_type
Iterator difference.
Definition nanodbc.h:2380
std::input_iterator_tag iterator_category
Category of iterator.
Definition nanodbc.h:2376
void operator++(int)
Iteration.
Definition nanodbc.h:2423
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:2426
result_iterator & operator++()
Iteration.
Definition nanodbc.h:2404
result_iterator(result &r)
Create result iterator for a given result set.
Definition nanodbc.h:2386
A resource for managing result sets from statement execution.
Definition nanodbc.h:1922
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.
result()=default
Empty result set.
bool move(long row)
Moves to and fetches the specified row in the current result set.
void * native_statement_handle() const noexcept
Returns the native ODBC statement handle.
bool async_next(void *event_handle)
Initiates an asynchronous fetch of the next row in the current result set.
void swap(result &rhs) noexcept
Member swap.
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 prior()
Fetches the prior row in the current result set.
Represents a statement on the database.
Definition nanodbc.h:875
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...
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.
bool open() const noexcept
Returns true if connection is open.
void complete_prepare()
Completes a previously initiated asynchronous query preparation.
void open(class connection &conn)
Creates a statement for the given connection.
param_direction
Provides support for retrieving output/return parameters.
Definition nanodbc.h:898
@ PARAM_OUT
Binding an output parameter.
Definition nanodbc.h:900
@ PARAM_INOUT
Binding an input/output parameter.
Definition nanodbc.h:901
@ PARAM_IN
Binding an input parameter.
Definition nanodbc.h:899
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(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.
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.
void open(statement &stmt, short param_index, std::size_t row_count)
Opens the parameter on a statement, ready for values to be bound to it.
void bind_null(short param_index)
Binds a null value to the given column of every row.
void close()
Finishes the parameter, so the statement can be executed or bound further.
short parameters() const noexcept
Returns the number of columns in the table valued parameter.
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:560
void rollback() noexcept
Marks this transaction for rollback.
transaction(const class connection &conn)
Begin a transaction on the given connection object.
void commit()
Commits transaction immediately.
void swap(transaction &rhs) noexcept
Member swap.
Type incompatible.
Definition nanodbc.h:277
char const * what() const noexcept override
Returns the message describing the incompatibility.
void bind(short param_index, T const *values, std::size_t batch_size, T const *null_sentry)
Binds multiple values.
void bind(short param_index, std::vector< std::vector< uint8_t > > const &values, std::vector< uint8_t > const &null_sentry)
Binds multiple values, those equal to the sentry, in size and bytes, as null.
void bind(short param_index, std::vector< std::vector< uint8_t > > const &values)
Binds multiple values.
void bind(short param_index, std::vector< std::vector< uint8_t > > const &values, bool const *nulls)
Binds multiple values.
void bind(short param_index, T const *values, std::size_t batch_size, param_direction direction=PARAM_IN)
Binds multiple values.
void bind(short param_index, T const *values, std::size_t batch_size, bool const *nulls)
Binds multiple values.
NANODBC_DEPRECATED void bind(short param_index, std::vector< std::vector< uint8_t > > const &values, uint8_t const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple values.
void bind(short param_index, std::vector< std::vector< uint8_t > > const &values, bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple values.
void bind(short param_index, std::vector< std::optional< T > > const &values, param_direction direction=PARAM_IN)
Binds a batch of values, any of which may be absent and bound as null.
Definition nanodbc.h:1403
void bind(short param_index, T const *values, std::size_t batch_size)
Binds multiple values.
void bind(short param_index, std::vector< T > const &values, param_direction direction=PARAM_IN)
Binds multiple values, holding a copy of them.
void bind(short param_index, T const *values, std::size_t batch_size, bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple values.
void bind(short param_index, std::vector< std::vector< uint8_t > > const &values, param_direction direction=PARAM_IN)
Binds multiple values.
void bind(short param_index, std::vector< std::vector< uint8_t > > const &values, std::vector< uint8_t > const &null_sentry, param_direction direction=PARAM_IN)
Binds multiple values, those equal to the sentry, in size and bytes, as null.
void bind(short param_index, T const *values, std::size_t batch_size, T const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple values.
void bind(short param_index, std::vector< T > const &values, bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple values, holding a copy of them.
NANODBC_DEPRECATED void bind(short param_index, std::vector< std::vector< uint8_t > > const &values, uint8_t const *null_sentry)
Binds multiple values.
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:1538
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls)
Binds multiple string values.
Definition nanodbc.h:811
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< std::optional< T > > const &values, param_direction direction=PARAM_IN)
Binds a batch of strings, any of which may be absent and bound as null.
Definition nanodbc.h:1566
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])
Binds multiple string values.
Definition nanodbc.h:751
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, 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:783
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], param_direction direction=PARAM_IN)
Binds multiple string values.
Definition nanodbc.h:1465
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)
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:1501
void bind_strings(short param_index, std::vector< T > const &values, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values)
Binds multiple string values.
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:2453
result_iterator begin(result &r)
Returns an iterator to the beginning of the given result set.
Definition nanodbc.h:2442
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:3234
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.
std::enable_if_t< is_character_v< T > > enable_if_character
Enables an overload only for the character types nanodbc binds as strings.
Definition nanodbc.h:504
constexpr bool is_owning_string_v
Whether a type is a string owning the characters it holds.
Definition nanodbc.h:485
std::bool_constant< std::is_same_v< std::decay_t< T >, std::string >||std::is_same_v< std::decay_t< T >, wide_string > > is_owning_string
A type trait for testing if a type is a string owning the characters it holds.
Definition nanodbc.h:481
constexpr bool is_string_v
Whether a type is a string compatible with the current nanodbc configuration.
Definition nanodbc.h:473
std::bool_constant< std::is_same_v< std::decay_t< T >, std::string >||std::is_same_v< std::decay_t< T >, wide_string >||std::is_same_v< std::decay_t< T >, std::string_view >||std::is_same_v< std::decay_t< T >, wide_string_view > > is_string
A type trait for testing if a type is a std::basic_string compatible with the current nanodbc configu...
Definition nanodbc.h:469
constexpr bool is_character_v
Whether a type is a character compatible with the current nanodbc configuration.
Definition nanodbc.h:496
std::enable_if_t< is_string_v< T > > enable_if_string
Enables an overload only for the string types nanodbc binds as strings.
Definition nanodbc.h:500
std::bool_constant< std::is_same_v< std::decay_t< T >, std::string::value_type >||std::is_same_v< std::decay_t< T >, wide_char_t > > is_character
A type trait for testing if a type is a character compatible with the current nanodbc configuration.
Definition nanodbc.h:492
Member const & read_field(Row const &row, Member Class::*field)
Reads a member through a pointer to it.
Definition nanodbc.h:3054
std::unique_ptr< bool[]> split_optional(std::vector< std::optional< T > > const &values, std::vector< T > &column)
Splits optionals into the values themselves and flags saying which are null.
Definition nanodbc.h:519
The entirety of nanodbc can be found within this one namespace.
Definition nanodbc.h:112
unspecified type string
string will be std::u16string or std::32string if NANODBC_ENABLE_UNICODE defined.
Definition nanodbc.h:230
unspecified type null_type
null_type will be int64_t for 64-bit compilations, otherwise long.
Definition nanodbc.h:232
#define NANODBC_DEPRECATED
Marks a declaration as deprecated.
Definition nanodbc.h:237
A type capturing parameter array length as well as number of rows in a rowset of a result.
Definition nanodbc.h:368
batch_ops()=default
Creates lengths of -1, meaning neither has been chosen.
batch_ops(const long all_length) noexcept
Creates both lengths with the same value.
Definition nanodbc.h:377
A data source name registered with the driver manager.
Definition nanodbc.h:3011
nanodbc::string driver
Driver description.
Definition nanodbc.h:3013
nanodbc::string name
DSN name.
Definition nanodbc.h:3012
A type for representing date data.
Definition nanodbc.h:384
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:386
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:387
std::int16_t year
Year [0-inf).
Definition nanodbc.h:385
Definition nanodbc.h:3098
Definition nanodbc.h:3095
Definition nanodbc.h:3092
Definition nanodbc.h:3089
Definition nanodbc.h:3103
The type an accessor yields for a row, stripped of reference and const.
Definition nanodbc.h:3069
Definition nanodbc.h:3076
Driver attributes.
Definition nanodbc.h:3000
nanodbc::string keyword
Driver keyword attribute.
Definition nanodbc.h:3001
nanodbc::string value
Driver attribute value.
Definition nanodbc.h:3002
Information on a configured ODBC driver.
Definition nanodbc.h:2997
nanodbc::string name
Driver name.
Definition nanodbc.h:3005
std::list< attribute > attributes
List of driver attributes.
Definition nanodbc.h:3006
A type for representing time data.
Definition nanodbc.h:392
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:393
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:394
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:395
A type for representing timestamp data.
Definition nanodbc.h:400
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:404
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:406
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:403
std::int16_t year
Year [0-inf).
Definition nanodbc.h:401
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:405
std::int32_t fract
Fractional seconds.
Definition nanodbc.h:407
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:402
A type for representing timestamp+offset data.
Definition nanodbc.h:412
std::int16_t offset_minute
Minutes part of time zome offset.
Definition nanodbc.h:415
timestamp stamp
Date and time, in the offset's local terms.
Definition nanodbc.h:413
std::int16_t offset_hour
Whole hour part of time zone offset.
Definition nanodbc.h:414