rs-odbc 0.2.0

Minimal safe Rust implementation of ODBC
Documentation
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
use crate::api::Descriptor;
use crate::attr::{Attr, AttrGet, AttrLen, AttrSet};
use crate::c_types::CScalar;
use crate::env::{OdbcVersion, SQL_OV_ODBC3, SQL_OV_ODBC3_80, SQL_OV_ODBC4};
use crate::handle::{RefSQLHDESC, RefUnsafeSQLHDESC, UnsafeSQLHDESC, SQLHDESC};
use crate::str::{OdbcChar, OdbcStr};
use crate::{
    Ident, OdbcBool, OdbcDefined, Scalar, SQLCHAR, SQLINTEGER, SQLSMALLINT, SQLUINTEGER, SQLULEN,
    SQLWCHAR,
};
use core::{cell::UnsafeCell, marker::PhantomData, mem::MaybeUninit};
use rs_odbc_derive::{odbc_type, Ident};

// TODO: It's unclear if this trait is required because
// of column lifetime binding or it can be removed
pub trait DescType<'buf> {}

// TODO: The statement attribute SQL_ATTR_USE_BOOKMARKS should always be set before calling SQLSetDescField to set bookmark fields. While this is not mandatory, it is strongly recommended.
pub trait DescField<'buf, D: Descriptor<'buf, DT, V>, DT, A: Ident, V: OdbcVersion>:
    Attr<A> + AttrLen<Self::DefinedBy, SQLINTEGER>
where
    D: ?Sized,
{
    // TODO: Implement for buffers to bind their lifetimes
    fn update_handle(&self, _: &D)
    where
        Self: AttrSet<A>,
    {
        // TODO: If an application calls SQLSetDescField to set any field other than SQL_DESC_COUNT
        // or the deferred fields SQL_DESC_DATA_PTR, SQL_DESC_OCTET_LENGTH_PTR, or SQL_DESC_INDICATOR_PTR,
        // the record becomes unbound.

        // When setting descriptor fields by calling SQLSetDescField, the application must follow a specific sequence:
        //  The application must first set the SQL_DESC_TYPE, SQL_DESC_CONCISE_TYPE, or SQL_DESC_DATETIME_INTERVAL_CODE field.
        //  After one of these fields has been set, the application can set an attribute of a data type, and the driver sets data type attribute fields to the appropriate default values for the data type. Automatic defaulting of type attribute fields ensures that the descriptor is always ready to use once the application has specified a data type. If the application explicitly sets a data type attribute, it is overriding the default attribute.
        //  After one of the fields listed in step 1 has been set, and data type attributes have been set, the application can set SQL_DESC_DATA_PTR. This prompts a consistency check of descriptor fields. If the application changes the data type or attributes after setting the SQL_DESC_DATA_PTR field, the driver sets SQL_DESC_DATA_PTR to a null pointer, unbinding the record. This forces the application to complete the proper steps in sequence, before the descriptor record is usable.
    }
}

#[derive(Debug)]
pub struct AppDesc<'buf> {
    pub(crate) rows_processed: PhantomData<&'buf ()>,
    pub(crate) data_ptrs: PhantomData<&'buf ()>,
}

#[derive(Debug)]
pub enum IRD {}
#[derive(Debug)]
pub enum IPD {}

impl<'buf> DescType<'buf> for AppDesc<'buf> {}
impl DescType<'_> for IPD {}
impl DescType<'_> for IRD {}

// Implement DescField for all versions of SQLHDESC descriptor fields
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, SQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for T
where
    T: DescField<
        'buf,
        SQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, SQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for T
where
    T: DescField<
        'buf,
        SQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, SQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for [T]
where
    [T]: DescField<
        'buf,
        SQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, SQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for [T]
where
    [T]: DescField<
        'buf,
        SQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, SQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        SQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, SQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        SQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}

// Implement DescField for all versions of UnsafeSQLHDESC descriptor fields
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, UnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for T
where
    T: DescField<
        'buf,
        UnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, UnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for T
