-
Notifications
You must be signed in to change notification settings - Fork 9
/
odbc_type.c
2483 lines (2195 loc) · 64.2 KB
/
odbc_type.c
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
/*
* Copyright (C) 2008 Search Solution Corporation. All rights reserved by Search Solution.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the <ORGANIZATION> nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <math.h>
#include <LIMITS.H>
#include "odbc_portable.h"
#include "sqlext.h"
#include "odbc_type.h"
#include "cas_cci.h"
#include "odbc_number.h"
#include "odbc_util.h"
#include "odbc_diag_record.h"
#define GET_SET_SIZE(x) ((sizeof (x)) / (sizeof ((x)[0])))
typedef int (*OCTET_LEN_FUNC) (int);
PRIVATE int octet_len_char (int precision);
PRIVATE int octet_len_binary (int precision);
typedef int (*DISPLAY_SIZE_FUNC) (int);
PRIVATE int display_size_char (int);
PRIVATE int display_size_decimal (int);
PRIVATE int display_size_binary (int);
typedef int (*COLUMN_SIZE_FUNC) (int);
PRIVATE int column_size_char (int);
PRIVATE int column_size_decimal (int);
PRIVATE int column_size_binary (int);
typedef struct tagDATA_TYPE_INFO
{
char *type_name;
int concise_sql_type;
int concise_c_type;
int default_decimal_digits;
int default_column_size;
int default_octet_length;
int default_display_size;
int decimal_digits;
int column_size;
COLUMN_SIZE_FUNC get_column_size;
int octet_length;
OCTET_LEN_FUNC get_octet_length;
int display_size;
DISPLAY_SIZE_FUNC get_display_size;
} DATA_TYPE_INFO;
typedef struct tagDATETIME_TYPE_INFO
{
int concise_sql_type;
int concise_c_type;
int verbose_type;
int type_subcode;
} DATETIME_TYPE_INFO;
typedef struct tagDATETIME_TYPE_BACKWARD
{
int current_type;
int backward_type;
} DATETIME_TYPE_BACKWARD;
typedef struct tagC_DATA_TYPE_INFO
{
int concise_c_type;
T_CCI_A_TYPE cci_a_type;
long c_type_size;
} C_DATA_TYPE_INFO;
PRIVATE DATA_TYPE_INFO odbc_data_type_info_set[] = {
{"CHAR", SQL_CHAR, SQL_C_CHAR, 0, 1, 1, 1,
0, -1, column_size_char, -1, octet_len_char, -1, display_size_char},
{"VARCHAR", SQL_VARCHAR, SQL_C_CHAR,
0, MAX_CUBRID_CHAR_LEN, MAX_CUBRID_CHAR_LEN, MAX_CUBRID_CHAR_LEN,
0, -1, column_size_char, -1, octet_len_char, -1, display_size_char},
{"VARCHAR", SQL_LONGVARCHAR, SQL_C_CHAR,
0, MAX_CUBRID_CHAR_LEN, MAX_CUBRID_CHAR_LEN, MAX_CUBRID_CHAR_LEN,
0, -1, column_size_char, -1, octet_len_char, -1, display_size_char},
{"STRING", SQL_LONGVARCHAR, SQL_C_CHAR,
0, MAX_CUBRID_CHAR_LEN, MAX_CUBRID_CHAR_LEN, MAX_CUBRID_CHAR_LEN,
0, 10, NULL, 10, NULL, 10, NULL},
{"DECIMAL", SQL_DECIMAL, SQL_C_DOUBLE, 0, 15, sizeof (SQL_NUMERIC_STRUCT),
16,
0, -1, column_size_decimal, sizeof (SQL_NUMERIC_STRUCT), NULL, -1,
display_size_decimal}
,
{"NUMERIC", SQL_NUMERIC, SQL_C_DOUBLE, 0, 15, sizeof (SQL_NUMERIC_STRUCT),
16,
0, -1, column_size_decimal, sizeof (SQL_NUMERIC_STRUCT), NULL, -1,
display_size_decimal}
,
{"SMALLINT", SQL_SMALLINT, SQL_C_SHORT, 0, 5, sizeof (short), 6,
0, 5, NULL, sizeof (short), NULL, 6, NULL},
{"SMALLINT", SQL_TINYINT, SQL_C_SHORT, 0, 5, sizeof (short), 6,
0, 5, NULL, sizeof (short), NULL, 6, NULL},
{"BIT", SQL_BIT, SQL_C_BIT, 0, 1, sizeof (unsigned char), 1,
0, 1, NULL, sizeof (unsigned char), NULL, 1, NULL},
{"INTEGER", SQL_INTEGER, SQL_C_LONG, 0, 10, sizeof (long), 11,
0, 10, NULL, sizeof (long), NULL, 11, NULL},
{"BIGINT", SQL_BIGINT, SQL_C_SBIGINT, 0, 19, sizeof (__int64), 20,
0, 19, NULL, sizeof (__int64), NULL, 20, NULL}
,
{"FLOAT", SQL_FLOAT, SQL_C_FLOAT, 0, 14, sizeof (float), 15,
0, 15, NULL, sizeof (float), NULL, 15, NULL},
{"REAL", SQL_REAL, SQL_C_FLOAT, 0, 14, sizeof (float), 15,
0, 15, NULL, sizeof (float), NULL, 15, NULL},
{"DOUBLE", SQL_DOUBLE, SQL_C_DOUBLE, 0, 28, sizeof (double), 22,
0, 22, NULL, sizeof (double), NULL, 22, NULL},
{"BIT", SQL_BINARY, SQL_C_BINARY, 0, 1, 1, 1,
0, -1, column_size_binary, -1, octet_len_binary, -1, display_size_binary},
{"BIT VARYING", SQL_VARBINARY, SQL_C_BINARY,
0, MAX_CUBRID_CHAR_LEN, (MAX_CUBRID_CHAR_LEN / 8) + 1, MAX_CUBRID_CHAR_LEN,
0, -1, column_size_binary, -1, octet_len_binary, -1, display_size_binary},
{"BIT VARYING", SQL_LONGVARBINARY, SQL_C_BINARY,
0, MAX_CUBRID_CHAR_LEN, (MAX_CUBRID_CHAR_LEN / 8) + 1, MAX_CUBRID_CHAR_LEN,
0, -1, column_size_binary, -1, octet_len_binary, -1, display_size_binary},
{"DATE", SQL_TYPE_DATE, SQL_TYPE_DATE, 0, 10, sizeof (SQL_DATE_STRUCT), 10,
0, 10, NULL, sizeof (SQL_DATE_STRUCT), NULL, 10, NULL}
,
{"TIME", SQL_TYPE_TIME, SQL_C_TYPE_TIME, 0, 8, sizeof (SQL_TIME_STRUCT), 11,
0, 8, NULL, sizeof (SQL_TIME_STRUCT), NULL, 11, NULL}
,
{"TIMESTAMP", SQL_TYPE_TIMESTAMP, SQL_C_TYPE_TIMESTAMP,
0, 23, sizeof (SQL_TIMESTAMP_STRUCT), 23,
0, 23, NULL, sizeof (SQL_TIMESTAMP_STRUCT), NULL, 23, NULL}
,
{"GUID", SQL_GUID, SQL_C_GUID, 36, sizeof (SQLGUID), 36, 0,
0, 36, NULL, sizeof (SQLGUID), NULL, 36, NULL}
,
/* For 2.x backward compatibility */
{"DATE", SQL_DATE, SQL_C_DATE, 0, 10, sizeof (SQL_DATE_STRUCT), 10,
0, 10, NULL, sizeof (SQL_DATE_STRUCT), NULL, 10, NULL}
,
{"TIME", SQL_TIME, SQL_C_TIME, 0, 12, sizeof (SQL_TIME_STRUCT), 12,
0, 12, NULL, sizeof (SQL_TIME_STRUCT), NULL, 12, NULL}
,
{"TIMESTAMP", SQL_TIMESTAMP, SQL_C_TIMESTAMP,
0, 23, sizeof (SQL_TIMESTAMP_STRUCT), 23,
0, 23, NULL, sizeof (SQL_TIMESTAMP_STRUCT), NULL, 23, NULL}
,
#if 0
/* CUBRID types */
{"MONETARY", SQL_UNI_MONETARY, SQL_C_UNI_MONETARY, 0, -1, NULL, -1, NULL,
-1, NULL}
,
{"OBJECT", SQL_UNI_OBJECT, SQL_C_UNI_OBJECT, 0, -1, NULL, -1, NULL, -1, NULL}
,
{"SET", SQL_UNI_SET, SQL_C_UNI_SET, 0, -1, NULL, -1, NULL, -1, NULL}
,
#endif
};
PRIVATE C_DATA_TYPE_INFO c_data_type_info_set[] = {
{SQL_WCHAR, CCI_A_TYPE_STR, sizeof (SQLCHAR)}
,
{SQL_WVARCHAR, CCI_A_TYPE_STR, sizeof (SQLCHAR)}
,
{SQL_WLONGVARCHAR, CCI_A_TYPE_STR, sizeof (SQLCHAR)}
,
{SQL_C_CHAR, CCI_A_TYPE_STR, sizeof (SQLCHAR)}
,
{SQL_C_SSHORT, CCI_A_TYPE_INT, sizeof (SQLSMALLINT)}
,
{SQL_C_USHORT, CCI_A_TYPE_INT, sizeof (SQLUSMALLINT)}
,
{SQL_C_SLONG, CCI_A_TYPE_INT, sizeof (SQLINTEGER)}
,
{SQL_C_ULONG, CCI_A_TYPE_INT, sizeof (SQLUINTEGER)}
,
{SQL_C_FLOAT, CCI_A_TYPE_FLOAT, sizeof (SQLREAL)}
,
{SQL_C_DOUBLE, CCI_A_TYPE_DOUBLE, sizeof (SQLDOUBLE)}
,
{SQL_C_STINYINT, CCI_A_TYPE_INT, sizeof (SQLSCHAR)}
,
{SQL_C_UTINYINT, CCI_A_TYPE_INT, sizeof (SQLCHAR)}
,
{SQL_C_NUMERIC, CCI_A_TYPE_STR, sizeof (SQL_NUMERIC_STRUCT)}
,
{SQL_C_GUID, CCI_A_TYPE_STR, sizeof (SQLGUID)}
,
{SQL_C_BIT, CCI_A_TYPE_BIT, sizeof (SQLCHAR)}
,
{SQL_BINARY, CCI_A_TYPE_BIT, sizeof (SQLCHAR)}
,
{SQL_VARBINARY, CCI_A_TYPE_BIT, sizeof (SQLCHAR)}
,
{SQL_BLOB, CCI_A_TYPE_BLOB, sizeof (SQLCHAR)}
,
{SQL_CLOB, CCI_A_TYPE_CLOB, sizeof (SQLCHAR)}
,
{SQL_C_SBIGINT, CCI_A_TYPE_BIGINT, sizeof (SQLBIGINT)}
,
{SQL_C_UBIGINT, CCI_A_TYPE_BIGINT, sizeof (SQLUBIGINT)}
,
{SQL_C_TYPE_DATE, CCI_A_TYPE_DATE, sizeof (SQL_DATE_STRUCT)}
,
{SQL_C_TYPE_TIME, CCI_A_TYPE_DATE, sizeof (SQL_TIME_STRUCT)}
,
{SQL_C_TYPE_TIMESTAMP, CCI_A_TYPE_DATE, sizeof (SQL_TIMESTAMP_STRUCT)}
,
{SQL_C_UBIGINT, CCI_A_TYPE_DATE, sizeof (SQL_TIMESTAMP_STRUCT)}
,
#if 0
/* CUBRID type */
{SQL_C_UNI_SET, CCI_A_TYPE_STR, sizeof (SQLCHAR)}
,
{SQL_C_UNI_OBJECT, CCI_A_TYPE_STR, sizeof (SQLCHAR)}
,
{SQL_C_UNI_MONETARY, -1, sizeof (SQLCHAR)}
,
#endif
/* For 2.x backward compatibility */
{SQL_C_TINYINT, CCI_A_TYPE_INT, sizeof (SQLSCHAR)}
,
{SQL_C_SHORT, CCI_A_TYPE_INT, sizeof (SQLSMALLINT)}
,
{SQL_C_LONG, CCI_A_TYPE_INT, sizeof (SQLINTEGER)}
,
{SQL_C_DATE, CCI_A_TYPE_DATE, sizeof (SQL_DATE_STRUCT)}
,
{SQL_C_TIME, CCI_A_TYPE_DATE, sizeof (SQL_TIME_STRUCT)}
,
{SQL_C_TIMESTAMP, CCI_A_TYPE_DATE, sizeof (SQL_TIMESTAMP_STRUCT)}
,
};
PRIVATE DATETIME_TYPE_INFO datetime_date_type_info_set[] = {
{SQL_TYPE_DATE, SQL_C_TYPE_DATE, SQL_DATETIME, SQL_CODE_DATE}
,
{SQL_TYPE_TIME, SQL_C_TYPE_TIME, SQL_DATETIME, SQL_CODE_TIME}
,
{SQL_TYPE_TIMESTAMP, SQL_C_TYPE_TIMESTAMP, SQL_DATETIME, SQL_CODE_TIMESTAMP}
,
/* For 2.x backward compatibility */
{SQL_DATE, SQL_C_DATE, SQL_DATETIME, SQL_CODE_DATE}
,
{SQL_TIME, SQL_C_TIME, SQL_DATETIME, SQL_CODE_TIME}
,
{SQL_TIMESTAMP, SQL_C_TIMESTAMP, SQL_DATETIME, SQL_CODE_TIMESTAMP}
,
};
PRIVATE DATETIME_TYPE_INFO datetime_internal_type_info_set[] = {
{SQL_INTERVAL_YEAR, SQL_C_INTERVAL_YEAR, SQL_INTERVAL, SQL_CODE_YEAR}
,
{SQL_INTERVAL_MONTH, SQL_C_INTERVAL_MONTH, SQL_INTERVAL, SQL_CODE_MONTH}
,
{SQL_INTERVAL_DAY, SQL_C_INTERVAL_DAY, SQL_INTERVAL, SQL_CODE_DAY}
,
{SQL_INTERVAL_HOUR, SQL_C_INTERVAL_HOUR, SQL_INTERVAL, SQL_CODE_HOUR}
,
{SQL_INTERVAL_MINUTE, SQL_C_INTERVAL_MINUTE, SQL_INTERVAL, SQL_CODE_MINUTE}
,
{SQL_INTERVAL_SECOND, SQL_C_INTERVAL_SECOND, SQL_INTERVAL, SQL_CODE_SECOND}
,
{SQL_INTERVAL_YEAR_TO_MONTH, SQL_C_INTERVAL_YEAR_TO_MONTH, SQL_INTERVAL,
SQL_CODE_YEAR_TO_MONTH}
,
{SQL_INTERVAL_DAY_TO_HOUR, SQL_C_INTERVAL_DAY_TO_HOUR, SQL_INTERVAL,
SQL_CODE_DAY_TO_HOUR}
,
{SQL_INTERVAL_DAY_TO_MINUTE, SQL_C_INTERVAL_DAY_TO_MINUTE, SQL_INTERVAL,
SQL_CODE_DAY_TO_MINUTE}
,
{SQL_INTERVAL_DAY_TO_SECOND, SQL_C_INTERVAL_DAY_TO_SECOND, SQL_INTERVAL,
SQL_CODE_DAY_TO_SECOND}
,
{SQL_INTERVAL_HOUR_TO_MINUTE, SQL_C_INTERVAL_HOUR_TO_MINUTE, SQL_INTERVAL,
SQL_CODE_HOUR_TO_MINUTE}
,
{SQL_INTERVAL_HOUR_TO_SECOND, SQL_C_INTERVAL_HOUR_TO_SECOND, SQL_INTERVAL,
SQL_CODE_HOUR_TO_SECOND}
,
{SQL_INTERVAL_MINUTE_TO_SECOND, SQL_C_INTERVAL_MINUTE_TO_SECOND,
SQL_INTERVAL, SQL_CODE_MINUTE_TO_SECOND}
,
};
PRIVATE DATETIME_TYPE_BACKWARD datetime_sql_type_backward_set[] = {
{SQL_TYPE_DATE, SQL_DATE}
,
{SQL_TYPE_TIME, SQL_TIME}
,
{SQL_TYPE_TIMESTAMP, SQL_TIMESTAMP}
,
};
PRIVATE DATETIME_TYPE_BACKWARD datetime_c_type_backward_set[] = {
{SQL_C_TYPE_DATE, SQL_C_DATE}
,
{SQL_C_TYPE_TIME, SQL_C_TIME}
,
{SQL_C_TYPE_TIMESTAMP, SQL_C_TIMESTAMP}
,
};
PRIVATE int c_common_type_set[] = {
SQL_C_CHAR,
SQL_C_SSHORT,
SQL_C_USHORT,
SQL_C_SLONG,
SQL_C_ULONG,
SQL_C_FLOAT,
SQL_C_DOUBLE,
SQL_C_NUMERIC,
SQL_C_BIT,
SQL_C_STINYINT,
SQL_C_UTINYINT,
SQL_C_SBIGINT,
SQL_C_UBIGINT,
SQL_C_BINARY,
SQL_C_BOOKMARK,
SQL_C_VARBOOKMARK,
SQL_C_DEFAULT,
SQL_C_UNI_OBJECT,
SQL_C_UNI_SET,
SQL_C_GUID,
/* For 2.x backward compatibility */
SQL_C_TINYINT,
SQL_C_SHORT,
SQL_C_LONG
};
PRIVATE int sql_common_type_set[] = {
SQL_CHAR,
SQL_VARCHAR,
SQL_LONGVARCHAR,
SQL_WCHAR,
SQL_WVARCHAR,
SQL_WLONGVARCHAR,
SQL_DECIMAL,
SQL_NUMERIC,
SQL_SMALLINT,
SQL_INTEGER,
SQL_REAL,
SQL_FLOAT,
SQL_DOUBLE,
SQL_BIT,
SQL_TINYINT,
SQL_BIGINT,
SQL_BINARY,
SQL_VARBINARY,
SQL_LONGVARBINARY,
SQL_GUID
};
PRIVATE int odbc_is_valid_concise_type (short odbc_type);
PRIVATE int odbc_is_valid_c_concise_type (short odbc_type);
PRIVATE int odbc_is_valid_sql_concise_type (short odbc_type);
PRIVATE int odbc_is_valid_verbose_type (short odbc_type);
PRIVATE int odbc_is_valid_c_verbose_type (short odbc_type);
PRIVATE int odbc_is_valid_sql_verbose_type (short odbc_type);
PRIVATE int odbc_is_valid_c_common_type (short c_type);
PRIVATE int odbc_is_valid_sql_common_type (short sql_type);
PRIVATE int odbc_is_valid_lob_type (short odbc_type);
PRIVATE int odbc_is_valid_sql_lob_type (short sql_type);
PRIVATE int odbc_is_valid_date_code (short code);
PRIVATE int odbc_is_valid_internal_code (short code);
PRIVATE int seek_in_common_type_set (int *set, int set_size, short id);
PUBLIC int
odbc_is_valid_type (short odbc_type)
{
return (odbc_is_valid_concise_type (odbc_type) ||
odbc_is_valid_verbose_type (odbc_type) ||
odbc_is_valid_lob_type (odbc_type));
}
PUBLIC int
odbc_is_valid_code (short code)
{
return (odbc_is_valid_date_code (code) ||
odbc_is_valid_internal_code (code));
}
PUBLIC int
odbc_is_valid_date_verbose_type (short odbc_type)
{
return (odbc_type == SQL_DATETIME);
}
PUBLIC int
odbc_is_valid_interval_verbose_type (short odbc_type)
{
return (odbc_type == SQL_INTERVAL);
}
PUBLIC int
odbc_is_valid_c_type (short odbc_type)
{
return (odbc_is_valid_c_common_type (odbc_type) ||
odbc_is_valid_c_date_type (odbc_type) ||
odbc_is_valid_c_interval_type (odbc_type) ||
odbc_is_valid_date_verbose_type (odbc_type) ||
odbc_is_valid_interval_verbose_type (odbc_type));
}
PUBLIC int
odbc_is_valid_sql_type (short odbc_type)
{
return (odbc_is_valid_sql_common_type (odbc_type) ||
odbc_is_valid_sql_date_type (odbc_type) ||
odbc_is_valid_sql_interval_type (odbc_type) ||
odbc_is_valid_date_verbose_type (odbc_type) ||
odbc_is_valid_interval_verbose_type (odbc_type));
}
PUBLIC int
odbc_is_valid_c_date_type (short c_type)
{
int i;
int type_info_set_size = GET_SET_SIZE (datetime_date_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (datetime_date_type_info_set[i].concise_c_type == c_type)
{
return _TRUE_;
}
}
return _FALSE_;
}
PUBLIC int
odbc_is_valid_sql_date_type (short sql_type)
{
int i;
int type_info_set_size = GET_SET_SIZE (datetime_date_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (datetime_date_type_info_set[i].concise_sql_type == sql_type)
{
return _TRUE_;
}
}
return _FALSE_;
}
PUBLIC int
odbc_is_valid_c_interval_type (short c_type)
{
int i;
int type_info_set_size = GET_SET_SIZE (datetime_internal_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (datetime_internal_type_info_set[i].concise_c_type == c_type)
{
return _TRUE_;
}
}
return _FALSE_;
}
PUBLIC int
odbc_is_valid_sql_interval_type (short sql_type)
{
int i;
int type_info_set_size = GET_SET_SIZE (datetime_internal_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (datetime_internal_type_info_set[i].concise_sql_type == sql_type)
{
return _TRUE_;
}
}
return _FALSE_;
}
PUBLIC short
odbc_concise_to_verbose_type (short type)
{
int i;
int date_set_size = GET_SET_SIZE (datetime_date_type_info_set);
int internal_set_size = GET_SET_SIZE (datetime_internal_type_info_set);
for (i = 0; i < date_set_size; i++)
{
if (datetime_date_type_info_set[i].concise_sql_type == type)
{
return datetime_date_type_info_set[i].verbose_type;
}
}
for (i = 0; i < date_set_size; i++)
{
if (datetime_internal_type_info_set[i].concise_sql_type == type)
{
return datetime_internal_type_info_set[i].verbose_type;
}
}
return type;
}
PUBLIC short
odbc_verbose_to_concise_type (short type, short code)
{
int i;
int date_set_size = GET_SET_SIZE (datetime_date_type_info_set);
for (i = 0; i < date_set_size; i++)
{
if (datetime_date_type_info_set[i].verbose_type == type)
{
return datetime_date_type_info_set[i].concise_sql_type;
}
}
return type;
}
PUBLIC short
odbc_subcode_type (short type)
{
int i;
int date_set_size = GET_SET_SIZE (datetime_date_type_info_set);
int internal_set_size = GET_SET_SIZE (datetime_internal_type_info_set);
for (i = 0; i < date_set_size; i++)
{
if (datetime_date_type_info_set[i].concise_sql_type == type)
{
return datetime_date_type_info_set[i].type_subcode;
}
}
for (i = 0; i < date_set_size; i++)
{
if (datetime_internal_type_info_set[i].concise_sql_type == type)
{
return datetime_internal_type_info_set[i].type_subcode;
}
}
return 0;
}
PUBLIC int
odbc_type_default_info_by_name (char *type_name,
ODBC_DATA_TYPE_INFO * type_info)
{
int i;
int set_size = GET_SET_SIZE (odbc_data_type_info_set);
DATA_TYPE_INFO type_info_in_set;
for (i = 0; i < set_size; i++)
{
type_info_in_set = odbc_data_type_info_set[i];
if (strcmp (type_info_in_set.type_name, type_name) == 0)
{
type_info->concise_c_type = type_info_in_set.concise_c_type;
type_info->concise_sql_type = type_info_in_set.concise_sql_type;
type_info->decimal_digits = type_info_in_set.default_decimal_digits;
type_info->column_size = type_info_in_set.default_column_size;
type_info->octet_length = type_info_in_set.default_octet_length;
type_info->display_size = type_info_in_set.default_display_size;
return 0;
}
}
return -1;
}
PUBLIC short
odbc_default_c_type (short odbc_type)
{
int i;
int set_size = GET_SET_SIZE (odbc_data_type_info_set);
for (i = 0; i < set_size; i++)
{
if (odbc_data_type_info_set[i].concise_sql_type == odbc_type)
{
return odbc_data_type_info_set[i].concise_c_type;
}
}
return SQL_C_CHAR;
}
PUBLIC long
odbc_size_of_by_type_id (short odbc_type)
{
int i;
int set_size = GET_SET_SIZE (c_data_type_info_set);
for (i = 0; i < set_size; i++)
{
if (c_data_type_info_set[i].concise_c_type == odbc_type)
{
return c_data_type_info_set[i].c_type_size;
}
}
return 0;
}
PUBLIC int
odbc_column_size (short odbc_type, int precision)
{
int i;
int type_info_set_size;
if (precision < 0)
{
precision = 0;
}
type_info_set_size = GET_SET_SIZE (odbc_data_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (odbc_data_type_info_set[i].concise_sql_type == odbc_type)
{
if (odbc_data_type_info_set[i].column_size == -1)
{
if (odbc_data_type_info_set[i].get_display_size != NULL)
{
return odbc_data_type_info_set[i].
get_column_size (precision);
}
else
{
break;
}
}
else
{
return odbc_data_type_info_set[i].column_size;
}
}
}
return 0;
}
PUBLIC int
odbc_buffer_length (short odbc_type, int precision)
{
return odbc_octet_length (odbc_type, precision);
}
PUBLIC int
odbc_decimal_digits (short odbc_type, int scale)
{
int i;
int type_info_set_size;
if (scale < 0)
{
scale = 0;
}
type_info_set_size = GET_SET_SIZE (odbc_data_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (odbc_data_type_info_set[i].concise_sql_type == odbc_type)
{
return (odbc_data_type_info_set[i].decimal_digits != -1) ?
odbc_data_type_info_set[i].decimal_digits : scale;
}
}
return 0;
}
PUBLIC int
odbc_octet_length (short odbc_type, int precision)
{
int i;
int type_info_set_size;
if (precision < 0)
{
precision = 0;
}
type_info_set_size = GET_SET_SIZE (odbc_data_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (odbc_data_type_info_set[i].concise_sql_type == odbc_type ||
odbc_data_type_info_set[i].concise_c_type == odbc_type)
{
if (odbc_data_type_info_set[i].octet_length == -1)
{
if (odbc_data_type_info_set[i].get_octet_length != NULL)
{
return odbc_data_type_info_set[i].
get_octet_length (precision);
}
else
{
break;
}
}
else
{
return odbc_data_type_info_set[i].octet_length;
}
}
}
return 0;
}
PUBLIC int
odbc_num_prec_radix (short odbc_type)
{
if (IS_STRING_TYPE (odbc_type) || IS_BINARY_TYPE (odbc_type))
{
return 0;
}
else
{
return 10;
}
}
PUBLIC int
odbc_display_size (short odbc_type, int precision)
{
int i;
int type_info_set_size;
if (precision < 0)
{
precision = 0;
}
type_info_set_size = GET_SET_SIZE (odbc_data_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (odbc_data_type_info_set[i].concise_sql_type == odbc_type)
{
if (odbc_data_type_info_set[i].octet_length == -1)
{
if (odbc_data_type_info_set[i].get_display_size != NULL)
{
return odbc_data_type_info_set[i].
get_display_size (precision);
}
else
{
break;
}
}
else
{
return odbc_data_type_info_set[i].display_size;
}
}
}
return 0;
}
PUBLIC short
odbc_type_by_cci (T_CCI_U_TYPE cci_type, int precision)
{
switch (cci_type)
{
case CCI_U_TYPE_CHAR:
return SQL_CHAR;
case CCI_U_TYPE_STRING:
case CCI_U_TYPE_VARNCHAR:
#ifdef DELPHI
if (precision == MAX_CUBRID_CHAR_LEN)
{
return SQL_LONGVARCHAR;
}
else
{
return SQL_VARCHAR;
}
#endif
if(precision > 8000)
{
return SQL_LONGVARCHAR;
}
return SQL_VARCHAR;
case CCI_U_TYPE_NCHAR:
return SQL_CHAR;
case CCI_U_TYPE_BIT:
return SQL_BINARY;
case CCI_U_TYPE_VARBIT:
return SQL_VARBINARY;
case CCI_U_TYPE_NUMERIC:
return SQL_NUMERIC;
case CCI_U_TYPE_BIGINT:
return SQL_BIGINT;
case CCI_U_TYPE_INT:
return SQL_INTEGER;
case CCI_U_TYPE_SHORT:
return SQL_SMALLINT;
case CCI_U_TYPE_FLOAT:
return SQL_FLOAT;
case CCI_U_TYPE_DOUBLE:
return SQL_DOUBLE;
case CCI_U_TYPE_DATE:
return SQL_TYPE_DATE;
case CCI_U_TYPE_TIME:
return SQL_TYPE_TIME;
case CCI_U_TYPE_TIMESTAMP:
case CCI_U_TYPE_DATETIME:
return SQL_TYPE_TIMESTAMP;
case CCI_U_TYPE_MONETARY:
return SQL_DOUBLE;
case CCI_U_TYPE_SET:
case CCI_U_TYPE_MULTISET:
case CCI_U_TYPE_SEQUENCE:
return SQL_VARCHAR;
case CCI_U_TYPE_OBJECT:
return SQL_CHAR;
case CCI_U_TYPE_BLOB:
return SQL_BLOB;
case CCI_U_TYPE_CLOB:
return SQL_CLOB;
case CCI_U_TYPE_UNKNOWN:
default:
return -1;
}
}
PUBLIC const char *
odbc_type_name (short odbc_type)
{
int i;
int type_info_set_size;
type_info_set_size = GET_SET_SIZE (odbc_data_type_info_set);
for (i = 0; i < type_info_set_size; i++)
{
if (odbc_data_type_info_set[i].concise_sql_type == odbc_type)
{
return odbc_data_type_info_set[i].type_name;
}
}
return NULL;
}
PUBLIC T_CCI_A_TYPE
odbc_type_to_cci_a_type (short c_type)
{
int i;
int set_size = GET_SET_SIZE (c_data_type_info_set);
for (i = 0; i < set_size; i++)
{
if (c_data_type_info_set[i].concise_c_type == c_type)
{
return c_data_type_info_set[i].cci_a_type;
}
}
return -1;
}
PUBLIC T_CCI_U_TYPE
odbc_type_to_cci_u_type (short sql_type)
{
switch (sql_type)
{
case SQL_CHAR:
case SQL_WCHAR:
return CCI_U_TYPE_CHAR;
case SQL_VARCHAR:
case SQL_WVARCHAR:
case SQL_LONGVARCHAR:
case SQL_WLONGVARCHAR:
return CCI_U_TYPE_STRING;
case SQL_BINARY:
return CCI_U_TYPE_BIT;
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
return CCI_U_TYPE_VARBIT;
case SQL_DECIMAL:
case SQL_NUMERIC:
return CCI_U_TYPE_NUMERIC;
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_TINYINT:
return CCI_U_TYPE_INT;
case SQL_BIGINT:
return CCI_U_TYPE_BIGINT;
case SQL_FLOAT:
case SQL_REAL:
return CCI_U_TYPE_FLOAT;
case SQL_DOUBLE:
return CCI_U_TYPE_DOUBLE;
case SQL_TYPE_DATE:
case SQL_DATE: // for 2.x backward compatibility
return CCI_U_TYPE_DATE;
case SQL_TYPE_TIME:
case SQL_TIME: // for 2.x backward compatibility
return CCI_U_TYPE_TIME;
case SQL_TYPE_TIMESTAMP:
case SQL_TIMESTAMP: // for 2.x backward compatibility