This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathodbc3.c
More file actions
3520 lines (3062 loc) · 84.7 KB
/
Copy pathodbc3.c
File metadata and controls
3520 lines (3062 loc) · 84.7 KB
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
/*
* odbc3.c
*
* $Id: odbc3.c,v 1.23 2006/01/20 15:58:35 source Exp $
*
* ODBC 3.x functions
*
* The iODBC driver manager.
*
* Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com>
* All Rights Reserved.
*
* This software is released under the terms of either of the following
* licenses:
*
* - GNU Library General Public License (see LICENSE.LGPL)
* - The BSD License (see LICENSE.BSD).
*
* Note that the only valid version of the LGPL license as far as this
* project is concerned is the original GNU Library General Public License
* Version 2, dated June 1991.
*
* While not mandated by the BSD license, any patches you make to the
* iODBC source code may be contributed back into the iODBC project
* at your discretion. Contributions will benefit the Open Source and
* Data Access community as a whole. Submissions may be made at:
*
* http://www.iodbc.org
*
*
* GNU Library Generic Public License Version 2
* ============================================
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; only
* Version 2 of the License dated June 1991.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* The BSD License
* ===============
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. Neither the name of OpenLink Software Inc. 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 OPENLINK 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 "iodbc.h"
#include <sql.h>
#include <sqlext.h>
#include <iodbcext.h>
#if (ODBCVER >= 0x300)
#include <sqlucode.h>
#include <unicode.h>
#include <dlproc.h>
#include <herr.h>
#include <henv.h>
#include <hdesc.h>
#include <hdbc.h>
#include <hstmt.h>
#include <itrace.h>
/*
* Externals
*/
SQLRETURN SQLAllocEnv_Internal (SQLHENV * phenv, int odbc_ver);
SQLRETURN SQLFreeEnv_Internal (SQLHENV henv);
SQLRETURN SQLAllocConnect_Internal (SQLHENV henv, SQLHDBC * phdbc);
SQLRETURN SQLFreeConnect_Internal (SQLHDBC hdbc);
SQLRETURN SQLAllocStmt_Internal (SQLHDBC hdbc, SQLHSTMT * phstmt);
SQLRETURN SQLFreeStmt_Internal (SQLHSTMT hstmt, SQLUSMALLINT fOption);
SQLRETURN SQLTransact_Internal (SQLHENV henv, SQLHDBC hdbc, SQLUSMALLINT fType);
RETCODE SQL_API
SQLAllocHandle_Internal (
SQLSMALLINT handleType,
SQLHANDLE inputHandle,
SQLHANDLE * outputHandlePtr)
{
switch (handleType)
{
case SQL_HANDLE_ENV:
return SQLAllocEnv_Internal (outputHandlePtr, 0);
case SQL_HANDLE_DBC:
{
GENV (genv, inputHandle);
if (!IS_VALID_HENV (genv))
{
return SQL_INVALID_HANDLE;
}
CLEAR_ERRORS (genv);
if (genv->odbc_ver == 0)
{
PUSHSQLERR (genv->herr, en_HY010);
return SQL_ERROR;
}
return SQLAllocConnect_Internal (inputHandle, outputHandlePtr);
}
case SQL_HANDLE_STMT:
return SQLAllocStmt_Internal (inputHandle, outputHandlePtr);
case SQL_HANDLE_DESC:
{
CONN (con, inputHandle);
HPROC hproc = SQL_NULL_HPROC;
RETCODE retcode;
DESC_t *new_desc;
if (((ENV_t *)(con->henv))->dodbc_ver == SQL_OV_ODBC2)
{
PUSHSQLERR (con->herr, en_HYC00);
return SQL_ERROR;
}
if (!outputHandlePtr)
{
PUSHSQLERR (con->herr, en_HY009);
return SQL_ERROR;
}
hproc = _iodbcdm_getproc (con, en_AllocHandle);
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (con->herr, en_IM001);
return SQL_ERROR;
}
new_desc = (DESC_t *) MEM_ALLOC (sizeof (DESC_t));
if (!new_desc)
{
PUSHSQLERR (con->herr, en_HY001);
return SQL_ERROR;
}
memset (new_desc, 0, sizeof (DESC_t));
CALL_DRIVER (con, con, retcode, hproc, en_AllocHandle,
(handleType, con->dhdbc, &new_desc->dhdesc));
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
MEM_FREE (new_desc);
return SQL_ERROR;
}
new_desc->type = SQL_HANDLE_DESC;
new_desc->hdbc = con;
new_desc->hstmt = NULL;
new_desc->herr = NULL;
new_desc->desc_cip = 0;
*outputHandlePtr = new_desc;
new_desc->next = (DESC_t *) con->hdesc;
con->hdesc = new_desc;
return SQL_SUCCESS;
}
default:
if (IS_VALID_HDBC (inputHandle))
{
CONN (con, inputHandle);
PUSHSQLERR (con->herr, en_HY092);
return SQL_ERROR;
}
else if (IS_VALID_HENV (inputHandle))
{
GENV (genv, inputHandle);
PUSHSQLERR (genv->herr, en_HY092);
return SQL_ERROR;
}
return SQL_INVALID_HANDLE;
}
}
RETCODE SQL_API
SQLAllocHandle (
SQLSMALLINT handleType,
SQLHANDLE inputHandle,
SQLHANDLE * outputHandlePtr)
{
int retcode = SQL_SUCCESS;
if (handleType == SQL_HANDLE_ENV)
{
/*
* One time initialization
*/
Init_iODBC();
ODBC_LOCK ();
retcode = SQLAllocEnv_Internal (outputHandlePtr, 0);
/*
* Start tracing
*/
TRACE (trace_SQLAllocHandle (TRACE_ENTER,
handleType, inputHandle, outputHandlePtr));
TRACE (trace_SQLAllocHandle (TRACE_LEAVE,
handleType, inputHandle, outputHandlePtr));
ODBC_UNLOCK ();
return retcode;
}
ODBC_LOCK ();
TRACE (trace_SQLAllocHandle (TRACE_ENTER,
handleType, inputHandle, outputHandlePtr));
retcode =
SQLAllocHandle_Internal (handleType, inputHandle, outputHandlePtr);
TRACE (trace_SQLAllocHandle (TRACE_LEAVE,
handleType, inputHandle, outputHandlePtr));
ODBC_UNLOCK ();
return retcode;
}
RETCODE SQL_API
SQLAllocHandleStd (
SQLSMALLINT handleType,
SQLHANDLE inputHandle,
SQLHANDLE * outputHandlePtr)
{
int retcode = SQL_SUCCESS;
if (handleType == SQL_HANDLE_ENV)
{
/*
* One time initialization
*/
Init_iODBC();
ODBC_LOCK ();
retcode = SQLAllocEnv_Internal (outputHandlePtr, SQL_OV_ODBC3);
/*
* Start tracing
*/
TRACE (trace_SQLAllocHandle (TRACE_ENTER,
handleType, inputHandle, outputHandlePtr));
TRACE (trace_SQLAllocHandle (TRACE_LEAVE,
handleType, inputHandle, outputHandlePtr));
ODBC_UNLOCK ();
return retcode;
}
ODBC_LOCK ();
TRACE (trace_SQLAllocHandle (TRACE_ENTER,
handleType, inputHandle, outputHandlePtr));
retcode =
SQLAllocHandle_Internal (handleType, inputHandle, outputHandlePtr);
TRACE (trace_SQLAllocHandle (TRACE_LEAVE,
handleType, inputHandle, outputHandlePtr));
ODBC_UNLOCK ();
return retcode;
}
/**** SQLFreeHandle ****/
extern unsigned long _iodbc_env_counter;
static RETCODE
_SQLFreeHandle_ENV (
SQLSMALLINT handleType,
SQLHANDLE handle)
{
int retcode = SQL_SUCCESS;
ODBC_LOCK ();
TRACE (trace_SQLFreeHandle (TRACE_ENTER, handleType, handle));
retcode = SQLFreeEnv_Internal ((SQLHENV) handle);
TRACE (trace_SQLFreeHandle (TRACE_LEAVE, handleType, handle));
MEM_FREE (handle);
/*
* Close trace after last environment handle is freed
*/
if (--_iodbc_env_counter == 0)
trace_stop();
ODBC_UNLOCK ();
return retcode;
}
static RETCODE
_SQLFreeHandle_DBC (
SQLSMALLINT handleType,
SQLHANDLE handle)
{
ENTER_HDBC ((SQLHDBC) handle, 1,
trace_SQLFreeHandle (TRACE_ENTER, handleType, handle));
retcode = SQLFreeConnect_Internal ((SQLHDBC) handle);
LEAVE_HDBC ((SQLHDBC) handle, 1,
trace_SQLFreeHandle (TRACE_LEAVE, handleType, handle);
MEM_FREE (handle)
);
}
static RETCODE
_SQLFreeHandle_STMT (
SQLSMALLINT handleType,
SQLHANDLE handle)
{
ENTER_STMT ((SQLHSTMT) handle,
trace_SQLFreeHandle (TRACE_ENTER, handleType, handle));
retcode = SQLFreeStmt_Internal ((SQLHSTMT) handle, SQL_DROP);
LEAVE_STMT ((SQLHSTMT) handle,
trace_SQLFreeHandle (TRACE_LEAVE, handleType, handle);
_iodbcdm_dropstmt ((SQLHSTMT) handle);
);
}
static RETCODE
_SQLFreeHandle_DESC (
SQLSMALLINT handleType,
SQLHANDLE handle)
{
DESC (pdesc, handle);
CONN (pdbc, pdesc->hdbc);
HPROC hproc;
RETCODE retcode = SQL_SUCCESS;
DESC_t *curr_desc;
if (IS_VALID_HSTMT (pdesc->hstmt))
{ /* the desc handle is implicit */
PUSHSQLERR (pdesc->herr, en_HY017);
return SQL_ERROR;
}
CLEAR_ERRORS (pdesc);
/* remove it from the dbc's list */
curr_desc = (DESC_t *) pdbc->hdesc;
while (curr_desc)
{
if (curr_desc == pdesc)
{
pdbc->hdesc = pdesc->next;
break;
}
if (curr_desc->next == pdesc)
{
curr_desc->next = pdesc->next;
break;
}
curr_desc = curr_desc->next;
}
if (!curr_desc)
return SQL_INVALID_HANDLE;
/* and call the driver's function */
hproc = SQL_NULL_HPROC;
if (pdesc->dhdesc)
{ /* the driver has descriptors */
hproc = _iodbcdm_getproc (pdbc, en_FreeHandle);
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (pdesc->herr, en_IM001);
retcode = SQL_ERROR;
}
else
CALL_DRIVER (pdbc, pdesc, retcode, hproc, en_FreeHandle,
(handleType, pdesc->dhdesc));
}
_iodbcdm_freesqlerrlist (pdesc->herr);
/* invalidate the handle */
pdesc->type = 0;
return retcode;
}
RETCODE SQL_API
SQLFreeHandle (
SQLSMALLINT handleType,
SQLHANDLE handle)
{
switch (handleType)
{
case SQL_HANDLE_ENV:
return _SQLFreeHandle_ENV (handleType, handle);
case SQL_HANDLE_DBC:
return _SQLFreeHandle_DBC (handleType, handle);
case SQL_HANDLE_STMT:
return _SQLFreeHandle_STMT (handleType, handle);
case SQL_HANDLE_DESC:
{
ENTER_DESC ((SQLHDESC) handle,
trace_SQLFreeHandle (TRACE_ENTER, handleType, handle));
retcode = _SQLFreeHandle_DESC (handleType, handle);
LEAVE_DESC ((SQLHDESC) handle,
trace_SQLFreeHandle (TRACE_LEAVE, handleType, handle);
MEM_FREE (handle);
);
}
break;
default:
if (IS_VALID_HDBC (handle))
{
CONN (con, handle);
PUSHSQLERR (con->herr, en_HY092);
return SQL_ERROR;
}
else if (IS_VALID_HENV (handle))
{
GENV (genv, handle);
PUSHSQLERR (genv->herr, en_HY092);
return SQL_ERROR;
}
}
return SQL_INVALID_HANDLE;
}
/**** SQLSetEnvAttr ****/
static RETCODE
SQLSetEnvAttr_Internal (SQLHENV environmentHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
GENV (genv, environmentHandle);
StringLength = StringLength; /*UNUSED*/
if (genv->hdbc)
{
PUSHSQLERR (genv->herr, en_HY010);
return SQL_ERROR;
}
switch (Attribute)
{
case SQL_ATTR_CONNECTION_POOLING:
switch ((SQLINTEGER) (SQLULEN) ValuePtr)
{
case SQL_CP_OFF:
case SQL_CP_ONE_PER_DRIVER:
case SQL_CP_ONE_PER_HENV:
return SQL_SUCCESS; /* not implemented yet */
default:
PUSHSQLERR (genv->herr, en_HY024);
return SQL_ERROR;
}
case SQL_ATTR_CP_MATCH:
switch ((SQLINTEGER) (SQLULEN) ValuePtr)
{
case SQL_CP_STRICT_MATCH:
case SQL_CP_RELAXED_MATCH:
return SQL_SUCCESS; /* not implemented yet */
default:
PUSHSQLERR (genv->herr, en_HY024);
return SQL_ERROR;
}
case SQL_ATTR_ODBC_VERSION:
switch ((SQLINTEGER) (SQLULEN) ValuePtr)
{
case SQL_OV_ODBC2:
case SQL_OV_ODBC3:
genv->odbc_ver = (SQLINTEGER) (SQLULEN) ValuePtr;
return (SQL_SUCCESS);
default:
PUSHSQLERR (genv->herr, en_HY024);
return SQL_ERROR;
}
case SQL_ATTR_OUTPUT_NTS:
switch ((SQLINTEGER) (SQLULEN) ValuePtr)
{
case SQL_TRUE:
return SQL_SUCCESS;
case SQL_FALSE:
PUSHSQLERR (genv->herr, en_HYC00);
return SQL_ERROR;
default:
PUSHSQLERR (genv->herr, en_HY024);
return SQL_ERROR;
}
default:
PUSHSQLERR (genv->herr, en_HY092);
return SQL_ERROR;
}
}
RETCODE SQL_API
SQLSetEnvAttr (
SQLHENV EnvironmentHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength)
{
ENTER_HENV (EnvironmentHandle,
trace_SQLSetEnvAttr (TRACE_ENTER,
EnvironmentHandle,
Attribute,
ValuePtr, StringLength));
retcode = SQLSetEnvAttr_Internal (
EnvironmentHandle,
Attribute,
ValuePtr, StringLength);
LEAVE_HENV (EnvironmentHandle,
trace_SQLSetEnvAttr (TRACE_LEAVE,
EnvironmentHandle,
Attribute,
ValuePtr, StringLength));
}
static RETCODE
SQLGetEnvAttr_Internal (
SQLHENV environmentHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER * StringLengthPtr)
{
GENV (genv, environmentHandle);
SQLRETURN retcode = SQL_SUCCESS;
if (Attribute != SQL_ATTR_CONNECTION_POOLING &&
Attribute != SQL_ATTR_CP_MATCH &&
Attribute != SQL_ATTR_ODBC_VERSION &&
Attribute != SQL_ATTR_OUTPUT_NTS &&
Attribute != SQL_ATTR_WCHAR_SIZE)
{
PUSHSQLERR (genv->herr, en_HY092);
return SQL_ERROR;
}
/* ODBC DM env attributes */
if (Attribute == SQL_ATTR_ODBC_VERSION)
{
if (ValuePtr)
*((SQLINTEGER *) ValuePtr) = genv->odbc_ver;
return SQL_SUCCESS;
}
if (Attribute == SQL_ATTR_CONNECTION_POOLING)
{
if (ValuePtr)
*((SQLUINTEGER *) ValuePtr) = SQL_CP_OFF;
return SQL_SUCCESS;
}
if (Attribute == SQL_ATTR_CP_MATCH)
{
if (ValuePtr)
*((SQLUINTEGER *) ValuePtr) = SQL_CP_STRICT_MATCH;
return SQL_SUCCESS;
}
if (Attribute == SQL_ATTR_OUTPUT_NTS)
{
if (ValuePtr)
*((SQLINTEGER *) ValuePtr) = SQL_TRUE;
return SQL_SUCCESS;
}
if (Attribute == SQL_ATTR_WCHAR_SIZE)
{
if (ValuePtr)
*((SQLINTEGER *) ValuePtr) = sizeof(wchar_t);
return SQL_SUCCESS;
}
/* fall back to the first driver */
if (IS_VALID_HDBC (genv->hdbc))
{
CONN (con, genv->hdbc);
HPROC hproc = _iodbcdm_getproc (con, en_GetEnvAttr);
if (hproc != SQL_NULL_HPROC)
{
ENVR (env, con->henv);
CALL_DRIVER (con, genv, retcode, hproc, en_GetEnvAttr,
(env->dhenv, Attribute, ValuePtr, BufferLength,
StringLengthPtr));
return retcode;
}
else
{ /* possibly an ODBC2 driver */
PUSHSQLERR (genv->herr, en_IM001);
return SQL_ERROR;
}
}
else
{
switch ((SQLINTEGER) Attribute)
{
case SQL_ATTR_CONNECTION_POOLING:
if (ValuePtr)
*((SQLINTEGER *) ValuePtr) = SQL_CP_OFF;
break;
case SQL_ATTR_CP_MATCH:
if (ValuePtr)
*((SQLINTEGER *) ValuePtr) = SQL_CP_STRICT_MATCH;
break;
case SQL_ATTR_ODBC_VERSION:
if (ValuePtr)
*((SQLINTEGER *) ValuePtr) = genv->odbc_ver;
break;
}
}
return SQL_SUCCESS;
}
RETCODE SQL_API
SQLGetEnvAttr (
SQLHENV EnvironmentHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER * StringLengthPtr)
{
ENTER_HENV (EnvironmentHandle,
trace_SQLGetEnvAttr (TRACE_ENTER,
EnvironmentHandle,
Attribute,
ValuePtr, BufferLength, StringLengthPtr));
retcode = SQLGetEnvAttr_Internal (
EnvironmentHandle,
Attribute,
ValuePtr, BufferLength, StringLengthPtr);
LEAVE_HENV (EnvironmentHandle,
trace_SQLGetEnvAttr (TRACE_LEAVE,
EnvironmentHandle,
Attribute,
ValuePtr, BufferLength, StringLengthPtr));
}
RETCODE SQL_API
SQLGetStmtAttr_Internal (
SQLHSTMT statementHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER * StringLengthPtr,
SQLCHAR waMode)
{
STMT (stmt, statementHandle);
CONN (pdbc, stmt->hdbc);
ENVR (penv, pdbc->henv);
HPROC hproc = SQL_NULL_HPROC;
SQLRETURN retcode = SQL_SUCCESS;
waMode = waMode; /*UNUSED*/
switch (Attribute)
{
case SQL_ATTR_IMP_PARAM_DESC:
if (ValuePtr)
{
if (IS_VALID_HDESC (stmt->desc[IMP_PARAM_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->desc[IMP_PARAM_DESC];
else if (IS_VALID_HDESC (stmt->imp_desc[IMP_PARAM_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->imp_desc[IMP_PARAM_DESC];
else
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
}
if (StringLengthPtr)
*StringLengthPtr = SQL_IS_POINTER;
return SQL_SUCCESS;
case SQL_ATTR_APP_PARAM_DESC:
if (ValuePtr)
{
if (IS_VALID_HDESC (stmt->desc[APP_PARAM_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->desc[APP_PARAM_DESC];
else if (IS_VALID_HDESC (stmt->imp_desc[APP_PARAM_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->imp_desc[APP_PARAM_DESC];
else
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
}
if (StringLengthPtr)
*StringLengthPtr = SQL_IS_POINTER;
return SQL_SUCCESS;
case SQL_ATTR_IMP_ROW_DESC:
if (ValuePtr)
{
if (IS_VALID_HDESC (stmt->desc[IMP_ROW_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->desc[IMP_ROW_DESC];
else if (IS_VALID_HDESC (stmt->imp_desc[IMP_ROW_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->imp_desc[IMP_ROW_DESC];
else
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
}
if (StringLengthPtr)
*StringLengthPtr = SQL_IS_POINTER;
return SQL_SUCCESS;
case SQL_ATTR_APP_ROW_DESC:
if (ValuePtr)
{
if (IS_VALID_HDESC (stmt->desc[APP_ROW_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->desc[APP_ROW_DESC];
else if (IS_VALID_HDESC (stmt->imp_desc[APP_ROW_DESC]))
*((SQLHANDLE *) ValuePtr) = (SQLHANDLE *) stmt->imp_desc[APP_ROW_DESC];
else
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
}
if (StringLengthPtr)
*StringLengthPtr = SQL_IS_POINTER;
return SQL_SUCCESS;
case SQL_ATTR_ROW_ARRAY_SIZE:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
}
else
{ /* an ODBC2 driver */
if (ValuePtr)
*((SQLUINTEGER *) ValuePtr) = stmt->row_array_size;
return SQL_SUCCESS;
}
case SQL_ATTR_ENABLE_AUTO_IPD:
case SQL_ATTR_CURSOR_SENSITIVITY:
case SQL_ATTR_CURSOR_SCROLLABLE:
case SQL_ATTR_PARAM_BIND_TYPE:
case SQL_ATTR_PARAM_OPERATION_PTR:
case SQL_ATTR_PARAM_STATUS_PTR:
case SQL_ATTR_PARAM_BIND_OFFSET_PTR:
case SQL_ATTR_ROW_BIND_OFFSET_PTR:
case SQL_ATTR_ROW_OPERATION_PTR:
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
case SQL_ATTR_FETCH_BOOKMARK_PTR:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
}
else
{ /* an ODBC2 driver */
if (ValuePtr)
*((SQLPOINTER *) ValuePtr) = stmt->fetch_bookmark_ptr;
return SQL_SUCCESS;
}
case SQL_ATTR_ROWS_FETCHED_PTR:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
}
else
{ /* an ODBC2 driver */
if (ValuePtr)
*((SQLPOINTER *) ValuePtr) = stmt->rows_fetched_ptr;
return SQL_SUCCESS;
}
case SQL_ATTR_METADATA_ID:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
}
else
{ /* an ODBC2 driver */
if (ValuePtr)
*((SQLUINTEGER *) ValuePtr) = SQL_FALSE;
return SQL_SUCCESS;
}
case SQL_ATTR_PARAMS_PROCESSED_PTR:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
}
else
{ /* an ODBC2 driver */
if (ValuePtr)
*((SQLUINTEGER **) ValuePtr) = (SQLUINTEGER *) stmt->params_processed_ptr;
return SQL_SUCCESS;
}
case SQL_ATTR_PARAMSET_SIZE:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
}
else
{ /* an ODBC2 driver */
if (ValuePtr)
*((SQLUINTEGER *) ValuePtr) = stmt->paramset_size;
return SQL_SUCCESS;
}
case SQL_ATTR_ROW_STATUS_PTR:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)
{
PUSHSQLERR (stmt->herr, en_IM001);
return SQL_ERROR;
}
return retcode;
}
else
{ /* an ODBC2 driver */
if (ValuePtr)
*((SQLUINTEGER **) ValuePtr) = stmt->row_status_allocated == SQL_FALSE ?
(SQLUINTEGER *) stmt->row_status_ptr :
NULL;
return SQL_SUCCESS;
}
case SQL_ATTR_ASYNC_ENABLE:
case SQL_ATTR_MAX_ROWS:
case SQL_ATTR_QUERY_TIMEOUT:
case SQL_ATTR_CONCURRENCY:
case SQL_ROWSET_SIZE:
case SQL_ATTR_CURSOR_TYPE:
case SQL_ATTR_KEYSET_SIZE:
case SQL_ATTR_NOSCAN:
case SQL_ATTR_RETRIEVE_DATA:
case SQL_ATTR_ROW_BIND_TYPE:
case SQL_ATTR_ROW_NUMBER:
case SQL_ATTR_SIMULATE_CURSOR:
case SQL_ATTR_USE_BOOKMARKS:
case SQL_ATTR_MAX_LENGTH:
if (((ENV_t *) ((DBC_t *) stmt->hdbc)->henv)->dodbc_ver == SQL_OV_ODBC3)
{
CALL_UDRIVER(stmt->hdbc, stmt, retcode, hproc,
penv->unicode_driver, en_GetStmtAttr, (stmt->dhstmt, Attribute,
ValuePtr, BufferLength, StringLengthPtr));
if (hproc == SQL_NULL_HPROC)