-
Notifications
You must be signed in to change notification settings - Fork 9
/
odbc_catalog.c
4100 lines (3594 loc) · 102 KB
/
odbc_catalog.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 <string.h>
#include "odbc_portable.h"
#include "sqlext.h"
#include "odbc_util.h"
#include "odbc_diag_record.h"
#include "odbc_statement.h"
#include "odbc_result.h"
#include "odbc_type.h"
#include "cas_cci.h"
#include "odbc_catalog.h"
#define TABLE_TYPE_TABLE ( 0x1 )
#define TABLE_TYPE_VIEW ( 0x2 )
#define TABLE_TYPE_SYSTEM ( 0x4 )
#define TABLE_TYPE_ALL ( TABLE_TYPE_TABLE | TABLE_TYPE_VIEW | TABLE_TYPE_SYSTEM )
/* NC:num columns */
#define NC_CATALOG_TABLES 5
#define NC_CATALOG_COLUMNS 18
#define NC_CATALOG_SPECIALCOLUMNS 8
#define NC_CATALOG_STATISTICS 13
#define NC_CATALOG_TYPE_INFO 19
#define NC_CATALOG_PRIMARY_KEYS 6
#define NC_CATALOG_FOREIGN_KEYS 14
#define NC_CATALOG_TABLE_PRIVILEGES 7
#define NC_CATALOG_PROCEDURES 8
#define NC_CATALOG_PROCEDURE_COLUMNS 19
#define MAX_TABLE_NAMME_LEN 255
#define MAX_OWNER_NAMME_LEN 255
typedef struct tagODBC_COL_INFO
{
const char *name;
short type;
int length;
short precision;
short scale;
} ODBC_COL_INFO;
typedef struct tagODBC_TABLE_VALUE
{
char *table_name;
char *table_type;
char *remarks;
} ODBC_TABLE_VALUE;
typedef struct tagODBC_COLUMN_VALUE
{
char *table_name;
char *column_name;
short concise_data_type;
char *type_name;
int column_size;
int buffer_length;
short decimal_digits;
short num_prec_radix;
short nullable;
char *default_value;
short verbose_data_type;
short subcode;
int octet_length;
int ordinal_position;
char *remarks;
} ODBC_COLUMN_VALUE;
typedef struct tagODBC_STAT_VALUE
{
char *table_name;
short type;
short non_unique;
char *index_name;
char *column_name;
char *asc_or_desc;
long cardinality;
long pages;
short ordinal_position;
} ODBC_STAT_VALUE;
typedef struct tagODBC_SPECIAL_COLUMN_VALUE
{
char *column_name;
short concise_data_type;
char *type_name;
int column_size;
int buffer_length;
short decimal_digits;
} ODBC_SP_COLUMN_VALUE;
typedef struct tagODBC_TYPE_INFO_VALUE
{
char *type_name;
short data_type;
int column_size;
char *literal_prefix;
char *literal_suffix;
char *create_params;
short nullable;
short case_sensitive;
short searchable;
short unsigned_attribute;
short fixed_prec_scale;
short auto_unique_value;
char *local_type_name;
short minimum_scale;
short maximum_scale;
short sql_data_type;
short sql_datetime_sub;
short num_prec_radix;
short interval_precision;
} ODBC_TYPE_INFO_VALUE;
typedef struct tagODBC_PRIMARY_KEYS_VALUE
{
char *table_name;
char *column_name;
short key_sequence;
char *key_name;
} ODBC_PRIMARY_KEYS_VALUE;
typedef struct tagODBC_FOREIGN_KEYS_VALUE
{
char *pk_table_name;
char *pk_column_name;
char *fk_table_name;
char *fk_column_name;
short key_sequence;
short update_rule;
short delete_rule;
char *fk_name;
char *pk_name;
} ODBC_FOREIGN_KEYS_VALUE;
typedef struct tagODBC_TABLE_PRIVILEGES_VALUE
{
char *table_name;
char *grantor;
char *grantee;
char *privilege;
char *is_grantable;
} ODBC_TABLE_PRIVILEGES_VALUE;
typedef struct tagODBC_PROCEDURES_VALUE
{
char *proc_name;
short proc_type;
} ODBC_PROCEDURES_VALUE;
typedef struct tagODBC_PROCEDURE_COLUMNS_VALUE
{
char *proc_name;
char *column_name;
short column_type;
short concise_data_type;
char *type_name;
int column_size;
int buffer_length;
short decimal_digits;
short num_prec_radix;
short nullable;
char *default_value;
short verbose_data_type;
short subcode;
int octet_length;
int ordinal_position;
} ODBC_PROCEDURE_COLUMNS_VALUE;
PRIVATE ODBC_COL_INFO table_cinfo[] = {
{"TABLE_CAT", SQL_VARCHAR, 128, 128, 0},
{"TABLE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"TABLE_NAME", SQL_VARCHAR, 128, 128, 0},
{"TABLE_TYPE", SQL_VARCHAR, 128, 128, 0},
{"REMARKS", SQL_VARCHAR, 128, 128, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO column_cinfo[] = {
{"TABLE_CAT", SQL_VARCHAR, 128, 128, 0},
{"TABLE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"TABLE_NAME", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_NAME", SQL_VARCHAR, 128, 128, 0},
{"DATA_TYPE", SQL_SMALLINT, 5, 5, 0},
{"TYPE_NAME", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_SIZE", SQL_INTEGER, 10, 10, 0},
{"BUFFER_LENGTH", SQL_INTEGER, 10, 10, 0},
{"DECIMAL_DIGITS", SQL_SMALLINT, 5, 5, 0},
{"NUM_PREC_RADIX", SQL_SMALLINT, 5, 5, 0},
{"NULLABLE", SQL_SMALLINT, 5, 5, 0},
{"REMARKS", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_DEF", SQL_VARCHAR, 128, 128, 0},
{"SQL_DATA_TYPE", SQL_SMALLINT, 5, 5, 0},
{"SQL_DATETIME_SUB", SQL_SMALLINT, 5, 5, 0},
{"CHAR_OCTET_LENGTH", SQL_INTEGER, 10, 10, 0},
{"ORDINAL_POSITION", SQL_INTEGER, 10, 10, 0},
{"IS_NULLABLE", SQL_VARCHAR, 128, 128, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO special_column_cinfo[] = {
{"SCOPE", SQL_SMALLINT, 5, 5, 0},
{"COLUMN_NAME", SQL_VARCHAR, 128, 128, 0},
{"DATA_TYPE", SQL_SMALLINT, 5, 5, 0},
{"TYPE_NAME", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_SIZE", SQL_INTEGER, 10, 10, 0},
{"BUFFER_LENGTH", SQL_INTEGER, 10, 10, 0},
{"DECIMAL_DIGITS", SQL_SMALLINT, 5, 5, 0},
{"PSEUDO_COLUMN", SQL_SMALLINT, 5, 5, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO statistics_cinfo[] = {
{"TABLE_CAT", SQL_VARCHAR, 128, 128, 0},
{"TABLE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"TABLE_NAME", SQL_VARCHAR, 128, 128, 0},
{"NON_UNIQUE", SQL_SMALLINT, 5, 5, 0},
{"INDEX_QUALIFIER", SQL_VARCHAR, 128, 128, 0},
{"INDEX_NAME", SQL_VARCHAR, 128, 128, 0},
{"TYPE", SQL_SMALLINT, 5, 5, 0},
{"ORDINAL_POSITION", SQL_SMALLINT, 5, 5, 0},
{"COLUMN_NAME", SQL_VARCHAR, 128, 128, 0},
{"ASC_OR_DESC", SQL_CHAR, 1, 1, 0},
{"CARDINALITY", SQL_INTEGER, 10, 10, 0},
{"PAGES", SQL_INTEGER, 10, 10, 0},
{"FILTER_CONDITION", SQL_VARCHAR, 128, 128, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO type_cinfo[] = {
{"TYPE_NAME", SQL_VARCHAR, 128, 128, 0},
{"DATA_TYPE", SQL_SMALLINT, 5, 5, 0},
{"COLUMN_SIZE", SQL_INTEGER, 10, 10, 0},
{"LITERAL_PREFIX", SQL_VARCHAR, 128, 128, 0},
{"LITERAL_SUFFIX", SQL_VARCHAR, 128, 128, 0},
{"CREATE_PARAMS", SQL_VARCHAR, 128, 128, 0},
{"NULLABLE", SQL_SMALLINT, 5, 5, 0},
{"CASE_SENSITIVE", SQL_SMALLINT, 5, 5, 0},
{"SEARCHABLE", SQL_SMALLINT, 5, 5, 0},
{"UNSIGNED_ATTRIBUTE", SQL_SMALLINT, 5, 5, 0},
{"FIXED_PREC_SCALE", SQL_SMALLINT, 5, 5, 0},
{"AUTO_UNIQUE_VALUE", SQL_SMALLINT, 5, 5, 0},
{"LOCAL_TYPE_NAME", SQL_VARCHAR, 128, 128, 0},
{"MINIMUM_SCALE", SQL_SMALLINT, 5, 5, 0},
{"MAXIMUM_SCALE", SQL_SMALLINT, 5, 5, 0},
{"SQL_DATA_TYPE", SQL_SMALLINT, 5, 5, 0},
{"SQL_DATETIME_SUB", SQL_SMALLINT, 5, 5, 0},
{"NUM_PREC_RADIX", SQL_INTEGER, 10, 10, 0},
{"INTERVAL_PRECISION", SQL_SMALLINT, 5, 5, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO primary_keys_cinfo[] = {
{"TABLE_CAT", SQL_VARCHAR, 128, 128, 0},
{"TABLE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"TABLE_NAME", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_NAME", SQL_VARCHAR, 128, 128, 0},
{"KEY_SEQ", SQL_SMALLINT, 5, 5, 0},
{"PK_NAME", SQL_VARCHAR, 128, 128, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO foreign_keys_cinfo[] = {
{"PKTABLE_CAT", SQL_VARCHAR, 128, 128, 0},
{"PKTABLE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"PKTABLE_NAME", SQL_VARCHAR, 128, 128, 0},
{"PKCOLUMN_NAME", SQL_VARCHAR, 128, 128, 0},
{"FKTABLE_CAT", SQL_VARCHAR, 128, 128, 0},
{"FKTABLE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"FKTABLE_NAME", SQL_VARCHAR, 128, 128, 0},
{"FKCOLUMN_NAME", SQL_VARCHAR, 128, 128, 0},
{"KEY_SEQ", SQL_SMALLINT, 5, 5, 0},
{"UPDATE_RULE", SQL_SMALLINT, 5, 5, 0},
{"DELETE_RULE", SQL_SMALLINT, 5, 5, 0},
{"FK_NAME", SQL_VARCHAR, 128, 128, 0},
{"PK_NAME", SQL_VARCHAR, 128, 128, 0},
{"DEFERRABILITY", SQL_SMALLINT, 5, 5, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO table_privileges_cinfo[] = {
{"TABLE_CAT", SQL_VARCHAR, 128, 128, 0},
{"TABLE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"TABLE_NAME", SQL_VARCHAR, 128, 128, 0},
{"GRANTOR", SQL_VARCHAR, 128, 128, 0},
{"GRANTEE", SQL_VARCHAR, 128, 128, 0},
{"PRIVILEGE", SQL_VARCHAR, 128, 128, 0},
{"IS_GRANTABLE", SQL_VARCHAR, 128, 128, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO procedures_cinfo[] = {
{"PROCEDURE_CAT", SQL_VARCHAR, 128, 128, 0},
{"PROCEDURE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"PROCEDURE_NAME", SQL_VARCHAR, 128, 128, 0},
{"NUM_INPUT_PARAMS", SQL_UNKNOWN_TYPE, 0, 0, 0},
{"NUM_OUTPUT_PARAMS", SQL_UNKNOWN_TYPE, 0, 0, 0},
{"NUM_RESULT_SETS", SQL_UNKNOWN_TYPE, 0, 0, 0},
{"REMARKS", SQL_VARCHAR, 128, 128, 0},
{"PROCEDURE_TYPE", SQL_SMALLINT, 5, 5, 0},
{NULL}
};
PRIVATE ODBC_COL_INFO procedure_columns_cinfo[] = {
{"PROCEDURE_CAT", SQL_VARCHAR, 128, 128, 0},
{"PROCEDURE_SCHEM", SQL_VARCHAR, 128, 128, 0},
{"PROCEDURE_NAME", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_NAME", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_TYPE", SQL_SMALLINT, 5, 5, 0},
{"DATA_TYPE", SQL_SMALLINT, 5, 5, 0},
{"TYPE_NAME", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_SIZE", SQL_INTEGER, 10, 10, 0},
{"BUFFER_LENGTH", SQL_INTEGER, 10, 10, 0},
{"DECIMAL_DIGITS", SQL_SMALLINT, 5, 5, 0},
{"NUM_PREC_RADIX", SQL_SMALLINT, 5, 5, 0},
{"NULLABLE", SQL_SMALLINT, 5, 5, 0},
{"REMARKS", SQL_VARCHAR, 128, 128, 0},
{"COLUMN_DEF", SQL_VARCHAR, 128, 128, 0},
{"SQL_DATA_TYPE", SQL_SMALLINT, 5, 5, 0},
{"SQL_DATETIME_SUB", SQL_SMALLINT, 5, 5, 0},
{"CHAR_OCTET_LENGTH", SQL_INTEGER, 10, 10, 0},
{"ORDINAL_POSITION", SQL_INTEGER, 10, 10, 0},
{"IS_NULLABLE", SQL_VARCHAR, 128, 128, 0},
{NULL}
};
static ODBC_TYPE_INFO_VALUE type_info[] = {
{"CHAR", SQL_CHAR, MAX_CUBRID_CHAR_LEN, "'", "'", "length", SQL_NULLABLE,
SQL_FALSE, SQL_SEARCHABLE, -1, SQL_FALSE, SQL_FALSE, "CHAR", -1, -1,
SQL_CHAR, -1, -1, -1},
{"VARCHAR", SQL_VARCHAR, MAX_CUBRID_CHAR_LEN, "'", "'", "length",
SQL_NULLABLE,
SQL_FALSE, SQL_SEARCHABLE, -1, SQL_FALSE, SQL_FALSE, "VARCHAR", -1, -1,
SQL_VARCHAR, -1, -1, -1},
{"BIT", SQL_BINARY, MAX_CUBRID_CHAR_LEN / 8, "X'", "'", "length",
SQL_NULLABLE,
SQL_FALSE, SQL_SEARCHABLE, -1, SQL_FALSE, SQL_FALSE, "BIT", -1, -1,
SQL_BINARY, -1, -1, -1},
{"BIT VARYING", SQL_VARBINARY, MAX_CUBRID_CHAR_LEN / 8, "X'", "'", "length",
SQL_NULLABLE,
SQL_FALSE, SQL_SEARCHABLE, -1, SQL_FALSE, SQL_FALSE, "BIT VARYING", -1, -1,
SQL_VARBINARY, -1, -1, -1},
{"NUMERIC", SQL_NUMERIC, 38, NULL, NULL, "precision,scale", SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "NUMERIC", 0,
38,
SQL_NUMERIC, -1, 10, -1},
{"DECIMAL", SQL_DECIMAL, 38, NULL, NULL, "precision,scale", SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "DECIMAL", 0,
38,
SQL_DECIMAL, -1, 10, -1},
{"INTEGER", SQL_INTEGER, 10, NULL, NULL, NULL, SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "INTEGER", -1,
-1,
SQL_INTEGER, -1, 10, -1},
{"SMALLINT", SQL_SMALLINT, 5, NULL, NULL, NULL, SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "SMALLINT", -1,
-1,
SQL_SMALLINT, -1, 10, -1},
{"REAL", SQL_REAL, 14, NULL, NULL, "precision", SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "REAL", -1, -1,
SQL_REAL, -1, 10, -1},
{"FLOAT", SQL_FLOAT, 14, NULL, NULL, "precision", SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "FLOAT", -1,
-1,
SQL_FLOAT, -1, 10, -1},
{"DOUBLE", SQL_DOUBLE, 28, NULL, NULL, "precision", SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "DOUBLE", -1,
-1,
SQL_DOUBLE, -1, 10, -1},
{"DATE", SQL_TYPE_DATE, 10, "DATE '", "'", NULL, SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "DATE", -1, -1,
SQL_DATETIME, SQL_CODE_DATE, -1, -1},
{"TIME", SQL_TYPE_TIME, 8, "TIME '", "'", NULL, SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "TIME", -1, -1,
SQL_DATETIME, SQL_CODE_TIME, -1, -1},
{"TIMESTAMP", SQL_TYPE_TIMESTAMP, 19, "TIMESTAMP '", "'", NULL,
SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "TIMESTAMP",
-1, -1,
SQL_DATETIME, SQL_CODE_TIMESTAMP, -1, -1},
{"BIGINT", SQL_BIGINT, 19, NULL, NULL, NULL, SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "BIGINT", -1,
-1,
SQL_INTEGER, -1, 10, -1},
{"DATETIME", SQL_TYPE_TIMESTAMP, 23, "DATETIME '", "'", NULL,
SQL_NULLABLE,
SQL_FALSE, SQL_PRED_BASIC, SQL_FALSE, SQL_FALSE, SQL_FALSE, "DATETIME",
-1, -1,
SQL_DATETIME, SQL_CODE_TIMESTAMP, -1, -1},
#ifdef DELPHI
{"STRING", SQL_LONGVARCHAR, MAX_CUBRID_CHAR_LEN, "'", "'", "length",
SQL_NULLABLE,
SQL_FALSE, SQL_SEARCHABLE, -1, SQL_FALSE, SQL_FALSE, "STRING", -1, -1,
SQL_LONGVARCHAR, -1, -1, -1},
#endif
{NULL}
};
PRIVATE RETCODE make_table_result_set (ODBC_STATEMENT * stmt, int req_handle,
int handle_type);
PRIVATE RETCODE make_column_result_set (ODBC_STATEMENT * stmt,
int req_handle);
PRIVATE RETCODE make_stat_result_set (ODBC_STATEMENT * stmt, int req_handle,
char *table_name,
unsigned short unique);
PRIVATE RETCODE make_sp_column_result_set (ODBC_STATEMENT * stmt,
int req_handle, char *table_name);
PRIVATE RETCODE make_primary_keys_result_set (ODBC_STATEMENT * stmt,
int req_handle);
PRIVATE RETCODE make_foreign_keys_result_set (ODBC_STATEMENT * stmt,
int req_handle);
PRIVATE RETCODE make_table_privileges_result_set (ODBC_STATEMENT * stmt,
int req_handle);
PRIVATE RETCODE make_procedures_result_set (ODBC_STATEMENT * stmt,
int req_handle);
PRIVATE RETCODE make_procedure_columns_result_set (ODBC_STATEMENT * stmt,
int req_handle);
PRIVATE RETCODE odbc_get_table_data (ODBC_STATEMENT * stmt, short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_column_data (ODBC_STATEMENT * stmt, short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_stat_data (ODBC_STATEMENT * stmt, short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_sp_column_data (ODBC_STATEMENT * stmt,
short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_type_info_data (ODBC_STATEMENT * stmt,
short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_primary_keys_data (ODBC_STATEMENT * stmt,
short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_foreign_keys_data (ODBC_STATEMENT * stmt,
short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_table_privileges_data (ODBC_STATEMENT * stmt,
short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_procedures_data (ODBC_STATEMENT * stmt,
short col_index,
VALUE_CONTAINER * c_value);
PRIVATE RETCODE odbc_get_procedure_columns_data (ODBC_STATEMENT * stmt,
short col_index,
VALUE_CONTAINER * c_value);
PRIVATE ODBC_TABLE_VALUE *create_table_value (void);
PRIVATE ODBC_COLUMN_VALUE *create_column_value (void);
PRIVATE ODBC_STAT_VALUE *create_stat_value (void);
PRIVATE ODBC_PRIMARY_KEYS_VALUE *create_primary_keys_value (void);
PRIVATE ODBC_FOREIGN_KEYS_VALUE *create_foreign_keys_value (void);
PRIVATE ODBC_SP_COLUMN_VALUE *create_sp_column_value (void);
PRIVATE ODBC_TYPE_INFO_VALUE *create_type_info_value (void);
PRIVATE ODBC_TABLE_PRIVILEGES_VALUE *create_table_privileges_value (void);
PRIVATE ODBC_PROCEDURES_VALUE *create_procedures_value (void);
PRIVATE ODBC_PROCEDURE_COLUMNS_VALUE *create_procedure_columns_value (void);
PRIVATE void free_table_value (ODBC_TABLE_VALUE * value);
PRIVATE void free_column_value (ODBC_COLUMN_VALUE * value);
PRIVATE void free_stat_value (ODBC_STAT_VALUE * value);
PRIVATE void free_sp_column_value (ODBC_SP_COLUMN_VALUE * value);
PRIVATE void free_type_info_value (ODBC_TYPE_INFO_VALUE * value);
PRIVATE void free_primary_keys_value (ODBC_PRIMARY_KEYS_VALUE * value);
PRIVATE void free_foreign_keys_value (ODBC_FOREIGN_KEYS_VALUE * value);
PRIVATE void free_table_privileges_value (ODBC_TABLE_PRIVILEGES_VALUE *
value);
PRIVATE void free_procedures_value (ODBC_PROCEDURES_VALUE * value);
PRIVATE void free_procedure_columns_value (ODBC_PROCEDURE_COLUMNS_VALUE *
value);
PRIVATE void free_table_node (ST_LIST * node);
PRIVATE void free_column_node (ST_LIST * node);
PRIVATE void free_stat_node (ST_LIST * node);
PRIVATE void free_sp_column_node (ST_LIST * node);
PRIVATE void free_type_info_node (ST_LIST * node);
PRIVATE void free_primary_keys_node (ST_LIST * node);
PRIVATE void free_foreign_keys_node (ST_LIST * node);
PRIVATE void free_table_privileges_node (ST_LIST * node);
PRIVATE void free_procedures_node (ST_LIST * node);
PRIVATE void free_procedure_columns_node (ST_LIST * node);
PRIVATE int retrieve_table_from_db_class (int cci_connection,
char *table_name, T_CCI_ERROR *error);
PRIVATE int schema_info_table_privileges (int cci_connection,
int *cci_request, char *table_name, T_CCI_ERROR *error);
PRIVATE int schema_info_procedures (int cci_connection, int *cci_request,
char *proc_name, T_CCI_ERROR *error);
PRIVATE int schema_info_procedure_columns (int cci_connection,
int *cci_request, char *proc_name,
char *column_name, T_CCI_ERROR *error);
PRIVATE int sql_execute (int cci_connection, int *cci_request,
char *sql_statment, char *param_name[],
int param_num, T_CCI_ERROR *error);
PRIVATE void catalog_result_set_init (ODBC_STATEMENT * stmt,
RESULT_TYPE task_type);
PRIVATE void catalog_set_ird (ODBC_STATEMENT * stmt,
ODBC_COL_INFO * colum_info, int column_num);
PRIVATE void err_msg_table_not_exist (char *err_msg, const char *db_name,
const char *table_name);
PUBLIC RETCODE
odbc_tables (ODBC_STATEMENT * stmt,
char *catalog_name, char *schema_name,
char *table_name, char *table_type)
{
int t_type = 0;
char search_pattern_flag;
int handle = -1;
T_CCI_ERROR cci_err_buf;
int cci_rc;
RETCODE rc;
catalog_result_set_init (stmt, TABLES);
catalog_set_ird (stmt, table_cinfo, NC_CATALOG_TABLES);
if (table_type == NULL||table_type[0] == 0)
{
t_type = TABLE_TYPE_ALL;
}
else
{
if (strstr (table_type, "VIEW") != NULL)
SET_OPTION (t_type, TABLE_TYPE_VIEW);
if (strstr (table_type, "TABLE") != NULL)
SET_OPTION (t_type, TABLE_TYPE_TABLE);
if (strstr (table_type, "SYSTEM") != NULL)
SET_OPTION (t_type, TABLE_TYPE_SYSTEM);
}
if (stmt->attr_metadata_id == SQL_TRUE)
{
search_pattern_flag = 0;
}
else
{
search_pattern_flag = CCI_CLASS_NAME_PATTERN_MATCH;
}
if(table_name!=NULL)
{
if(table_name[0]==0)
{
table_name=NULL;
}
}
cci_rc = cci_schema_info (stmt->conn->connhd, CCI_SCH_CLASS,
table_name, NULL, search_pattern_flag,
&cci_err_buf);
ERROR_GOTO (cci_rc, cci_error);
handle = cci_rc;
rc = make_table_result_set (stmt, handle, t_type);
ERROR_GOTO (rc, error);
if (stmt->conn->attr_autocommit == SQL_AUTOCOMMIT_ON)
{
odbc_auto_commit(stmt->conn);
}
cci_close_req_handle (handle);
handle = -1;
return ODBC_SUCCESS;
cci_error:
odbc_set_diag_by_cci (stmt->diag, cci_rc, &cci_err_buf);
error:
if (handle > 0)
{
cci_close_req_handle (handle);
}
return ODBC_ERROR;
}
PUBLIC RETCODE
odbc_columns (ODBC_STATEMENT * stmt,
char *catalog_name,
char *schema_name, char *table_name, char *column_name)
{
RETCODE rc;
char search_pattern_flag;
int handle = -1;
int cci_rc;
T_CCI_ERROR cci_err_buf;
char qualified_tablename[1024];
catalog_result_set_init (stmt, COLUMNS);
catalog_set_ird (stmt, column_cinfo, NC_CATALOG_COLUMNS);
if (stmt->attr_metadata_id == SQL_TRUE)
{
search_pattern_flag = 0;
}
else
{
search_pattern_flag =
CCI_CLASS_NAME_PATTERN_MATCH | CCI_ATTR_NAME_PATTERN_MATCH;
}
if (stmt->conn->omit_schema)
{
sprintf(qualified_tablename, "%s.%s", stmt->conn->user, table_name);
}
else
{
strcpy(qualified_tablename, table_name);
}
cci_rc = cci_schema_info (stmt->conn->connhd, CCI_SCH_ATTRIBUTE,
qualified_tablename, column_name, search_pattern_flag,
&cci_err_buf);
ERROR_GOTO (cci_rc, cci_error);
handle = cci_rc;
rc = make_column_result_set (stmt, handle);
ERROR_GOTO (rc, error);
cci_close_req_handle (handle);
return ODBC_SUCCESS;
cci_error:
odbc_set_diag_by_cci (stmt->diag, cci_rc, &cci_err_buf);
error:
if (handle > 0)
cci_close_req_handle (handle);
return ODBC_ERROR;
}
PUBLIC RETCODE
odbc_statistics (ODBC_STATEMENT * stmt,
char *catalog_name, char *schema_name,
char *table_name, unsigned short unique,
unsigned short reversed)
{
int cci_retval = 0;
int cci_request = 0;
T_CCI_ERROR cci_error;
char err_msg[SQL_MAX_MESSAGE_LENGTH + 1];
catalog_result_set_init (stmt, STATISTICS);
catalog_set_ird (stmt, statistics_cinfo, NC_CATALOG_STATISTICS);
cci_retval = retrieve_table_from_db_class (stmt->conn->connhd, table_name, &cci_error);
if (cci_retval == 0)
{
err_msg_table_not_exist (err_msg, stmt->conn->db_name, table_name);
odbc_set_diag (stmt->diag, "HY000", 0, err_msg);
goto error;
}
else if (cci_retval < 0)
{
goto cci_error;
}
if ((cci_request =
cci_schema_info (stmt->conn->connhd, CCI_SCH_CONSTRAINT, table_name,
NULL, 0, &cci_error)) < 0)
{
goto cci_error;
}
if (make_stat_result_set (stmt, cci_request, table_name, unique) < 0)
{
goto error;
}
cci_close_req_handle (cci_request);
return ODBC_SUCCESS;
cci_error:
odbc_set_diag_by_cci (stmt->diag, cci_retval, &cci_error);
error:
if (cci_request > 0)
{
cci_close_req_handle (cci_request);
}
return ODBC_ERROR;
}
PUBLIC RETCODE
odbc_special_columns (ODBC_STATEMENT * stmt,
short identifier_type,
char *catalog_name,
char *schema_name,
char *table_name, short scope, short nullable)
{
int cci_retval = 0;
int cci_request = 0;
T_CCI_ERROR cci_error;
char err_msg[SQL_MAX_MESSAGE_LENGTH + 1];
catalog_result_set_init (stmt, SPECIALCOLUMNS);
catalog_set_ird (stmt, special_column_cinfo, NC_CATALOG_SPECIALCOLUMNS);
/* CUBRID not have auto-update value */
if (identifier_type == SQL_ROWVER)
{
return ODBC_SUCCESS;
}
cci_retval = retrieve_table_from_db_class (stmt->conn->connhd, table_name, &cci_error);
if (cci_retval == 0)
{
err_msg_table_not_exist (err_msg, stmt->conn->db_name, table_name);
odbc_set_diag (stmt->diag, "HY000", 0, err_msg);
goto error;
}
else if (cci_retval < 0)
{
goto cci_error;
}
if ((cci_request =
cci_schema_info (stmt->conn->connhd, CCI_SCH_CONSTRAINT, table_name,
NULL, 0, &cci_error)) < 0)
{
goto cci_error;
}
if (make_sp_column_result_set (stmt, cci_request, table_name) < 0)
{
goto error;
}
cci_close_req_handle (cci_request);
return ODBC_SUCCESS;
cci_error:
odbc_set_diag_by_cci (stmt->diag, cci_retval, &cci_error);
error:
if (cci_request > 0)
{
cci_close_req_handle (cci_request);
}
return ODBC_ERROR;
}
PUBLIC RETCODE
odbc_foreign_keys (ODBC_STATEMENT * stmt, char *pktablename,
char *fktablename)
{
int cci_retval = 0;
int cci_request = 0;
char *pk_table_name = pktablename;
char *fk_table_name = fktablename;
char pk[MAX_TABLE_NAMME_LEN+1];
char fk[MAX_TABLE_NAMME_LEN+1];
T_CCI_ERROR cci_error;
char search_pattern_flag;
char err_msg[SQL_MAX_MESSAGE_LENGTH + 1];
catalog_result_set_init (stmt, FOREIGN_KEYS);
catalog_set_ird (stmt, foreign_keys_cinfo, NC_CATALOG_FOREIGN_KEYS);
if (stmt->conn->omit_schema)
{
if (pk_table_name)
{
sprintf(pk, "%s.%s", stmt->conn->user, pk_table_name);
pk_table_name = pk;
}
if (fk_table_name)
{
sprintf(fk, "%s.%s", stmt->conn->user, fk_table_name);
fk_table_name = fk;
}
}
if (pk_table_name)
{
cci_retval =
retrieve_table_from_db_class (stmt->conn->connhd, pk_table_name, &cci_error);
if (cci_retval == 0)
{
err_msg_table_not_exist (err_msg, stmt->conn->db_name,
pk_table_name);
odbc_set_diag (stmt->diag, "HY000", 0, err_msg);
goto error;
}
else if (cci_retval < 0)
{
goto cci_error;
}
}
if (fk_table_name)
{
cci_retval =
retrieve_table_from_db_class (stmt->conn->connhd, fk_table_name, &cci_error);
if (cci_retval == 0)
{
err_msg_table_not_exist (err_msg, stmt->conn->db_name,
fk_table_name);
odbc_set_diag (stmt->diag, "HY000", 0, err_msg);
goto error;
}
else if (cci_retval < 0)
{
goto cci_error;
}
}
if (stmt->attr_metadata_id == SQL_TRUE)
{
search_pattern_flag = 0;
}
else
{
search_pattern_flag = CCI_CLASS_NAME_PATTERN_MATCH;
}
if (pk_table_name && fk_table_name)
{
cci_request =
cci_schema_info (stmt->conn->connhd, CCI_SCH_CROSS_REFERENCE,
pk_table_name, fk_table_name, search_pattern_flag,
&cci_error);
}
else if (pk_table_name)
{
cci_request =
cci_schema_info (stmt->conn->connhd, CCI_SCH_EXPORTED_KEYS,
pk_table_name, NULL, search_pattern_flag,
&cci_error);
}
else if (fk_table_name)
{
cci_request =
cci_schema_info (stmt->conn->connhd, CCI_SCH_IMPORTED_KEYS,
fk_table_name, NULL, search_pattern_flag,
&cci_error);
}
if (cci_request < 0)
{
cci_retval = cci_request;
goto cci_error;
}
if (make_foreign_keys_result_set (stmt, cci_request) < 0)
{
goto error;
}
cci_close_req_handle (cci_request);
return ODBC_SUCCESS;
cci_error:
odbc_set_diag_by_cci (stmt->diag, cci_retval, &cci_error);
error:
if (cci_request > 0)
{
cci_close_req_handle (cci_request);
}
return ODBC_ERROR;
}
PUBLIC RETCODE
odbc_primary_keys (ODBC_STATEMENT * stmt, char *catalog_name,
char *schema_name, char *tablename)
{
int cci_retval = 0;
int cci_request = 0;
T_CCI_ERROR cci_error;
char search_pattern_flag;
char err_msg[SQL_MAX_MESSAGE_LENGTH + 1];
char *table_name = tablename;
char pk[MAX_TABLE_NAMME_LEN+MAX_OWNER_NAMME_LEN + 1];
catalog_result_set_init (stmt, PRIMARY_KEYS);
catalog_set_ird (stmt, primary_keys_cinfo, NC_CATALOG_PRIMARY_KEYS);
if (stmt->conn->omit_schema)
{
if (table_name)
{
sprintf (pk, "%s.%s", stmt->conn->user, table_name);
table_name = pk;
}
}
cci_retval = retrieve_table_from_db_class (stmt->conn->connhd, table_name, &cci_error);
if (cci_retval == 0)
{
err_msg_table_not_exist (err_msg, stmt->conn->db_name, table_name);
odbc_set_diag (stmt->diag, "HY000", 0, err_msg);
goto error;
}
else if (cci_retval < 0)
{
goto cci_error;
}
if (stmt->attr_metadata_id == SQL_TRUE)
{
search_pattern_flag = 0;
}
else
{
search_pattern_flag = CCI_CLASS_NAME_PATTERN_MATCH;
}
if ((cci_request =
cci_schema_info (stmt->conn->connhd, CCI_SCH_PRIMARY_KEY, table_name,
NULL, search_pattern_flag, &cci_error)) < 0)
{
cci_retval = cci_request;
goto cci_error;
}
if (make_primary_keys_result_set (stmt, cci_request) < 0)
{
goto error;
}
cci_close_req_handle (cci_request);
return ODBC_SUCCESS;
cci_error:
odbc_set_diag_by_cci (stmt->diag, cci_retval, &cci_error);
error:
if (cci_request > 0)
{
cci_close_req_handle (cci_request);
}
return ODBC_ERROR;
}