-
Notifications
You must be signed in to change notification settings - Fork 15
/
info.c
6110 lines (5568 loc) · 182 KB
/
info.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
/*--------
* Module: info.c
*
* Description: This module contains routines related to
* ODBC informational functions.
*
* Classes: n/a
*
* API functions: SQLGetInfo, SQLGetTypeInfo, SQLGetFunctions,
* SQLTables, SQLColumns, SQLStatistics, SQLSpecialColumns,
* SQLPrimaryKeys, SQLForeignKeys,
* SQLProcedureColumns, SQLProcedures,
* SQLTablePrivileges, SQLColumnPrivileges(NI)
*
* Comments: See "readme.txt" for copyright and license information.
*--------
*/
#include "psqlodbc.h"
#include "unicode_support.h"
#include <string.h>
#include <stdio.h>
#ifndef WIN32
#include <ctype.h>
#endif
#include "tuple.h"
#include "pgtypes.h"
#include "dlg_specific.h"
#include "environ.h"
#include "connection.h"
#include "statement.h"
#include "qresult.h"
#include "bind.h"
#include "misc.h"
#include "pgtypes.h"
#include "pgapifunc.h"
#include "multibyte.h"
#include "catfunc.h"
/* Trigger related stuff for SQLForeign Keys */
#define TRIGGER_SHIFT 3
#define TRIGGER_MASK 0x03
#define TRIGGER_DELETE 0x01
#define TRIGGER_UPDATE 0x02
static const SQLCHAR *pubstr = (SQLCHAR *) "public";
static const char *likeop = "like";
static const char *eqop = "=";
/* group of SQL_CVT_(chars) */
#define PG_CONVERT_CH SQL_CVT_CHAR | SQL_CVT_VARCHAR | SQL_CVT_LONGVARCHAR
/* group of SQL_CVT_(numbers) */
#define PG_CONVERT_NUM SQL_CVT_SMALLINT | SQL_CVT_INTEGER | SQL_CVT_BIGINT | SQL_CVT_REAL | SQL_CVT_FLOAT | SQL_CVT_DOUBLE | SQL_CVT_NUMERIC | SQL_CVT_DECIMAL
/* group of SQL_CVT_(date time) */
#define PG_CONVERT_DT SQL_CVT_DATE | SQL_CVT_TIME | SQL_CVT_TIMESTAMP
/* group of SQL_CVT_(wchars) */
#ifdef UNICODE_SUPPORT
#define PG_CONVERT_WCH SQL_CVT_WCHAR | SQL_CVT_WVARCHAR | SQL_CVT_WLONGVARCHAR
#else
#define PG_CONVERT_WCH 0
#endif /* UNICODE_SUPPORT */
#define QR_set_field_info_EN(self, field_num, adtid, adtsize) (CI_set_field_info(self->fields, field_num, catcn[field_num][is_ODBC2], adtid, adtsize, -1, 0, 0))
const SQLLEN mask_longvarbinary = SQL_CVT_LONGVARBINARY;
RETCODE SQL_API
PGAPI_GetInfo(HDBC hdbc,
SQLUSMALLINT fInfoType,
PTR rgbInfoValue,
SQLSMALLINT cbInfoValueMax,
SQLSMALLINT * pcbInfoValue)
{
CSTR func = "PGAPI_GetInfo";
ConnectionClass *conn = (ConnectionClass *) hdbc;
ConnInfo *ci;
const char *p = NULL;
char tmp[MAX_INFO_STRING];
SQLULEN len = 0,
value = 0;
RETCODE ret = SQL_ERROR;
char odbcver[16];
MYLOG(0, "entering...fInfoType=%d\n", fInfoType);
if (!conn)
{
CC_log_error(func, NULL_STRING, NULL);
return SQL_INVALID_HANDLE;
}
ci = &(conn->connInfo);
switch (fInfoType)
{
case SQL_ACCESSIBLE_PROCEDURES: /* ODBC 1.0 */
p = "N";
break;
case SQL_ACCESSIBLE_TABLES: /* ODBC 1.0 */
p = CC_accessible_only(conn) ? "Y" : "N";
break;
case SQL_ACTIVE_CONNECTIONS: /* ODBC 1.0 */
len = 2;
value = 0;
break;
case SQL_ACTIVE_STATEMENTS: /* ODBC 1.0 */
len = 2;
value = 0;
break;
case SQL_ALTER_TABLE: /* ODBC 2.0 */
len = 4;
value = SQL_AT_ADD_COLUMN
| SQL_AT_DROP_COLUMN
| SQL_AT_ADD_COLUMN_SINGLE
| SQL_AT_ADD_CONSTRAINT
| SQL_AT_ADD_TABLE_CONSTRAINT
| SQL_AT_CONSTRAINT_INITIALLY_DEFERRED
| SQL_AT_CONSTRAINT_INITIALLY_IMMEDIATE
| SQL_AT_CONSTRAINT_DEFERRABLE
| SQL_AT_DROP_TABLE_CONSTRAINT_RESTRICT
| SQL_AT_DROP_TABLE_CONSTRAINT_CASCADE
| SQL_AT_DROP_COLUMN_RESTRICT
| SQL_AT_DROP_COLUMN_CASCADE;
break;
case SQL_BOOKMARK_PERSISTENCE: /* ODBC 2.0 */
/* very simple bookmark support */
len = 4;
value = SQL_BP_SCROLL | SQL_BP_DELETE | SQL_BP_UPDATE | SQL_BP_TRANSACTION;
break;
case SQL_COLUMN_ALIAS: /* ODBC 2.0 */
p = "Y";
break;
case SQL_CONCAT_NULL_BEHAVIOR: /* ODBC 1.0 */
len = 2;
value = SQL_CB_NON_NULL;
break;
case SQL_CONVERT_BIT:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : SQL_CVT_BIT | SQL_CVT_INTEGER | PG_CONVERT_CH | PG_CONVERT_WCH;
MYLOG(0, "SQL_CONVERT_ mask=" FORMAT_ULEN "\n", value);
break;
case SQL_CONVERT_INTEGER:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : SQL_CVT_BIT | PG_CONVERT_NUM | PG_CONVERT_CH | PG_CONVERT_WCH;
break;
case SQL_CONVERT_SMALLINT:
case SQL_CONVERT_BIGINT:
case SQL_CONVERT_DECIMAL:
case SQL_CONVERT_DOUBLE:
case SQL_CONVERT_FLOAT:
case SQL_CONVERT_NUMERIC:
case SQL_CONVERT_REAL:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : PG_CONVERT_NUM | PG_CONVERT_CH | PG_CONVERT_WCH;
break;
case SQL_CONVERT_CHAR:
case SQL_CONVERT_VARCHAR: /* ODBC 1.0 */
case SQL_CONVERT_LONGVARCHAR:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : SQL_CVT_BIT | PG_CONVERT_NUM | PG_CONVERT_CH | PG_CONVERT_WCH;
break;
case SQL_CONVERT_DATE:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : PG_CONVERT_CH | SQL_CVT_DATE | SQL_CVT_TIMESTAMP | PG_CONVERT_WCH;
break;
case SQL_CONVERT_TIME:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : PG_CONVERT_CH | SQL_CVT_TIME | PG_CONVERT_WCH;
break;
case SQL_CONVERT_TIMESTAMP:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : PG_CONVERT_CH | PG_CONVERT_DT | PG_CONVERT_WCH;
break;
case SQL_CONVERT_LONGVARBINARY:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : SQL_CVT_LONGVARBINARY;
break;
#ifdef UNICODE_SUPPORT
case SQL_CONVERT_WCHAR:
case SQL_CONVERT_WLONGVARCHAR:
case SQL_CONVERT_WVARCHAR:
len = sizeof(SQLUINTEGER);
value = ci->disable_convert_func ? 0 : SQL_CVT_BIT | PG_CONVERT_NUM | PG_CONVERT_DT | PG_CONVERT_WCH;
break;
#endif /* UNICODE_SUPPORT */
case SQL_CONVERT_TINYINT:
case SQL_CONVERT_BINARY:
case SQL_CONVERT_VARBINARY: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = 0; /* CONVERT is unavailable */
break;
case SQL_CONVERT_FUNCTIONS: /* ODBC 1.0 */
len = sizeof(SQLUINTEGER);
value = SQL_FN_CVT_CONVERT;
MYLOG(0, "CONVERT_FUNCTIONS=" FORMAT_ULEN "\n", value);
break;
case SQL_CORRELATION_NAME: /* ODBC 1.0 */
/*
* Saying no correlation name makes Query not work right.
* value = SQL_CN_NONE;
*/
len = 2;
value = SQL_CN_ANY;
break;
case SQL_CURSOR_COMMIT_BEHAVIOR: /* ODBC 1.0 */
len = 2;
value = SQL_CB_PRESERVE;
break;
case SQL_CURSOR_ROLLBACK_BEHAVIOR: /* ODBC 1.0 */
len = 2;
if (!ci->drivers.use_declarefetch)
value = SQL_CB_PRESERVE;
else
value = SQL_CB_CLOSE;
break;
case SQL_DATA_SOURCE_NAME: /* ODBC 1.0 */
p = CC_get_DSN(conn);
break;
case SQL_DATA_SOURCE_READ_ONLY: /* ODBC 1.0 */
p = CC_is_onlyread(conn) ? "Y" : "N";
break;
case SQL_DATABASE_NAME: /* Support for old ODBC 1.0 Apps */
/*
* Returning the database name causes problems in MS Query. It
* generates query like: "SELECT DISTINCT a FROM byronnbad3
* bad3"
*
* p = CC_get_database(conn);
*/
p = CurrCatString(conn);
break;
case SQL_DBMS_NAME: /* ODBC 1.0 */
if (CC_fake_mss(conn))
p = "Microsoft SQL Server";
else
p = "PostgreSQL";
break;
case SQL_DBMS_VER: /* ODBC 1.0 */
/*
* The ODBC spec wants ##.##.#### ...whatever... so prepend
* the driver
*/
/* version number to the dbms version string */
/*
SPRINTF_FIXED(tmp, "%s %s", POSTGRESDRIVERVERSION, conn->pg_version);
tmp[sizeof(tmp) - 1] = '\0'; */
if (CC_fake_mss(conn))
p = "09.00.1399";
else
{
STRCPY_FIXED(tmp, conn->pg_version);
p = tmp;
}
break;
case SQL_DEFAULT_TXN_ISOLATION: /* ODBC 1.0 */
len = 4;
if (0 == conn->default_isolation)
conn->isolation = CC_get_isolation(conn);
value = conn->default_isolation;
break;
case SQL_DRIVER_NAME: /* ODBC 1.0 */
p = DRIVER_FILE_NAME;
break;
case SQL_DRIVER_ODBC_VER:
SPRINTF_FIXED(odbcver, "%02x.%02x", ODBCVER / 256, ODBCVER % 256);
/* p = DRIVER_ODBC_VER; */
p = odbcver;
break;
case SQL_DRIVER_VER: /* ODBC 1.0 */
p = POSTGRESDRIVERVERSION;
break;
case SQL_EXPRESSIONS_IN_ORDERBY: /* ODBC 1.0 */
p = "Y";
break;
case SQL_FETCH_DIRECTION: /* ODBC 1.0 */
len = 4;
value = (SQL_FD_FETCH_NEXT |
SQL_FD_FETCH_FIRST |
SQL_FD_FETCH_LAST |
SQL_FD_FETCH_PRIOR |
SQL_FD_FETCH_ABSOLUTE |
SQL_FD_FETCH_RELATIVE |
SQL_FD_FETCH_BOOKMARK);
break;
case SQL_FILE_USAGE: /* ODBC 2.0 */
len = 2;
value = SQL_FILE_NOT_SUPPORTED;
break;
case SQL_GETDATA_EXTENSIONS: /* ODBC 2.0 */
len = 4;
value = (SQL_GD_ANY_COLUMN | SQL_GD_ANY_ORDER | SQL_GD_BOUND | SQL_GD_BLOCK);
break;
case SQL_GROUP_BY: /* ODBC 2.0 */
len = 2;
value = SQL_GB_GROUP_BY_EQUALS_SELECT;
break;
case SQL_IDENTIFIER_CASE: /* ODBC 1.0 */
/*
* are identifiers case-sensitive (yes, but only when quoted.
* If not quoted, they default to lowercase)
*/
len = 2;
value = SQL_IC_LOWER;
break;
case SQL_IDENTIFIER_QUOTE_CHAR: /* ODBC 1.0 */
/* the character used to quote "identifiers" */
p = "\"";
break;
case SQL_KEYWORDS: /* ODBC 2.0 */
p = NULL_STRING;
break;
case SQL_LIKE_ESCAPE_CLAUSE: /* ODBC 2.0 */
p = "Y";
break;
case SQL_LOCK_TYPES: /* ODBC 2.0 */
len = 4;
value = ci->drivers.lie ? (SQL_LCK_NO_CHANGE | SQL_LCK_EXCLUSIVE | SQL_LCK_UNLOCK) : SQL_LCK_NO_CHANGE;
break;
case SQL_MAX_BINARY_LITERAL_LEN: /* ODBC 2.0 */
len = 4;
value = 0;
break;
case SQL_MAX_CHAR_LITERAL_LEN: /* ODBC 2.0 */
len = 4;
value = 0;
break;
case SQL_MAX_COLUMN_NAME_LEN: /* ODBC 1.0 */
len = 2;
value = CC_get_max_idlen(conn);
if (0 == value)
value = NAMEDATALEN_V73 - 1;
break;
case SQL_MAX_COLUMNS_IN_GROUP_BY: /* ODBC 2.0 */
len = 2;
value = 0;
break;
case SQL_MAX_COLUMNS_IN_INDEX: /* ODBC 2.0 */
len = 2;
value = 0;
break;
case SQL_MAX_COLUMNS_IN_ORDER_BY: /* ODBC 2.0 */
len = 2;
value = 0;
break;
case SQL_MAX_COLUMNS_IN_SELECT: /* ODBC 2.0 */
len = 2;
value = 0;
break;
case SQL_MAX_COLUMNS_IN_TABLE: /* ODBC 2.0 */
len = 2;
value = 0;
break;
case SQL_MAX_CURSOR_NAME_LEN: /* ODBC 1.0 */
len = 2;
value = MAX_CURSOR_LEN;
break;
case SQL_MAX_INDEX_SIZE: /* ODBC 2.0 */
len = 4;
value = 0;
break;
case SQL_MAX_OWNER_NAME_LEN: /* ODBC 1.0 */
len = 2;
value = 0;
if (PG_VERSION_GT(conn, 7.4))
value = CC_get_max_idlen(conn);
#ifdef MAX_SCHEMA_LEN
else
value = MAX_SCHEMA_LEN;
#endif /* MAX_SCHEMA_LEN */
if (0 == value)
value = NAMEDATALEN_V73 - 1;
break;
case SQL_MAX_PROCEDURE_NAME_LEN: /* ODBC 1.0 */
len = 2;
value = 0;
break;
case SQL_MAX_QUALIFIER_NAME_LEN: /* ODBC 1.0 */
len = 2;
value = 0;
break;
case SQL_MAX_ROW_SIZE: /* ODBC 2.0 */
len = 4;
/* No limit with tuptoaster in 7.1+ */
value = 0;
break;
case SQL_MAX_STATEMENT_LEN: /* ODBC 2.0 */
len = 4;
value = 0;
break;
case SQL_MAX_TABLE_NAME_LEN: /* ODBC 1.0 */
len = 2;
if (PG_VERSION_GT(conn, 7.4))
value = CC_get_max_idlen(conn);
#ifdef MAX_TABLE_LEN
else
value = MAX_TABLE_LEN;
#endif /* MAX_TABLE_LEN */
if (0 == value)
value = NAMEDATALEN_V73 - 1;
break;
case SQL_MAX_TABLES_IN_SELECT: /* ODBC 2.0 */
len = 2;
value = 0;
break;
case SQL_MAX_USER_NAME_LEN:
len = 2;
value = 0;
break;
case SQL_MULT_RESULT_SETS: /* ODBC 1.0 */
/* Don't support multiple result sets but say yes anyway? */
p = "Y";
break;
case SQL_MULTIPLE_ACTIVE_TXN: /* ODBC 1.0 */
p = "Y";
break;
case SQL_NEED_LONG_DATA_LEN: /* ODBC 2.0 */
/*
* Don't need the length, SQLPutData can handle any size and
* multiple calls
*/
p = "N";
break;
case SQL_NON_NULLABLE_COLUMNS: /* ODBC 1.0 */
len = 2;
value = SQL_NNC_NON_NULL;
break;
case SQL_NULL_COLLATION: /* ODBC 2.0 */
/* where are nulls sorted? */
len = 2;
value = SQL_NC_HIGH;
break;
case SQL_NUMERIC_FUNCTIONS: /* ODBC 1.0 */
len = 4;
value = SQL_FN_NUM_ABS | SQL_FN_NUM_ACOS | SQL_FN_NUM_ASIN | SQL_FN_NUM_ATAN |
SQL_FN_NUM_ATAN2 | SQL_FN_NUM_CEILING | SQL_FN_NUM_COS | SQL_FN_NUM_COT |
SQL_FN_NUM_DEGREES | SQL_FN_NUM_EXP | SQL_FN_NUM_FLOOR | SQL_FN_NUM_LOG |
SQL_FN_NUM_LOG10 | SQL_FN_NUM_MOD | SQL_FN_NUM_PI | SQL_FN_NUM_POWER |
SQL_FN_NUM_RADIANS | SQL_FN_NUM_RAND | SQL_FN_NUM_ROUND | SQL_FN_NUM_SIGN |
SQL_FN_NUM_SIN | SQL_FN_NUM_SQRT | SQL_FN_NUM_TAN | SQL_FN_NUM_TRUNCATE;
break;
case SQL_ODBC_API_CONFORMANCE: /* ODBC 1.0 */
len = 2;
value = SQL_OAC_LEVEL1;
break;
case SQL_ODBC_SAG_CLI_CONFORMANCE: /* ODBC 1.0 */
len = 2;
value = SQL_OSCC_NOT_COMPLIANT;
break;
case SQL_ODBC_SQL_CONFORMANCE: /* ODBC 1.0 */
len = 2;
value = SQL_OSC_CORE;
break;
case SQL_ODBC_SQL_OPT_IEF: /* ODBC 1.0 */
p = "N";
break;
case SQL_OJ_CAPABILITIES: /* ODBC 2.01 */
len = 4;
value = (SQL_OJ_LEFT |
SQL_OJ_RIGHT |
SQL_OJ_FULL |
SQL_OJ_NESTED |
SQL_OJ_NOT_ORDERED |
SQL_OJ_INNER |
SQL_OJ_ALL_COMPARISON_OPS);
break;
case SQL_ORDER_BY_COLUMNS_IN_SELECT: /* ODBC 2.0 */
p = "Y";
break;
case SQL_OUTER_JOINS: /* ODBC 1.0 */
p = "Y";
break;
case SQL_OWNER_TERM: /* ODBC 1.0 */
p = "schema";
break;
case SQL_OWNER_USAGE: /* ODBC 2.0 */
len = 4;
value = SQL_OU_DML_STATEMENTS
| SQL_OU_TABLE_DEFINITION
| SQL_OU_INDEX_DEFINITION
| SQL_OU_PRIVILEGE_DEFINITION;
break;
case SQL_POS_OPERATIONS: /* ODBC 2.0 */
len = 4;
value = (SQL_POS_POSITION | SQL_POS_REFRESH);
if (0 != ci->updatable_cursors)
value |= (SQL_POS_UPDATE | SQL_POS_DELETE | SQL_POS_ADD);
break;
case SQL_POSITIONED_STATEMENTS: /* ODBC 2.0 */
len = 4;
value = ci->drivers.lie ? (SQL_PS_POSITIONED_DELETE |
SQL_PS_POSITIONED_UPDATE |
SQL_PS_SELECT_FOR_UPDATE) : 0;
break;
case SQL_PROCEDURE_TERM: /* ODBC 1.0 */
p = "procedure";
break;
case SQL_PROCEDURES: /* ODBC 1.0 */
p = "Y";
break;
case SQL_QUALIFIER_LOCATION: /* ODBC 2.0 */
len = 2;
if (CurrCat(conn))
value = SQL_QL_START;
else
value = 0;
break;
case SQL_QUALIFIER_NAME_SEPARATOR: /* ODBC 1.0 */
if (CurrCat(conn))
p = ".";
else
p = NULL_STRING;
break;
case SQL_QUALIFIER_TERM: /* ODBC 1.0 */
if (CurrCat(conn))
p = "catalog";
else
p = NULL_STRING;
break;
case SQL_QUALIFIER_USAGE: /* ODBC 2.0 */
len = 4;
if (CurrCat(conn))
value = SQL_CU_DML_STATEMENTS;
else
value = 0;
break;
case SQL_QUOTED_IDENTIFIER_CASE: /* ODBC 2.0 */
/* are "quoted" identifiers case-sensitive? YES! */
len = 2;
value = SQL_IC_SENSITIVE;
break;
case SQL_ROW_UPDATES: /* ODBC 1.0 */
/*
* Driver doesn't support keyset-driven or mixed cursors, so
* not much point in saying row updates are supported
*/
p = (0 != ci->updatable_cursors) ? "Y" : "N";
break;
case SQL_SCROLL_CONCURRENCY: /* ODBC 1.0 */
len = 4;
value = SQL_SCCO_READ_ONLY;
if (0 != ci->updatable_cursors)
value |= SQL_SCCO_OPT_ROWVER;
if (ci->drivers.lie)
value |= (SQL_SCCO_LOCK | SQL_SCCO_OPT_VALUES);
break;
case SQL_SCROLL_OPTIONS: /* ODBC 1.0 */
len = 4;
value = SQL_SO_FORWARD_ONLY | SQL_SO_STATIC;
if (0 != (ci->updatable_cursors & ALLOW_KEYSET_DRIVEN_CURSORS))
value |= SQL_SO_KEYSET_DRIVEN;
if (ci->drivers.lie)
value |= (SQL_SO_DYNAMIC | SQL_SO_MIXED);
break;
case SQL_SEARCH_PATTERN_ESCAPE: /* ODBC 1.0 */
p = "\\";
break;
case SQL_SERVER_NAME: /* ODBC 1.0 */
p = CC_get_server(conn);
break;
case SQL_SPECIAL_CHARACTERS: /* ODBC 2.0 */
p = "_";
break;
case SQL_STATIC_SENSITIVITY: /* ODBC 2.0 */
len = 4;
value = 0;
if (0 != ci->updatable_cursors)
value |= (SQL_SS_ADDITIONS | SQL_SS_DELETIONS | SQL_SS_UPDATES);
break;
case SQL_STRING_FUNCTIONS: /* ODBC 1.0 */
len = 4;
value = SQL_FN_STR_ASCII | SQL_FN_STR_CHAR | SQL_FN_STR_CONCAT |
SQL_FN_STR_INSERT | SQL_FN_STR_LCASE | SQL_FN_STR_LEFT |
SQL_FN_STR_LENGTH | SQL_FN_STR_LOCATE | SQL_FN_STR_LOCATE_2 |
SQL_FN_STR_LTRIM | SQL_FN_STR_REPEAT | SQL_FN_STR_RIGHT |
SQL_FN_STR_RTRIM | SQL_FN_STR_SPACE | SQL_FN_STR_SUBSTRING | SQL_FN_STR_UCASE;
break;
case SQL_SUBQUERIES: /* ODBC 2.0 */
/* postgres 6.3 supports subqueries */
len = 4;
value = (SQL_SQ_QUANTIFIED |
SQL_SQ_IN |
SQL_SQ_EXISTS |
SQL_SQ_COMPARISON);
break;
case SQL_SYSTEM_FUNCTIONS: /* ODBC 1.0 */
len = 4;
value = SQL_FN_SYS_IFNULL | SQL_FN_SYS_USERNAME;
break;
case SQL_TABLE_TERM: /* ODBC 1.0 */
p = "table";
break;
case SQL_TIMEDATE_ADD_INTERVALS: /* ODBC 2.0 */
len = 4;
value = SQL_FN_TSI_DAY | SQL_FN_TSI_HOUR | SQL_FN_TSI_MINUTE | SQL_FN_TSI_SECOND
| SQL_FN_TSI_FRAC_SECOND | SQL_FN_TSI_YEAR | SQL_FN_TSI_MONTH | SQL_FN_TSI_WEEK;
break;
case SQL_TIMEDATE_DIFF_INTERVALS: /* ODBC 2.0 */
len = 4;
value = SQL_FN_TSI_DAY | SQL_FN_TSI_HOUR | SQL_FN_TSI_MINUTE
| SQL_FN_TSI_SECOND | SQL_FN_TSI_SECOND;
break;
case SQL_TIMEDATE_FUNCTIONS: /* ODBC 1.0 */
len = 4;
value = SQL_FN_TD_NOW | SQL_FN_TD_CURRENT_DATE | SQL_FN_TD_CURRENT_TIME
| SQL_FN_TD_CURRENT_TIMESTAMP | SQL_FN_TD_CURDATE | SQL_FN_TD_CURTIME
| SQL_FN_TD_DAYNAME | SQL_FN_TD_DAYOFMONTH | SQL_FN_TD_DAYOFWEEK
| SQL_FN_TD_DAYOFYEAR | SQL_FN_TD_HOUR | SQL_FN_TD_MINUTE
| SQL_FN_TD_MONTH | SQL_FN_TD_MONTHNAME | SQL_FN_TD_NOW
| SQL_FN_TD_QUARTER | SQL_FN_TD_SECOND | SQL_FN_TD_WEEK | SQL_FN_TD_YEAR
| SQL_FN_TD_TIMESTAMPADD | SQL_FN_TD_TIMESTAMPDIFF | SQL_FN_TD_EXTRACT;
break;
case SQL_TXN_CAPABLE: /* ODBC 1.0 */
/*
* Postgres can deal with create or drop table statements in a
* transaction
*/
len = 2;
value = SQL_TC_ALL;
break;
case SQL_TXN_ISOLATION_OPTION: /* ODBC 1.0 */
len = 4;
value = SQL_TXN_READ_UNCOMMITTED | SQL_TXN_READ_COMMITTED |
SQL_TXN_REPEATABLE_READ | SQL_TXN_SERIALIZABLE;
break;
case SQL_UNION: /* ODBC 2.0 */
/* unions with all supported in postgres 6.3 */
len = 4;
value = (SQL_U_UNION | SQL_U_UNION_ALL);
break;
case SQL_USER_NAME: /* ODBC 1.0 */
p = CC_get_username(conn);
break;
/* Keys for ODBC 3.0 */
case SQL_DYNAMIC_CURSOR_ATTRIBUTES1:
len = 4;
value = 0;
break;
case SQL_DYNAMIC_CURSOR_ATTRIBUTES2:
len = 4;
value = 0;
break;
case SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1:
len = 4;
value = SQL_CA1_NEXT; /* others aren't allowed in ODBC spec */
break;
case SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2:
len = 4;
value = SQL_CA2_READ_ONLY_CONCURRENCY;
if (!ci->drivers.use_declarefetch || ci->drivers.lie)
value |= SQL_CA2_CRC_EXACT;
break;
case SQL_KEYSET_CURSOR_ATTRIBUTES1:
len = 4;
value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE
| SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK
| SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION
| SQL_CA1_POS_REFRESH;
if (0 != (ci->updatable_cursors & ALLOW_KEYSET_DRIVEN_CURSORS))
value |= (SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE
| SQL_CA1_BULK_ADD
| SQL_CA1_BULK_UPDATE_BY_BOOKMARK
| SQL_CA1_BULK_DELETE_BY_BOOKMARK
| SQL_CA1_BULK_FETCH_BY_BOOKMARK
);
if (ci->drivers.lie)
value |= (SQL_CA1_LOCK_EXCLUSIVE
| SQL_CA1_LOCK_UNLOCK
| SQL_CA1_POSITIONED_UPDATE
| SQL_CA1_POSITIONED_DELETE
| SQL_CA1_SELECT_FOR_UPDATE
);
break;
case SQL_KEYSET_CURSOR_ATTRIBUTES2:
len = 4;
value = SQL_CA2_READ_ONLY_CONCURRENCY;
if (0 != (ci->updatable_cursors & ALLOW_KEYSET_DRIVEN_CURSORS))
value |= (SQL_CA2_OPT_ROWVER_CONCURRENCY
/*| SQL_CA2_CRC_APPROXIMATE*/
);
if (0 != (ci->updatable_cursors & SENSE_SELF_OPERATIONS))
value |= (SQL_CA2_SENSITIVITY_DELETIONS
| SQL_CA2_SENSITIVITY_UPDATES
| SQL_CA2_SENSITIVITY_ADDITIONS
);
if (!ci->drivers.use_declarefetch || ci->drivers.lie)
value |= SQL_CA2_CRC_EXACT;
if (ci->drivers.lie)
value |= (SQL_CA2_LOCK_CONCURRENCY
| SQL_CA2_OPT_VALUES_CONCURRENCY
| SQL_CA2_MAX_ROWS_SELECT
| SQL_CA2_MAX_ROWS_INSERT
| SQL_CA2_MAX_ROWS_DELETE
| SQL_CA2_MAX_ROWS_UPDATE
| SQL_CA2_MAX_ROWS_CATALOG
| SQL_CA2_MAX_ROWS_AFFECTS_ALL
| SQL_CA2_SIMULATE_NON_UNIQUE
| SQL_CA2_SIMULATE_TRY_UNIQUE
| SQL_CA2_SIMULATE_UNIQUE
);
break;
case SQL_STATIC_CURSOR_ATTRIBUTES1:
len = 4;
value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE
| SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK
| SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION
| SQL_CA1_POS_REFRESH;
if (0 != (ci->updatable_cursors & ALLOW_STATIC_CURSORS))
value |= (SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE
);
if (0 != (ci->updatable_cursors & ALLOW_BULK_OPERATIONS))
value |= (SQL_CA1_BULK_ADD
| SQL_CA1_BULK_UPDATE_BY_BOOKMARK
| SQL_CA1_BULK_DELETE_BY_BOOKMARK
| SQL_CA1_BULK_FETCH_BY_BOOKMARK
);
break;
case SQL_STATIC_CURSOR_ATTRIBUTES2:
len = 4;
value = SQL_CA2_READ_ONLY_CONCURRENCY;
if (0 != (ci->updatable_cursors & ALLOW_STATIC_CURSORS))
value |= (SQL_CA2_OPT_ROWVER_CONCURRENCY
);
if (0 != (ci->updatable_cursors & SENSE_SELF_OPERATIONS))
value |= (SQL_CA2_SENSITIVITY_DELETIONS
| SQL_CA2_SENSITIVITY_UPDATES
| SQL_CA2_SENSITIVITY_ADDITIONS
);
if (!ci->drivers.use_declarefetch || ci->drivers.lie)
value |= (SQL_CA2_CRC_EXACT
);
break;
case SQL_ODBC_INTERFACE_CONFORMANCE:
len = 4;
value = SQL_OIC_CORE;
if (ci->drivers.lie)
value = SQL_OIC_LEVEL2;
break;
case SQL_ACTIVE_ENVIRONMENTS:
len = 2;
value = 0;
break;
case SQL_AGGREGATE_FUNCTIONS:
len = 4;
value = SQL_AF_ALL;
break;
case SQL_ALTER_DOMAIN:
len = 4;
value = 0;
break;
case SQL_ASYNC_MODE:
len = 4;
value = SQL_AM_NONE;
break;
case SQL_BATCH_ROW_COUNT:
len = 4;
value = SQL_BRC_EXPLICIT;
break;
case SQL_BATCH_SUPPORT:
len = 4;
value = SQL_BS_SELECT_EXPLICIT | SQL_BS_ROW_COUNT_EXPLICIT;
break;
case SQL_CATALOG_NAME:
if (CurrCat(conn))
p = "Y";
else
p = "N";
break;
case SQL_COLLATION_SEQ:
p = "";
break;
case SQL_CREATE_ASSERTION:
len = 4;
value = 0;
break;
case SQL_CREATE_CHARACTER_SET:
len = 4;
value = 0;
break;
case SQL_CREATE_COLLATION:
len = 4;
value = 0;
break;
case SQL_CREATE_DOMAIN:
len = 4;
value = 0;
break;
case SQL_CREATE_SCHEMA:
len = 4;
value = SQL_CS_CREATE_SCHEMA | SQL_CS_AUTHORIZATION;
break;
case SQL_CREATE_TABLE:
len = 4;
value = SQL_CT_CREATE_TABLE
| SQL_CT_COLUMN_CONSTRAINT
| SQL_CT_COLUMN_DEFAULT
| SQL_CT_GLOBAL_TEMPORARY
| SQL_CT_TABLE_CONSTRAINT
| SQL_CT_CONSTRAINT_NAME_DEFINITION
| SQL_CT_CONSTRAINT_INITIALLY_DEFERRED
| SQL_CT_CONSTRAINT_INITIALLY_IMMEDIATE
| SQL_CT_CONSTRAINT_DEFERRABLE;
break;
case SQL_CREATE_TRANSLATION:
len = 4;
value = 0;
break;
case SQL_CREATE_VIEW:
len = 4;
value = SQL_CV_CREATE_VIEW;
break;
case SQL_DDL_INDEX:
len = 4;
value = SQL_DI_CREATE_INDEX | SQL_DI_DROP_INDEX;
break;
case SQL_DESCRIBE_PARAMETER:
p = "N";
break;
case SQL_DROP_ASSERTION:
len = 4;
value = 0;
break;
case SQL_DROP_CHARACTER_SET:
len = 4;
value = 0;
break;
case SQL_DROP_COLLATION:
len = 4;
value = 0;
break;
case SQL_DROP_DOMAIN:
len = 4;
value = 0;
break;
case SQL_DROP_SCHEMA:
len = 4;
value = SQL_DS_DROP_SCHEMA | SQL_DS_RESTRICT | SQL_DS_CASCADE;
break;
case SQL_DROP_TABLE:
len = 4;
value = SQL_DT_DROP_TABLE;
value |= (SQL_DT_RESTRICT | SQL_DT_CASCADE);
break;
case SQL_DROP_TRANSLATION:
len = 4;
value = 0;
break;
case SQL_DROP_VIEW:
len = 4;
value = SQL_DV_DROP_VIEW;
value |= (SQL_DV_RESTRICT | SQL_DV_CASCADE);
break;
case SQL_INDEX_KEYWORDS:
len = 4;
value = SQL_IK_NONE;
break;
case SQL_INFO_SCHEMA_VIEWS:
len = 4;
value = 0;
break;
case SQL_INSERT_STATEMENT:
len = 4;
value = SQL_IS_INSERT_LITERALS | SQL_IS_INSERT_SEARCHED | SQL_IS_SELECT_INTO;
break;
case SQL_MAX_IDENTIFIER_LEN:
len = 2;
value = CC_get_max_idlen(conn);
if (0 == value)
value = NAMEDATALEN_V73 - 1;
break;
case SQL_MAX_ROW_SIZE_INCLUDES_LONG:
p = "Y";
break;
case SQL_PARAM_ARRAY_ROW_COUNTS:
len = 4;
value = SQL_PARC_BATCH;
break;
case SQL_PARAM_ARRAY_SELECTS:
len = 4;
value = SQL_PAS_BATCH;
break;
case SQL_SQL_CONFORMANCE:
len = 4;
value = SQL_SC_SQL92_ENTRY;
break;
case SQL_SQL92_DATETIME_FUNCTIONS:
len = 4;
value = SQL_SDF_CURRENT_DATE | SQL_SDF_CURRENT_TIME | SQL_SDF_CURRENT_TIMESTAMP;
break;
case SQL_SQL92_FOREIGN_KEY_DELETE_RULE:
len = 4;
value = SQL_SFKD_CASCADE | SQL_SFKD_NO_ACTION | SQL_SFKD_SET_DEFAULT | SQL_SFKD_SET_NULL;
break;
case SQL_SQL92_FOREIGN_KEY_UPDATE_RULE:
len = 4;
value = SQL_SFKU_CASCADE | SQL_SFKU_NO_ACTION | SQL_SFKU_SET_DEFAULT | SQL_SFKU_SET_NULL;