1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
//! ODBC types those representation is compatible with the ODBC C API.
//!
//! This layer has not been created using automatic code generation. It is incomplete, i.e. it does
//! not contain every symbol or constant defined in the ODBC C headers. Symbols which are
//! deprecated since ODBC 3 have been left out intentionally. While some extra type safety has been
//! added by grouping some of C's `#define` constants into `enum`-types it mostly offers the same
//! power (all) and safety guarantess(none) as the wrapped C-API.
//! ODBC 4.0 is still under development by Microsoft, so these symbols are deactivated by default
//! in the cargo.toml

pub use self::attributes::*;
pub use self::c_data_type::*;
pub use self::fetch_orientation::*;
pub use self::info_type::*;
pub use self::input_output::*;
pub use self::nullable::*;
pub use self::sql_bulk_operations::*;
pub use self::sqlreturn::*;
use std::os::raw::c_void;

mod attributes;
mod c_data_type;
mod fetch_orientation;
mod info_type;
mod input_output;
mod nullable;
mod sql_bulk_operations;
mod sqlreturn;

//These types can never be instantiated in Rust code.
pub enum Obj {}

pub enum Env {}

pub enum Dbc {}

pub enum Stmt {}

pub enum Desc {}

pub type SQLHANDLE = *mut Obj;
pub type SQLHENV = *mut Env;
pub type SQLHDESC = *mut Desc;

/// The connection handle references storage of all information about the connection to the data
/// source, including status, transaction state, and error information.
pub type SQLHDBC = *mut Dbc;
pub type SQLHSTMT = *mut Stmt;

pub type SQLSMALLINT = i16;
pub type SQLUSMALLINT = u16;
pub type SQLINTEGER = i32;
pub type SQLUINTEGER = u32;
pub type SQLPOINTER = *mut c_void;
pub type SQLCHAR = u8;
pub type SQLWCHAR = u16;

#[cfg(target_pointer_width = "64")]
pub type SQLLEN = i64;
#[cfg(target_pointer_width = "32")]
pub type SQLLEN = SQLINTEGER;

#[cfg(target_pointer_width = "64")]
pub type SQLULEN = u64;
#[cfg(target_pointer_width = "32")]
pub type SQLULEN = SQLUINTEGER;

pub type SQLHWND = SQLPOINTER;

pub type RETCODE = i16;

// flags for null-terminated string
pub const SQL_NTS: SQLSMALLINT = -3;
pub const SQL_NTSL: SQLINTEGER = -3;

/// Maximum message length
pub const SQL_MAX_MESSAGE_LENGTH: SQLSMALLINT = 512;
pub const SQL_SQLSTATE_SIZE: usize = 5;
pub const SQL_SQLSTATE_SIZEW: usize = 10;

// Special SQLGetData indicator values
pub const SQL_NULL_DATA: SQLLEN = -1;
pub const SQL_NO_TOTAL: SQLLEN = -4;
pub const SQL_SS_LENGTH_UNLIMITED: SQLULEN = 0;

/// SQL Free Statement options
#[repr(u16)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum FreeStmtOption {
    /// Closes the cursor associated with StatementHandle (if one was defined) and discards all
    /// pending results. The application can reopen this cursor later by executing a SELECT
    /// statement again with the same or different parameter values. If no cursor is open, this
    /// option has no effect for the application. `SQLCloseCursor` can also be called to close a
    /// cursor.
    SQL_CLOSE = 0,
    // SQL_DROP = 1, is deprecated in favour of SQLFreeHandle
    /// Sets the `SQL_DESC_COUNT` field of the ARD to 0, releasing all column buffers bound by
    /// `SQLBindCol` for the given StatementHandle. This does not unbind the bookmark column; to do
    /// that, the `SQL_DESC_DATA_PTR` field of the ARD for the bookmark column is set to NULL.
    /// Notice that if this operation is performed on an explicitly allocated descriptor that is
    /// shared by more than one statement, the operation will affect the bindings of all statements
    /// that share the descriptor.
    SQL_UNBIND = 2,
    /// Sets the `SQL_DESC_COUNT` field of the APD to 0, releasing all parameter buffers set by
    /// `SQLBindParameter` for the given StatementHandle. If this operation is performed on an
    /// explicitly allocated descriptor that is shared by more than one statement, this operation
    /// will affect the bindings of all the statements that share the descriptor.
    SQL_RESET_PARAMS = 3,
}

pub use FreeStmtOption::*;

