nanodbc
A small C++ wrapper for the native C ODBC API
Loading...
Searching...
No Matches
nanodbc.h
Go to the documentation of this file.
1
2
76
77#ifndef NANODBC_NANODBC_H
78#define NANODBC_NANODBC_H
79
80#include <any>
81#include <cstddef>
82#include <cstdint>
83#include <exception>
84#include <functional>
85#include <iterator>
86#include <list>
87#include <memory>
88#include <optional>
89#include <stdexcept>
90#include <string>
91#include <string_view>
92#include <type_traits>
93#include <utility>
94#include <variant>
95#include <vector>
96
97// nanodbc requires C++17, so these always hold. They are still defined, so that code
98// written against an earlier release and asking whether the feature is there keeps
99// compiling; new code has no reason to ask.
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
104
111namespace nanodbc
112{
113
114// clang-format off
115// .d8888b. .d888 d8b 888 d8b
116// d88P Y88b d88P" Y8P 888 Y8P
117// 888 888 888 888
118// 888 .d88b. 88888b. 888888 888 .d88b. 888 888 888d888 8888b. 888888 888 .d88b. 88888b.
119// 888 d88""88b 888 "88b 888 888 d88P"88b 888 888 888P" "88b 888 888 d88""88b 888 "88b
120// 888 888 888 888 888 888 888 888 888 888 888 888 888 .d888888 888 888 888 888 888 888
121// Y88b d88P Y88..88P 888 888 888 888 Y88b 888 Y88b 888 888 888 888 Y88b. 888 Y88..88P 888 888
122// "Y8888P" "Y88P" 888 888 888 888 "Y88888 "Y88888 888 "Y888888 "Y888 888 "Y88P" 888 888
123// 888
124// Y8b d88P
125// "Y88P"
126// MARK: Configuration -
127// clang-format on
128
133#ifdef DOXYGEN
134
140#define NANODBC_THROW_NO_SOURCE_LOCATION 1
141
156#define NANODBC_ASSERT(expression) assert(expression)
157
158#endif
160
161// You must explicitly request Unicode support by defining NANODBC_ENABLE_UNICODE at compile time.
162// NANODBC_ENABLE_UTF8 keeps string narrow, holding UTF-8, and calls the wide ODBC functions.
163#if defined(NANODBC_ENABLE_UNICODE) && defined(NANODBC_ENABLE_UTF8)
164#error "NANODBC_ENABLE_UNICODE and NANODBC_ENABLE_UTF8 are alternatives; define one"
165#endif
166#ifndef DOXYGEN
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;
172#else
173#ifdef _MSC_VER
174using string = std::wstring;
175using string_view = std::wstring_view;
176#define NANODBC_TEXT(s) L##s
177#else
178using string = std::u16string;
179using string_view = std::u16string_view;
180#define NANODBC_TEXT(s) u##s
181#endif
182#endif
183#else
184using string = std::string;
185using string_view = std::string_view;
186#define NANODBC_TEXT(s) s
187#endif
188
189#ifdef NANODBC_USE_IODBC_WIDE_STRINGS
190using wide_string = std::u32string;
191using wide_string_view = std::u32string_view;
192#else
193#ifdef _MSC_VER
194using wide_string = std::wstring;
195using wide_string_view = std::wstring_view;
196#else
197using wide_string = std::u16string;
198using wide_string_view = std::u16string_view;
199#endif
200#endif
201
202using wide_char_t = wide_string::value_type;
203
204#if defined(_WIN64)
205// LLP64 machine: Windows
206using null_type = std::int64_t;
207#elif !defined(_WIN64) && defined(__LP64__)
208// LP64 machine: OS X or Linux
209using null_type = long;
210#else
211// 32-bit machine
212using null_type = long;
213#endif
214#else
224#define NANODBC_TEXT(s) s
225
230typedef unspecified - type string;
232typedef unspecified - type null_type;
233#endif
234
237#define NANODBC_DEPRECATED [[deprecated]]
238
239// forward declare
240#ifndef NANODBC_DISABLE_MSSQL_TVP
241class table_valued_parameter;
242#endif
243class statement;
244class connection;
245class transaction;
246class catalog;
247class result;
248
249// clang-format off
250// 8888888888 888 888 888 888 d8b
251// 888 888 888 888 888 Y8P
252// 888 888 888 888 888
253// 8888888 888d888 888d888 .d88b. 888d888 8888888888 8888b. 88888b. .d88888 888 888 88888b. .d88b.
254// 888 888P" 888P" d88""88b 888P" 888 888 "88b 888 "88b d88" 888 888 888 888 "88b d88P"88b
255// 888 888 888 888 888 888 888 888 .d888888 888 888 888 888 888 888 888 888 888 888
256// 888 888 888 Y88..88P 888 888 888 888 888 888 888 Y88b 888 888 888 888 888 Y88b 888
257// 8888888888 888 888 "Y88P" 888 888 888 "Y888888 888 888 "Y88888 888 888 888 888 "Y88888
258// 888
259// Y8b d88P
260// "Y88P"
261// MARK: Error Handling -
262// clang-format on
263
273
276class type_incompatible_error : public std::runtime_error
277{
278public:
280
282 char const* what() const noexcept override;
283};
284
287class null_access_error : public std::runtime_error
288{
289public:
291
293 char const* what() const noexcept override;
294};
295
298class index_range_error : public std::runtime_error
299{
300public:
302
304 char const* what() const noexcept override;
305};
306
309class programming_error : public std::runtime_error
310{
311public:
314 explicit programming_error(std::string const& info);
315
317 char const* what() const noexcept override;
318};
319
322class database_error : public std::runtime_error
323{
324public:
329 database_error(void* handle, short handle_type, std::string const& info = "");
330
332 char const* what() const noexcept override;
333
335 long native() const noexcept;
336
338 std::string const& state() const noexcept;
339
340private:
341 long native_error;
342 std::string sql_state;
343 std::string message;
344};
345
347
348// clang-format off
349// 888 888 888 d8b 888 d8b 888 d8b
350// 888 888 888 Y8P 888 Y8P 888 Y8P
351// 888 888 888 888 888
352// 888 888 888888 888 888 888 888888 888 .d88b. .d8888b
353// 888 888 888 888 888 888 888 888 d8P Y8b 88K
354// 888 888 888 888 888 888 888 888 88888888 "Y8888b.
355// Y88b. .d88P Y88b. 888 888 888 Y88b. 888 Y8b. X88
356// "Y88888P" "Y888 888 888 888 "Y888 888 "Y8888 88888P'
357// MARK: Utilities -
358// clang-format on
359
364
368{
369 long parameter_array_length{-1};
370 long rowset_size{-1};
371
373 batch_ops() = default;
374
377 batch_ops(const long all_length) noexcept
378 : parameter_array_length(all_length)
379 , rowset_size(all_length) {};
380};
381
383struct date
384{
385 std::int16_t year;
386 std::int16_t month;
387 std::int16_t day;
388};
389
391struct time
392{
393 std::int16_t hour;
394 std::int16_t min;
395 std::int16_t sec;
396};
397
400{
401 std::int16_t year;
402 std::int16_t month;
403 std::int16_t day;
404 std::int16_t hour;
405 std::int16_t min;
406 std::int16_t sec;
407 std::int32_t fract;
408};
409
412{
414 std::int16_t offset_hour;
415 std::int16_t offset_minute;
416};
417
422// `SQLSetConnectAttr`, or `SQLSetStmtAttr`. The second is the StringLength,
423// and the third is used to inform the ValuePtr argument. This argument,
430{
431public:
432#ifdef NANODBC_ENABLE_UNICODE
433 using variant =
434 std::variant<std::vector<uint8_t>, string, std::string, std::intptr_t, std::uintptr_t>;
435#else
436 using variant = std::variant<std::vector<uint8_t>, string, std::intptr_t, std::uintptr_t>;
437#endif
438 attribute() = delete;
439 attribute& operator=(attribute const&) = delete;
440
442 attribute(attribute const& other) noexcept;
443
448 attribute(long const& attribute, long const& string_length, variant resource) noexcept;
449
450protected:
455 void extractValuePtr() noexcept;
456
457 long attribute_;
458 long string_length_;
459 variant resource_;
460 void* value_ptr_{};
461};
462
465template <typename T>
466using is_string = std::bool_constant<
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>>;
470
472template <typename T>
473inline constexpr bool is_string_v = is_string<T>::value;
474
479template <typename T>
480using is_owning_string = std::bool_constant<
481 std::is_same_v<std::decay_t<T>, std::string> || std::is_same_v<std::decay_t<T>, wide_string>>;
482
484template <typename T>
486
489template <typename T>
490using is_character = std::bool_constant<
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>>;
493
495template <typename T>
497
499template <typename T>
500using enable_if_string = std::enable_if_t<is_string_v<T>>;
501
503template <typename T>
504using enable_if_character = std::enable_if_t<is_character_v<T>>;
505
506namespace detail
507{
508
517template <class T>
518std::unique_ptr<bool[]>
519split_optional(std::vector<std::optional<T>> const& values, std::vector<T>& column)
520{
521 auto nulls = std::make_unique<bool[]>(values.size());
522 column.reserve(values.size());
523 std::size_t i = 0;
524 for (auto const& value : values)
525 {
526 nulls[i++] = !value.has_value();
527 column.push_back(value ? *value : T());
528 }
529 return nulls;
530}
531
532} // namespace detail
533
535
540
541// clang-format off
542// 88888888888 888 d8b
543// 888 888 Y8P
544// 888 888
545// 888 888d888 8888b. 88888b. .d8888b 8888b. .d8888b 888888 888 .d88b. 88888b.
546// 888 888P" "88b 888 "88b 88K "88b d88P" 888 888 d88""88b 888 "88b
547// 888 888 .d888888 888 888 "Y8888b. .d888888 888 888 888 888 888 888 888
548// 888 888 888 888 888 888 X88 888 888 Y88b. Y88b. 888 Y88..88P 888 888
549// 888 888 "Y888888 888 888 88888P' "Y888888 "Y8888P "Y888 888 "Y88P" 888 888
550// MARK: Transaction -
551// clang-format on
552
560{
561public:
565 explicit transaction(const class connection& conn);
566
568 void swap(transaction& rhs) noexcept;
569
572 void commit();
573
575 void rollback() noexcept;
576
578 class connection& connection() noexcept;
579
581 const class connection& connection() const noexcept;
582
584 operator class connection &() noexcept;
585
587 operator const class connection &() const noexcept;
588
589private:
590 class transaction_impl;
591 friend class nanodbc::connection;
592
593private:
594 std::shared_ptr<transaction_impl> impl_;
595};
596
597// clang-format off
598// 888b d888 .d8888b. .d8888b. .d88888b. 888 88888888888 888 888 8888888b.
599// 8888b d8888 d88P Y88b d88P Y88b d88P" "Y88b 888 888 888 888 888 Y88b
600// 88888b.d88888 Y88b. Y88b. 888 888 888 888 888 888 888 888
601// 888Y88888P888 "Y888b. "Y888b. 888 888 888 888 Y88b d88P 888 d88P
602// 888 Y888P 888 "Y88b. "Y88b. 888 888 888 888 Y88b d88P 8888888P"
603// 888 Y8P 888 "888 "888 888 Y8b 888 888 888888 888 Y88o88P 888
604// 888 " 888 Y88b d88P Y88b d88P Y88b.Y8b88P 888 888 Y888P 888
605// 888 888 "Y8888P" "Y8888P" "Y888888" 88888888 888 Y8P 888
606// Y8b
607// MARK: MSSQL - TVP (Table Valued Parameters) -
608// clang-format on
609#ifndef NANODBC_DISABLE_MSSQL_TVP
612{
613public:
616
619 void operator=(const table_valued_parameter&) = delete;
620 void operator=(table_valued_parameter&&) = delete;
621
624 table_valued_parameter(statement& stmt, short param_index, size_t row_count);
625
635 void open(statement& stmt, short param_index, std::size_t row_count);
636
639 void close();
640
660
663 template <class T>
664 void bind(short param_index, T const* values, std::size_t batch_size);
665
668 template <class T>
669 void bind(short param_index, T const* values, std::size_t batch_size, T const* null_sentry);
670
673 template <class T>
674 void bind(short param_index, T const* values, std::size_t batch_size, bool const* nulls);
675
678 void bind(short param_index, std::vector<std::vector<uint8_t>> const& values);
679
682 void
683 bind(short param_index, std::vector<std::vector<uint8_t>> const& values, bool const* nulls);
684
693 short param_index,
694 std::vector<std::vector<uint8_t>> const& values,
695 uint8_t const* null_sentry);
696
699 void bind(
700 short param_index,
701 std::vector<std::vector<uint8_t>> const& values,
702 std::vector<uint8_t> const& null_sentry);
703
705
725
728 template <class T, typename = enable_if_character<T>>
730 short param_index,
731 T const* values,
732 std::size_t value_size,
733 std::size_t batch_size);
734
741 template <class T, typename = enable_if_string<T>>
742 void bind_strings(short param_index, std::vector<T> const& values);
743
746 template <
747 std::size_t BatchSize,
748 std::size_t ValueSize,
749 class T,
750 typename = enable_if_character<T>>
751 void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize])
752 {
753 auto param_values = reinterpret_cast<T const*>(values);
754 bind_strings(param_index, param_values, ValueSize, BatchSize);
755 }
756
759 template <class T, typename = enable_if_character<T>>
761 short param_index,
762 T const* values,
763 std::size_t value_size,
764 std::size_t batch_size,
765 T const* null_sentry);
766
769 template <class T, typename = enable_if_string<T>>
771 short param_index,
772 std::vector<T> const& values,
773 typename T::value_type const* null_sentry);
774
777 template <
778 std::size_t BatchSize,
779 std::size_t ValueSize,
780 class T,
781 typename = enable_if_character<T>>
782 void
783 bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], T const* null_sentry)
784 {
785 auto param_values = reinterpret_cast<T const*>(values);
786 bind_strings(param_index, param_values, ValueSize, BatchSize, nullptr, null_sentry);
787 }
788
791 template <class T, typename = enable_if_character<T>>
793 short param_index,
794 T const* values,
795 std::size_t value_size,
796 std::size_t batch_size,
797 bool const* nulls);
798
801 template <class T, typename = enable_if_string<T>>
802 void bind_strings(short param_index, std::vector<T> const& values, bool const* nulls);
803
806 template <
807 std::size_t BatchSize,
808 std::size_t ValueSize,
809 class T,
810 typename = enable_if_character<T>>
811 void bind_strings(short param_index, T const (&values)[BatchSize][ValueSize], bool const* nulls)
812 {
813 auto param_values = reinterpret_cast<T const*>(values);
814 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls);
815 }
816
818
822 void bind_null(short param_index);
823
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);
839
841 short parameters() const noexcept;
842
844 unsigned long parameter_size(short param_index) const;
845
847 short parameter_scale(short param_index) const;
848
850 short parameter_type(short param_index) const;
851
852private:
853 class table_valued_parameter_impl;
854 friend class statement;
855
856private:
857 std::shared_ptr<table_valued_parameter_impl> impl_;
858};
859#endif // NANODBC_DISABLE_MSSQL_TVP
860
861// clang-format off
862// .d8888b. 888 888 888
863// d88P Y88b 888 888 888
864// Y88b. 888 888 888
865// "Y888b. 888888 8888b. 888888 .d88b. 88888b.d88b. .d88b. 88888b. 888888
866// "Y88b. 888 "88b 888 d8P Y8b 888 "888 "88b d8P Y8b 888 "88b 888
867// "888 888 .d888888 888 88888888 888 888 888 88888888 888 888 888
868// Y88b d88P Y88b. 888 888 Y88b. Y8b. 888 888 888 Y8b. 888 888 Y88b.
869// "Y8888P" "Y888 "Y888888 "Y888 "Y8888 888 888 888 "Y8888 888 888 "Y888
870// MARK: Statement -
871// clang-format on
872
875{
876
877private:
878 class statement_impl;
879
880public:
882 {
883 public:
884 attribute(
885 long const& attribute,
886 long const& string_length,
887 variant const& resource) noexcept
888 : nanodbc::attribute(attribute, string_length, resource) {};
889
890 private:
891 friend class nanodbc::statement::statement_impl;
892 };
893
894public:
907
908public:
912
916 explicit statement(class connection& conn);
917
923 explicit statement(class connection& conn, std::list<attribute> const& attributes);
924
930 statement(class connection& conn, string const& query, long timeout = 0);
931
933 void swap(statement& rhs) noexcept;
934
938 void open(class connection& conn);
939
941 [[nodiscard]] bool open() const noexcept;
942
944 [[nodiscard]] bool connected() const noexcept;
945
947 class connection& connection() noexcept;
948
950 const class connection& connection() const noexcept;
951
953 [[nodiscard]] void* native_statement_handle() const noexcept;
954
956 void close();
957
960 void cancel();
961
968 void prepare(class connection& conn, string const& query, long timeout = 0);
969
977 void prepare(string const& query, long timeout = 0);
978
981 void timeout(long timeout = 0);
982
993 class result execute_direct(
994 class connection& conn,
995 string const& query,
996 long batch_operations = 1,
997 long timeout = 0);
998
1009 class result execute_direct(
1010 class connection& conn,
1011 string const& query,
1012 batch_ops const& array_sizes,
1013 long timeout = 0);
1014
1015#if !defined(NANODBC_DISABLE_ASYNC)
1032 bool async_prepare(string const& query, void* event_handle, long timeout = 0);
1033
1046
1067 class connection& conn,
1068 void* event_handle,
1069 string const& query,
1070 long batch_operations = 1,
1071 long timeout = 0);
1072
1090 bool async_execute(void* event_handle, long batch_operations = 1, long timeout = 0);
1091
1105 class result complete_execute(long batch_operations = 1);
1106
1108 void enable_async(void* event_handle);
1109
1111 void disable_async() const;
1112#endif
1113
1124 class connection& conn,
1125 string const& query,
1126 long batch_operations = 1,
1127 long timeout = 0);
1128
1137 class result execute(long batch_operations = 1, long timeout = 0);
1138
1153 class result execute(batch_ops const& array_sizes, long timeout = 0);
1154
1162 void just_execute(long batch_operations = 1, long timeout = 0);
1163
1171 class result procedure_columns(
1172 string const& catalog,
1173 string const& schema,
1174 string const& procedure,
1175 string const& column);
1176
1179 [[nodiscard]] long affected_rows() const;
1180
1183 [[nodiscard]] short columns() const;
1184
1186 void reset_parameters() noexcept;
1187
1190 short parameters() const;
1191
1193 unsigned long parameter_size(short param_index) const;
1194
1196 short parameter_scale(short param_index) const;
1197
1199 short parameter_type(short param_index) const;
1200
1212 bool parameter_is_null(short param_index, std::size_t batch_index = 0) const;
1213
1237
1250 template <class T>
1251 void bind(short param_index, T const* value, param_direction direction = PARAM_IN);
1252
1269 template <class T>
1270 void
1271 bind(short param_index, std::optional<T> const& value, param_direction direction = PARAM_IN)
1272 {
1273 if (!value.has_value())
1274 {
1275 bind_null(param_index, 1);
1276 return;
1277 }
1278 if constexpr (is_owning_string_v<T>)
1279 bind(param_index, value->c_str(), direction);
1280 else
1281 bind(param_index, &*value, direction);
1282 }
1283
1302
1305 template <class T>
1306 void bind(
1307 short param_index,
1308 T const* values,
1309 std::size_t batch_size,
1310 param_direction direction = PARAM_IN);
1311
1314 template <class T>
1315 void bind(
1316 short param_index,
1317 T const* values,
1318 std::size_t batch_size,
1319 T const* null_sentry,
1320 param_direction direction = PARAM_IN);
1321
1324 template <class T>
1325 void bind(
1326 short param_index,
1327 T const* values,
1328 std::size_t batch_size,
1329 bool const* nulls,
1330 param_direction direction = PARAM_IN);
1331
1334 void bind(
1335 short param_index,
1336 std::vector<std::vector<uint8_t>> const& values,
1337 param_direction direction = PARAM_IN);
1338
1341 void bind(
1342 short param_index,
1343 std::vector<std::vector<uint8_t>> const& values,
1344 bool const* nulls,
1345 param_direction direction = PARAM_IN);
1346
1355 short param_index,
1356 std::vector<std::vector<uint8_t>> const& values,
1357 uint8_t const* null_sentry,
1358 param_direction direction = PARAM_IN);
1359
1362 void bind(
1363 short param_index,
1364 std::vector<std::vector<uint8_t>> const& values,
1365 std::vector<uint8_t> const& null_sentry,
1366 param_direction direction = PARAM_IN);
1367
1374 template <class T>
1375 void
1376 bind(short param_index, std::vector<T> const& values, param_direction direction = PARAM_IN);
1377
1380 template <class T>
1381 void bind(
1382 short param_index,
1383 std::vector<T> const& values,
1384 bool const* nulls,
1385 param_direction direction = PARAM_IN);
1386
1403 template <class T>
1404 void bind(
1405 short param_index,
1406 std::vector<std::optional<T>> const& values,
1407 param_direction direction = PARAM_IN)
1408 {
1409 std::vector<T> column;
1410 auto const nulls = detail::split_optional(values, column);
1411 bind(param_index, column, nulls.get(), direction);
1412 }
1413
1415
1436
1439 template <class T, typename = enable_if_character<T>>
1441 short param_index,
1442 T const* values,
1443 std::size_t value_size,
1444 std::size_t batch_size,
1445 param_direction direction = PARAM_IN);
1446
1453 template <class T, typename = enable_if_string<T>>
1455 short param_index,
1456 std::vector<T> const& values,
1457 param_direction direction = PARAM_IN);
1458
1461 template <
1462 std::size_t BatchSize,
1463 std::size_t ValueSize,
1464 class T,
1465 typename = enable_if_character<T>>
1467 short param_index,
1468 T const (&values)[BatchSize][ValueSize],
1469 param_direction direction = PARAM_IN)
1470 {
1471 auto param_values = reinterpret_cast<T const*>(values);
1472 bind_strings(param_index, param_values, ValueSize, BatchSize, direction);
1473 }
1474
1477 template <class T, typename = enable_if_character<T>>
1479 short param_index,
1480 T const* values,
1481 std::size_t value_size,
1482 std::size_t batch_size,
1483 T const* null_sentry,
1484 param_direction direction = PARAM_IN);
1485
1488 template <class T, typename = enable_if_string<T>>
1490 short param_index,
1491 std::vector<T> const& values,
1492 typename T::value_type const* null_sentry,
1493 param_direction direction = PARAM_IN);
1494
1497 template <
1498 std::size_t BatchSize,
1499 std::size_t ValueSize,
1500 class T,
1501 typename = enable_if_character<T>>
1503 short param_index,
1504 T const (&values)[BatchSize][ValueSize],
1505 T const* null_sentry,
1506 param_direction direction = PARAM_IN)
1507 {
1508 auto param_values = reinterpret_cast<T const*>(values);
1509 bind_strings(param_index, param_values, ValueSize, BatchSize, null_sentry, direction);
1510 }
1511
1514 template <class T, typename = enable_if_character<T>>
1516 short param_index,
1517 T const* values,
1518 std::size_t value_size,
1519 std::size_t batch_size,
1520 bool const* nulls,
1521 param_direction direction = PARAM_IN);
1522
1525 template <class T, typename = enable_if_string<T>>
1527 short param_index,
1528 std::vector<T> const& values,
1529 bool const* nulls,
1530 param_direction direction = PARAM_IN);
1531
1534 template <
1535 std::size_t BatchSize,
1536 std::size_t ValueSize,
1537 class T,
1538 typename = enable_if_character<T>>
1540 short param_index,
1541 T const (&values)[BatchSize][ValueSize],
1542 bool const* nulls,
1543 param_direction direction = PARAM_IN)
1544 {
1545 auto param_values = reinterpret_cast<T const*>(values);
1546 bind_strings(param_index, param_values, ValueSize, BatchSize, nulls, direction);
1547 }
1548
1566 template <class T, typename = enable_if_string<T>>
1568 short param_index,
1569 std::vector<std::optional<T>> const& values,
1570 param_direction direction = PARAM_IN)
1571 {
1572 std::vector<T> column;
1573 auto const nulls = detail::split_optional(values, column);
1574 bind_strings(param_index, column, nulls.get(), direction);
1575 }
1576
1578
1590 void bind_null(short param_index, std::size_t batch_size = 1);
1591
1593
1612 const std::vector<short>& idx,
1613 const std::vector<short>& type,
1614 const std::vector<unsigned long>& size,
1615 const std::vector<short>& scale);
1616
1617private:
1618 using null_predicate_type = std::function<bool(std::size_t)>;
1619 friend class nanodbc::result;
1620#ifndef NANODBC_DISABLE_MSSQL_TVP
1621 friend class nanodbc::table_valued_parameter::table_valued_parameter_impl;
1622#endif
1623
1624private:
1625 std::shared_ptr<statement_impl> impl_;
1626};
1627
1628// clang-format off
1629// .d8888b. 888 d8b
1630// d88P Y88b 888 Y8P
1631// 888 888 888
1632// 888 .d88b. 88888b. 88888b. .d88b. .d8888b 888888 888 .d88b. 88888b.
1633// 888 d88""88b 888 "88b 888 "88b d8P Y8b d88P" 888 888 d88""88b 888 "88b
1634// 888 888 888 888 888 888 888 888 88888888 888 888 888 888 888 888 888
1635// Y88b d88P Y88..88P 888 888 888 888 Y8b. Y88b. Y88b. 888 Y88..88P 888 888
1636// "Y8888P" "Y88P" 888 888 888 888 "Y8888 "Y8888P "Y888 888 "Y88P" 888 888
1637// MARK: Connection -
1638// clang-format on
1639
1642{
1643
1644private:
1645 class connection_impl;
1646 friend class nanodbc::transaction::transaction_impl;
1647
1648public:
1650 {
1651 public:
1652 attribute(
1653 long const& attribute,
1654 long const& string_length,
1655 variant const& resource) noexcept
1656 : nanodbc::attribute(attribute, string_length, resource) {};
1657
1658 private:
1659 friend class nanodbc::connection::connection_impl;
1660 };
1661
1662public:
1665
1667 void swap(connection&) noexcept;
1668
1679 connection(string const& dsn, string const& user, string const& pass, long timeout = 0);
1680
1690 explicit connection(string const& connection_string, long timeout = 0);
1691
1704
1706 string const& dsn,
1707 string const& user,
1708 string const& pass,
1709 std::list<attribute> const& attributes);
1720 connection(string const& connection_string, std::list<attribute> const& attributes);
1721
1730 void allocate();
1731
1735
1743 void connect(string const& dsn, string const& user, string const& pass, long timeout = 0);
1744
1750 void connect(string const& connection_string, long timeout = 0);
1751
1761 string const& dsn,
1762 string const& user,
1763 string const& pass,
1764 std::list<attribute> const& attributes);
1765
1772 void connect(string const& connection_string, std::list<attribute> const& attributes);
1773
1790 string browse_connect(string const& connection_string, bool& more_wanted);
1791#if !defined(NANODBC_DISABLE_ASYNC)
1810 string const& dsn,
1811 string const& user,
1812 string const& pass,
1813 void* event_handle,
1814 long timeout = 0);
1815
1831 bool async_connect(string const& connection_string, void* event_handle, long timeout = 0);
1832
1838#endif
1839
1845 [[nodiscard]] bool connected() const noexcept;
1846
1848 void disconnect();
1849
1851 [[nodiscard]] std::size_t transactions() const noexcept;
1852
1854 [[nodiscard]] void* native_dbc_handle() const noexcept;
1855
1857 [[nodiscard]] void* native_env_handle() const noexcept;
1858
1862 template <class T>
1863 T get_info(short info_type) const;
1864
1868 string dbms_name() const;
1869
1873 string dbms_version() const;
1874
1877 string driver_name() const;
1878
1881 string driver_version() const;
1882
1885 string database_name() const;
1886
1889 string catalog_name() const;
1890
1891private:
1892 std::size_t ref_transaction() noexcept;
1893 std::size_t unref_transaction() noexcept;
1894 bool rollback() const noexcept;
1895 void rollback(bool onoff) noexcept;
1896 bool restore_autocommit() const noexcept;
1897 void restore_autocommit(bool onoff) noexcept;
1898
1899private:
1900 std::shared_ptr<connection_impl> impl_;
1901};
1902
1903// clang-format off
1904// 8888888b. 888 888
1905// 888 Y88b 888 888
1906// 888 888 888 888
1907// 888 d88P .d88b. .d8888b 888 888 888 888888
1908// 8888888P" d8P Y8b 88K 888 888 888 888
1909// 888 T88b 88888888 "Y8888b. 888 888 888 888
1910// 888 T88b Y8b. X88 Y88b 888 888 Y88b.
1911// 888 T88b "Y8888 88888P' "Y88888 888 "Y888
1912// MARK: Result -
1913// clang-format on
1914
1915class catalog;
1916class variant_row_cached_result;
1917
1923{
1924public:
1926 result() = default;
1927
1929 void swap(result& rhs) noexcept;
1930
1932 [[nodiscard]] void* native_statement_handle() const noexcept;
1933
1935 [[nodiscard]] long rowset_size() const noexcept;
1936
1939 [[nodiscard]] long affected_rows() const;
1940
1949 bool has_affected_rows() const;
1950
1952 [[nodiscard]] long rows() const noexcept;
1953
1956 [[nodiscard]] short columns() const;
1957
1961 [[nodiscard]] bool first();
1962
1966 [[nodiscard]] bool last();
1967
1971 [[nodiscard]] bool next();
1972
1973#if !defined(NANODBC_DISABLE_ASYNC)
1978 bool async_next(void* event_handle);
1979
1984#endif
1985
1989 [[nodiscard]] bool prior();
1990
1998 [[nodiscard]] bool move(long row);
1999
2003 [[nodiscard]] bool skip(long rows);
2004
2006 unsigned long position() const;
2007
2009 bool at_end() const noexcept;
2010
2016 void unbind();
2017
2025 void unbind(string const& column_name);
2026
2042 void unbind(short column);
2043
2060
2070 template <class T>
2071 void get_ref(short column, T& result) const;
2072
2084 template <class T>
2085 void get_ref(short column, T const& fallback, T& result) const;
2086
2095 template <class T>
2096 void get_ref(string const& column_name, T& result) const;
2097
2108 template <class T>
2109 void get_ref(string const& column_name, T const& fallback, T& result) const;
2110
2123 template <class T>
2124 [[nodiscard]] T get(short column) const;
2125
2136 template <class T>
2137 [[nodiscard]] T get(short column, T const& fallback) const;
2138
2158 template <class T>
2159 [[nodiscard]] T get_as(short column) const;
2160
2163 template <class T>
2164 [[nodiscard]] T get_as(string const& column_name) const;
2165
2173 template <class T>
2174 [[nodiscard]] T get(string const& column_name) const;
2175
2185 template <class T>
2186 [[nodiscard]] T get(string const& column_name, T const& fallback) const;
2187
2189
2207 template <class T>
2208 bool get_chunks(
2209 short column,
2210 std::function<void(T const&)> const& callback,
2211 std::size_t chunk_size = 65536) const;
2212
2215 template <class T>
2216 bool get_chunks(
2217 string const& column_name,
2218 std::function<void(T const&)> const& callback,
2219 std::size_t chunk_size = 65536) const;
2220
2242 [[nodiscard]] bool is_null(short column) const;
2243
2251 [[nodiscard]] bool is_null(string const& column_name) const;
2252
2263 bool is_bound(short column) const;
2264
2271 bool is_bound(string const& column_name) const;
2272
2278 [[nodiscard]] short column(string const& column_name) const;
2279
2285 [[nodiscard]] string column_name(short column) const;
2286
2292 [[nodiscard]] long column_size(short column) const;
2293
2295 [[nodiscard]] long column_size(string const& column_name) const;
2296
2305 int column_decimal_digits(short column) const;
2306
2308 int column_decimal_digits(string const& column_name) const;
2309
2311 [[nodiscard]] int column_datatype(short column) const;
2312
2314 [[nodiscard]] int column_datatype(string const& column_name) const;
2315
2323 string column_datatype_name(short column) const;
2324
2332 string column_datatype_name(string const& column_name) const;
2333
2335 int column_c_datatype(short column) const;
2336
2338 int column_c_datatype(string const& column_name) const;
2339
2347 bool column_unsigned(short column) const;
2348
2351 bool column_unsigned(string const& column_name) const;
2352
2354 bool next_result();
2355
2357 [[nodiscard]] explicit operator bool() const noexcept;
2358
2359private:
2360 result(statement statement, long rowset_size);
2361
2362 class result_impl;
2363 friend class nanodbc::statement::statement_impl;
2364 friend class nanodbc::catalog;
2365#ifdef _MSC_VER
2366 friend class nanodbc::variant_row_cached_result;
2367#endif
2368
2369private:
2370 std::shared_ptr<result_impl> impl_;
2371};
2372
2375{
2376public:
2377 using iterator_category = std::input_iterator_tag;
2379 using pointer = result*;
2381 using difference_type = std::ptrdiff_t;
2382
2384 result_iterator() = default;
2385
2388 : result_{r}
2389 {
2390 ++*this;
2391 }
2392
2394 reference operator*() const noexcept { return result_; }
2395
2398 {
2399 if (!result_)
2400 throw std::runtime_error("result is empty");
2401 return &operator*();
2402 }
2403
2406 {
2407 try
2408 {
2409 if (!result_.next())
2410 result_ = {};
2411 }
2412 catch (...)
2413 {
2414 result_ = {};
2415 }
2416 return *this;
2417 }
2418
2424 void operator++(int) { ++*this; }
2425
2427 bool operator==(result_iterator const& rhs) const noexcept
2428 {
2429 if (result_ && rhs.result_)
2430 return result_.native_statement_handle() == rhs.result_.native_statement_handle();
2431 else
2432 return !result_ && !rhs.result_;
2433 }
2434
2436 bool operator!=(result_iterator const& rhs) const noexcept { return !(*this == rhs); }
2437
2438private:
2439 mutable result result_;
2440};
2441
2444{
2445 return result_iterator(r);
2446}
2447
2454inline result_iterator end(result& /*r*/) noexcept
2455{
2456 return {};
2457}
2458
2459// clang-format off
2460// 8888888b. d8b 888
2461// 888 "Y88b Y8P 888
2462// 888 888 888
2463// 888 888 .d88b. .d8888b .d8888b 888d888 888 88888b. 888888 .d88b. 888d888 .d8888b
2464// 888 888 d8P Y8b 88K d88P" 888P" 888 888 "88b 888 d88""88b 888P" 88K
2465// 888 888 88888888 "Y8888b. 888 888 888 888 888 888 888 888 888 "Y8888b.
2466// 888 .d88P Y8b. X88 Y88b. 888 888 888 d88P Y88b. Y88..88P 888 X88
2467// 8888888P" "Y8888 88888P' "Y8888P 888 888 88888P" "Y888 "Y88P" 888 88888P'
2468// 888
2469// 888
2470// 888
2471// MARK: Descriptors -
2472// clang-format on
2473
2480{
2481public:
2484
2497
2499 auto alloc_type() const -> short;
2500
2502 auto count() const noexcept -> short;
2503
2504 // Descriptor record fields (records) accessors
2505
2507 auto auto_unique_value(short record) const -> bool;
2508
2510 auto base_column_name(short record) const -> string;
2511
2513 auto base_table_name(short record) const -> string;
2514
2516 auto case_sensitive(short record) const -> bool;
2517
2519 auto catalog_name(short record) const -> string;
2520
2522 auto concise_type(short record) const -> short;
2523
2525 auto display_size(short record) const -> std::int64_t;
2526
2528 auto fixed_prec_scale(short record) const -> short;
2529
2531 auto label(short record) const -> string;
2532
2534 auto length(short record) const -> std::uint64_t;
2535
2537 auto local_type_name(short record) const -> string;
2538
2540 auto name(short record) const -> string;
2541
2545 auto nullable(short record) const -> short;
2546
2548 auto num_prec_radix(short record) const -> short;
2549
2551 auto octet_length(short record) const -> std::int64_t;
2552
2554 auto precision(short record) const -> short;
2555
2557 auto rowver(short record) const -> short;
2558
2560 auto scale(short record) const -> short;
2561
2563 auto schema_name(short record) const -> string;
2564
2569 auto searchable(short record) const -> short;
2570
2572 auto table_name(short record) const -> string;
2573
2575 auto type(short record) const -> short;
2576
2578 auto type_name(short record) const -> string;
2579
2581 auto unnamed(short record) const -> bool;
2582
2584 auto unsigned_(short record) const -> bool;
2585
2590 auto updatable(short record) const -> short;
2591
2592private:
2593 // Convenience wrapper for SQLGetDescrField accesor.
2594 struct sql_get_descr_field
2595 {
2596 sql_get_descr_field(
2598 short record,
2599 std::uint16_t field_identifier) noexcept;
2600 operator std::int64_t() const;
2601 operator std::uint64_t() const;
2602 operator string() const;
2603
2605 short record_;
2606 std::uint16_t field_identifier_;
2607 };
2608 friend sql_get_descr_field;
2609
2610 void initialize_descriptor();
2611 void throw_if_record_is_out_of_range(short record) const;
2612
2613 void* statement_handle_{nullptr};
2614 short statement_columns_count_{0};
2615 void* descriptor_handle_{nullptr};
2616 short descriptor_records_count_{0};
2617};
2618
2619// clang-format off
2620//
2621// .d8888b. 888 888
2622// d88P Y88b 888 888
2623// 888 888 888 888
2624// 888 8888b. 888888 8888b. 888 .d88b. .d88b.
2625// 888 "88b 888 "88b 888 d88""88b d88P"88b
2626// 888 888 .d888888 888 .d888888 888 888 888 888 888
2627// Y88b d88P 888 888 Y88b. 888 888 888 Y88..88P Y88b 888
2628// "Y8888P" "Y888888 "Y888 "Y888888 888 "Y88P" "Y88888
2629// 888
2630// Y8b d88P
2631// "Y88P"
2632// MARK: Catalog -
2633// clang-format on
2634
2641{
2642public:
2645 {
2646 public:
2647 [[nodiscard]] bool next();
2648 string table_catalog() const;
2649 string table_schema() const;
2650 string table_name() const;
2651 string table_type() const;
2652 string table_remarks() const;
2653
2654 private:
2655 friend class nanodbc::catalog;
2656 explicit tables(result& find_result) noexcept;
2657 result result_;
2658 };
2659
2662 {
2663 public:
2664 [[nodiscard]] bool next();
2665 string table_catalog() const;
2666 string table_schema() const;
2667 string table_name() const;
2668 string column_name() const;
2669 short data_type() const;
2670 string type_name() const;
2671 long column_size() const;
2672 long buffer_length() const;
2673 short decimal_digits() const;
2675 short nullable() const;
2676 string remarks() const;
2677 string column_default() const;
2678 short sql_data_type() const;
2679 short sql_datetime_subtype() const;
2680 long char_octet_length() const;
2681
2685 long ordinal_position() const;
2686
2692 string is_nullable() const;
2693
2694 private:
2695 friend class nanodbc::catalog;
2696 explicit columns(result& find_result) noexcept;
2697 result result_;
2698 };
2699
2702 {
2703 public:
2704 [[nodiscard]] bool next();
2705 string table_catalog() const;
2706 string table_schema() const;
2707 string table_name() const;
2708 string column_name() const;
2709
2712 short column_number() const;
2713
2717 string primary_key_name() const;
2718
2719 private:
2720 friend class nanodbc::catalog;
2721 explicit primary_keys(result& find_result) noexcept;
2722 result result_;
2723 };
2724
2727 {
2728 public:
2729 [[nodiscard]] bool next();
2730 string table_catalog() const;
2731 string table_schema() const;
2732 string table_name() const;
2733 string grantor() const;
2734 string grantee() const;
2735 string privilege() const;
2737 string is_grantable() const;
2738
2739 private:
2740 friend class nanodbc::catalog;
2741 explicit table_privileges(result& find_result) noexcept;
2742 result result_;
2743 };
2744
2747 {
2748 public:
2749 [[nodiscard]] bool next();
2750 string procedure_catalog() const;
2751 string procedure_schema() const;
2752 string procedure_name() const;
2753 string procedure_remarks() const;
2754 short procedure_type() const;
2755
2756 private:
2757 friend class nanodbc::catalog;
2758 explicit procedures(result& find_result) noexcept;
2759 result result_;
2760 };
2761
2764 {
2765 public:
2766 [[nodiscard]] bool next();
2767 string procedure_catalog() const;
2768 string procedure_schema() const;
2769 string procedure_name() const;
2770 string column_name() const;
2771 short column_type() const;
2772 short data_type() const;
2773 string type_name() const;
2774 long column_size() const;
2775 long buffer_length() const;
2776 short decimal_digits() const;
2778 short nullable() const;
2779 string remarks() const;
2780 string column_default() const;
2781 short sql_data_type() const;
2782 short sql_datetime_subtype() const;
2783 long char_octet_length() const;
2784
2788 long ordinal_position() const;
2789
2795 string is_nullable() const;
2796
2797 private:
2798 friend class nanodbc::catalog;
2799 explicit procedure_columns(result& find_result) noexcept;
2800 result result_;
2801 };
2802
2804 explicit catalog(connection& conn) noexcept;
2805
2816 string const& table = {},
2817 string const& type = {},
2818 string const& schema = {},
2819 string const& catalog = {});
2820
2835 string const& catalog,
2836 string const& table = {},
2837 string const& schema = {});
2838
2849 string const& column = {},
2850 string const& table = {},
2851 string const& schema = {},
2852 string const& catalog = {});
2853
2862 catalog::primary_keys
2863 find_primary_keys(string const& table, string const& schema = {}, string const& catalog = {});
2864
2874
2876 string const& procedure = {},
2877 string const& schema = {},
2878 string const& catalog = {});
2879
2891 string const& column = {},
2892 string const& procedure = {},
2893 string const& schema = {},
2894 string const& catalog = {});
2895
2899 std::list<string> list_catalogs();
2900
2904 std::list<string> list_schemas();
2905
2910 std::list<string> list_table_types();
2911
2912private:
2913 connection conn_;
2914};
2915
2917
2918// clang-format off
2919// 8888888888 8888888888 888 d8b
2920// 888 888 888 Y8P
2921// 888 888 888
2922// 8888888 888d888 .d88b. .d88b. 8888888 888 888 88888b. .d8888b 888888 888 .d88b. 88888b. .d8888b
2923// 888 888P" d8P Y8b d8P Y8b 888 888 888 888 "88b d88P" 888 888 d88""88b 888 "88b 88K
2924// 888 888 88888888 88888888 888 888 888 888 888 888 888 888 888 888 888 888 "Y8888b.
2925// 888 888 Y8b. Y8b. 888 Y88b 888 888 888 Y88b. Y88b. 888 Y88..88P 888 888 X88
2926// 888 888 "Y8888 "Y8888 888 "Y88888 888 888 "Y8888P "Y888 888 "Y88P" 888 888 88888P'
2928namespace detail
2929{
2930
2931// Moves what a column held, which get<std::any>() worked out from the type the driver
2932// reports, into whatever the caller asked to hold it.
2933template <class T>
2934struct hold_column_value;
2935
2936template <>
2937struct hold_column_value<std::any>
2938{
2939 static std::any from(std::any value) noexcept { return value; }
2940};
2941
2942template <class Alternative, class Variant>
2943inline bool hold_alternative(Variant& variant, std::any const& value)
2944{
2945 if (auto const* held = std::any_cast<Alternative>(&value))
2946 {
2947 variant = *held;
2948 return true;
2949 }
2950 return false;
2951}
2952
2953template <class... Ts>
2954struct hold_column_value<std::variant<Ts...>>
2955{
2956 static std::variant<Ts...> from(std::any const& value)
2957 {
2958 std::variant<Ts...> variant;
2959 if (!value.has_value())
2960 return variant; // the first alternative, which is what monostate is for
2961
2962 // A disjunction fold, which stops at the first alternative able to hold it.
2963 bool const held = (hold_alternative<Ts>(variant, value) || ...);
2964
2965 // The column holds something none of the alternatives can, which the compiler
2966 // cannot catch: what a column holds is only known once the driver has said.
2967 if (!held)
2968 throw type_incompatible_error();
2969
2970 return variant;
2971 }
2972};
2973
2974} // namespace detail
2975
2976template <class T>
2977T result::get_as(short column) const
2978{
2979 return detail::hold_column_value<T>::from(get<std::any>(column));
2980}
2981
2982template <class T>
2983T result::get_as(string const& column_name) const
2984{
2985 return get_as<T>(this->column(column_name));
2986}
2987
2988// MARK: Free Functions -
2989// clang-format on
2990
2995
2998{
3005
3007 std::list<attribute> attributes;
3008};
3009
3016
3018std::list<driver> list_drivers();
3019
3021std::list<datasource> list_datasources();
3022
3033result execute(connection& conn, string const& query, long batch_operations = 1, long timeout = 0);
3034
3044 connection& conn,
3045 string const& query,
3046 long batch_operations = 1,
3047 long timeout = 0);
3048
3050namespace detail
3051{
3052
3054template <class Row, class Member, class Class>
3055Member const& read_field(Row const& row, Member Class::* field)
3056{
3057 return row.*field;
3058}
3059
3061template <class Row, class Accessor>
3062auto read_field(Row const& row, Accessor const& accessor) -> decltype(accessor(row))
3063{
3064 return accessor(row);
3065}
3066
3068template <class Row, class Accessor>
3070{
3071 using type = std::decay_t<
3072 decltype(read_field(std::declval<Row const&>(), std::declval<Accessor const&>()))>;
3073};
3074
3075template <class T>
3076struct is_optional : std::false_type
3077{
3078};
3079
3080template <class T>
3081struct is_optional<std::optional<T>> : std::true_type
3082{
3083};
3084
3085template <class T>
3086inline constexpr bool is_optional_v = is_optional<T>::value;
3087
3088// Four ways to bind a column, told apart by what the accessor yields.
3090{
3091};
3093{
3094};
3096{
3097};
3099{
3100};
3101
3102template <class T, bool IsOptional = is_optional_v<T>>
3104{
3105 using type = std::conditional_t<is_owning_string_v<T>, bind_as_string, bind_as_value>;
3106};
3107
3108template <class T>
3109struct bind_kind<T, true>
3110{
3111 using type = std::conditional_t<
3112 is_owning_string_v<typename T::value_type>,
3115};
3116
3117template <class Rows, class Accessor>
3118void bind_column(
3119 statement& stmt,
3120 short param_index,
3121 Rows const& rows,
3122 Accessor const& accessor,
3124{
3125 using value_type = typename field_type<typename Rows::value_type, Accessor>::type;
3126 std::vector<value_type> column;
3127 column.reserve(rows.size());
3128 for (auto const& row : rows)
3129 column.push_back(read_field(row, accessor));
3130 stmt.bind(param_index, column);
3131}
3132
3133template <class Rows, class Accessor>
3134void bind_column(
3135 statement& stmt,
3136 short param_index,
3137 Rows const& rows,
3138 Accessor const& accessor,
3139 bind_as_string)
3140{
3141 using value_type = typename field_type<typename Rows::value_type, Accessor>::type;
3142 std::vector<value_type> column;
3143 column.reserve(rows.size());
3144 for (auto const& row : rows)
3145 column.push_back(read_field(row, accessor));
3146 stmt.bind_strings(param_index, column);
3147}
3148
3149// An absent value still occupies its place in the column, so that the values line up with
3150// the flags marking which of them are null.
3151template <class Rows, class Accessor, class Column>
3152std::unique_ptr<bool[]> gather_optional(Rows const& rows, Accessor const& accessor, Column& column)
3153{
3154 auto nulls = std::make_unique<bool[]>(rows.size());
3155 std::size_t i = 0;
3156 for (auto const& row : rows)
3157 {
3158 auto const& value = read_field(row, accessor);
3159 nulls[i++] = !value.has_value();
3160 column.push_back(value ? *value : typename Column::value_type());
3161 }
3162 return nulls;
3163}
3164
3165template <class Rows, class Accessor>
3166void bind_column(
3167 statement& stmt,
3168 short param_index,
3169 Rows const& rows,
3170 Accessor const& accessor,
3171 bind_as_optional_value)
3172{
3173 using optional_type = typename field_type<typename Rows::value_type, Accessor>::type;
3174 std::vector<typename optional_type::value_type> column;
3175 column.reserve(rows.size());
3176 auto const nulls = gather_optional(rows, accessor, column);
3177 stmt.bind(param_index, column, nulls.get());
3178}
3179
3180template <class Rows, class Accessor>
3181void bind_column(
3182 statement& stmt,
3183 short param_index,
3184 Rows const& rows,
3185 Accessor const& accessor,
3186 bind_as_optional_string)
3187{
3188 using optional_type = typename field_type<typename Rows::value_type, Accessor>::type;
3189 std::vector<typename optional_type::value_type> column;
3190 column.reserve(rows.size());
3191 auto const nulls = gather_optional(rows, accessor, column);
3192 stmt.bind_strings(param_index, column, nulls.get());
3193}
3194
3195template <class Rows, class Accessor>
3196void bind_one(statement& stmt, short param_index, Rows const& rows, Accessor const& accessor)
3197{
3198 using value_type = typename field_type<typename Rows::value_type, Accessor>::type;
3199 bind_column(stmt, param_index, rows, accessor, typename bind_kind<value_type>::type());
3200}
3201
3202} // namespace detail
3203
3234template <class Rows, class... Accessors>
3235void bind_rows(statement& stmt, Rows const& rows, Accessors const&... accessors)
3236{
3237 short param_index = 0;
3238 // A comma fold, which is ordered left to right, so the accessors line up with the
3239 // parameter markers in the order they were named.
3240 (detail::bind_one(stmt, param_index++, rows, accessors), ...);
3241}
3242
3251result execute(statement& stmt, long batch_operations = 1);
3252
3260void just_execute(statement& stmt, long batch_operations = 1);
3261
3270result transact(statement& stmt, long batch_operations);
3271
3279void just_transact(statement& stmt, long batch_operations);
3280
3290void prepare(statement& stmt, string const& query, long timeout = 0);
3291
3293
3294} // namespace nanodbc
3295
3296#endif
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:2662
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:2702
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:2764
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:2747
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:2727
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:2645
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:2641
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:1650
Manages and encapsulates ODBC resources such as the connection and environment handles.
Definition nanodbc.h:1642
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:2480
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:2375
reference operator*() const noexcept
Dereference.
Definition nanodbc.h:2394
pointer operator->() const
Access through dereference.
Definition nanodbc.h:2397
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:2436
std::ptrdiff_t difference_type
Iterator difference.
Definition nanodbc.h:2381
std::input_iterator_tag iterator_category
Category of iterator.
Definition nanodbc.h:2377
void operator++(int)
Iteration.
Definition nanodbc.h:2424
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:2427
result_iterator & operator++()
Iteration.
Definition nanodbc.h:2405
result_iterator(result &r)
Create result iterator for a given result set.
Definition nanodbc.h:2387
A resource for managing result sets from statement execution.
Definition nanodbc.h:1923
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.
Definition nanodbc.h:882
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:1404
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:1539
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:1567
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:1466
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:1502
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:2454
result_iterator begin(result &r)
Returns an iterator to the beginning of the given result set.
Definition nanodbc.h:2443
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:3235
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:3055
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:3012
nanodbc::string driver
Driver description.
Definition nanodbc.h:3014
nanodbc::string name
DSN name.
Definition nanodbc.h:3013
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:3093
Definition nanodbc.h:3090
Definition nanodbc.h:3104
The type an accessor yields for a row, stripped of reference and const.
Definition nanodbc.h:3070
Definition nanodbc.h:3077
Driver attributes.
Definition nanodbc.h:3001
nanodbc::string keyword
Driver keyword attribute.
Definition nanodbc.h:3002
nanodbc::string value
Driver attribute value.
Definition nanodbc.h:3003
Information on a configured ODBC driver.
Definition nanodbc.h:2998
nanodbc::string name
Driver name.
Definition nanodbc.h:3006
std::list< attribute > attributes
List of driver attributes.
Definition nanodbc.h:3007
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