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#ifdef NANODBC_ENABLE_UNICODE
164#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
165#define NANODBC_TEXT(s) U##s
166using string = std::u32string;
167using string_view = std::u32string_view;
170using string = std::wstring;
171using string_view = std::wstring_view;
172#define NANODBC_TEXT(s) L##s
174using string = std::u16string;
175using string_view = std::u16string_view;
176#define NANODBC_TEXT(s) u##s
180using string = std::string;
181using string_view = std::string_view;
182#define NANODBC_TEXT(s) s
185#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
186using wide_string = std::u32string;
187using wide_string_view = std::u32string_view;
190using wide_string = std::wstring;
191using wide_string_view = std::wstring_view;
193using wide_string = std::u16string;
194using wide_string_view = std::u16string_view;
198using wide_char_t = wide_string::value_type;
203#elif !defined(_WIN64) && defined(__LP64__)
220#define NANODBC_TEXT(s) s
233#define NANODBC_DEPRECATED [[deprecated]]
236#ifndef NANODBC_DISABLE_MSSQL_TVP
237class table_valued_parameter;
278 char const*
what() const noexcept override;
289 char const*
what() const noexcept override;
300 char const*
what() const noexcept override;
313 char const*
what() const noexcept override;
328 char const*
what() const noexcept override;
331 long native() const noexcept;
334 std::
string const& state() const noexcept;
338 std::
string sql_state;
370 : parameter_array_length(-1L)
371 , rowset_size(-1L) {};
376 : parameter_array_length(all_length)
377 , rowset_size(all_length) {};
430#ifdef NANODBC_ENABLE_UNICODE
432 std::variant<std::vector<uint8_t>,
string, std::string, std::intptr_t, std::uintptr_t>;
434 using variant = std::variant<std::vector<uint8_t>,
string, std::intptr_t, std::uintptr_t>;
465 std::is_same_v<std::decay_t<T>, std::
string> || std::is_same_v<std::decay_t<T>, wide_string> ||
466 std::is_same_v<std::decay_t<T>, std::string_view> ||
467 std::is_same_v<std::decay_t<T>, wide_string_view>>;
479 std::is_same_v<std::decay_t<T>, std::
string> || std::is_same_v<std::decay_t<T>, wide_string>>;
489 std::is_same_v<std::decay_t<T>, std::
string::value_type> ||
490 std::is_same_v<std::decay_t<T>, wide_char_t>>;
516std::unique_ptr<bool[]>
517split_optional(std::vector<std::optional<T>>
const& values, std::vector<T>& column)
519 auto nulls = std::make_unique<bool[]>(values.size());
520 column.reserve(values.size());
522 for (
auto const& value : values)
524 nulls[i++] = !value.has_value();
525 column.push_back(value ? *value : T());
582 void rollback() noexcept;
597 class transaction_impl;
601 std::shared_ptr<transaction_impl> impl_;
616#ifndef NANODBC_DISABLE_MSSQL_TVP
646 void open(
statement& stmt,
short param_index, std::
size_t row_count);
675 void bind(
short param_index, T const* values, std::
size_t batch_size);
680 void bind(
short param_index, T const* values, std::
size_t batch_size, T const* null_sentry);
685 void bind(
short param_index, T const* values, std::
size_t batch_size,
bool const* nulls);
689 void bind(
short param_index, std::vector<std::vector<uint8_t>> const& values);
694 bind(
short param_index, std::vector<std::vector<uint8_t>> const& values,
bool const* nulls);
700 std::vector<std::vector<uint8_t>> const& values,
701 uint8_t const* null_sentry);
731 std::
size_t value_size,
732 std::
size_t batch_size);
741 void bind_strings(
short param_index, std::vector<T> const& values);
746 std::
size_t BatchSize,
747 std::
size_t ValueSize,
750 void bind_strings(
short param_index, T const (&values)[BatchSize][ValueSize])
752 auto param_values =
reinterpret_cast<T const*
>(values);
753 bind_strings(param_index, param_values, ValueSize, BatchSize);
758 template <
class T,
typename = enable_if_
character<T>>
762 std::size_t value_size,
763 std::size_t batch_size,
764 T
const* null_sentry);
768 template <
class T,
typename = enable_if_
string<T>>
771 std::vector<T>
const& values,
772 typename T::value_type
const* null_sentry);
777 std::size_t BatchSize,
778 std::size_t ValueSize,
782 bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize], T
const* null_sentry)
784 auto param_values =
reinterpret_cast<T const*
>(values);
785 bind_strings(param_index, param_values, ValueSize, BatchSize,
nullptr, null_sentry);
790 template <
class T,
typename = enable_if_
character<T>>
794 std::size_t value_size,
795 std::size_t batch_size,
800 template <
class T,
typename = enable_if_
string<T>>
801 void bind_strings(
short param_index, std::vector<T>
const& values,
bool const* nulls);
806 std::size_t BatchSize,
807 std::size_t ValueSize,
810 void bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize],
bool const* nulls)
812 auto param_values =
reinterpret_cast<T const*
>(values);
813 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls);
834 const std::vector<short>& idx,
835 const std::vector<short>& type,
836 const std::vector<unsigned long>& size,
837 const std::vector<short>& scale);
843 unsigned long parameter_size(
short param_index) const;
846 short parameter_scale(
short param_index) const;
849 short parameter_type(
short param_index) const;
852 class table_valued_parameter_impl;
856 std::shared_ptr<table_valued_parameter_impl> impl_;
877 class statement_impl;
885 long const& string_length,
886 variant
const& resource) noexcept
890 friend class nanodbc::statement::statement_impl;
953 [[nodiscard]]
bool open() const noexcept;
956 [[nodiscard]]
bool connected() const noexcept;
965 [[nodiscard]]
void* native_statement_handle() const noexcept;
980 void prepare(class
connection& conn,
string const& query,
long timeout = 0);
989 void prepare(
string const& query,
long timeout = 0);
993 void timeout(
long timeout = 0);
1007 string const& query,
1008 long batch_operations = 1,
1023 string const& query,
1027#if !defined(NANODBC_DISABLE_ASYNC)
1081 string const& query,
1082 long batch_operations = 1,
1102 bool async_execute(
void* event_handle,
long batch_operations = 1,
long timeout = 0);
1117 class result complete_execute(long batch_operations = 1);
1137 string const& query,
1138 long batch_operations = 1,
1185 string const& schema,
1186 string const& procedure,
1187 string const& column);
1202 short parameters() const;
1205 unsigned long parameter_size(
short param_index) const;
1208 short parameter_scale(
short param_index) const;
1211 short parameter_type(
short param_index) const;
1224 bool parameter_is_null(
short param_index, std::
size_t batch_index = 0) const;
1282 bind(
short param_index, std::optional<T> const& value,
param_direction direction = PARAM_IN)
1284 if (!value.has_value())
1286 bind_null(param_index, 1);
1289 if constexpr (is_owning_string_v<T>)
1290 bind(param_index, value->c_str(), direction);
1292 bind(param_index, &*value, direction);
1320 std::size_t batch_size,
1329 std::size_t batch_size,
1330 T
const* null_sentry,
1339 std::size_t batch_size,
1347 std::vector<std::vector<uint8_t>>
const& values,
1354 std::vector<std::vector<uint8_t>>
const& values,
1362 std::vector<std::vector<uint8_t>>
const& values,
1363 uint8_t
const* null_sentry,
1381 std::vector<T>
const& values,
1404 std::vector<std::optional<T>>
const& values,
1407 std::vector<T> column;
1408 auto const nulls = detail::split_optional(values, column);
1409 bind(param_index, column, nulls.get(), direction);
1437 template <
class T,
typename = enable_if_
character<T>>
1441 std::size_t value_size,
1442 std::size_t batch_size,
1451 template <
class T,
typename = enable_if_
string<T>>
1454 std::vector<T>
const& values,
1460 std::size_t BatchSize,
1461 std::size_t ValueSize,
1466 T
const (&values)[BatchSize][ValueSize],
1469 auto param_values =
reinterpret_cast<T const*
>(values);
1470 bind_strings(param_index, param_values, ValueSize, BatchSize, direction);
1475 template <
class T,
typename = enable_if_
character<T>>
1479 std::size_t value_size,
1480 std::size_t batch_size,
1481 T
const* null_sentry,
1486 template <
class T,
typename = enable_if_
string<T>>
1489 std::vector<T>
const& values,
1490 typename T::value_type
const* null_sentry,
1496 std::size_t BatchSize,
1497 std::size_t ValueSize,
1502 T
const (&values)[BatchSize][ValueSize],
1503 T
const* null_sentry,
1506 auto param_values =
reinterpret_cast<T const*
>(values);
1507 bind_strings(param_index, param_values, ValueSize, BatchSize, null_sentry, direction);
1512 template <
class T,
typename = enable_if_
character<T>>
1516 std::size_t value_size,
1517 std::size_t batch_size,
1523 template <
class T,
typename = enable_if_
string<T>>
1526 std::vector<T>
const& values,
1533 std::size_t BatchSize,
1534 std::size_t ValueSize,
1539 T
const (&values)[BatchSize][ValueSize],
1543 auto param_values =
reinterpret_cast<T const*
>(values);
1544 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls, direction);
1564 template <
class T,
typename = enable_if_
string<T>>
1567 std::vector<std::optional<T>>
const& values,
1570 std::vector<T> column;
1571 auto const nulls = detail::split_optional(values, column);
1572 bind_strings(param_index, column, nulls.get(), direction);
1588 void bind_null(
short param_index, std::size_t batch_size = 1);
1610 const std::vector<short>& idx,
1611 const std::vector<short>& type,
1612 const std::vector<unsigned long>& size,
1613 const std::vector<short>& scale);
1616 using null_predicate_type = std::function<bool(std::size_t)>;
1618#ifndef NANODBC_DISABLE_MSSQL_TVP
1619 friend class nanodbc::table_valued_parameter::table_valued_parameter_impl;
1623 std::shared_ptr<statement_impl> impl_;
1643 class connection_impl;
1644 friend class nanodbc::transaction::transaction_impl;
1652 long const& string_length,
1653 variant
const& resource) noexcept
1657 friend class nanodbc::connection::connection_impl;
1686 connection(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1697 explicit connection(
string const& connection_string,
long timeout = 0);
1716 std::list<attribute>
const& attributes);
1727 connection(
string const& connection_string, std::list<attribute>
const& attributes);
1755 void connect(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1762 void connect(
string const& connection_string,
long timeout = 0);
1776 std::list<
attribute> const& attributes);
1784 void connect(
string const& connection_string, std::list<
attribute> const& attributes);
1802 string browse_connect(
string const& connection_string,
bool& more_wanted);
1803#if !defined(NANODBC_DISABLE_ASYNC)
1843 bool async_connect(
string const& connection_string,
void* event_handle,
long timeout = 0);
1859 [[nodiscard]] std::
size_t transactions() const noexcept;
1862 [[nodiscard]]
void* native_dbc_handle() const noexcept;
1865 [[nodiscard]]
void* native_env_handle() const noexcept;
1871 T get_info(
short info_type) const;
1876 string dbms_name() const;
1881 string dbms_version() const;
1885 string driver_name() const;
1889 string driver_version() const;
1893 string database_name() const;
1897 string catalog_name() const;
1900 std::
size_t ref_transaction() noexcept;
1901 std::
size_t unref_transaction() noexcept;
1902 bool rollback() const noexcept;
1903 void rollback(
bool onoff) noexcept;
1906 std::shared_ptr<connection_impl> impl_;
1922class variant_row_cached_result;
1950 [[nodiscard]]
void* native_statement_handle() const noexcept;
1953 [[nodiscard]]
long rowset_size() const noexcept;
1957 [[nodiscard]]
long affected_rows() const;
1967 bool has_affected_rows() const;
1970 [[nodiscard]]
long rows() const noexcept;
1974 [[nodiscard]]
short columns() const;
1979 [[nodiscard]]
bool first();
1984 [[nodiscard]]
bool last();
1989 [[nodiscard]]
bool next();
1991#if !defined(NANODBC_DISABLE_ASYNC)
2021 [[nodiscard]]
bool skip(
long rows);
2043 void unbind(
string const& column_name);
2060 void unbind(
short column);
2103 void get_ref(
short column, T const& fallback, T&
result) const;
2114 void get_ref(
string const& column_name, T&
result) const;
2127 void get_ref(
string const& column_name, T const& fallback, T&
result) const;
2142 [[nodiscard]] T get(
short column) const;
2155 [[nodiscard]] T get(
short column, T const& fallback) const;
2177 [[nodiscard]] T get_as(
short column) const;
2182 [[nodiscard]] T get_as(
string const& column_name) const;
2192 [[nodiscard]] T get(
string const& column_name) const;
2204 [[nodiscard]] T get(
string const& column_name, T const& fallback) const;
2229 [[nodiscard]]
bool is_null(
short column) const;
2238 [[nodiscard]]
bool is_null(
string const& column_name) const;
2250 bool is_bound(
short column) const;
2258 bool is_bound(
string const& column_name) const;
2265 [[nodiscard]]
short column(
string const& column_name) const;
2272 [[nodiscard]]
string column_name(
short column) const;
2279 [[nodiscard]]
long column_size(
short column) const;
2282 [[nodiscard]]
long column_size(
string const& column_name) const;
2292 int column_decimal_digits(
short column) const;
2295 int column_decimal_digits(
string const& column_name) const;
2298 [[nodiscard]]
int column_datatype(
short column) const;
2301 [[nodiscard]]
int column_datatype(
string const& column_name) const;
2310 string column_datatype_name(
short column) const;
2319 string column_datatype_name(
string const& column_name) const;
2322 int column_c_datatype(
short column) const;
2325 int column_c_datatype(
string const& column_name) const;
2334 bool column_unsigned(
short column) const;
2338 bool column_unsigned(
string const& column_name) const;
2344 [[nodiscard]] explicit operator
bool() const noexcept;
2354 friend class nanodbc::variant_row_cached_result;
2358 std::shared_ptr<result_impl> impl_;
2388 throw std::runtime_error(
"result is empty");
2389 return &(operator*());
2397 if (!result_.next())
2417 if (result_ && rhs.result_)
2418 return result_.native_statement_handle() == rhs.result_.native_statement_handle();
2420 return !result_ && !rhs.result_;
2490 auto count() const noexcept ->
short;
2495 auto auto_unique_value(
short record) const ->
bool;
2498 auto base_column_name(
short record) const ->
string;
2501 auto base_table_name(
short record) const ->
string;
2504 auto case_sensitive(
short record) const ->
bool;
2507 auto catalog_name(
short record) const ->
string;
2510 auto concise_type(
short record) const ->
short;
2513 auto display_size(
short record) const -> std::int64_t;
2516 auto fixed_prec_scale(
short record) const ->
short;
2519 auto label(
short record) const ->
string;
2522 auto length(
short record) const -> std::uint64_t;
2525 auto local_type_name(
short record) const ->
string;
2528 auto name(
short record) const ->
string;
2533 auto nullable(
short record) const ->
short;
2536 auto num_prec_radix(
short record) const ->
short;
2539 auto octet_length(
short record) const -> std::int64_t;
2542 auto precision(
short record) const ->
short;
2545 auto rowver(
short record) const ->
short;
2548 auto scale(
short record) const ->
short;
2551 auto schema_name(
short record) const ->
string;
2557 auto searchable(
short record) const ->
short;
2560 auto table_name(
short record) const ->
string;
2563 auto type(
short record) const ->
short;
2566 auto type_name(
short record) const ->
string;
2569 auto unnamed(
short record) const ->
bool;
2572 auto unsigned_(
short record) const ->
bool;
2578 auto updatable(
short record) const ->
short;
2582 struct sql_get_descr_field
2584 sql_get_descr_field(
2587 std::uint16_t field_identifier)
noexcept;
2588 operator std::int64_t()
const;
2589 operator std::uint64_t()
const;
2594 std::uint16_t field_identifier_;
2596 friend sql_get_descr_field;
2598 void initialize_descriptor();
2599 void throw_if_record_is_out_of_range(
short record)
const;
2601 void* statement_handle_{
nullptr};
2602 short statement_columns_count_{0};
2603 void* descriptor_handle_{
nullptr};
2604 short descriptor_records_count_{0};
2804 string const& table =
string(),
2805 string const& type =
string(),
2806 string const& schema =
string(),
2807 string const&
catalog =
string());
2824 string const& table =
string(),
2825 string const& schema =
string());
2837 string const& column =
string(),
2838 string const& table =
string(),
2839 string const& schema =
string(),
2840 string const&
catalog =
string());
2851 string const& table,
2852 string const& schema =
string(),
2853 string const&
catalog =
string());
2866 string const& procedure =
string(),
2867 string const& schema =
string(),
2868 string const&
catalog =
string());
2881 string const& column =
string(),
2882 string const& procedure =
string(),
2883 string const& schema =
string(),
2884 string const&
catalog =
string());
2924struct hold_column_value;
2927struct hold_column_value<std::any>
2929 static std::any from(std::any value)
noexcept {
return value; }
2932template <
class Alternative,
class Variant>
2933inline bool hold_alternative(Variant& variant, std::any
const& value)
2935 if (
auto const* held = std::any_cast<Alternative>(&value))
2943template <
class... Ts>
2944struct hold_column_value<std::variant<Ts...>>
2946 static std::variant<Ts...> from(std::any
const& value)
2948 std::variant<Ts...> variant;
2949 if (!value.has_value())
2953 bool const held = (hold_alternative<Ts>(variant, value) || ...);
2958 throw type_incompatible_error();
2967T result::get_as(
short column)
const
2969 return detail::hold_column_value<T>::from(get<std::any>(column));
2973T result::get_as(
string const& column_name)
const
2975 return get_as<T>(this->column(column_name));
3035 string const& query,
3036 long batch_operations = 1,
3044template <
class Row,
class Member,
class Class>
3051template <
class Row,
class Accessor>
3052auto read_field(Row
const& row, Accessor
const& accessor) ->
decltype(accessor(row))
3054 return accessor(row);
3058template <
class Row,
class Accessor>
3061 using type = std::decay_t<
3062 decltype(
read_field(std::declval<Row const&>(), std::declval<Accessor const&>()))>;
3092template <
class T,
bool IsOptional = is_optional_v<T>>
3101 using type = std::conditional_t<
3102 is_owning_string_v<typename T::value_type>,
3107template <
class Rows,
class Accessor>
3112 Accessor
const& accessor,
3115 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3116 std::vector<value_type> column;
3117 column.reserve(rows.size());
3118 for (
auto const& row : rows)
3120 stmt.
bind(param_index, column);
3123template <
class Rows,
class Accessor>
3128 Accessor
const& accessor,
3131 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3132 std::vector<value_type> column;
3133 column.reserve(rows.size());
3134 for (
auto const& row : rows)
3135 column.push_back(read_field(row, accessor));
3141template <
class Rows,
class Accessor,
class Column>
3142std::unique_ptr<bool[]> gather_optional(Rows
const& rows, Accessor
const& accessor, Column& column)
3144 auto nulls = std::make_unique<bool[]>(rows.size());
3146 for (
auto const& row : rows)
3148 auto const& value = read_field(row, accessor);
3149 nulls[i++] = !value.has_value();
3150 column.push_back(value ? *value : typename Column::value_type());
3155template <
class Rows,
class Accessor>
3160 Accessor
const& accessor,
3161 bind_as_optional_value)
3163 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3164 std::vector<typename optional_type::value_type> column;
3165 column.reserve(rows.size());
3166 auto const nulls = gather_optional(rows, accessor, column);
3167 stmt.bind(param_index, column, nulls.get());
3170template <
class Rows,
class Accessor>
3175 Accessor
const& accessor,
3176 bind_as_optional_string)
3178 using optional_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3179 std::vector<typename optional_type::value_type> column;
3180 column.reserve(rows.size());
3181 auto const nulls = gather_optional(rows, accessor, column);
3182 stmt.bind_strings(param_index, column, nulls.get());
3185template <
class Rows,
class Accessor>
3186void bind_one(statement& stmt,
short param_index, Rows
const& rows, Accessor
const& accessor)
3188 using value_type =
typename field_type<typename Rows::value_type, Accessor>::type;
3189 bind_column(stmt, param_index, rows, accessor,
typename bind_kind<value_type>::type());
3224template <
class Rows,
class... Accessors>
3227 short param_index = 0;
3230 (detail::bind_one(stmt, param_index++, rows, accessors), ...);
A class representing a connection or a statement attribute.
Definition nanodbc.h:428
attribute(long const &attribute, long const &string_length, variant const &resource) noexcept
Creates an attribute from the three arguments the ODBC call takes.
attribute(attribute const &other) noexcept
Copy constructor.
void extractValuePtr() noexcept
Points value_ptr_ at the resource, according to which type it holds.
Result set for a list of columns in one or more tables.
Definition nanodbc.h:2650
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:2690
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:2752
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:2735
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:2715
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:2633
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:2629
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:1648
Manages and encapsulates ODBC resources such as the connection and environment handles.
Definition nanodbc.h:1640
~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:319
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:2468
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:295
char const * what() const noexcept override
Returns the message describing the out of range index.
Accessed null data.
Definition nanodbc.h:284
char const * what() const noexcept override
Returns the message describing the null access.
Programming logic error.
Definition nanodbc.h:306
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:2363
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:2424
std::ptrdiff_t difference_type
Iterator difference.
Definition nanodbc.h:2369
pointer operator->()
Access through dereference.
Definition nanodbc.h:2385
std::input_iterator_tag iterator_category
Category of iterator.
Definition nanodbc.h:2365
void operator++(int)
Iteration.
Definition nanodbc.h:2412
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:2415
result_iterator & operator++()
Iteration.
Definition nanodbc.h:2393
reference operator*() noexcept
Dereference.
Definition nanodbc.h:2382
result_iterator(result &r)
Create result iterator for a given result set.
Definition nanodbc.h:2375
A resource for managing result sets from statement execution.
Definition nanodbc.h:1929
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:874
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:897
@ PARAM_OUT
Binding an output parameter.
Definition nanodbc.h:899
@ PARAM_INOUT
Binding an input/output parameter.
Definition nanodbc.h:900
@ PARAM_IN
Binding an input parameter.
Definition nanodbc.h:898
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:619
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:555
~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:273
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, param_direction direction=PARAM_IN)
Binds multiple values.
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:1402
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, 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.
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:1537
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls)
Binds multiple string values.
Definition nanodbc.h:810
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:1565
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, 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:782
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], param_direction direction=PARAM_IN)
Binds multiple string values.
Definition nanodbc.h:1464
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:1500
void bind_strings(short param_index, std::vector< T > const &values, param_direction direction=PARAM_IN)
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:2442
result_iterator begin(result &r)
Returns an iterator to the beginning of the given result set.
Definition nanodbc.h:2431
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:3225
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:502
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:479
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:467
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:498
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:490
Member const & read_field(Row const &row, Member Class::*field)
Reads a member through a pointer to it.
Definition nanodbc.h:3045
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:517
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:226
unspecified type null_type
null_type will be int64_t for 64-bit compilations, otherwise long.
Definition nanodbc.h:228
A type capturing parameter array length as well as number of rows in a rowset of a result.
Definition nanodbc.h:364
batch_ops() noexcept
Creates lengths of -1, meaning neither has been chosen.
Definition nanodbc.h:369
batch_ops(const long all_length) noexcept
Creates both lengths with the same value.
Definition nanodbc.h:375
long rowset_size
Number of rows fetched into a rowset at a time.
Definition nanodbc.h:366
long parameter_array_length
Number of parameter values bound per execution.
Definition nanodbc.h:365
A data source name registered with the driver manager.
Definition nanodbc.h:3002
nanodbc::string driver
Driver description.
Definition nanodbc.h:3004
nanodbc::string name
DSN name.
Definition nanodbc.h:3003
A type for representing date data.
Definition nanodbc.h:382
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:384
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:385
std::int16_t year
Year [0-inf).
Definition nanodbc.h:383
Definition nanodbc.h:3089
Definition nanodbc.h:3086
Definition nanodbc.h:3083
Definition nanodbc.h:3080
Definition nanodbc.h:3094
The type an accessor yields for a row, stripped of reference and const.
Definition nanodbc.h:3060
Definition nanodbc.h:3067
Driver attributes.
Definition nanodbc.h:2991
nanodbc::string keyword
Driver keyword attribute.
Definition nanodbc.h:2992
nanodbc::string value
Driver attribute value.
Definition nanodbc.h:2993
Information on a configured ODBC driver.
Definition nanodbc.h:2988
nanodbc::string name
Driver name.
Definition nanodbc.h:2996
std::list< attribute > attributes
List of driver attributes.
Definition nanodbc.h:2997
A type for representing time data.
Definition nanodbc.h:390
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:391
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:392
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:393
A type for representing timestamp data.
Definition nanodbc.h:398
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:402
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:404
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:401
std::int16_t year
Year [0-inf).
Definition nanodbc.h:399
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:403
std::int32_t fract
Fractional seconds.
Definition nanodbc.h:405
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:400
A type for representing timestamp+offset data.
Definition nanodbc.h:410
std::int16_t offset_minute
Minutes part of time zome offset.
Definition nanodbc.h:413
timestamp stamp
Date and time, in the offset's local terms.
Definition nanodbc.h:411
std::int16_t offset_hour
Whole hour part of time zone offset.
Definition nanodbc.h:412