/// SQL Data Types
#[repr(i16)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlDataType {
    SQL_UNKNOWN_TYPE = 0,
    // also called SQL_VARIANT_TYPE since odbc 4.0
    SQL_CHAR = 1,
    SQL_NUMERIC = 2,
    SQL_DECIMAL = 3,
    SQL_INTEGER = 4,
    SQL_SMALLINT = 5,
    SQL_FLOAT = 6,
    SQL_REAL = 7,
    SQL_DOUBLE = 8,
    SQL_DATETIME = 9,
    SQL_VARCHAR = 12,
    #[cfg(feature = "odbc_version_4")]
    SQL_UDT = 17,
    #[cfg(feature = "odbc_version_4")]
    SQL_ROW = 19,
    #[cfg(feature = "odbc_version_4")]
    SQL_ARRAY = 50,
    #[cfg(feature = "odbc_version_4")]
    SQL_MULTISET = 55,

    // one-parameter shortcuts for date/time data types
    SQL_DATE = 91,
    SQL_TIME = 92,
    SQL_TIMESTAMP = 93,
    #[cfg(feature = "odbc_version_4")]
    SQL_TIME_WITH_TIMEZONE = 94,
    #[cfg(feature = "odbc_version_4")]
    SQL_TIMESTAMP_WITH_TIMEZONE = 95,

    //SQL extended datatypes:
    SQL_EXT_TIME_OR_INTERVAL = 10,
    SQL_EXT_TIMESTAMP = 11,
    SQL_EXT_LONGVARCHAR = -1,
    SQL_EXT_BINARY = -2,
    SQL_EXT_VARBINARY = -3,
    SQL_EXT_LONGVARBINARY = -4,
    SQL_EXT_BIGINT = -5,
    SQL_EXT_TINYINT = -6,
    SQL_EXT_BIT = -7,
    SQL_EXT_WCHAR = -8,
    SQL_EXT_WVARCHAR = -9,
    SQL_EXT_WLONGVARCHAR = -10,
    SQL_EXT_GUID = -11,
    SQL_SS_VARIANT = -150,
    SQL_SS_UDT = -151,
    SQL_SS_XML = -152,
    SQL_SS_TABLE = -153,
    SQL_SS_TIME2 = -154,
    SQL_SS_TIMESTAMPOFFSET = -155,
}

pub use self::SqlDataType::*;

/// Represented in C headers as SQLSMALLINT
#[repr(i16)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum HandleType {
    SQL_HANDLE_ENV = 1,
    SQL_HANDLE_DBC = 2,
    SQL_HANDLE_STMT = 3,
    SQL_HANDLE_DESC = 4,
}

pub use self::HandleType::*;

/// Options for `SQLDriverConnect`
#[repr(u16)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlDriverConnectOption {
    SQL_DRIVER_NOPROMPT = 0,
    SQL_DRIVER_COMPLETE = 1,
    SQL_DRIVER_PROMPT = 2,
    SQL_DRIVER_COMPLETE_REQUIRED = 3,
}

pub use self::SqlDriverConnectOption::*;

#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlAttributeStringLength {
    SQL_IS_POINTER = -4,
    SQL_IS_UINTEGER = -5,
    SQL_IS_INTEGER = -6,
    SQL_IS_USMALLINT = -7,
    SQL_IS_SMALLINT = -8,
}