where
    T: DescField<
        'buf,
        UnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, UnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for [T]
where
    [T]: DescField<
        'buf,
        UnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, UnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for [T]
where
    [T]: DescField<
        'buf,
        UnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, UnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80>
    for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        UnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, UnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        UnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}

// Implement DescField for all versions of RefSQLHDESC descriptor fields
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for T
where
    T: DescField<
        'buf,
        RefSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for T
where
    T: DescField<
        'buf,
        RefSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for [T]
where
    [T]: DescField<
        'buf,
        RefSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for [T]
where
    [T]: DescField<
        'buf,
        RefSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, RefSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        RefSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, RefSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        RefSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}

// Implement DescField for all versions of RefUnsafeSQLHDESC descriptor fields
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefUnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for T
where
    T: DescField<
        'buf,
        RefUnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefUnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for T
where
    T: DescField<
        'buf,
        RefUnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefUnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80> for [T]
where
    [T]: DescField<
        'buf,
        RefUnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, T: Scalar>
    DescField<'buf, RefUnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for [T]
where
    [T]: DescField<
        'buf,
        RefUnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, RefUnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC3_80>, DT, A, SQL_OV_ODBC3_80>
    for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        RefUnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC3_80 as OdbcVersion>::PrevVersion,
    >,
{
}
impl<'conn, 'buf, DT: DescType<'buf>, A: Ident, CH: OdbcChar>
    DescField<'buf, RefUnsafeSQLHDESC<'conn, DT, SQL_OV_ODBC4>, DT, A, SQL_OV_ODBC4> for OdbcStr<CH>
where
    OdbcStr<CH>: DescField<
        'buf,
        RefUnsafeSQLHDESC<'conn, DT, <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion>,
        DT,
        A,
        <SQL_OV_ODBC4 as OdbcVersion>::PrevVersion,
    >,
{
}

// Implement DescField for uninitialized descriptor fields
impl<'buf, D: Descriptor<'buf, DT, V>, DT, A: Ident, T: Scalar, V: OdbcVersion>
    DescField<'buf, D, DT, A, V> for MaybeUninit<T>
where
    T: DescField<'buf, D, DT, A, V> + AttrGet<A>,
    Self: AttrLen<Self::DefinedBy, SQLINTEGER>,
{
}
impl<'buf, D: Descriptor<'buf, DT, V>, DT, A: Ident, T: Scalar, V: OdbcVersion>
    DescField<'buf, D, DT, A, V> for [MaybeUninit<T>]
where
    [T]: DescField<'buf, D, DT, A, V> + AttrGet<A>,
    Self: AttrLen<Self::DefinedBy, SQLINTEGER>,
{
}
impl<'buf, D: Descriptor<'buf, DT, V>, A: Ident, DT, V: OdbcVersion> DescField<'buf, D, DT, A, V>
    for OdbcStr<MaybeUninit<SQLCHAR>>
where
    OdbcStr<SQLCHAR>: DescField<'buf, D, DT, A, V> + AttrGet<A>,
{
}
impl<'buf, D: Descriptor<'buf, DT, V>, DT, A: Ident, V: OdbcVersion> DescField<'buf, D, DT, A, V>
    for OdbcStr<MaybeUninit<SQLWCHAR>>
where
    OdbcStr<SQLWCHAR>: DescField<'buf, D, DT, A, V> + AttrGet<A>,
{
}

// Implement DescField for references to unsized (used by AttrSet)
impl<'buf, D: Descriptor<'buf, DT, V>, DT, A: Ident, T: Scalar, V: OdbcVersion>
    DescField<'buf, D, DT, A, V> for &[T]
where
    [T]: DescField<'buf, D, DT, A, V>,
    Self: AttrSet<A>,
{
}
impl<'buf, D: Descriptor<'buf, DT, V>, DT, A: Ident, CH: OdbcChar, V: OdbcVersion>
    DescField<'buf, D, DT, A, V> for &OdbcStr<CH>
where
    OdbcStr<CH>: DescField<'buf, D, DT, A, V>,
    Self: AttrSet<A>,
{
}

