-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgapi30.c
executable file
·2128 lines (2056 loc) · 58.9 KB
/
pgapi30.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: pgapi30.c
*
* Description: This module contains routines related to ODBC 3.0
* most of their implementations are temporary
* and must be rewritten properly.
* 2001/07/23 inoue
*
* Classes: n/a
*
* API functions: PGAPI_ColAttribute, PGAPI_GetDiagRec,
PGAPI_GetConnectAttr, PGAPI_GetStmtAttr,
PGAPI_SetConnectAttr, PGAPI_SetStmtAttr
*-------
*/
#include "psqlodbc.h"
#include "misc.h"
#include <stdio.h>
#include <string.h>
#include "environ.h"
#include "connection.h"
#include "statement.h"
#include "descriptor.h"
#include "qresult.h"
#include "pgapifunc.h"
#include "loadlib.h"
#include "dlg_specific.h"
/* SQLError -> SQLDiagRec */
RETCODE SQL_API
PGAPI_GetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT RecNumber, SQLCHAR *Sqlstate,
SQLINTEGER *NativeError, SQLCHAR *MessageText,
SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
{
RETCODE ret;
MYLOG(0, "entering type=%d rec=%d\n", HandleType, RecNumber);
switch (HandleType)
{
case SQL_HANDLE_ENV:
ret = PGAPI_EnvError(Handle, RecNumber, Sqlstate,
NativeError, MessageText,
BufferLength, TextLength, 0);
break;
case SQL_HANDLE_DBC:
ret = PGAPI_ConnectError(Handle, RecNumber, Sqlstate,
NativeError, MessageText, BufferLength,
TextLength, 0);
break;
case SQL_HANDLE_STMT:
ret = PGAPI_StmtError(Handle, RecNumber, Sqlstate,
NativeError, MessageText, BufferLength,
TextLength, 0);
break;
case SQL_HANDLE_DESC:
ret = PGAPI_DescError(Handle, RecNumber, Sqlstate,
NativeError,
MessageText, BufferLength,
TextLength, 0);
break;
default:
ret = SQL_ERROR;
}
MYLOG(0, "leaving %d\n", ret);
return ret;
}
/*
* Minimal implementation.
*
*/
RETCODE SQL_API
PGAPI_GetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,
PTR DiagInfoPtr, SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr)
{
RETCODE ret = SQL_ERROR, rtn;
ConnectionClass *conn;
StatementClass *stmt;
SQLLEN rc;
SQLSMALLINT pcbErrm;
ssize_t rtnlen = -1;
int rtnctype = SQL_C_CHAR;
MYLOG(0, "entering rec=%d\n", RecNumber);
switch (HandleType)
{
case SQL_HANDLE_ENV:
switch (DiagIdentifier)
{
case SQL_DIAG_CLASS_ORIGIN:
case SQL_DIAG_SUBCLASS_ORIGIN:
case SQL_DIAG_CONNECTION_NAME:
case SQL_DIAG_SERVER_NAME:
rtnlen = 0;
if (DiagInfoPtr && BufferLength > rtnlen)
{
ret = SQL_SUCCESS;
*((char *) DiagInfoPtr) = '\0';
}
else
ret = SQL_SUCCESS_WITH_INFO;
break;
case SQL_DIAG_MESSAGE_TEXT:
ret = PGAPI_EnvError(Handle, RecNumber,
NULL, NULL, DiagInfoPtr,
BufferLength, StringLengthPtr, 0);
break;
case SQL_DIAG_NATIVE:
rtnctype = SQL_C_LONG;
ret = PGAPI_EnvError(Handle, RecNumber,
NULL, (SQLINTEGER *) DiagInfoPtr, NULL,
0, NULL, 0);
break;
case SQL_DIAG_NUMBER:
rtnctype = SQL_C_LONG;
ret = PGAPI_EnvError(Handle, RecNumber,
NULL, NULL, NULL,
0, NULL, 0);
if (SQL_SUCCEEDED(ret))
{
*((SQLINTEGER *) DiagInfoPtr) = 1;
}
break;
case SQL_DIAG_SQLSTATE:
rtnlen = 5;
ret = PGAPI_EnvError(Handle, RecNumber,
DiagInfoPtr, NULL, NULL,
0, NULL, 0);
if (SQL_SUCCESS_WITH_INFO == ret)
ret = SQL_SUCCESS;
break;
case SQL_DIAG_RETURNCODE: /* driver manager returns */
break;
case SQL_DIAG_CURSOR_ROW_COUNT:
case SQL_DIAG_ROW_COUNT:
case SQL_DIAG_DYNAMIC_FUNCTION:
case SQL_DIAG_DYNAMIC_FUNCTION_CODE:
/* options for statement type only */
break;
}
break;
case SQL_HANDLE_DBC:
conn = (ConnectionClass *) Handle;
switch (DiagIdentifier)
{
case SQL_DIAG_CLASS_ORIGIN:
case SQL_DIAG_SUBCLASS_ORIGIN:
case SQL_DIAG_CONNECTION_NAME:
rtnlen = 0;
if (DiagInfoPtr && BufferLength > rtnlen)
{
ret = SQL_SUCCESS;
*((char *) DiagInfoPtr) = '\0';
}
else
ret = SQL_SUCCESS_WITH_INFO;
break;
case SQL_DIAG_SERVER_NAME:
rtnlen = strlen(CC_get_DSN(conn));
if (DiagInfoPtr)
{
strncpy_null(DiagInfoPtr, CC_get_DSN(conn), BufferLength);
ret = (BufferLength > rtnlen ? SQL_SUCCESS : SQL_SUCCESS_WITH_INFO);
}
else
ret = SQL_SUCCESS_WITH_INFO;
break;
case SQL_DIAG_MESSAGE_TEXT:
ret = PGAPI_ConnectError(Handle, RecNumber,
NULL, NULL, DiagInfoPtr,
BufferLength, StringLengthPtr, 0);
break;
case SQL_DIAG_NATIVE:
rtnctype = SQL_C_LONG;
ret = PGAPI_ConnectError(Handle, RecNumber,
NULL, (SQLINTEGER *) DiagInfoPtr, NULL,
0, NULL, 0);
break;
case SQL_DIAG_NUMBER:
rtnctype = SQL_C_LONG;
ret = PGAPI_ConnectError(Handle, RecNumber,
NULL, NULL, NULL,
0, NULL, 0);
if (SQL_SUCCEEDED(ret))
{
*((SQLINTEGER *) DiagInfoPtr) = 1;
}
break;
case SQL_DIAG_SQLSTATE:
rtnlen = 5;
ret = PGAPI_ConnectError(Handle, RecNumber,
DiagInfoPtr, NULL, NULL,
0, NULL, 0);
if (SQL_SUCCESS_WITH_INFO == ret)
ret = SQL_SUCCESS;
break;
case SQL_DIAG_RETURNCODE: /* driver manager returns */
break;
case SQL_DIAG_CURSOR_ROW_COUNT:
case SQL_DIAG_ROW_COUNT:
case SQL_DIAG_DYNAMIC_FUNCTION:
case SQL_DIAG_DYNAMIC_FUNCTION_CODE:
/* options for statement type only */
break;
}
break;
case SQL_HANDLE_STMT:
conn = (ConnectionClass *) SC_get_conn(((StatementClass *) Handle));
switch (DiagIdentifier)
{
case SQL_DIAG_CLASS_ORIGIN:
case SQL_DIAG_SUBCLASS_ORIGIN:
case SQL_DIAG_CONNECTION_NAME:
rtnlen = 0;
if (DiagInfoPtr && BufferLength > rtnlen)
{
ret = SQL_SUCCESS;
*((char *) DiagInfoPtr) = '\0';
}
else
ret = SQL_SUCCESS_WITH_INFO;
break;
case SQL_DIAG_SERVER_NAME:
rtnlen = strlen(CC_get_DSN(conn));
if (DiagInfoPtr)
{
strncpy_null(DiagInfoPtr, CC_get_DSN(conn), BufferLength);
ret = (BufferLength > rtnlen ? SQL_SUCCESS : SQL_SUCCESS_WITH_INFO);
}
else
ret = SQL_SUCCESS_WITH_INFO;
break;
case SQL_DIAG_MESSAGE_TEXT:
ret = PGAPI_StmtError(Handle, RecNumber,
NULL, NULL, DiagInfoPtr,
BufferLength, StringLengthPtr, 0);
break;
case SQL_DIAG_NATIVE:
rtnctype = SQL_C_LONG;
ret = PGAPI_StmtError(Handle, RecNumber,
NULL, (SQLINTEGER *) DiagInfoPtr, NULL,
0, NULL, 0);
break;
case SQL_DIAG_NUMBER:
rtnctype = SQL_C_LONG;
*((SQLINTEGER *) DiagInfoPtr) = 0;
ret = SQL_NO_DATA_FOUND;
stmt = (StatementClass *) Handle;
rtn = PGAPI_StmtError(Handle, -1, NULL,
NULL, NULL, 0, &pcbErrm, 0);
switch (rtn)
{
case SQL_SUCCESS:
case SQL_SUCCESS_WITH_INFO:
ret = SQL_SUCCESS;
if (pcbErrm > 0 && stmt->pgerror)
*((SQLINTEGER *) DiagInfoPtr) = (pcbErrm - 1)/ stmt->pgerror->recsize + 1;
break;
default:
break;
}
break;
case SQL_DIAG_SQLSTATE:
rtnlen = 5;
ret = PGAPI_StmtError(Handle, RecNumber,
DiagInfoPtr, NULL, NULL,
0, NULL, 0);
if (SQL_SUCCESS_WITH_INFO == ret)
ret = SQL_SUCCESS;
break;
case SQL_DIAG_CURSOR_ROW_COUNT:
rtnctype = SQL_C_LONG;
stmt = (StatementClass *) Handle;
rc = -1;
if (stmt->status == STMT_FINISHED)
{
QResultClass *res = SC_get_Curres(stmt);
/*if (!res)
return SQL_ERROR;*/
if (stmt->proc_return > 0)
rc = 0;
else if (res && QR_NumResultCols(res) > 0 && !SC_is_fetchcursor(stmt))
rc = QR_get_num_total_tuples(res) - res->dl_count;
}
*((SQLLEN *) DiagInfoPtr) = rc;
MYLOG(DETAIL_LOG_LEVEL, "rc=" FORMAT_LEN "\n", rc);
ret = SQL_SUCCESS;
break;
case SQL_DIAG_ROW_COUNT:
rtnctype = SQL_C_LONG;
stmt = (StatementClass *) Handle;
*((SQLLEN *) DiagInfoPtr) = stmt->diag_row_count;
ret = SQL_SUCCESS;
break;
case SQL_DIAG_ROW_NUMBER:
rtnctype = SQL_C_LONG;
*((SQLLEN *) DiagInfoPtr) = SQL_ROW_NUMBER_UNKNOWN;
ret = SQL_SUCCESS;
break;
case SQL_DIAG_COLUMN_NUMBER:
rtnctype = SQL_C_LONG;
*((SQLINTEGER *) DiagInfoPtr) = SQL_COLUMN_NUMBER_UNKNOWN;
ret = SQL_SUCCESS;
break;
case SQL_DIAG_RETURNCODE: /* driver manager returns */
break;
}
break;
case SQL_HANDLE_DESC:
conn = DC_get_conn(((DescriptorClass *) Handle));
switch (DiagIdentifier)
{
case SQL_DIAG_CLASS_ORIGIN:
case SQL_DIAG_SUBCLASS_ORIGIN:
case SQL_DIAG_CONNECTION_NAME:
rtnlen = 0;
if (DiagInfoPtr && BufferLength > rtnlen)
{
ret = SQL_SUCCESS;
*((char *) DiagInfoPtr) = '\0';
}
else
ret = SQL_SUCCESS_WITH_INFO;
break;
case SQL_DIAG_SERVER_NAME:
rtnlen = strlen(CC_get_DSN(conn));
if (DiagInfoPtr)
{
strncpy_null(DiagInfoPtr, CC_get_DSN(conn), BufferLength);
ret = (BufferLength > rtnlen ? SQL_SUCCESS : SQL_SUCCESS_WITH_INFO);
}
else
ret = SQL_SUCCESS_WITH_INFO;
break;
case SQL_DIAG_MESSAGE_TEXT:
case SQL_DIAG_NATIVE:
case SQL_DIAG_NUMBER:
break;
case SQL_DIAG_SQLSTATE:
rtnlen = 5;
ret = PGAPI_DescError(Handle, RecNumber,
DiagInfoPtr, NULL, NULL,
0, NULL, 0);
if (SQL_SUCCESS_WITH_INFO == ret)
ret = SQL_SUCCESS;
break;
case SQL_DIAG_RETURNCODE: /* driver manager returns */
break;
case SQL_DIAG_CURSOR_ROW_COUNT:
case SQL_DIAG_ROW_COUNT:
case SQL_DIAG_DYNAMIC_FUNCTION:
case SQL_DIAG_DYNAMIC_FUNCTION_CODE:
rtnctype = SQL_C_LONG;
/* options for statement type only */
break;
}
break;
default:
ret = SQL_ERROR;
}
if (SQL_C_LONG == rtnctype)
{
if (SQL_SUCCESS_WITH_INFO == ret)
ret = SQL_SUCCESS;
if (StringLengthPtr)
*StringLengthPtr = sizeof(SQLINTEGER);
}
else if (rtnlen >= 0)
{
if (rtnlen >= BufferLength)
{
if (SQL_SUCCESS == ret)
ret = SQL_SUCCESS_WITH_INFO;
if (BufferLength > 0)
((char *) DiagInfoPtr) [BufferLength - 1] = '\0';
}
if (StringLengthPtr)
*StringLengthPtr = (SQLSMALLINT) rtnlen;
}
MYLOG(0, "leaving %d\n", ret);
return ret;
}
/* SQLGetConnectOption -> SQLGetconnectAttr */
RETCODE SQL_API
PGAPI_GetConnectAttr(HDBC ConnectionHandle,
SQLINTEGER Attribute, PTR Value,
SQLINTEGER BufferLength, SQLINTEGER *StringLength)
{
ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
RETCODE ret = SQL_SUCCESS;
SQLINTEGER len = 4;
MYLOG(0, "entering %d\n", Attribute);
switch (Attribute)
{
case SQL_ATTR_ASYNC_ENABLE:
*((SQLINTEGER *) Value) = SQL_ASYNC_ENABLE_OFF;
break;
case SQL_ATTR_AUTO_IPD:
*((SQLINTEGER *) Value) = SQL_FALSE;
break;
case SQL_ATTR_CONNECTION_DEAD:
*((SQLUINTEGER *) Value) = CC_not_connected(conn);
break;
case SQL_ATTR_CONNECTION_TIMEOUT:
*((SQLUINTEGER *) Value) = 0;
break;
case SQL_ATTR_METADATA_ID:
*((SQLUINTEGER *) Value) = conn->stmtOptions.metadata_id;
break;
case SQL_ATTR_PGOPT_DEBUG:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.debug;
break;
case SQL_ATTR_PGOPT_COMMLOG:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.commlog;
break;
case SQL_ATTR_PGOPT_PARSE:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.parse;
break;
case SQL_ATTR_PGOPT_USE_DECLAREFETCH:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.use_declarefetch;
break;
case SQL_ATTR_PGOPT_SERVER_SIDE_PREPARE:
*((SQLINTEGER *) Value) = conn->connInfo.use_server_side_prepare;
break;
case SQL_ATTR_PGOPT_FETCH:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.fetch_max;
break;
case SQL_ATTR_PGOPT_UNKNOWNSIZES:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.unknown_sizes;
break;
case SQL_ATTR_PGOPT_TEXTASLONGVARCHAR:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.text_as_longvarchar;
break;
case SQL_ATTR_PGOPT_UNKNOWNSASLONGVARCHAR:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.unknowns_as_longvarchar;
break;
case SQL_ATTR_PGOPT_BOOLSASCHAR:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.bools_as_char;
break;
case SQL_ATTR_PGOPT_MAXVARCHARSIZE:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.max_varchar_size;
break;
case SQL_ATTR_PGOPT_MAXLONGVARCHARSIZE:
*((SQLINTEGER *) Value) = conn->connInfo.drivers.max_longvarchar_size;
break;
case SQL_ATTR_PGOPT_MSJET:
*((SQLINTEGER *) Value) = conn->ms_jet;
break;
default:
ret = PGAPI_GetConnectOption(ConnectionHandle, (UWORD) Attribute, Value, &len, BufferLength);
}
if (StringLength)
*StringLength = len;
return ret;
}
static SQLHDESC
descHandleFromStatementHandle(HSTMT StatementHandle, SQLINTEGER descType)
{
StatementClass *stmt = (StatementClass *) StatementHandle;
switch (descType)
{
case SQL_ATTR_APP_ROW_DESC: /* 10010 */
return (HSTMT) stmt->ard;
case SQL_ATTR_APP_PARAM_DESC: /* 10011 */
return (HSTMT) stmt->apd;
case SQL_ATTR_IMP_ROW_DESC: /* 10012 */
return (HSTMT) stmt->ird;
case SQL_ATTR_IMP_PARAM_DESC: /* 10013 */
return (HSTMT) stmt->ipd;
}
return (HSTMT) 0;
}
static void column_bindings_set(ARDFields *opts, int cols, BOOL maxset)
{
int i;
if (cols == opts->allocated)
return;
if (cols > opts->allocated)
{
extend_column_bindings(opts, cols);
return;
}
if (maxset) return;
for (i = opts->allocated; i > cols; i--)
reset_a_column_binding(opts, i);
opts->allocated = cols;
if (0 == cols)
{
free(opts->bindings);
opts->bindings = NULL;
}
}
static RETCODE SQL_API
ARDSetField(DescriptorClass *desc, SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier, PTR Value, SQLINTEGER BufferLength)
{
RETCODE ret = SQL_SUCCESS;
ARDFields *opts = &(desc->ardf);
SQLSMALLINT row_idx;
BOOL unbind = TRUE;
switch (FieldIdentifier)
{
case SQL_DESC_ARRAY_SIZE:
opts->size_of_rowset = CAST_UPTR(SQLULEN, Value);
return ret;
case SQL_DESC_ARRAY_STATUS_PTR:
opts->row_operation_ptr = Value;
return ret;
case SQL_DESC_BIND_OFFSET_PTR:
opts->row_offset_ptr = Value;
return ret;
case SQL_DESC_BIND_TYPE:
opts->bind_size = CAST_UPTR(SQLUINTEGER, Value);
return ret;
case SQL_DESC_COUNT:
column_bindings_set(opts, CAST_PTR(SQLSMALLINT, Value), FALSE);
return ret;
case SQL_DESC_TYPE:
case SQL_DESC_DATETIME_INTERVAL_CODE:
case SQL_DESC_CONCISE_TYPE:
column_bindings_set(opts, RecNumber, TRUE);
break;
}
if (RecNumber < 0 || RecNumber > opts->allocated)
{
DC_set_error(desc, DESC_INVALID_COLUMN_NUMBER_ERROR, "invalid column number");
return SQL_ERROR;
}
if (0 == RecNumber) /* bookmark column */
{
BindInfoClass *bookmark = ARD_AllocBookmark(opts);
switch (FieldIdentifier)
{
case SQL_DESC_DATA_PTR:
bookmark->buffer = Value;
break;
case SQL_DESC_INDICATOR_PTR:
bookmark->indicator = Value;
break;
case SQL_DESC_OCTET_LENGTH_PTR:
bookmark->used = Value;
break;
default:
DC_set_error(desc, DESC_INVALID_COLUMN_NUMBER_ERROR, "invalid column number");
ret = SQL_ERROR;
}
return ret;
}
row_idx = RecNumber - 1;
switch (FieldIdentifier)
{
case SQL_DESC_TYPE:
opts->bindings[row_idx].returntype = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_DATETIME_INTERVAL_CODE:
switch (opts->bindings[row_idx].returntype)
{
case SQL_DATETIME:
case SQL_C_TYPE_DATE:
case SQL_C_TYPE_TIME:
case SQL_C_TYPE_TIMESTAMP:
switch ((LONG_PTR) Value)
{
case SQL_CODE_DATE:
opts->bindings[row_idx].returntype = SQL_C_TYPE_DATE;
break;
case SQL_CODE_TIME:
opts->bindings[row_idx].returntype = SQL_C_TYPE_TIME;
break;
case SQL_CODE_TIMESTAMP:
opts->bindings[row_idx].returntype = SQL_C_TYPE_TIMESTAMP;
break;
}
break;
}
break;
case SQL_DESC_CONCISE_TYPE:
opts->bindings[row_idx].returntype = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_DATA_PTR:
unbind = FALSE;
opts->bindings[row_idx].buffer = Value;
break;
case SQL_DESC_INDICATOR_PTR:
unbind = FALSE;
opts->bindings[row_idx].indicator = Value;
break;
case SQL_DESC_OCTET_LENGTH_PTR:
unbind = FALSE;
opts->bindings[row_idx].used = Value;
break;
case SQL_DESC_OCTET_LENGTH:
opts->bindings[row_idx].buflen = CAST_PTR(SQLLEN, Value);
break;
case SQL_DESC_PRECISION:
opts->bindings[row_idx].precision = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_SCALE:
opts->bindings[row_idx].scale = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_ALLOC_TYPE: /* read-only */
case SQL_DESC_DATETIME_INTERVAL_PRECISION:
case SQL_DESC_LENGTH:
case SQL_DESC_NUM_PREC_RADIX:
default:ret = SQL_ERROR;
DC_set_error(desc, DESC_INVALID_DESCRIPTOR_IDENTIFIER,
"invalid descriptor identifier");
}
if (unbind)
opts->bindings[row_idx].buffer = NULL;
return ret;
}
static void parameter_bindings_set(APDFields *opts, int params, BOOL maxset)
{
int i;
if (params == opts->allocated)
return;
if (params > opts->allocated)
{
extend_parameter_bindings(opts, params);
return;
}
if (maxset) return;
for (i = opts->allocated; i > params; i--)
reset_a_parameter_binding(opts, i);
opts->allocated = params;
if (0 == params)
{
free(opts->parameters);
opts->parameters = NULL;
}
}
static void parameter_ibindings_set(IPDFields *opts, int params, BOOL maxset)
{
int i;
if (params == opts->allocated)
return;
if (params > opts->allocated)
{
extend_iparameter_bindings(opts, params);
return;
}
if (maxset) return;
for (i = opts->allocated; i > params; i--)
reset_a_iparameter_binding(opts, i);
opts->allocated = params;
if (0 == params)
{
free(opts->parameters);
opts->parameters = NULL;
}
}
static RETCODE SQL_API
APDSetField(DescriptorClass *desc, SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier, PTR Value, SQLINTEGER BufferLength)
{
RETCODE ret = SQL_SUCCESS;
APDFields *opts = &(desc->apdf);
SQLSMALLINT para_idx;
BOOL unbind = TRUE;
switch (FieldIdentifier)
{
case SQL_DESC_ARRAY_SIZE:
opts->paramset_size = CAST_UPTR(SQLUINTEGER, Value);
return ret;
case SQL_DESC_ARRAY_STATUS_PTR:
opts->param_operation_ptr = Value;
return ret;
case SQL_DESC_BIND_OFFSET_PTR:
opts->param_offset_ptr = Value;
return ret;
case SQL_DESC_BIND_TYPE:
opts->param_bind_type = CAST_UPTR(SQLUINTEGER, Value);
return ret;
case SQL_DESC_COUNT:
parameter_bindings_set(opts, CAST_PTR(SQLSMALLINT, Value), FALSE);
return ret;
case SQL_DESC_TYPE:
case SQL_DESC_DATETIME_INTERVAL_CODE:
case SQL_DESC_CONCISE_TYPE:
parameter_bindings_set(opts, RecNumber, TRUE);
break;
}
if (RecNumber <=0)
{
MYLOG(DETAIL_LOG_LEVEL, "RecN=%d allocated=%d\n", RecNumber, opts->allocated);
DC_set_error(desc, DESC_BAD_PARAMETER_NUMBER_ERROR,
"bad parameter number");
return SQL_ERROR;
}
if (RecNumber > opts->allocated)
{
MYLOG(DETAIL_LOG_LEVEL, "RecN=%d allocated=%d\n", RecNumber, opts->allocated);
parameter_bindings_set(opts, RecNumber, TRUE);
/* DC_set_error(desc, DESC_BAD_PARAMETER_NUMBER_ERROR,
"bad parameter number");
return SQL_ERROR;*/
}
para_idx = RecNumber - 1;
switch (FieldIdentifier)
{
case SQL_DESC_TYPE:
opts->parameters[para_idx].CType = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_DATETIME_INTERVAL_CODE:
switch (opts->parameters[para_idx].CType)
{
case SQL_DATETIME:
case SQL_C_TYPE_DATE:
case SQL_C_TYPE_TIME:
case SQL_C_TYPE_TIMESTAMP:
switch ((LONG_PTR) Value)
{
case SQL_CODE_DATE:
opts->parameters[para_idx].CType = SQL_C_TYPE_DATE;
break;
case SQL_CODE_TIME:
opts->parameters[para_idx].CType = SQL_C_TYPE_TIME;
break;
case SQL_CODE_TIMESTAMP:
opts->parameters[para_idx].CType = SQL_C_TYPE_TIMESTAMP;
break;
}
break;
}
break;
case SQL_DESC_CONCISE_TYPE:
opts->parameters[para_idx].CType = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_DATA_PTR:
unbind = FALSE;
opts->parameters[para_idx].buffer = Value;
break;
case SQL_DESC_INDICATOR_PTR:
unbind = FALSE;
opts->parameters[para_idx].indicator = Value;
break;
case SQL_DESC_OCTET_LENGTH:
opts->parameters[para_idx].buflen = CAST_PTR(Int4, Value);
break;
case SQL_DESC_OCTET_LENGTH_PTR:
unbind = FALSE;
opts->parameters[para_idx].used = Value;
break;
case SQL_DESC_PRECISION:
opts->parameters[para_idx].precision = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_SCALE:
opts->parameters[para_idx].scale = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_ALLOC_TYPE: /* read-only */
case SQL_DESC_DATETIME_INTERVAL_PRECISION:
case SQL_DESC_LENGTH:
case SQL_DESC_NUM_PREC_RADIX:
default:ret = SQL_ERROR;
DC_set_error(desc, DESC_INVALID_DESCRIPTOR_IDENTIFIER,
"invaid descriptor identifier");
}
if (unbind)
opts->parameters[para_idx].buffer = NULL;
return ret;
}
static RETCODE SQL_API
IRDSetField(DescriptorClass *desc, SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier, PTR Value, SQLINTEGER BufferLength)
{
RETCODE ret = SQL_SUCCESS;
IRDFields *opts = &(desc->irdf);
switch (FieldIdentifier)
{
case SQL_DESC_ARRAY_STATUS_PTR:
opts->rowStatusArray = (SQLUSMALLINT *) Value;
break;
case SQL_DESC_ROWS_PROCESSED_PTR:
opts->rowsFetched = (SQLULEN *) Value;
break;
case SQL_DESC_ALLOC_TYPE: /* read-only */
case SQL_DESC_COUNT: /* read-only */
case SQL_DESC_AUTO_UNIQUE_VALUE: /* read-only */
case SQL_DESC_BASE_COLUMN_NAME: /* read-only */
case SQL_DESC_BASE_TABLE_NAME: /* read-only */
case SQL_DESC_CASE_SENSITIVE: /* read-only */
case SQL_DESC_CATALOG_NAME: /* read-only */
case SQL_DESC_CONCISE_TYPE: /* read-only */
case SQL_DESC_DATETIME_INTERVAL_CODE: /* read-only */
case SQL_DESC_DATETIME_INTERVAL_PRECISION: /* read-only */
case SQL_DESC_DISPLAY_SIZE: /* read-only */
case SQL_DESC_FIXED_PREC_SCALE: /* read-only */
case SQL_DESC_LABEL: /* read-only */
case SQL_DESC_LENGTH: /* read-only */
case SQL_DESC_LITERAL_PREFIX: /* read-only */
case SQL_DESC_LITERAL_SUFFIX: /* read-only */
case SQL_DESC_LOCAL_TYPE_NAME: /* read-only */
case SQL_DESC_NAME: /* read-only */
case SQL_DESC_NULLABLE: /* read-only */
case SQL_DESC_NUM_PREC_RADIX: /* read-only */
case SQL_DESC_OCTET_LENGTH: /* read-only */
case SQL_DESC_PRECISION: /* read-only */
case SQL_DESC_ROWVER: /* read-only */
case SQL_DESC_SCALE: /* read-only */
case SQL_DESC_SCHEMA_NAME: /* read-only */
case SQL_DESC_SEARCHABLE: /* read-only */
case SQL_DESC_TABLE_NAME: /* read-only */
case SQL_DESC_TYPE: /* read-only */
case SQL_DESC_TYPE_NAME: /* read-only */
case SQL_DESC_UNNAMED: /* read-only */
case SQL_DESC_UNSIGNED: /* read-only */
case SQL_DESC_UPDATABLE: /* read-only */
default:ret = SQL_ERROR;
DC_set_error(desc, DESC_INVALID_DESCRIPTOR_IDENTIFIER,
"invalid descriptor identifier");
}
return ret;
}
static RETCODE SQL_API
IPDSetField(DescriptorClass *desc, SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier, PTR Value, SQLINTEGER BufferLength)
{
RETCODE ret = SQL_SUCCESS;
IPDFields *ipdopts = &(desc->ipdf);
SQLSMALLINT para_idx;
switch (FieldIdentifier)
{
case SQL_DESC_ARRAY_STATUS_PTR:
ipdopts->param_status_ptr = (SQLUSMALLINT *) Value;
return ret;
case SQL_DESC_ROWS_PROCESSED_PTR:
ipdopts->param_processed_ptr = (SQLULEN *) Value;
return ret;
case SQL_DESC_COUNT:
parameter_ibindings_set(ipdopts, CAST_PTR(SQLSMALLINT, Value), FALSE);
return ret;
case SQL_DESC_UNNAMED: /* only SQL_UNNAMED is allowed */
if (SQL_UNNAMED != CAST_PTR(SQLSMALLINT, Value))
{
ret = SQL_ERROR;
DC_set_error(desc, DESC_INVALID_DESCRIPTOR_IDENTIFIER,
"invalid descriptor identifier");
return ret;
}
case SQL_DESC_NAME:
case SQL_DESC_TYPE:
case SQL_DESC_DATETIME_INTERVAL_CODE:
case SQL_DESC_CONCISE_TYPE:
parameter_ibindings_set(ipdopts, RecNumber, TRUE);
break;
}
if (RecNumber <= 0 || RecNumber > ipdopts->allocated)
{
MYLOG(DETAIL_LOG_LEVEL, "RecN=%d allocated=%d\n", RecNumber, ipdopts->allocated);
DC_set_error(desc, DESC_BAD_PARAMETER_NUMBER_ERROR,
"bad parameter number");
return SQL_ERROR;
}
para_idx = RecNumber - 1;
switch (FieldIdentifier)
{
case SQL_DESC_TYPE:
if (ipdopts->parameters[para_idx].SQLType != CAST_PTR(SQLSMALLINT, Value))
{
reset_a_iparameter_binding(ipdopts, RecNumber);
ipdopts->parameters[para_idx].SQLType = CAST_PTR(SQLSMALLINT, Value);
}
break;
case SQL_DESC_DATETIME_INTERVAL_CODE:
switch (ipdopts->parameters[para_idx].SQLType)
{
case SQL_DATETIME:
case SQL_TYPE_DATE:
case SQL_TYPE_TIME:
case SQL_TYPE_TIMESTAMP:
switch ((LONG_PTR) Value)
{
case SQL_CODE_DATE:
ipdopts->parameters[para_idx].SQLType = SQL_TYPE_DATE;
break;
case SQL_CODE_TIME:
ipdopts->parameters[para_idx].SQLType = SQL_TYPE_TIME;
break;
case SQL_CODE_TIMESTAMP:
ipdopts->parameters[para_idx].SQLType = SQL_TYPE_TIMESTAMP;
break;
}
break;
}
break;
case SQL_DESC_CONCISE_TYPE:
ipdopts->parameters[para_idx].SQLType = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_NAME:
if (Value)
STR_TO_NAME(ipdopts->parameters[para_idx].paramName, Value);
else
NULL_THE_NAME(ipdopts->parameters[para_idx].paramName);
break;
case SQL_DESC_PARAMETER_TYPE:
ipdopts->parameters[para_idx].paramType = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_SCALE:
ipdopts->parameters[para_idx].decimal_digits = CAST_PTR(SQLSMALLINT, Value);
break;
case SQL_DESC_UNNAMED: /* only SQL_UNNAMED is allowed */
if (SQL_UNNAMED != CAST_PTR(SQLSMALLINT, Value))
{
ret = SQL_ERROR;
DC_set_error(desc, DESC_INVALID_DESCRIPTOR_IDENTIFIER,
"invalid descriptor identifier");
}
else
NULL_THE_NAME(ipdopts->parameters[para_idx].paramName);
break;
case SQL_DESC_ALLOC_TYPE: /* read-only */
case SQL_DESC_CASE_SENSITIVE: /* read-only */
case SQL_DESC_DATETIME_INTERVAL_PRECISION:
case SQL_DESC_FIXED_PREC_SCALE: /* read-only */
case SQL_DESC_LENGTH:
case SQL_DESC_LOCAL_TYPE_NAME: /* read-only */
case SQL_DESC_NULLABLE: /* read-only */
case SQL_DESC_NUM_PREC_RADIX:
case SQL_DESC_OCTET_LENGTH:
case SQL_DESC_PRECISION:
case SQL_DESC_ROWVER: /* read-only */
case SQL_DESC_TYPE_NAME: /* read-only */
case SQL_DESC_UNSIGNED: /* read-only */
default:ret = SQL_ERROR;
DC_set_error(desc, DESC_INVALID_DESCRIPTOR_IDENTIFIER,
"invalid descriptor identifier");
}
return ret;
}
static RETCODE SQL_API
ARDGetField(DescriptorClass *desc, SQLSMALLINT RecNumber,
SQLSMALLINT FieldIdentifier, PTR Value, SQLINTEGER BufferLength,
SQLINTEGER *StringLength)
{
RETCODE ret = SQL_SUCCESS;
SQLLEN ival = 0;
SQLINTEGER len, rettype = 0;
PTR ptr = NULL;
const ARDFields *opts = &(desc->ardf);
SQLSMALLINT row_idx;
len = sizeof(SQLINTEGER);
if (0 == RecNumber) /* bookmark */
{
BindInfoClass *bookmark = opts->bookmark;
switch (FieldIdentifier)
{
case SQL_DESC_DATA_PTR:
rettype = SQL_IS_POINTER;
ptr = bookmark ? bookmark->buffer : NULL;
break;
case SQL_DESC_INDICATOR_PTR:
rettype = SQL_IS_POINTER;
ptr = bookmark ? bookmark->indicator : NULL;
break;
case SQL_DESC_OCTET_LENGTH_PTR:
rettype = SQL_IS_POINTER;
ptr = bookmark ? bookmark->used : NULL;
break;
}
if (ptr)
{