pub use self::SqlAttributeStringLength::*;

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SQLINTERVAL {
    SQL_IS_YEAR = 1,
    SQL_IS_MONTH = 2,
    SQL_IS_DAY = 3,
    SQL_IS_HOUR = 4,
    SQL_IS_MINUTE = 5,
    SQL_IS_SECOND = 6,
    SQL_IS_YEAR_TO_MONTH = 7,
    SQL_IS_DAY_TO_HOUR = 8,
    SQL_IS_DAY_TO_MINUTE = 9,
    SQL_IS_DAY_TO_SECOND = 10,
    SQL_IS_HOUR_TO_MINUTE = 11,
    SQL_IS_HOUR_TO_SECOND = 12,
    SQL_IS_MINUTE_TO_SECOND = 13,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQL_YEAR_MONTH_STRUCT {
    pub year: SQLUINTEGER,
    pub month: SQLUINTEGER,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQL_DAY_SECOND_STRUCT {
    pub day: SQLUINTEGER,
    pub hour: SQLUINTEGER,
    pub minute: SQLUINTEGER,
    pub second: SQLUINTEGER,
    pub fraction: SQLUINTEGER,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub union SQL_INTERVAL_UNION {
    pub year_month: SQL_YEAR_MONTH_STRUCT,
    pub day_second: SQL_DAY_SECOND_STRUCT,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy)]
pub struct SQL_INTERVAL_STRUCT {
    pub interval_type: SQLINTERVAL,
    pub interval_sign: SQLSMALLINT,
    pub interval_value: SQL_INTERVAL_UNION,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQL_DATE_STRUCT {
    pub year: SQLSMALLINT,
    pub month: SQLUSMALLINT,
    pub day: SQLUSMALLINT,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQL_TIME_STRUCT {
    pub hour: SQLUSMALLINT,
    pub minute: SQLUSMALLINT,
    pub second: SQLUSMALLINT,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQL_TIMESTAMP_STRUCT {
    pub year: SQLSMALLINT,
    pub month: SQLUSMALLINT,
    pub day: SQLUSMALLINT,
    pub hour: SQLUSMALLINT,
    pub minute: SQLUSMALLINT,
    pub second: SQLUSMALLINT,
    pub fraction: SQLUINTEGER,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQLGUID {
    pub d1: u32,
    pub d2: u16,
    pub d3: u16,
    pub d4: [u8; 8],
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQL_SS_TIME2_STRUCT {
    pub hour: SQLUSMALLINT,
    pub minute: SQLUSMALLINT,
    pub second: SQLUSMALLINT,
    pub fraction: SQLUINTEGER,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
pub struct SQL_SS_TIMESTAMPOFFSET_STRUCT {
    pub year: SQLSMALLINT,
    pub month: SQLUSMALLINT,
    pub day: SQLUSMALLINT,
    pub hour: SQLUSMALLINT,
    pub minute: SQLUSMALLINT,
    pub second: SQLUSMALLINT,
    pub fraction: SQLUINTEGER,
    pub timezone_hour: SQLSMALLINT,
    pub timezone_minute: SQLSMALLINT,
}

/// Statement attributes for `SQLSetStmtAttr`
#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlStatementAttribute {
    SQL_ATTR_PARAM_BIND_TYPE = 18,
    SQL_ATTR_PARAMSET_SIZE = 22,
    SQL_ATTR_ROW_BIND_TYPE = 5,
    SQL_ATTR_ROW_ARRAY_SIZE = 27,
    SQL_ATTR_ROWS_FETCHED_PTR = 26,
    SQL_ATTR_ASYNC_ENABLE = 4,
}

pub use self::SqlStatementAttribute::*;

/// Connection attributes for `SQLSetConnectAttr`
#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlConnectionAttribute {
    SQL_ATTR_ASYNC_ENABLE = 4,
    SQL_ATTR_ACCESS_MODE = 101,
    SQL_ATTR_AUTOCOMMIT = 102,
    SQL_ATTR_LOGIN_TIMEOUT = 103,
    SQL_ATTR_TRACE = 104,
    SQL_ATTR_TRACEFILE = 105,
    SQL_ATTR_TRANSLATE_LIB = 106,
    SQL_ATTR_TRANSLATE_OPTION = 107,
    SQL_ATTR_TXN_ISOLATION = 108,
    SQL_ATTR_CURRENT_CATALOG = 109,
    SQL_ATTR_ODBC_CURSORS = 110,
    SQL_ATTR_QUIET_MODE = 111,
    SQL_ATTR_PACKET_SIZE = 112,
    SQL_ATTR_CONNECTION_TIMEOUT = 113,
    SQL_ATTR_DISCONNECT_BEHAVIOR = 114,
    SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE = 117,
    SQL_ATTR_ENLIST_IN_DTC = 1207,
    SQL_ATTR_ENLIST_IN_XA = 1208,
    SQL_ATTR_CONNECTION_DEAD = 1209,
    SQL_ATTR_AUTO_IPD = 10001,
    SQL_ATTR_METADATA_ID = 10014,
}

/// `DiagIdentifier` for `SQLGetDiagField`
#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlHeaderDiagnosticIdentifier {
    SQL_DIAG_RETURNCODE = 1,
    SQL_DIAG_NUMBER = 2,
    SQL_DIAG_ROW_COUNT = 3,
    SQL_DIAG_SQLSTATE = 4,
    SQL_DIAG_NATIVE = 5,
    SQL_DIAG_MESSAGE_TEXT = 6,
    SQL_DIAG_DYNAMIC_FUNCTION = 7,
    SQL_DIAG_CLASS_ORIGIN = 8,
    SQL_DIAG_SUBCLASS_ORIGIN = 9,
    SQL_DIAG_CONNECTION_NAME = 10,
    SQL_DIAG_SERVER_NAME = 11,
    SQL_DIAG_DYNAMIC_FUNCTION_CODE = 12,
    SQL_DIAG_CURSOR_ROW_COUNT = -1249,
    SQL_DIAG_ROW_NUMBER = -1248,
    SQL_DIAG_COLUMN_NUMBER = -1247,
}

#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlAsyncConnectionBehavior {
    SQL_ASYNC_DBC_ENABLE_ON = 1,
    SQL_ASYNC_DBC_ENABLE_OFF = 0,
}

pub use self::SqlAsyncConnectionBehavior::*;

impl Default for SqlAsyncConnectionBehavior {
    fn default() -> SqlAsyncConnectionBehavior {
        SqlAsyncConnectionBehavior::SQL_ASYNC_DBC_ENABLE_OFF
    }
}

#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlDynamicDiagnosticIdentifier {
    SQL_DIAG_ALTER_DOMAIN = 3,
    SQL_DIAG_ALTER_TABLE = 4,
    SQL_DIAG_CALL = 7,
    SQL_DIAG_CREATE_ASSERTION = 6,
    SQL_DIAG_CREATE_CHARACTER_SET = 8,
    SQL_DIAG_CREATE_COLLATION = 10,
    SQL_DIAG_CREATE_DOMAIN = 23,
    SQL_DIAG_CREATE_INDEX = -1,
    SQL_DIAG_CREATE_SCHEMA = 64,
    SQL_DIAG_CREATE_TABLE = 77,
    SQL_DIAG_CREATE_TRANSLATION = 79,
    SQL_DIAG_CREATE_VIEW = 84,
    SQL_DIAG_DELETE_WHERE = 19,
    SQL_DIAG_DROP_ASSERTION = 24,
    SQL_DIAG_DROP_CHARACTER_SET = 25,
    SQL_DIAG_DROP_COLLATION = 26,
    SQL_DIAG_DROP_DOMAIN = 27,
    SQL_DIAG_DROP_INDEX = -2,
    SQL_DIAG_DROP_SCHEMA = 31,
    SQL_DIAG_DROP_TABLE = 32,
    SQL_DIAG_DROP_TRANSLATION = 33,
    SQL_DIAG_DROP_VIEW = 36,
    SQL_DIAG_DYNAMIC_DELETE_CURSOR = 38,
    SQL_DIAG_DYNAMIC_UPDATE_CURSOR = 81,
    SQL_DIAG_GRANT = 48,
    SQL_DIAG_INSERT = 50,
    SQL_DIAG_REVOKE = 59,
    SQL_DIAG_SELECT_CURSOR = 85,
    SQL_DIAG_UNKNOWN_STATEMENT = 0,
    SQL_DIAG_UPDATE_WHERE = 82,
}

pub use self::SqlConnectionAttribute::*;

/// Completion types for `SQLEndTrans`
#[repr(i16)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlCompletionType {
    SQL_COMMIT = 0,
    SQL_ROLLBACK = 1,
}

pub use self::SqlCompletionType::*;

#[cfg_attr(windows, link(name = "odbc32"))]
#[cfg_attr(not(windows), link(name = "odbc"))]
extern "system" {
    /// Allocates an environment, connection, statement, or descriptor handle.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLAllocHandle(
        handle_type: HandleType,
        input_handle: SQLHANDLE,
        output_handle: *mut SQLHANDLE,
    ) -> SQLRETURN;

    /// Frees resources associated with a specific environment, connection, statement, or
    /// descriptor handle.
    ///
    /// If `SQL_ERRQR` is returned the handle is still valid.
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLFreeHandle(handle_type: HandleType, handle: SQLHANDLE) -> SQLRETURN;

    /// Gets attributes that govern aspects of environments
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLGetEnvAttr(
        environment_handle: SQLHENV,
        attribute: EnvironmentAttribute,
        value_ptr: SQLPOINTER,
        buffer_length: SQLINTEGER,
        string_length: *mut SQLINTEGER,
    ) -> SQLRETURN;

    /// Sets attributes that govern aspects of environments
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLSetEnvAttr(
        environment_handle: SQLHENV,
        attribute: EnvironmentAttribute,
        value: SQLPOINTER,
        string_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Closes the connection associated with a specific connection handle.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLDisconnect(connection_handle: SQLHDBC) -> SQLRETURN;

    /// Return the current values of multiple fields of a diagnostic record that contains eror,
    /// warning, and status information.
    ///
    /// # Returns
    ///
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLGetDiagRec(
        handle_type: HandleType,
        handle: SQLHANDLE,
        RecNumber: SQLSMALLINT,
        state: *mut SQLCHAR,
        native_error_ptr: *mut SQLINTEGER,
        message_text: *mut SQLCHAR,
        buffer_length: SQLSMALLINT,
        text_length_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Return the current values of multiple fields of a diagnostic record that contains eror,
    /// warning, and status information.
    ///
    /// # Returns
    ///
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLGetDiagRecW(
        handle_type: HandleType,
        handle: SQLHANDLE,
        record_rumber: SQLSMALLINT,
        state: *mut SQLWCHAR,
        native_error_ptr: *mut SQLINTEGER,
        message_text: *mut SQLWCHAR,
        buffer_length: SQLSMALLINT,
        text_length_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns the current value of a field of a record of the diagnostic data structure (associated with a specified handle) that contains error, warning, and status information.
    ///
    /// Note:
    /// `diag_identifier` is either `SqlHeaderDiagnosticIdentifier` or `SqlDynamicDiagnosticIdentifier`
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_NO_DATA`.
    pub fn SQLGetDiagFieldW(
        handle_type: HandleType,
        handle: SQLHANDLE,
        record_rumber: SQLSMALLINT,
        diag_identifier: SQLSMALLINT,
        diag_info_ptr: SQLPOINTER,
        buffer_length: SQLSMALLINT,
        string_length_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Executes a preparable statement, using the current values of the parameter marker variables
    /// if any parameters exist in the statement. This is the fastest way to submit an SQL
    /// statement for one-time execution
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_NEED_DATA`, `SQL_STILL_EXECUTING`, `SQL_ERROR`
    /// , `SQL_NO_DATA`, `SQL_INVALID_HANDLE`, or `SQL_PARAM_DATA_AVAILABLE`.
    pub fn SQLExecDirect(
        statement_handle: SQLHSTMT,
        statement_text: *const SQLCHAR,
        text_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Executes a preparable statement, using the current values of the parameter marker variables
    /// if any parameters exist in the statement. This is the fastest way to submit an SQL
    /// statement for one-time execution
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_NEED_DATA`, `SQL_STILL_EXECUTING`, `SQL_ERROR`
    /// , `SQL_NO_DATA`, `SQL_INVALID_HANDLE`, or `SQL_PARAM_DATA_AVAILABLE`.
    pub fn SQLExecDirectW(
        statement_handle: SQLHSTMT,
        statement_text: *const SQLWCHAR,
        text_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Returns the number of columns in a result set
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE` or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLNumResultCols(
        statement_handle: SQLHSTMT,
        column_count_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Determines whether more results are available on a statement
    /// containing SELECT, UPDATE, INSERT, or DELETE statements and, if so, initializes processing for those results.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_STILL_EXECUTING`, `SQL_NO_DATA`, `SQL_ERROR`,
    /// `SQL_INVALID_HANDLE`, or `SQL_PARAM_DATA_AVAILABLE`.
    pub fn SQLMoreResults(statement_handle: SQLHSTMT) -> SQLRETURN;

    // Can be used since odbc version 3.8 to stream results
    pub fn SQLGetData(
        statement_handle: SQLHSTMT,
        col_or_param_num: SQLUSMALLINT,
        target_type: SqlCDataType,
        target_value_ptr: SQLPOINTER,
        buffer_length: SQLLEN,
        str_len_or_ind_ptr: *mut SQLLEN,
    ) -> SQLRETURN;

    /// SQLGetTypeInfo returns information about data types supported by the data source.
    /// The driver returns the information in the form of an SQL result set.
    /// The data types are intended for use in Data Definition Language (DDL) statements.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_STILL_EXECUTING`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`.
    pub fn SQLGetTypeInfo(statement_handle: SQLHSTMT, data_type: SqlDataType) -> SQLRETURN;

    /// SQLFetch fetches the next rowset of data from the result set and returns data for all bound
    /// columns.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, `SQL_NO_DATA` or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLFetch(statement_handle: SQLHSTMT) -> SQLRETURN;

    /// Returns general information about the driver and data source associated with a connection
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLGetInfo(
        connection_handle: SQLHDBC,
        info_type: InfoType,
        info_value_ptr: SQLPOINTER,
        buffer_length: SQLSMALLINT,
        string_length_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns general information about the driver and data source associated with a connection
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLGetInfoW(
        connection_handle: SQLHDBC,
        info_type: InfoType,
        info_value_ptr: SQLPOINTER,
        buffer_length: SQLSMALLINT,
        string_length_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// SQLConnect establishes connections to a driver and a data source. The connection handle
    /// references storage of all information about the connection to the data source, including
    /// status, transaction state, and error information.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLConnectW(
        connection_handle: SQLHDBC,
        server_name: *const SQLWCHAR,
        name_length_1: SQLSMALLINT,
        user_name: *const SQLWCHAR,
        name_length_2: SQLSMALLINT,
        authentication: *const SQLWCHAR,
        name_length_3: SQLSMALLINT,
    ) -> SQLRETURN;

    /// SQLConnect establishes connections to a driver and a data source. The connection handle
    /// references storage of all information about the connection to the data source, including
    /// status, transaction state, and error information.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLConnect(
        connection_handle: SQLHDBC,
        server_name: *const SQLCHAR,
        name_length_1: SQLSMALLINT,
        user_name: *const SQLCHAR,
        name_length_2: SQLSMALLINT,
        authentication: *const SQLCHAR,
        name_length_3: SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns the list of table, catalog, or schema names, and table types, stored in a specific
    /// data source. The driver returns the information as a result set
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLTables(
        statement_handle: SQLHSTMT,
        catalog_name: *const SQLCHAR,
        name_length_1: SQLSMALLINT,
        schema_name: *const SQLCHAR,
        name_length_2: SQLSMALLINT,
        table_name: *const SQLCHAR,
        name_length_3: SQLSMALLINT,
        TableType: *const SQLCHAR,
        name_length_4: SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns the list of table, catalog, or schema names, and table types, stored in a specific
    /// data source. The driver returns the information as a result set
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLTablesW(
        statement_handle: SQLHSTMT,
        catalog_name: *const SQLWCHAR,
        name_length_1: SQLSMALLINT,
        schema_name: *const SQLWCHAR,
        name_length_2: SQLSMALLINT,
        table_name: *const SQLWCHAR,
        name_length_3: SQLSMALLINT,
        table_type: *const SQLWCHAR,
        name_length_4: SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns information about a data source. This function is implemented only by the Driver
    /// Manager.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_NO_DATA`
    pub fn SQLDataSources(
        environment_handle: SQLHENV,
        direction: FetchOrientation,
        server_name: *mut SQLCHAR,
        buffer_length_1: SQLSMALLINT,
        name_length_1: *mut SQLSMALLINT,
        description: *mut SQLCHAR,
        buffer_length_2: SQLSMALLINT,
        name_length_2: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns information about a data source. This function is implemented only by the Driver
    /// Manager.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_NO_DATA`
    pub fn SQLDataSourcesW(
        environment_handle: SQLHENV,
        direction: FetchOrientation,
        server_name: *mut SQLWCHAR,
        buffer_length_1: SQLSMALLINT,
        name_length_1: *mut SQLSMALLINT,
        description: *mut SQLWCHAR,
        buffer_length_2: SQLSMALLINT,
        name_length_2: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// An alternative to `SQLConnect`. It supports data sources that require more connection
    /// information than the three arguments in `SQLConnect`, dialog boxes to prompt the user for
    /// all connection information, and data sources that are not defined in the system information
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, `SQL_NO_DATA`,
    /// or `SQL_STILL_EXECUTING`
    pub fn SQLDriverConnect(
        connection_handle: SQLHDBC,
        window_handle: SQLHWND,
        in_connection_string: *const SQLCHAR,
        string_length_1: SQLSMALLINT,
        out_connection_string: *mut SQLCHAR,
        buffer_length: SQLSMALLINT,
        string_length_2: *mut SQLSMALLINT,
        DriverCompletion: SqlDriverConnectOption,
    ) -> SQLRETURN;

    /// An alternative to `SQLConnect`. It supports data sources that require more connection
    /// information than the three arguments in `SQLConnect`, dialog boxes to prompt the user for
    /// all connection information, and data sources that are not defined in the system information
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, `SQL_NO_DATA`,
    /// or `SQL_STILL_EXECUTING`
    pub fn SQLDriverConnectW(
        connection_handle: SQLHDBC,
        window_handle: SQLHWND,
        in_connection_string: *const SQLWCHAR,
        string_length_1: SQLSMALLINT,
        out_connection_string: *mut SQLWCHAR,
        buffer_length: SQLSMALLINT,
        string_length_2: *mut SQLSMALLINT,
        driver_completion: SqlDriverConnectOption,
    ) -> SQLRETURN;

    /// Lists driver descriptions and driver attribute keywords. This function is implemented only
    /// by the Driver Manager.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_NO_DATA`
    pub fn SQLDrivers(
        henv: SQLHENV,
        direction: FetchOrientation,
        driver_desc: *mut SQLCHAR,
        driver_desc_max: SQLSMALLINT,
        out_driver_desc: *mut SQLSMALLINT,
        driver_attributes: *mut SQLCHAR,
        drvr_attr_max: SQLSMALLINT,
        out_drvr_attr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Lists driver descriptions and driver attribute keywords. This function is implemented only
    /// by the Driver Manager.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_NO_DATA`
    pub fn SQLDriversW(
        henv: SQLHENV,
        direction: FetchOrientation,
        driver_desc: *mut SQLWCHAR,
        driver_desc_max: SQLSMALLINT,
        out_driver_desc: *mut SQLSMALLINT,
        driver_attributes: *mut SQLWCHAR,
        drvr_attr_max: SQLSMALLINT,
        out_drvr_attr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Closes a cursor that has been opened on a statement and discards pending results.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR` or `SQL_INVALID_HANDLE`
    pub fn SQLCloseCursor(hstmt: SQLHSTMT) -> SQLRETURN;

    /// Binds a buffer to a parameter marker in an SQL statement
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR` or `SQL_INVALID_HANDLE`
    pub fn SQLBindParameter(
        hstmt: SQLHSTMT,
        parameter_number: SQLUSMALLINT,
        input_output_type: InputOutput,
        value_type: SqlCDataType,
        parmeter_type: SqlDataType,
        column_size: SQLULEN,
        decimal_digits: SQLSMALLINT,
        parameter_value_ptr: SQLPOINTER,
        buffer_length: SQLLEN,
        str_len_or_ind_ptr: *mut SQLLEN,
    ) -> SQLRETURN;

    /// Performs bulk insertions and bulk bookmark operations, including update, delete, and fetch by bookmark.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_NEED_DATA`, `SQL_STILL_EXECUTING`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`.
    pub fn SQLBulkOperations(statement_handle: SQLHSTMT, operation: SqlBulkOperation) -> SQLRETURN;

    /// Cancels the processing on a statement.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR` or `SQL_INVALID_HANDLE`
    pub fn SQLCancel(statement_handle: SQLHSTMT) -> SQLRETURN;

    /// Cancels the processing on a connection or statement.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR` or `SQL_INVALID_HANDLE`
    pub fn SQLCancelHandle(handle_type: HandleType, handle: SQLHANDLE) -> SQLRETURN;

    /// Compiles the statement and generates an access plan.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLPrepare(
        hstmt: SQLHSTMT,
        statement_text: *const SQLCHAR,
        text_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Compiles the statement and generates an access plan.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or
    /// `SQL_STILL_EXECUTING`
    pub fn SQLPrepareW(
        hstmt: SQLHSTMT,
        statement_text: *const SQLWCHAR,
        text_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Executes a prepared statement, using the current values of the parameter marker variables
    /// if any paramater markers exis in the statement.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_NEED_DATA`, `SQL_STILL_EXECUTING`, `SQL_ERROR`
    /// , `SQL_NO_DATA`, `SQL_INVALID_HANDLE`, or `SQL_PARAM_DATA_AVAILABLE`.
    pub fn SQLExecute(hstmt: SQLHSTMT) -> SQLRETURN;

    /// Stops processing associated with a specific statement, closes any open cursors associated
    /// with the statement, discards pending results, or, optionally, frees all resources
    /// associated with the statement handle.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`.
    pub fn SQLFreeStmt(hstmt: SQLHSTMT, option: FreeStmtOption) -> SQLRETURN;

    /// Binds application data bufferst to columns in the result set.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`.
    pub fn SQLBindCol(
        hstmt: SQLHSTMT,
        col_number: SQLUSMALLINT,
        target_type: SqlCDataType,
        target_value: SQLPOINTER,
        buffer_length: SQLLEN,
        length_or_indicatior: *mut SQLLEN,
    ) -> SQLRETURN;

    /// SQLBrowseConnect supports an iterative method of discovering and enumerating the attributes
    /// and attribute values required to connect to a data source.
    /// Each call to SQLBrowseConnect returns successive levels of attributes and attribute values.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_NEED_DATA`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLBrowseConnectW(
        connection_handle: SQLHDBC,
        in_connection_string: *const SQLWCHAR,
        string_length: SQLSMALLINT,
        out_connection_string: *mut SQLWCHAR,
        buffer_length: SQLSMALLINT,
        out_buffer_length: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns descriptor information for a column in a result set.
    /// Descriptor information is returned as a character string,
    /// a descriptor-dependent value, or an integer value.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLColAttributeW(
        statement_handle: SQLHSTMT,
        column_number: SQLUSMALLINT,
        field_identifier: SQLUSMALLINT,
        character_attribute_ptr: SQLPOINTER,
        buffer_length: SQLSMALLINT,
        string_length_ptr: *mut SQLSMALLINT,
        numeric_attribute_ptr: *mut SQLLEN,
    ) -> SQLRETURN;

    /// Copies descriptor information from one descriptor handle to another.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_ERROR`, `SQL_NO_DATA`, or `SQL_INVALID_HANDLE`.
    pub fn SQLCopyDesc(source_desc_handle: SQLHDESC, target_desc_handle: SQLHDESC) -> SQLRETURN;

    /// Returns the current setting of a connection attribute.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_ERROR`, `SQL_NO_DATA`, or `SQL_INVALID_HANDLE`.
    pub fn SQLGetConnectAttrW(
        connection_handle: SQLHDBC,
        attribute: SqlConnectionAttribute,
        value_ptr: SQLPOINTER,
        buffer_length: SQLINTEGER,
        string_length_ptr: *mut SQLINTEGER,
    ) -> SQLRETURN;

    /// Returns the cursor name associated with a specified statement.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`.
    pub fn SQLGetCursorNameW(
        statement_handle: SQLHSTMT,
        cursor_name: *mut SQLWCHAR,
        buffer_length: SQLSMALLINT,
        name_length_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns the current setting or value of a single field of a descriptor record.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_NO_DATA`, or `SQL_INVALID_HANDLE`.
    /// `SQL_NO_DATA` is returned if RecNumber is greater than the current number of descriptor records.
    /// `SQL_NO_DATA` is returned if DescriptorHandle is an IRD handle and the statement is in the prepared or executed state but there was no open cursor associated with it.
    pub fn SQLGetDescFieldW(
        descriptor_handle: SQLHDESC,
        record_number: SQLSMALLINT,
        field_identifier: SQLSMALLINT,
        value_ptr: SQLPOINTER,
        buffer_length: SQLINTEGER,
        string_length_ptr: *mut SQLINTEGER,
    ) -> SQLRETURN;

    /// Returns the current settings or values of multiple fields of a descriptor record.
    /// The fields returned describe the name, data type, and storage of column or parameter data.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_NO_DATA`, or `SQL_INVALID_HANDLE`.
    /// `SQL_NO_DATA` is returned if RecNumber is greater than the current number of descriptor records.
    /// `SQL_NO_DATA` is returned if DescriptorHandle is an IRD handle and the statement is in the prepared or executed state but there was no open cursor associated with it.
    pub fn SQLGetDescRecW(
        descriptor_handle: SQLHDESC,
        record_number: SQLSMALLINT,
        name: *mut SQLWCHAR,
        buffer_length: SQLSMALLINT,
        string_length_ptr: *mut SQLSMALLINT,
        type_ptr: *mut SQLSMALLINT,
        sub_type_ptr: *mut SQLSMALLINT,
        length_ptr: *mut SQLLEN,
        precision_ptr: *mut SQLSMALLINT,
        scale_ptr: *mut SQLSMALLINT,
        nullable_ptr: *mut Nullable,
    ) -> SQLRETURN;

    /// Returns a list of columns and associated privileges for the specified table.
    /// The driver returns the information as a result set on the specified StatementHandle.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLColumnPrivilegesW(
        statement_handle: SQLHSTMT,
        catalog_name: *const SQLWCHAR,
        catalog_name_length: SQLSMALLINT,
        schema_name: *const SQLWCHAR,
        schema_name_length: SQLSMALLINT,
        table_name: *const SQLWCHAR,
        table_name_length: SQLSMALLINT,
        column_name: *const SQLWCHAR,
        column_name_length: SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns the list of column names in specified tables.
    /// The driver returns this information as a result set on the specified StatementHandle.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLColumnsW(
        statement_handle: SQLHSTMT,
        catalog_name: *const SQLWCHAR,
        catalog_name_length: SQLSMALLINT,
        schema_name: *const SQLWCHAR,
        schema_name_length: SQLSMALLINT,
        table_name: *const SQLWCHAR,
        table_name_length: SQLSMALLINT,
        column_name: *const SQLWCHAR,
        column_name_length: SQLSMALLINT,
    ) -> SQLRETURN;

    /// Can be used to determine when an asynchronous function is complete using either notification- or polling-based processing.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_ERROR`, `SQL_NO_DATA`, or `SQL_INVALID_HANDLE`.
    #[cfg(feature = "odbc_version_3_80")]
    pub fn SQLCompleteAsync(
        handle_type: HandleType,
        handle: SQLHANDLE,
        async_ret_code_ptr: *mut RETCODE,
    ) -> SQLRETURN;

    /// Returns the current setting of a statement attribute.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`
    pub fn SQLGetStmtAttrW(
        handle: SQLHSTMT,
        attribute: SqlStatementAttribute,
        value_ptr: SQLPOINTER,
        buffer_length: SQLINTEGER,
        string_length_ptr: *mut SQLINTEGER,
    ) -> SQLRETURN;

    /// Fetches the specified rowset of data from the result set and returns data for all bound columns.
    /// Rowsets can be specified at an absolute or relative position or by bookmark.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLFetchScroll(
        statement_handle: SQLHSTMT,
        fetch_orientation: FetchOrientation,
        fetch_offset: SQLLEN,
    ) -> SQLRETURN;

    /// Can return:
    /// - A list of foreign keys in the specified table (columns in the specified table that refer to primary keys in other tables).
    /// - A list of foreign keys in other tables that refer to the primary key in the specified table.
    ///
    /// The driver returns each list as a result set on the specified statement.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLForeignKeysW(
        statement_handle: SQLHSTMT,
        pk_catalog_name: *const SQLWCHAR,
        pk_catalog_name_length: SQLSMALLINT,
        pk_schema_name: *const SQLWCHAR,
        pk_schema_name_length: SQLSMALLINT,
        pk_table_name: *const SQLWCHAR,
        pk_table_name_length: SQLSMALLINT,
        fk_catalog_name: *const SQLWCHAR,
        fk_catalog_name_length: SQLSMALLINT,
        fk_schema_name: *const SQLWCHAR,
        fk_schema_name_length: SQLSMALLINT,
        fk_table_name: *const SQLWCHAR,
        fk_table_name_length: SQLSMALLINT,
    ) -> SQLRETURN;

    /// Returns the result descriptor for one column in the result set — column name, type, column
    /// size, decimal digits, and nullability.
    ///
    /// This information also is available in the fields of the IRD.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_STILL_EXECUTING`, `SQL_ERROR`, or
    /// `SQL_INVALID_HANDLE`.
    pub fn SQLDescribeCol(
        hstmt: SQLHSTMT,
        col_number: SQLUSMALLINT,
        col_name: *mut SQLCHAR,
        buffer_length: SQLSMALLINT,
        name_length: *mut SQLSMALLINT,
        data_type: *mut SqlDataType,
        col_size: *mut SQLULEN,
        decimal_digits: *mut SQLSMALLINT,
        nullable: *mut Nullable,
    ) -> SQLRETURN;

    /// Returns the result descriptor for one column in the result set — column name, type, column
    /// size, decimal digits, and nullability.
    ///
    /// This information also is available in the fields of the IRD.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_STILL_EXECUTING`, `SQL_ERROR`, or
    /// `SQL_INVALID_HANDLE`.
    pub fn SQLDescribeColW(
        hstmt: SQLHSTMT,
        col_number: SQLUSMALLINT,
        col_name: *mut SQLWCHAR,
        buffer_length: SQLSMALLINT,
        name_length: *mut SQLSMALLINT,
        data_type: *mut SqlDataType,
        col_size: *mut SQLULEN,
        decimal_digits: *mut SQLSMALLINT,
        nullable: *mut Nullable,
    ) -> SQLRETURN;

    /// Returns the description of a parameter marker associated with a prepared SQL statement.
    /// This information is also available in the fields of the IPD.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_STILL_EXECUTING`, `SQL_ERROR`, or
    /// `SQL_INVALID_HANDLE`.
    pub fn SQLDescribeParam(
        statement_handle: SQLHSTMT,
        parameter_number: SQLUSMALLINT,
        data_type_ptr: *mut SqlDataType,
        parameter_size_ptr: *mut SQLULEN,
        decimal_digits_ptr: *mut SQLSMALLINT,
        nullable_ptr: *mut SQLSMALLINT,
    ) -> SQLRETURN;

    /// Sets attributes related to a statement.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`.
    pub fn SQLSetStmtAttr(
        hstmt: SQLHSTMT,
        attr: SqlStatementAttribute,
        value: SQLPOINTER,
        str_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Sets attributes related to a statement.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, or `SQL_INVALID_HANDLE`.
    pub fn SQLSetStmtAttrW(
        hstmt: SQLHSTMT,
        attr: SqlStatementAttribute,
        value: SQLPOINTER,
        str_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Sets attributes that govern aspects of connections.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLSetConnectAttr(
        hdbc: SQLHDBC,
        attr: SqlConnectionAttribute,
        value: SQLPOINTER,
        str_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Sets attributes that govern aspects of connections.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLSetConnectAttrW(
        hdbc: SQLHDBC,
        attr: SqlConnectionAttribute,
        value: SQLPOINTER,
        str_length: SQLINTEGER,
    ) -> SQLRETURN;

    /// Requests a commit or rollback operation for all active operations on all statements associated with a handle.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR`, `SQL_INVALID_HANDLE`, or `SQL_STILL_EXECUTING`.
    pub fn SQLEndTran(
        handle_type: HandleType,
        handle: SQLHANDLE,
        completion_type: SqlCompletionType,
    ) -> SQLRETURN;

    /// Returns the number of rows affected by an UPDATE, INSERT, or DELETE statement; an `SQL_ADD`,
    /// `SQL_UPDATE_BY_BOOKMARK`, or `SQL_DELETE_BY_BOOKMARK` operation in SQLBulkOperations; or an
    /// `SQL_UPDATE` or `SQL_DELETE` operation in `SQLSetPos`.
    ///
    /// # Returns
    /// `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_INVALID_HANDLE`, or `SQL_ERROR`.
    pub fn SQLRowCount(hstmt: SQLHSTMT, row_count: *mut SQLLEN) -> SQLRETURN;
}