//=====================================================================================//
//-------------------------------------Attributes--------------------------------------//

/////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Header fields ////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1099)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_ALLOC_TYPE;
// This is read-only attribute
unsafe impl Attr<SQL_DESC_ALLOC_TYPE> for AllocType {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, DT, SQL_OV_ODBC3>, DT>
    DescField<'buf, D, DT, SQL_DESC_ALLOC_TYPE, SQL_OV_ODBC3> for AllocType
{
}
unsafe impl AttrGet<SQL_DESC_ALLOC_TYPE> for AllocType {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 20)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_ARRAY_SIZE;
unsafe impl Attr<SQL_DESC_ARRAY_SIZE> for SQLULEN {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, AppDesc<'buf>, SQL_OV_ODBC3>>
    DescField<'buf, D, AppDesc<'buf>, SQL_DESC_ARRAY_SIZE, SQL_OV_ODBC3> for SQLULEN
{
}
unsafe impl AttrGet<SQL_DESC_ARRAY_SIZE> for SQLULEN {}
unsafe impl AttrSet<SQL_DESC_ARRAY_SIZE> for SQLULEN {}

//#[derive(Ident)]
//#[identifier(SQLSMALLINT, 21)]
//#[allow(non_camel_case_types)]
//pub struct SQL_DESC_ARRAY_STATUS_PTR;
//unsafe impl Attr<SQL_DESC_ARRAY_STATUS_PTR> for [UnsafeCell<>] {
//    type DefinedBy = OdbcDefined;
//}
//impl<DT> DescField<SQL_DESC_ARRAY_STATUS_PTR, DT> for [UnsafeCell<>] {
//    fn update_handle<V: OdbcVersion>(&self, _: &UnsafeSQLHDESC<DT, V>) where Self: AttrSet<A> {
//        // TODO: Do something
//    }
//}
//unsafe impl AttrGet<SQL_DESC_ARRAY_STATUS_PTR> for [UnsafeCell<>] {}
//unsafe impl AttrSet<SQL_DESC_ARRAY_STATUS_PTR> for &[UnsafeCell<>] {}

//#[derive(Ident)]
//#[identifier(SQLSMALLINT, 24)]
//#[allow(non_camel_case_types)]
//pub struct SQL_DESC_BIND_OFFSET_PTR;
//unsafe impl Attr<SQL_DESC_BIND_OFFSET_PTR> for UnsafeCell<SQLLEN> {
//    type DefinedBy = OdbcDefined;
//}
//impl<'buf, V: OdbcVersion> UnsafeDescField<'buf, SQL_DESC_BIND_OFFSET_PTR, UnsafeSQLHDESC<'buf, AppDesc<'buf>, V>, AppDesc<'buf>, V> for UnsafeCell<SQLLEN> {
//    fn update_handle<V: OdbcVersion>(&self, DescriptorHandle: &UnsafeSQLHDESC<'buf, AppDesc<'buf>, V>)
//    {
//        DescriptorHandle.bind_offset.set(*self);
//    }
//}
//unsafe impl AttrGet<SQL_DESC_BIND_OFFSET_PTR> for UnsafeCell<SQLLEN> {}
//unsafe impl AttrSet<SQL_DESC_BIND_OFFSET_PTR> for &UnsafeCell<SQLLEN> {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 25)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_BIND_TYPE;
unsafe impl Attr<SQL_DESC_BIND_TYPE> for BindType {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, AppDesc<'buf>, SQL_OV_ODBC3>>
    DescField<'buf, D, AppDesc<'buf>, SQL_DESC_BIND_TYPE, SQL_OV_ODBC3> for BindType
{
}
unsafe impl AttrGet<SQL_DESC_BIND_TYPE> for BindType {}
unsafe impl AttrSet<SQL_DESC_BIND_TYPE> for BindType {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1001)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_COUNT;
unsafe impl Attr<SQL_DESC_COUNT> for SQLSMALLINT {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, DT, SQL_OV_ODBC3>, DT>
    DescField<'buf, D, DT, SQL_DESC_COUNT, SQL_OV_ODBC3> for SQLSMALLINT
{
}
unsafe impl AttrGet<SQL_DESC_COUNT> for SQLSMALLINT {}
unsafe impl AttrSet<SQL_DESC_COUNT> for SQLSMALLINT {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 34)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_ROWS_PROCESSED_PTR;
unsafe impl Attr<SQL_DESC_ROWS_PROCESSED_PTR> for [UnsafeCell<SQLUINTEGER>] {
    type DefinedBy = OdbcDefined;
}
unsafe impl Attr<SQL_DESC_ROWS_PROCESSED_PTR> for [UnsafeCell<SQLULEN>] {
    type DefinedBy = OdbcDefined;
}
impl<'conn, 'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>>
    DescField<'buf, D, IRD, SQL_DESC_ROWS_PROCESSED_PTR, SQL_OV_ODBC3> for [UnsafeCell<SQLULEN>]
{
    #[cfg(feature = "odbc_debug")]
    fn update_handle<V: OdbcVersion>(&self, DescriptorHandle: &UnsafeSQLHDESC<'conn, IRD, V>) {
        unimplemented!()
    }
}
impl<'buf, D: Descriptor<'buf, IPD, SQL_OV_ODBC3>>
    DescField<'buf, D, IPD, SQL_DESC_ROWS_PROCESSED_PTR, SQL_OV_ODBC3>
    for [UnsafeCell<SQLUINTEGER>]
{
    #[cfg(feature = "odbc_debug")]
    fn update_handle<V: OdbcVersion>(&self, DescriptorHandle: &UnsafeSQLHDESC<'conn, IPD, V>) {
        unimplemented!()
    }
}
unsafe impl AttrGet<SQL_DESC_ROWS_PROCESSED_PTR> for [UnsafeCell<SQLUINTEGER>] {}
unsafe impl AttrGet<SQL_DESC_ROWS_PROCESSED_PTR> for [UnsafeCell<SQLULEN>] {}
unsafe impl AttrSet<SQL_DESC_ROWS_PROCESSED_PTR> for &[UnsafeCell<SQLUINTEGER>] {}
unsafe impl AttrSet<SQL_DESC_ROWS_PROCESSED_PTR> for &[UnsafeCell<SQLULEN>] {}

/////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Record fields ////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

#[derive(Ident)]
#[identifier(SQLSMALLINT, 11)]
#[allow(non_camel_case_types)]
// This is read-only attribute
pub struct SQL_DESC_AUTO_UNIQUE_VALUE;
unsafe impl Attr<SQL_DESC_AUTO_UNIQUE_VALUE> for OdbcBool {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>>
    DescField<'buf, D, IRD, SQL_DESC_AUTO_UNIQUE_VALUE, SQL_OV_ODBC3> for OdbcBool
{
}
unsafe impl AttrGet<SQL_DESC_AUTO_UNIQUE_VALUE> for OdbcBool {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 22)]
#[allow(non_camel_case_types)]
// This is read-only attribute
pub struct SQL_DESC_BASE_COLUMN_NAME;
unsafe impl<CH: OdbcChar> Attr<SQL_DESC_BASE_COLUMN_NAME> for OdbcStr<CH> {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>, CH: OdbcChar>
    DescField<'buf, D, IRD, SQL_DESC_BASE_COLUMN_NAME, SQL_OV_ODBC3> for OdbcStr<CH>
{
}
unsafe impl<CH: OdbcChar> AttrGet<SQL_DESC_BASE_COLUMN_NAME> for OdbcStr<CH> {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 23)]
#[allow(non_camel_case_types)]
// This is read-only attribute
pub struct SQL_DESC_BASE_TABLE_NAME;
unsafe impl<CH: OdbcChar> Attr<SQL_DESC_BASE_TABLE_NAME> for OdbcStr<CH> {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>, CH: OdbcChar>
    DescField<'buf, D, IRD, SQL_DESC_BASE_TABLE_NAME, SQL_OV_ODBC3> for OdbcStr<CH>
{
}
unsafe impl<CH: OdbcChar> AttrGet<SQL_DESC_BASE_TABLE_NAME> for OdbcStr<CH> {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 12)]
#[allow(non_camel_case_types)]
// This is read-only attribute
pub struct SQL_DESC_CASE_SENSITIVE;
unsafe impl Attr<SQL_DESC_CASE_SENSITIVE> for OdbcBool {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>>
    DescField<'buf, D, IRD, SQL_DESC_CASE_SENSITIVE, SQL_OV_ODBC3> for OdbcBool
{
}
unsafe impl AttrGet<SQL_DESC_CASE_SENSITIVE> for OdbcBool {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 17)]
#[allow(non_camel_case_types)]
// This is read-only attribute
pub struct SQL_DESC_CATALOG_NAME;
unsafe impl<CH: OdbcChar> Attr<SQL_DESC_CATALOG_NAME> for OdbcStr<CH> {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>, CH: OdbcChar>
    DescField<'buf, D, IRD, SQL_DESC_CATALOG_NAME, SQL_OV_ODBC3> for OdbcStr<CH>
{
}
unsafe impl<CH: OdbcChar> AttrGet<SQL_DESC_CATALOG_NAME> for OdbcStr<CH> {}

// TODO:
//#[derive(Ident)]
//#[identifier(SQLSMALLINT, 2)]
//#[allow(non_camel_case_types)]
//pub struct SQL_DESC_CONCISE_TYPE;
//unsafe impl Attr<SQL_DESC_CONCISE_TYPE> for SqlType {
//    type DefinedBy = OdbcDefined;
//}
//impl<DT, V: OdbcVersion> DescField<SQL_DESC_CONCISE_TYPE, DT> for SqlType {}
//unsafe impl AttrGet<SQL_DESC_CONCISE_TYPE> for SqlType {}
//unsafe impl AttrSet<SQL_DESC_CONCISE_TYPE> for SqlType {}

//#[derive(Ident)]
//#[identifier(SQLSMALLINT, 1007)]
//#[allow(non_camel_case_types)]
//pub struct SQL_DESC_DATETIME_INTERVAL_CODE;
//unsafe impl Attr<SQL_DESC_DATETIME_INTERVAL_CODE> for DatetimeIntervalCode {
//    type DefinedBy = OdbcDefined;
//}
//impl<DT, V: OdbcVersion> DescField<SQL_DESC_DATETIME_INTERVAL_CODE, DT> for DatetimeIntervalCode {}
//unsafe impl AttrGet<SQL_DESC_DATETIME_INTERVAL_CODE> for DatetimeIntervalCode {}
//unsafe impl AttrSet<SQL_DESC_DATETIME_INTERVAL_CODE> for DatetimeIntervalCode {}

//#[derive(Ident)]
//#[identifier(SQLSMALLINT, 26)]
//#[allow(non_camel_case_types)]
//pub struct SQL_DESC_DATETIME_INTERVAL_PRECISION;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1010)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_DATA_PTR;
unsafe impl<T> Attr<SQL_DESC_DATA_PTR> for UnsafeCell<T> {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IPD, SQL_OV_ODBC3>, T: CScalar>
    DescField<'buf, D, IPD, SQL_DESC_DATA_PTR, SQL_OV_ODBC3> for UnsafeCell<T>
{
}
impl<'buf, D: Descriptor<'buf, AppDesc<'buf>, SQL_OV_ODBC3>, T: CScalar>
    DescField<'buf, D, AppDesc<'buf>, SQL_DESC_DATA_PTR, SQL_OV_ODBC3> for UnsafeCell<T>
{
}
unsafe impl<T: CScalar> AttrGet<SQL_DESC_DATA_PTR> for UnsafeCell<T> {}
unsafe impl<T: CScalar> AttrSet<SQL_DESC_DATA_PTR> for &UnsafeCell<T> {}

unsafe impl<T> Attr<SQL_DESC_DATA_PTR> for [UnsafeCell<T>] {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, DT, SQL_OV_ODBC3>, DT, T>
    DescField<'buf, D, DT, SQL_DESC_DATA_PTR, SQL_OV_ODBC3> for [UnsafeCell<T>]
{
}
unsafe impl<T> AttrGet<SQL_DESC_DATA_PTR> for [UnsafeCell<T>] {}
unsafe impl<T> AttrSet<SQL_DESC_DATA_PTR> for &[UnsafeCell<T>] {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 6)]
#[allow(non_camel_case_types)]
// This is read-only attribute
pub struct SQL_DESC_DISPLAY_SIZE;
unsafe impl Attr<SQL_DESC_DISPLAY_SIZE> for SQLINTEGER {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>>
    DescField<'buf, D, IRD, SQL_DESC_DISPLAY_SIZE, SQL_OV_ODBC3> for SQLINTEGER
{
}
unsafe impl AttrGet<SQL_DESC_DISPLAY_SIZE> for SQLINTEGER {}

//#[derive(Ident)]
//#[identifier(SQLSMALLINT, 1009)]
//#[allow(non_camel_case_types)]
//pub struct SQL_DESC_INDICATOR_PTR;
//unsafe impl Attr<SQL_DESC_DISPLAY_SIZE> for {
//    type DefinedBy = OdbcDefined;
//}
//impl DescField<SQL_DESC_DISPLAY_SIZE, AppDesc<'_>> for {}
//unsafe impl AttrGet<SQL_DESC_DISPLAY_SIZE> for {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 9)]
#[allow(non_camel_case_types)]
// This is read-only attribute
pub struct SQL_DESC_FIXED_PREC_SCALE;
unsafe impl Attr<SQL_DESC_FIXED_PREC_SCALE> for OdbcBool {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, IRD, SQL_OV_ODBC3>>
    DescField<'buf, D, IRD, SQL_DESC_FIXED_PREC_SCALE, SQL_OV_ODBC3> for OdbcBool
{
}
impl<'buf, D: Descriptor<'buf, IPD, SQL_OV_ODBC3>>
    DescField<'buf, D, IPD, SQL_DESC_FIXED_PREC_SCALE, SQL_OV_ODBC3> for OdbcBool
{
}

unsafe impl AttrGet<SQL_DESC_FIXED_PREC_SCALE> for OdbcBool {}

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1004)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_OCTET_LENGTH_PTR;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 33)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_PARAMETER_TYPE;

#[cfg(feature = "v3_5")]
#[derive(Ident)]
#[identifier(SQLSMALLINT, 35)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_ROWVER;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1012)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_UNNAMED;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1002)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_TYPE;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1003)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_LENGTH;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1005)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_PRECISION;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1006)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_SCALE;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1008)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_NULLABLE;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1011)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_NAME;

#[derive(Ident)]
#[identifier(SQLSMALLINT, 1013)]
#[allow(non_camel_case_types)]
pub struct SQL_DESC_OCTET_LENGTH;
unsafe impl Attr<SQL_DESC_OCTET_LENGTH> for OdbcBool {
    type DefinedBy = OdbcDefined;
}
impl<'buf, D: Descriptor<'buf, DT, SQL_OV_ODBC3>, DT>
    DescField<'buf, D, DT, SQL_DESC_OCTET_LENGTH, SQL_OV_ODBC3> for OdbcBool
{
}
unsafe impl AttrGet<SQL_DESC_OCTET_LENGTH> for OdbcBool {}

//#if (ODBCVER >= 0x0300)
//#define SQL_DESC_ARRAY_SIZE                     20
//#define SQL_DESC_AUTO_UNIQUE_VALUE              SQL_COLUMN_AUTO_INCREMENT
//#define SQL_DESC_BASE_COLUMN_NAME               22
//#define SQL_DESC_BASE_TABLE_NAME                23
//#define SQL_DESC_BIND_OFFSET_PTR                24
//#define SQL_DESC_BIND_TYPE                      25
//#define SQL_DESC_CASE_SENSITIVE                 SQL_COLUMN_CASE_SENSITIVE
//#define SQL_DESC_CATALOG_NAME                   SQL_COLUMN_QUALIFIER_NAME
//#define SQL_DESC_CONCISE_TYPE                   SQL_COLUMN_TYPE
//#define SQL_DESC_DATETIME_INTERVAL_PRECISION    26
//#define SQL_DESC_DISPLAY_SIZE                   SQL_COLUMN_DISPLAY_SIZE
//#define SQL_DESC_FIXED_PREC_SCALE               SQL_COLUMN_MONEY
//#define SQL_DESC_LABEL                          SQL_COLUMN_LABEL
//#define SQL_DESC_LITERAL_PREFIX                 27
//#define SQL_DESC_LITERAL_SUFFIX                 28
//#define SQL_DESC_LOCAL_TYPE_NAME                29
//#define SQL_DESC_MAXIMUM_SCALE                  30
//#define SQL_DESC_MINIMUM_SCALE                  31
//#define SQL_DESC_NUM_PREC_RADIX                 32
//#define SQL_DESC_PARAMETER_TYPE                 33
//#define SQL_DESC_ROWS_PROCESSED_PTR             34
//#if (ODBCVER >= 0x0350)
//#define SQL_DESC_ROWVER                         35
//#endif /* ODBCVER >= 0x0350 */
//#define SQL_DESC_SCHEMA_NAME                    SQL_COLUMN_OWNER_NAME
//#define SQL_DESC_SEARCHABLE                     SQL_COLUMN_SEARCHABLE
//#define SQL_DESC_TYPE_NAME                      SQL_COLUMN_TYPE_NAME
//#define SQL_DESC_TABLE_NAME                     SQL_COLUMN_TABLE_NAME
//#define SQL_DESC_UNSIGNED                       SQL_COLUMN_UNSIGNED
//#define SQL_DESC_UPDATABLE                      SQL_COLUMN_UPDATABLE
//#endif /* ODBCVER >= 0x0300 */
//// TODO: Not mentioned anywhere in the documentation
//// SQL_DESC_MAXIMUM_SCALE = 30,
//// SQL_DESC_MINIMUM_SCALE = 31,
//#[cfg(feature = "v4")]
//SQL_DESC_CHARACTER_SET_CATALOG = 1018,
//#[cfg(feature = "v4")]
//SQL_DESC_CHARACTER_SET_SCHEMA = 1019,
//#[cfg(feature = "v4")]
//SQL_DESC_CHARACTER_SET_NAME = 1020,
//#[cfg(feature = "v4")]
//SQL_DESC_COLLATION_CATALOG = 1015,
//#[cfg(feature = "v4")]
//SQL_DESC_COLLATION_SCHEMA = 1016,
//#[cfg(feature = "v4")]
//SQL_DESC_COLLATION_NAME = 1017,
//#[cfg(feature = "v4")]
//SQL_DESC_USER_DEFINED_TYPE_CATALOG = 1026,
//#[cfg(feature = "v4")]
//SQL_DESC_USER_DEFINED_TYPE_SCHEMA = 1027,
//#[cfg(feature = "v4")]
//SQL_DESC_USER_DEFINED_TYPE_NAME = 1028,
//#[cfg(feature = "v4")]
//SQL_DESC_MIME_TYPE = 36,

//    pub enum SQL_DESC_ARRAY_STATUS_PTR {
//        SQL_PARAM_SUCCESS = 0,
//        SQL_PARAM_SUCCESS_WITH_INFO = 6,
//        SQL_PARAM_ERROR = 5,
//        SQL_PARAM_UNUSED = 7,
//        SQL_PARAM_DIAG_UNAVAILABLE = 1,
//        // TODO: What are these?
//        //SQL_PARAM_PROCEED = 0,
//        //SQL_PARAM_IGNORE = 1,
//    }

//=====================================================================================//

#[odbc_type(SQLSMALLINT)]
pub struct AllocType;
pub const SQL_DESC_ALLOC_AUTO: AllocType = AllocType(1);
pub const SQL_DESC_ALLOC_USER: AllocType = AllocType(2);

// TODO: May be SQLINTEGER?
#[odbc_type(SQLUINTEGER)]
pub struct BindType;
pub const SQL_BIND_BY_COLUMN: BindType = BindType(1);