77#ifndef NANODBC_NANODBC_H
78#define NANODBC_NANODBC_H
93#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
94#define NANODBC_HAS_STD_STRING_VIEW
96#define NANODBC_HAS_STD_OPTIONAL
98#define NANODBC_HAS_STD_VARIANT
136#define NANODBC_THROW_NO_SOURCE_LOCATION 1
152#define NANODBC_ASSERT(expression) assert(expression)
159#ifdef NANODBC_ENABLE_UNICODE
160#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
161#define NANODBC_TEXT(s) U##s
162typedef std::u32string
string;
163#ifdef NANODBC_HAS_STD_STRING_VIEW
164typedef std::u32string_view string_view;
168typedef std::wstring
string;
169#ifdef NANODBC_HAS_STD_STRING_VIEW
170typedef std::wstring_view string_view;
172#define NANODBC_TEXT(s) L##s
174typedef std::u16string
string;
175#ifdef NANODBC_HAS_STD_STRING_VIEW
176typedef std::u16string_view string_view;
178#define NANODBC_TEXT(s) u##s
182typedef std::string
string;
183#ifdef NANODBC_HAS_STD_STRING_VIEW
184typedef std::string_view string_view;
186#define NANODBC_TEXT(s) s
189#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
190typedef std::u32string wide_string;
191#ifdef NANODBC_HAS_STD_STRING_VIEW
192typedef std::u32string_view wide_string_view;
196typedef std::wstring wide_string;
197#ifdef NANODBC_HAS_STD_STRING_VIEW
198typedef std::wstring_view wide_string_view;
201typedef std::u16string wide_string;
202#ifdef NANODBC_HAS_STD_STRING_VIEW
203typedef std::u16string_view wide_string_view;
208typedef wide_string::value_type wide_char_t;
213#elif !defined(_WIN64) && defined(__LP64__)
230#define NANODBC_TEXT(s) s
243#define NANODBC_DEPRECATED [[deprecated]]
246#ifndef NANODBC_DISABLE_MSSQL_TVP
247class table_valued_parameter;
288 char const*
what() const noexcept override;
299 char const*
what() const noexcept override;
310 char const*
what() const noexcept override;
323 char const*
what() const noexcept override;
338 char const*
what() const noexcept override;
341 long native() const noexcept;
344 std::
string const& state() const noexcept;
348 std::
string sql_state;
380 : parameter_array_length(-1L)
381 , rowset_size(-1L) {};
386 : parameter_array_length(all_length)
387 , rowset_size(all_length) {};
426#ifdef NANODBC_HAS_STD_VARIANT
441#ifdef NANODBC_ENABLE_UNICODE
442 typedef std::variant<std::vector<uint8_t>,
string, std::string, std::intptr_t, std::uintptr_t>
445 typedef std::variant<std::vector<uint8_t>,
string, std::intptr_t, std::uintptr_t> variant;
457 attribute(
long const&
attribute,
long const& string_length, variant
const& resource)
noexcept;
461 void extractValuePtr();
484 , string_length_(string_length)
485 , value_ptr_((
void*)value_ptr) {};
499 std::is_same<typename std::decay<T>::type, std::string>::value ||
500 std::is_same<typename std::decay<T>::type, wide_string>::value
501#ifdef NANODBC_HAS_STD_STRING_VIEW
502 || std::is_same<typename std::decay<T>::type, std::string_view>::value ||
503 std::is_same<typename std::decay<T>::type, wide_string_view>::value
512 std::is_same<typename std::decay<T>::type, std::string::value_type>::value ||
513 std::is_same<typename std::decay<T>::type, wide_char_t>::value>;
573 void rollback() noexcept;
588 class transaction_impl;
592 std::shared_ptr<transaction_impl> impl_;
607#ifndef NANODBC_DISABLE_MSSQL_TVP
637 void open(
statement& stmt,
short param_index, std::
size_t row_count);
666 void bind(
short param_index, T const* values, std::
size_t batch_size);
671 void bind(
short param_index, T const* values, std::
size_t batch_size, T const* null_sentry);
676 void bind(
short param_index, T const* values, std::
size_t batch_size,
bool const* nulls);
680 void bind(
short param_index, std::vector<std::vector<uint8_t>> const& values);
685 bind(
short param_index, std::vector<std::vector<uint8_t>> const& values,
bool const* nulls);
691 std::vector<std::vector<uint8_t>> const& values,
692 uint8_t const* null_sentry);
722 std::
size_t value_size,
723 std::
size_t batch_size);
732 void bind_strings(
short param_index, std::vector<T> const& values);
737 std::
size_t BatchSize,
738 std::
size_t ValueSize,
741 void bind_strings(
short param_index, T const (&values)[BatchSize][ValueSize])
743 auto param_values =
reinterpret_cast<T const*
>(values);
744 bind_strings(param_index, param_values, ValueSize, BatchSize);
749 template <
class T,
typename = enable_if_
character<T>>
753 std::size_t value_size,
754 std::size_t batch_size,
755 T
const* null_sentry);
759 template <
class T,
typename = enable_if_
string<T>>
762 std::vector<T>
const& values,
763 typename T::value_type
const* null_sentry);
768 std::size_t BatchSize,
769 std::size_t ValueSize,
773 bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize], T
const* null_sentry)
775 auto param_values =
reinterpret_cast<T const*
>(values);
776 bind_strings(param_index, param_values, ValueSize, BatchSize,
nullptr, null_sentry);
781 template <
class T,
typename = enable_if_
character<T>>
785 std::size_t value_size,
786 std::size_t batch_size,
791 template <
class T,
typename = enable_if_
string<T>>
792 void bind_strings(
short param_index, std::vector<T>
const& values,
bool const* nulls);
797 std::size_t BatchSize,
798 std::size_t ValueSize,
801 void bind_strings(
short param_index, T
const (&values)[BatchSize][ValueSize],
bool const* nulls)
803 auto param_values =
reinterpret_cast<T const*
>(values);
804 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls);
825 const std::vector<short>& idx,
826 const std::vector<short>& type,
827 const std::vector<unsigned long>& size,
828 const std::vector<short>& scale);
834 unsigned long parameter_size(
short param_index) const;
837 short parameter_scale(
short param_index) const;
840 short parameter_type(
short param_index) const;
843 class table_valued_parameter_impl;
847 std::shared_ptr<table_valued_parameter_impl> impl_;
868 class statement_impl;
870#ifdef NANODBC_HAS_STD_VARIANT
875 attribute(attribute
const& other) noexcept
878 long const& attribute,
879 long const& string_length,
880 variant
const& resource) noexcept
884 friend class nanodbc::statement::statement_impl;
892 long const& attribute,
893 long const& string_length,
894 std::uintptr_t value_ptr) noexcept
898 friend class nanodbc::statement::statement_impl;
960 bool open() const noexcept;
963 bool connected() const noexcept;
972 void* native_statement_handle() const noexcept;
987 void prepare(class
connection& conn,
string const& query,
long timeout = 0);
996 void prepare(
string const& query,
long timeout = 0);
1000 void timeout(
long timeout = 0);
1014 string const& query,
1015 long batch_operations = 1,
1030 string const& query,
1034#if !defined(NANODBC_DISABLE_ASYNC)
1088 string const& query,
1089 long batch_operations = 1,
1109 bool async_execute(
void* event_handle,
long batch_operations = 1,
long timeout = 0);
1124 class result complete_execute(long batch_operations = 1);
1144 string const& query,
1145 long batch_operations = 1,
1176 string const& schema,
1177 string const& procedure,
1178 string const& column);
1193 short parameters() const;
1196 unsigned long parameter_size(
short param_index) const;
1199 short parameter_scale(
short param_index) const;
1202 short parameter_type(
short param_index) const;
1267 std::
size_t batch_size,
1276 std::
size_t batch_size,
1277 T const* null_sentry,
1286 std::
size_t batch_size,
1294 std::vector<std::vector<uint8_t>> const& values,
1301 std::vector<std::vector<uint8_t>> const& values,
1309 std::vector<std::vector<uint8_t>> const& values,
1310 uint8_t const* null_sentry,
1342 std::
size_t value_size,
1343 std::
size_t batch_size,
1355 std::vector<T> const& values,
1361 std::
size_t BatchSize,
1362 std::
size_t ValueSize,
1367 T const (&values)[BatchSize][ValueSize],
1370 auto param_values =
reinterpret_cast<T const*
>(values);
1371 bind_strings(param_index, param_values, ValueSize, BatchSize, direction);
1376 template <
class T,
typename = enable_if_
character<T>>
1380 std::size_t value_size,
1381 std::size_t batch_size,
1382 T
const* null_sentry,
1387 template <
class T,
typename = enable_if_
string<T>>
1390 std::vector<T>
const& values,
1391 typename T::value_type
const* null_sentry,
1397 std::size_t BatchSize,
1398 std::size_t ValueSize,
1403 T
const (&values)[BatchSize][ValueSize],
1404 T
const* null_sentry,
1407 auto param_values =
reinterpret_cast<T const*
>(values);
1408 bind_strings(param_index, param_values, ValueSize, BatchSize, null_sentry, direction);
1413 template <
class T,
typename = enable_if_
character<T>>
1417 std::size_t value_size,
1418 std::size_t batch_size,
1424 template <
class T,
typename = enable_if_
string<T>>
1427 std::vector<T>
const& values,
1434 std::size_t BatchSize,
1435 std::size_t ValueSize,
1440 T
const (&values)[BatchSize][ValueSize],
1444 auto param_values =
reinterpret_cast<T const*
>(values);
1445 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls, direction);
1461 void bind_null(
short param_index, std::size_t batch_size = 1);
1483 const std::vector<short>& idx,
1484 const std::vector<short>& type,
1485 const std::vector<unsigned long>& size,
1486 const std::vector<short>& scale);
1489 typedef std::function<bool(std::size_t)> null_predicate_type;
1491#ifndef NANODBC_DISABLE_MSSQL_TVP
1492 friend class nanodbc::table_valued_parameter::table_valued_parameter_impl;
1496 std::shared_ptr<statement_impl> impl_;
1516 class connection_impl;
1517 friend class nanodbc::transaction::transaction_impl;
1519#ifdef NANODBC_HAS_STD_VARIANT
1524 attribute(attribute
const& other) noexcept
1527 long const& attribute,
1528 long const& string_length,
1529 variant
const& resource) noexcept
1533 friend class nanodbc::connection::connection_impl;
1541 long const& attribute,
1542 long const& string_length,
1543 std::uintptr_t value_ptr) noexcept
1547 friend class nanodbc::connection::connection_impl;
1576 connection(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1587 explicit connection(
string const& connection_string,
long timeout = 0);
1589#ifdef NANODBC_HAS_STD_VARIANT
1607 std::list<attribute>
const& attributes);
1618 connection(
string const& connection_string, std::list<attribute>
const& attributes);
1647 void connect(
string const& dsn,
string const& user,
string const& pass,
long timeout = 0);
1654 void connect(
string const& connection_string,
long timeout = 0);
1656#ifdef NANODBC_HAS_STD_VARIANT
1669 std::list<attribute>
const& attributes);
1677 void connect(
string const& connection_string, std::list<attribute>
const& attributes);
1679#if !defined(NANODBC_DISABLE_ASYNC)
1719 bool async_connect(
string const& connection_string,
void* event_handle,
long timeout = 0);
1735 std::
size_t transactions() const noexcept;
1738 void* native_dbc_handle() const noexcept;
1741 void* native_env_handle() const noexcept;
1747 T get_info(
short info_type) const;
1752 string dbms_name() const;
1757 string dbms_version() const;
1761 string driver_name() const;
1765 string driver_version() const;
1769 string database_name() const;
1773 string catalog_name() const;
1776 std::
size_t ref_transaction() noexcept;
1777 std::
size_t unref_transaction() noexcept;
1778 bool rollback() const noexcept;
1779 void rollback(
bool onoff) noexcept;
1782 std::shared_ptr<connection_impl> impl_;
1798class variant_row_cached_result;
1826 void* native_statement_handle() const noexcept;
1829 long rowset_size() const noexcept;
1833 long affected_rows() const;
1843 bool has_affected_rows() const;
1846 long rows() const noexcept;
1850 short columns() const;
1867#if !defined(NANODBC_DISABLE_ASYNC)
1915 void unbind(
string const& column_name);
1932 void unbind(
short column);
1975 void get_ref(
short column, T const& fallback, T&
result) const;
1986 void get_ref(
string const& column_name, T&
result) const;
1999 void get_ref(
string const& column_name, T const& fallback, T&
result) const;
2010 T get(
short column) const;
2023 T get(
short column, T const& fallback) const;
2033 T get(
string const& column_name) const;
2045 T get(
string const& column_name, T const& fallback) const;
2070 bool is_null(
short column) const;
2079 bool is_null(
string const& column_name) const;
2091 bool is_bound(
short column) const;
2099 bool is_bound(
string const& column_name) const;
2106 short column(
string const& column_name) const;
2113 string column_name(
short column) const;
2120 long column_size(
short column) const;
2123 long column_size(
string const& column_name) const;
2133 int column_decimal_digits(
short column) const;
2136 int column_decimal_digits(
string const& column_name) const;
2139 int column_datatype(
short column) const;
2142 int column_datatype(
string const& column_name) const;
2151 string column_datatype_name(
short column) const;
2160 string column_datatype_name(
string const& column_name) const;
2163 int column_c_datatype(
short column) const;
2166 int column_c_datatype(
string const& column_name) const;
2175 bool column_unsigned(
short column) const;
2179 bool column_unsigned(
string const& column_name) const;
2185 explicit operator
bool() const noexcept;
2195 friend class nanodbc::variant_row_cached_result;
2199 std::shared_ptr<result_impl> impl_;
2229 throw std::runtime_error(
"result is empty");
2230 return &(operator*());
2238 if (!result_.next())
2258 if (result_ && rhs.result_)
2259 return result_.native_statement_handle() == rhs.result_.native_statement_handle();
2261 return !result_ && !rhs.result_;
2331 auto count() const noexcept ->
short;
2336 auto auto_unique_value(
short record) const ->
bool;
2339 auto base_column_name(
short record) const ->
string;
2342 auto base_table_name(
short record) const ->
string;
2345 auto case_sensitive(
short record) const ->
bool;
2348 auto catalog_name(
short record) const ->
string;
2351 auto concise_type(
short record) const ->
short;
2354 auto display_size(
short record) const -> std::int64_t;
2357 auto fixed_prec_scale(
short record) const ->
short;
2360 auto label(
short record) const ->
string;
2363 auto length(
short record) const -> std::uint64_t;
2366 auto local_type_name(
short record) const ->
string;
2369 auto name(
short record) const ->
string;
2374 auto nullable(
short record) const ->
short;
2377 auto num_prec_radix(
short record) const ->
short;
2380 auto octet_length(
short record) const -> std::int64_t;
2383 auto precision(
short record) const ->
short;
2386 auto rowver(
short record) const ->
short;
2389 auto scale(
short record) const ->
short;
2392 auto schema_name(
short record) const ->
string;
2398 auto searchable(
short record) const ->
short;
2401 auto table_name(
short record) const ->
string;
2404 auto type(
short record) const ->
short;
2407 auto type_name(
short record) const ->
string;
2410 auto unnamed(
short record) const ->
bool;
2413 auto unsigned_(
short record) const ->
bool;
2419 auto updatable(
short record) const ->
short;
2423 struct sql_get_descr_field
2425 sql_get_descr_field(
2428 std::uint16_t field_identifier)
noexcept;
2429 operator std::int64_t()
const;
2430 operator std::uint64_t()
const;
2435 std::uint16_t field_identifier_;
2437 friend sql_get_descr_field;
2439 void initialize_descriptor();
2440 void throw_if_record_is_out_of_range(
short record)
const;
2442 void* statement_handle_{
nullptr};
2443 short statement_columns_count_{0};
2444 void* descriptor_handle_{
nullptr};
2445 short descriptor_records_count_{0};
2645 string const& table =
string(),
2646 string const& type =
string(),
2647 string const& schema =
string(),
2648 string const&
catalog =
string());
2665 string const& table =
string(),
2666 string const& schema =
string());
2678 string const& column =
string(),
2679 string const& table =
string(),
2680 string const& schema =
string(),
2681 string const&
catalog =
string());
2692 string const& table,
2693 string const& schema =
string(),
2694 string const&
catalog =
string());
2707 string const& procedure =
string(),
2708 string const& schema =
string(),
2709 string const&
catalog =
string());
2722 string const& column =
string(),
2723 string const& procedure =
string(),
2724 string const& schema =
string(),
2725 string const&
catalog =
string());
2815 string const& query,
2816 long batch_operations = 1,
A class representing a connection or a statement attribute.
Definition nanodbc.h:476
long string_length_
The StringLength argument of the ODBC call.
Definition nanodbc.h:489
void * value_ptr_
The ValuePtr argument of the ODBC call.
Definition nanodbc.h:490
long attribute_
The Attribute argument of the ODBC call.
Definition nanodbc.h:488
attribute(long const &attribute, long const &string_length, std::uintptr_t value_ptr) noexcept
Creates an attribute from the three arguments the ODBC call takes.
Definition nanodbc.h:482
Result set for a list of columns in one or more tables.
Definition nanodbc.h:2491
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:2531
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:2593
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:2576
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:2556
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:2474
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:2470
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.
Manages and encapsulates ODBC resources such as the connection and environment handles.
Definition nanodbc.h:1513
~connection() noexcept
Automatically disconnects from the database and frees all associated resources.
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 &dsn, string const &user, string const &pass, long timeout=0)
Create new connection object and immediately connect to the given data source.
connection & operator=(connection rhs) noexcept
Assignment.
connection()
Create new connection object, initially not connected.
bool async_connect(string const &dsn, string const &user, string const &pass, void *event_handle, long timeout=0)
Initiate an asynchronous connection operation to the given data source.
void swap(connection &) noexcept
Member swap.
connection(string const &connection_string, long timeout=0)
Create new connection object and immediately connect using the given connection string.
General database error.
Definition nanodbc.h:329
char const * what() const noexcept override
Returns the full message, including the driver's own text.
database_error(void *handle, short handle_type, std::string const &info="")
Creates runtime_error with message about last ODBC error.
Provides access to metadata in the Implementation Row Descriptor (IRD) implicitly allocated for a pre...
Definition nanodbc.h:2309
implementation_row_descriptor(statement const &statement)
Initializes IRD access from prepared or executed statement.
implementation_row_descriptor(result const &result)
Initializes IRD access from statement of executed result set.
auto alloc_type() const -> short
Value of the header field SQL_DESC_ALLOC_AUTO.
Index out of range.
Definition nanodbc.h:305
char const * what() const noexcept override
Returns the message describing the out of range index.
Accessed null data.
Definition nanodbc.h:294
char const * what() const noexcept override
Returns the message describing the null access.
Programming logic error.
Definition nanodbc.h:316
programming_error(std::string const &info)
Creates a programming error with the given message.
char const * what() const noexcept override
Returns the message describing the error.
Single pass input iterator that accesses successive rows in the attached result set.
Definition nanodbc.h:2204
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:2265
result * pointer
Pointer to iteration values.
Definition nanodbc.h:2208
pointer operator->()
Access through dereference.
Definition nanodbc.h:2226
result value_type
Values returned by iterator access.
Definition nanodbc.h:2207
void operator++(int)
Iteration.
Definition nanodbc.h:2253
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:2256
result_iterator & operator++()
Iteration.
Definition nanodbc.h:2234
reference operator*() noexcept
Dereference.
Definition nanodbc.h:2223
result & reference
Reference to iteration values.
Definition nanodbc.h:2209
result_iterator(result &r)
Create result iterator for a given result set.
Definition nanodbc.h:2216
std::ptrdiff_t difference_type
Iterator difference.
Definition nanodbc.h:2210
std::input_iterator_tag iterator_category
Category of iterator.
Definition nanodbc.h:2206
A resource for managing result sets from statement execution.
Definition nanodbc.h:1805
bool complete_next()
Completes a previously-initiated async fetch for next row in the current result set.
unsigned long position() const
Returns the row position in the current result set.
bool move(long row)
Moves to and fetches the specified row in the current result set.
bool async_next(void *event_handle)
Initiates an asynchronous fetch of the next row in the current result set.
bool at_end() const noexcept
Returns true if there are no more results in the current result set.
bool skip(long rows)
Skips a number of rows and then fetches the resulting row in the current result set.
result() noexcept
Empty result set.
bool prior()
Fetches the prior row in the current result set.
Represents a statement on the database.
Definition nanodbc.h:865
statement(class connection &conn, std::list< attribute > const &attributes)
Constructs a statement object and associates it to the given connection, applying the given ODBC stat...
statement & operator=(statement rhs) noexcept
Assignment.
void just_execute_direct(class connection &conn, string const &query, long batch_operations=1, long timeout=0)
Execute the previously prepared query now without constructing result object.
void complete_prepare()
Completes a previously initiated asynchronous query preparation.
param_direction
Provides support for retrieving output/return parameters.
Definition nanodbc.h:906
@ PARAM_OUT
Binding an output parameter.
Definition nanodbc.h:908
@ PARAM_INOUT
Binding an input/output parameter.
Definition nanodbc.h:909
@ PARAM_IN
Binding an input parameter.
Definition nanodbc.h:907
bool async_prepare(string const &query, void *event_handle, long timeout=0)
Prepare the given statement, in asynchronous mode.
short columns() const
Returns the number of columns in a result set.
void disable_async() const
undocumented - for internal use only (used from result_impl)
bool async_execute_direct(class connection &conn, void *event_handle, string const &query, long batch_operations=1, long timeout=0)
Opens, prepares, and executes query directly on the given connection, in async mode.
void describe_parameters(const std::vector< short > &idx, const std::vector< short > &type, const std::vector< unsigned long > &size, const std::vector< short > &scale)
Sets descriptions for parameters in the prepared statement.
statement(statement &&rhs) noexcept
Move constructor.
~statement() noexcept
Closes the statement.
statement(class connection &conn)
Constructs a statement object and associates it to the given connection.
void swap(statement &rhs) noexcept
Member swap.
bool async_execute(void *event_handle, long batch_operations=1, long timeout=0)
Execute the previously prepared query now, in asynchronous mode.
statement()
Creates a new un-prepared statement.
statement(const statement &rhs) noexcept
Copy constructor.
void enable_async(void *event_handle)
undocumented - for internal use only (used from result_impl)
statement(class connection &conn, string const &query, long timeout=0)
Constructs and prepares a statement using the given connection and query.
void reset_parameters() noexcept
Resets all currently bound parameters.
void just_execute(long batch_operations=1, long timeout=0)
Execute the previously prepared query now without constructing result object.
long affected_rows() const
Returns rows affected by the request or -1 if affected rows is not available.
Support for table-valued parameter.
Definition nanodbc.h:610
table_valued_parameter(statement &stmt, short param_index, size_t row_count)
Creates a table-valued parameter and opens it on the given statement.
~table_valued_parameter() noexcept
Closes the parameter, if it is still open.
void bind_null(short param_index)
Binds a null value to the given column of every row.
table_valued_parameter(const table_valued_parameter &rhs) noexcept
Copy constructor.
short parameters() const noexcept
Returns the number of columns in the table valued parameter.
table_valued_parameter(table_valued_parameter &&rhs) noexcept
Move constructor.
table_valued_parameter()
Creates a table-valued parameter that is not yet open.
void describe_parameters(const std::vector< short > &idx, const std::vector< short > &type, const std::vector< unsigned long > &size, const std::vector< short > &scale)
Sets descriptions for columns of the table-valued parameter.
A resource for managing transaction commits and rollbacks.
Definition nanodbc.h:546
~transaction() noexcept
If this transaction has not been committed, it will rollback any modifying ops.
transaction(const class connection &conn)
Begin a transaction on the given connection object.
transaction(transaction &&rhs) noexcept
Move constructor.
transaction(const transaction &rhs) noexcept
Copy constructor.
transaction & operator=(transaction rhs) noexcept
Assignment.
void swap(transaction &rhs) noexcept
Member swap.
Type incompatible.
Definition nanodbc.h:283
char const * what() const noexcept override
Returns the message describing the incompatibility.
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple string values.
Definition nanodbc.h:1438
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const *nulls)
Binds multiple string values.
Definition nanodbc.h:801
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, T const *null_sentry)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, bool const *nulls)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, typename T::value_type const *null_sentry)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], T const *null_sentry)
Binds multiple string values.
Definition nanodbc.h:773
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, T const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, bool const *nulls)
Binds multiple string values.
void bind_strings(short param_index, std::vector< T > const &values, typename T::value_type const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const *values, std::size_t value_size, std::size_t batch_size, bool const *nulls, param_direction direction=PARAM_IN)
Binds multiple string values.
void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], T const *null_sentry, param_direction direction=PARAM_IN)
Binds multiple string values.
Definition nanodbc.h:1401
void bind_null(short param_index, std::size_t batch_size=1)
Binds null values to the 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:2283
result_iterator begin(result &r)
Returns an iterator to the beginning of the given result set.
Definition nanodbc.h:2272
void prepare(statement &stmt, string const &query, long timeout=0)
Prepares the given statement to execute on it associated connection.
result execute(connection &conn, string const &query, long batch_operations=1, long timeout=0)
Immediately opens, prepares, and executes the given query directly on the given connection.
void just_transact(statement &stmt, long batch_operations)
Execute the previously prepared query now and without creating result object.
result transact(statement &stmt, long batch_operations)
Execute the previously prepared query now.
std::list< driver > list_drivers()
Returns a list of ODBC drivers on your system.
std::list< datasource > list_datasources()
Returns a list of ODBC data sources on your system.
void just_execute(connection &conn, string const &query, long batch_operations=1, long timeout=0)
Opens, prepares, and executes query directly without creating result object.
typename std::enable_if< is_string< T >::value >::type enable_if_string
Enables an overload only for the string types nanodbc binds as strings.
Definition nanodbc.h:517
typename std::enable_if< is_character< T >::value >::type enable_if_character
Enables an overload only for the character types nanodbc binds as strings.
Definition nanodbc.h:521
std::integral_constant< bool, std::is_same< typename std::decay< T >::type, std::string >::value||std::is_same< typename std::decay< T >::type, wide_string >::value > is_string
A type trait for testing if a type is a std::basic_string compatible with the current nanodbc configu...
Definition nanodbc.h:505
std::integral_constant< bool, std::is_same< typename std::decay< T >::type, std::string::value_type >::value||std::is_same< typename std::decay< T >::type, wide_char_t >::value > is_character
A type trait for testing if a type is a character compatible with the current nanodbc configuration.
Definition nanodbc.h:513
The entirety of nanodbc can be found within this one namespace.
Definition nanodbc.h:108
unspecified type string
string will be std::u16string or std::32string if NANODBC_ENABLE_UNICODE defined.
Definition nanodbc.h:236
unspecified type null_type
null_type will be int64_t for 64-bit compilations, otherwise long.
Definition nanodbc.h:238
A type capturing parameter array length as well as number of rows in a rowset of a result.
Definition nanodbc.h:374
batch_ops() noexcept
Creates lengths of -1, meaning neither has been chosen.
Definition nanodbc.h:379
batch_ops(const long all_length) noexcept
Creates both lengths with the same value.
Definition nanodbc.h:385
long rowset_size
Number of rows fetched into a rowset at a time.
Definition nanodbc.h:376
long parameter_array_length
Number of parameter values bound per execution.
Definition nanodbc.h:375
A data source name registered with the driver manager.
Definition nanodbc.h:2782
nanodbc::string driver
Driver description.
Definition nanodbc.h:2784
nanodbc::string name
DSN name.
Definition nanodbc.h:2783
A type for representing date data.
Definition nanodbc.h:392
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:394
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:395
std::int16_t year
Year [0-inf).
Definition nanodbc.h:393
Driver attributes.
Definition nanodbc.h:2771
nanodbc::string keyword
Driver keyword attribute.
Definition nanodbc.h:2772
nanodbc::string value
Driver attribute value.
Definition nanodbc.h:2773
Information on a configured ODBC driver.
Definition nanodbc.h:2768
nanodbc::string name
Driver name.
Definition nanodbc.h:2776
std::list< attribute > attributes
List of driver attributes.
Definition nanodbc.h:2777
A type for representing time data.
Definition nanodbc.h:400
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:401
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:402
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:403
A type for representing timestamp data.
Definition nanodbc.h:408
std::int16_t hour
Hours since midnight [0-23].
Definition nanodbc.h:412
std::int16_t sec
Seconds after the minute.
Definition nanodbc.h:414
std::int16_t day
Day of the month [1-31].
Definition nanodbc.h:411
std::int16_t year
Year [0-inf).
Definition nanodbc.h:409
std::int16_t min
Minutes after the hour [0-59].
Definition nanodbc.h:413
std::int32_t fract
Fractional seconds.
Definition nanodbc.h:415
std::int16_t month
Month of the year [1-12].
Definition nanodbc.h:410
A type for representing timestamp+offset data.
Definition nanodbc.h:420
std::int16_t offset_minute
Minutes part of time zome offset.
Definition nanodbc.h:423
timestamp stamp
Date and time, in the offset's local terms.
Definition nanodbc.h:421
std::int16_t offset_hour
Whole hour part of time zone offset.
Definition nanodbc.h:422