forked from CUBRID/cubrid-odbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathodbc_statement.c
More file actions
3270 lines (2802 loc) · 82 KB
/
Copy pathodbc_statement.c
File metadata and controls
3270 lines (2802 loc) · 82 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
/*
* 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 "odbc_portable.h"
#include "sqlext.h"
#include "odbc_util.h"
#include "odbc_diag_record.h"
#include "odbc_env.h"
#include "odbc_connection.h"
#include "odbc_statement.h"
#include "odbc_result.h"
#include "odbc_descriptor.h"
#include "odbc_type.h"
#include "odbc_catalog.h"
#include "cas_cci.h"
/*----------------------------------------------------------------------
STMT_NEED_DATA - SQL stmt에 parameter가 있으며, binding된 param이
SQL_DATA_AT_EXEC가 설정된 경우로 stmt가 SQLPutData를
필요로 하는 경우
STMT_NEED_NO_MORE_DATA - binding된 param이 없거나 SQL_DATA_AT_EXEC
가 아닌 경우이거나 SQLPutData로 data를 모두 보낸 경우
*-----------------------------------------------------------------------*/
#define STMT_NEED_DATA (-1)
#define STMT_NEED_NO_MORE_DATA (-100)
#define IS_UPDATABLE( cursor ) \
( cursor == SQL_CURSOR_DYNAMIC || cursor == SQL_CURSOR_KEYSET_DRIVEN )
typedef struct __st_ParamArray
{
int value_type;
int *ind_array;
void *value_array;
} ParamArray;
typedef struct __st_DescInfo
{
short type;
long bind_type;
long offset_size;
void *value_ptr;
unsigned long length;
long *ind_ptr;
short precision;
short scale;
long *octet_len_ptr;
} DescInfo;
PRIVATE SQLSMALLINT next_param_data_at_exec (ODBC_STATEMENT * stmt,
SQLSMALLINT param_pos);
PRIVATE void get_appl_desc_info (ODBC_DESC * desc,
short col_index, DescInfo * desc_info_ptr);
PRIVATE void recalculate_bind_pointer (DescInfo * desc_info_ptr,
SQLSETPOSIROW row_index,
UINT_PTR * value_addr,
UINT_PTR * ind_addr,
UINT_PTR * octet_len_addr);
PRIVATE void make_param_array (ODBC_STATEMENT * stmt, short column_index,
DescInfo * desc_info, ParamArray * param_array,
int array_size);
PRIVATE void reset_revised_sql (ODBC_STATEMENT * stmt);
PRIVATE int revised_param_pos (char *param_pos, int i);
PRIVATE char get_flag_of_cci_execute (ODBC_STATEMENT * stmt);
PRIVATE char get_flag_of_cci_prepare (ODBC_STATEMENT * stmt);
PRIVATE void create_bookmark_ird (ODBC_STATEMENT * stmt);
PRIVATE void memory_alloc_param_array (ParamArray * param_array,
int array_size);
PRIVATE RETCODE delete_row_by_cursor_pos (ODBC_STATEMENT * stmt,
unsigned long cursor_pos);
PRIVATE RETCODE odbc_set_pos_update (ODBC_STATEMENT * stmt,
DescInfo * bookmark_desc_info_ptr,
DescInfo * desc_info_ptr,
SQLSETPOSIROW row_pos);
PRIVATE RETCODE odbc_set_pos_delete (ODBC_STATEMENT * stmt,
DescInfo * boomark_desc_info_ptr,
SQLSETPOSIROW row_pos);
PRIVATE void free_param_array (ParamArray * param_ptr, int array_count,
int member_count);
PRIVATE short default_type_to_c_type (short value_type, short parameter_type);
#ifdef _DEBUG
PRIVATE void debug_print_appl_desc (DescInfo * desc_info,
void *value_ptr, long *ind_ptr);
#endif
/************************************************************************
* name: odbc_alloc_statement
* arguments:
* con : connection
* st_pointer : returned statement structure
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC RETCODE
odbc_alloc_statement (ODBC_CONNECTION * conn, ODBC_STATEMENT ** stmt_ptr)
{
ODBC_STATEMENT *s;
/* HY009 - DM */
if (stmt_ptr == NULL)
{
odbc_set_diag (conn->diag, "HY009", 0, NULL);
goto error;
}
s = (ODBC_STATEMENT *) UT_ALLOC (sizeof (ODBC_STATEMENT));
if (s == NULL)
{
odbc_set_diag (conn->diag, "HY001", 0, NULL);
goto error;
}
s->canceled = _FALSE_;
s->handle_type = SQL_HANDLE_STMT;
s->stmthd = 0;
s->conn = NULL;
s->next = NULL;
s->cursor = NULL;
s->sql_text = NULL;
s->is_prepared = _FALSE_;
s->query_plan = _FALSE_;
memset (&s->revised_sql, 0, sizeof (s->revised_sql));
s->result_type = NULL_RESULT;
s->data_at_exec_state = STMT_NEED_NO_MORE_DATA;
s->tpl_number = 0;
s->current_tpl_pos = 0; /* 0 means cursor closed, prev first tuple,
* -1 means over last tuple */
s->param_number = 0;
s->stmt_type = 0;
InitStr (&s->param_data.val);
s->param_data.index = 0;
s->catalog_result.value = NULL;
s->catalog_result.current = NULL;
free_column_data (&s->column_data, INIT);
odbc_alloc_desc (NULL, &(s->i_apd));
odbc_alloc_desc (NULL, &(s->i_ard));
odbc_alloc_desc (NULL, &(s->i_ipd));
odbc_alloc_desc (NULL, &(s->i_ird));
s->apd = s->i_apd;
s->ard = s->i_ard;
s->ipd = s->i_ipd;
s->ird = s->i_ird;
s->i_apd->stmt = s;
s->i_ard->stmt = s;
s->i_ipd->stmt = s;
s->i_ird->stmt = s;
// SQL_ATTR_ASYNC_ENABLE의 경우 connection으로부터 상속받는다.
s->attr_async_enable = conn->attr_async_enable;
s->attr_cursor_scrollable = SQL_NONSCROLLABLE;
//s->attr_cursor_type = SQL_CURSOR_DYNAMIC;
//s->attr_concurrency = SQL_CONCUR_LOCK;
s->attr_concurrency = SQL_CONCUR_READ_ONLY;
s->attr_cursor_type = SQL_CURSOR_FORWARD_ONLY;
s->attr_cursor_sensitivity = SQL_UNSPECIFIED;
s->attr_enable_auto_ipd = SQL_FALSE;
s->attr_fetch_bookmark_ptr = NULL;
s->attr_keyset_size = 0;
s->attr_max_length = 0;
s->attr_max_rows = 0;
s->attr_metadata_id = SQL_FALSE;
s->attr_noscan = SQL_NOSCAN_OFF;
s->attr_query_timeout = 0;
s->attr_retrieve_data = SQL_RD_ON;
s->attr_simulate_cursor = SQL_SC_NON_UNIQUE;
s->attr_use_bookmark = SQL_UB_OFF;
s->diag = odbc_alloc_diag ();
s->conn = conn;
s->next = conn->statements;
conn->statements = s;
*stmt_ptr = s;
return ODBC_SUCCESS;
error:
return ODBC_ERROR;
}
/************************************************************************
* name: odbc_reset_statement
* arguments:
* returns/side-effects:
* description:
* NOTE:
* SQLFreeStmt와 match된다.
************************************************************************/
PUBLIC RETCODE
odbc_reset_statement (ODBC_STATEMENT * stmt, unsigned short option)
{
RETCODE rc = ODBC_SUCCESS;
switch (option)
{
case SQL_CLOSE:
rc = odbc_close_cursor (stmt);
break;
case SQL_UNBIND:
reset_descriptor (stmt->ard);
stmt->ird->rows_processed_ptr = NULL;
break;
case SQL_RESET_PARAMS:
reset_descriptor (stmt->apd);
reset_descriptor (stmt->ipd);
break;
case SQL_DROP:
odbc_free_statement (stmt);
break;
}
return rc;
}
/************************************************************************
* name: odbc_free_statement
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC RETCODE
odbc_free_statement (ODBC_STATEMENT * stmt)
{
ODBC_STATEMENT *s, *prev;
if (stmt == NULL || stmt->handle_type != SQL_HANDLE_STMT)
return SQL_INVALID_HANDLE;
if (stmt->conn != NULL)
{
for (s = stmt->conn->statements, prev = NULL;
s != NULL && s != stmt; s = s->next)
{
prev = s;
}
if (s == stmt)
{
if (prev != NULL)
prev->next = stmt->next;
else
stmt->conn->statements = stmt->next;
}
odbc_close_cursor (stmt);
}
/* free memebers */
NA_FREE (stmt->sql_text);
reset_revised_sql (stmt);
odbc_free_diag (stmt->diag, FREE_ALL);
stmt->diag = NULL;
FreeStr (&stmt->param_data.val);
stmt->param_data.index = 0;
odbc_free_desc (stmt->i_apd);
odbc_free_desc (stmt->i_ard);
odbc_free_desc (stmt->i_ipd);
odbc_free_desc (stmt->i_ird);
stmt->i_apd = NULL;
stmt->i_ard = NULL;
stmt->i_ipd = NULL;
stmt->i_ird = NULL;
/* WARN : implement descriptor? */
stmt->apd = NULL;
stmt->ard = NULL;
stmt->ird = NULL;
stmt->ipd = NULL;
UT_FREE (stmt);
return SQL_SUCCESS;
}
/************************************************************************
* name: odbc_set_stmt_attr
* arguments:
* is_driver - SQLSetStmtAttr에 의한 ftn call인지 판단.
* 0 - SQLSetStmtAttr, 1 - driver
* returns/side-effects:
* description:
* is_client의 값에 따라 read-only ATTR에 대해 다른 작업
* NOTE:
************************************************************************/
PUBLIC RETCODE
odbc_set_stmt_attr (ODBC_STATEMENT * stmt,
long attribute,
void *valueptr, long stringlength, short is_driver)
{
RETCODE rc;
switch (attribute)
{
case SQL_ATTR_APP_PARAM_DESC:
if (valueptr == SQL_NULL_HDESC)
{
stmt->apd = stmt->i_apd;
}
else
{
stmt->apd = valueptr;
}
break;
case SQL_ATTR_APP_ROW_DESC:
if (valueptr == SQL_NULL_HDESC)
{
stmt->ard = stmt->i_ard;
}
else
{
stmt->ard = valueptr;
}
break;
case SQL_ATTR_ASYNC_ENABLE:
switch ((unsigned long) valueptr)
{
case SQL_ASYNC_ENABLE_OFF:
case SQL_ASYNC_ENABLE_ON:
stmt->attr_async_enable = (unsigned long) valueptr;
break;
default:
odbc_set_diag (stmt->diag, "HY024", 0, NULL);
goto error;
}
break;
case SQL_ATTR_CURSOR_SENSITIVITY:
switch ((unsigned long) valueptr)
{
case SQL_INSENSITIVE:
/* implicit setting */
stmt->attr_concurrency = SQL_CONCUR_READ_ONLY;
stmt->attr_cursor_type = SQL_CURSOR_STATIC;
break;
case SQL_SENSITIVE:
break;
case SQL_UNSPECIFIED:
break;
default:
odbc_set_diag (stmt->diag, "HY024", 0, NULL);
goto error;
}
stmt->attr_cursor_sensitivity = (unsigned long) valueptr;
break;
case SQL_ATTR_CURSOR_SCROLLABLE:
switch ((unsigned long) valueptr)
{
case SQL_NONSCROLLABLE:
case SQL_SCROLLABLE:
stmt->attr_cursor_scrollable = (unsigned long) valueptr;
break;
default:
odbc_set_diag (stmt->diag, "HY024", 0, NULL);
goto error;
}
break;
case SQL_ATTR_CURSOR_TYPE:
switch ((unsigned long) valueptr)
{
case SQL_CURSOR_FORWARD_ONLY:
stmt->attr_cursor_type = (unsigned long) valueptr;
/* implicit setting */
stmt->attr_cursor_scrollable = SQL_NONSCROLLABLE;
break;
case SQL_CURSOR_STATIC:
stmt->attr_cursor_type = (unsigned long) valueptr;
/* implicit setting */
stmt->attr_cursor_scrollable = SQL_SCROLLABLE;
if (stmt->attr_concurrency == SQL_CONCUR_READ_ONLY)
{
stmt->attr_cursor_sensitivity = SQL_INSENSITIVE;
}
else
{
/* or SQL_SESITIVE */
stmt->attr_cursor_sensitivity = SQL_UNSPECIFIED;
}
break;
case SQL_CURSOR_KEYSET_DRIVEN:
case SQL_CURSOR_DYNAMIC:
stmt->attr_cursor_type = (unsigned long) valueptr;
/* implicit setting */
stmt->attr_cursor_scrollable = SQL_SCROLLABLE;
stmt->attr_cursor_sensitivity = SQL_SENSITIVE;
break;
default:
odbc_set_diag (stmt->diag, "HY024", 0, NULL);
goto error;
}
break;
case SQL_ATTR_FETCH_BOOKMARK_PTR:
stmt->attr_fetch_bookmark_ptr = valueptr;
break;
case SQL_ATTR_IMP_PARAM_DESC:
if (is_driver == 1)
{
if (valueptr == SQL_NULL_HDESC)
{
stmt->ipd = stmt->i_ipd;
}
else
{
stmt->ipd = valueptr;
}
}
else
{
/* DM SQLSTATE - READ-ONLY */
odbc_set_diag (stmt->diag, "HY092", 0, NULL);
goto error;
}
break;
case SQL_ATTR_IMP_ROW_DESC:
if (is_driver == 1)
{
if (valueptr == SQL_NULL_HDESC)
{
stmt->ird = stmt->ird;
}
else
{
stmt->ird = valueptr;
}
}
else
{
/* DM SQLSTATE - READ-ONLY */
odbc_set_diag (stmt->diag, "HY092", 0, NULL);
goto error;
}
break;
case SQL_ATTR_METADATA_ID:
switch ((unsigned long) valueptr)
{
case SQL_TRUE:
case SQL_FALSE:
stmt->attr_metadata_id = (unsigned long) valueptr;
break;
default:
odbc_set_diag (stmt->diag, "HY024", 0, NULL);
goto error;
}
break;
case SQL_ATTR_PARAM_BIND_OFFSET_PTR:
odbc_set_desc_field (stmt->apd, 0, SQL_DESC_BIND_OFFSET_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_PARAM_BIND_TYPE:
rc = odbc_set_desc_field (stmt->apd, 0, SQL_DESC_BIND_TYPE,
valueptr, sizeof (valueptr), 1);
if (rc < 0)
{
odbc_set_diag (stmt->diag, "HY024", 0, NULL);
goto error;
}
break;
case SQL_ATTR_PARAM_OPERATION_PTR:
odbc_set_desc_field (stmt->apd, 0, SQL_DESC_ARRAY_STATUS_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_PARAM_STATUS_PTR:
odbc_set_desc_field (stmt->ipd, 0, SQL_DESC_ARRAY_STATUS_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_PARAMS_PROCESSED_PTR:
odbc_set_desc_field (stmt->ipd, 0, SQL_DESC_ROWS_PROCESSED_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_PARAMSET_SIZE:
odbc_set_desc_field (stmt->apd, 0, SQL_DESC_ARRAY_SIZE,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_ROW_ARRAY_SIZE:
case SQL_ROWSET_SIZE: // for 2.x backward compatiablity
odbc_set_desc_field (stmt->ard, 0, SQL_DESC_ARRAY_SIZE,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_ROW_BIND_OFFSET_PTR:
odbc_set_desc_field (stmt->ard, 0, SQL_DESC_BIND_OFFSET_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_ROW_BIND_TYPE:
rc = odbc_set_desc_field (stmt->ard, 0, SQL_DESC_BIND_TYPE,
valueptr, sizeof (valueptr), 1);
if (rc < 0)
{
odbc_set_diag (stmt->diag, "HY024", 0, NULL);
goto error;
}
break;
case SQL_ATTR_ROW_STATUS_PTR:
odbc_set_desc_field (stmt->ird, 0, SQL_DESC_ARRAY_STATUS_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_ROW_OPERATION_PTR:
odbc_set_desc_field (stmt->ard, 0, SQL_DESC_ARRAY_STATUS_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_ROWS_FETCHED_PTR:
odbc_set_desc_field (stmt->ird, 0, SQL_DESC_ROWS_PROCESSED_PTR,
valueptr, sizeof (valueptr), 1);
break;
case SQL_ATTR_ROW_NUMBER:
// READ-ONLY
odbc_set_diag (stmt->diag, "HY092", 0, NULL);
goto error;
case SQL_ATTR_USE_BOOKMARKS:
stmt->attr_use_bookmark = (unsigned long) valueptr;
break;
// Not supported attribute
// 어떠한 작업도 하지 않는다.
case SQL_ATTR_CONCURRENCY:
case SQL_ATTR_ENABLE_AUTO_IPD:
case SQL_ATTR_KEYSET_SIZE:
case SQL_ATTR_MAX_LENGTH:
case SQL_ATTR_MAX_ROWS:
case SQL_ATTR_NOSCAN:
case SQL_ATTR_QUERY_TIMEOUT:
case SQL_ATTR_RETRIEVE_DATA:
break;
default:
odbc_set_diag (stmt->diag, "HY092", 0, NULL);
goto error;
}
return ODBC_SUCCESS;
error:
return ODBC_ERROR;
}
/************************************************************************
* name: odbc_get_stmt_attr
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC RETCODE
odbc_get_stmt_attr (ODBC_STATEMENT * stmt,
long attr,
SQLPOINTER value_ptr, SQLINTEGER buffer_length,
SQLINTEGER * length_ptr)
{
SQLLEN tmp_length;
if (value_ptr == NULL)
{
odbc_set_diag (stmt->diag, "HY009", 0, NULL);
goto error;
}
switch (attr)
{
case SQL_ATTR_APP_PARAM_DESC:
if (value_ptr != NULL)
*(ODBC_DESC **) value_ptr = stmt->apd;
if (length_ptr != NULL)
*length_ptr = sizeof (stmt->apd);
break;
case SQL_ATTR_APP_ROW_DESC:
if (value_ptr != NULL)
*(ODBC_DESC **) value_ptr = stmt->ard;
if (length_ptr != NULL)
*length_ptr = sizeof (stmt->ard);
break;
case SQL_ATTR_ASYNC_ENABLE:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = stmt->attr_async_enable;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_CURSOR_SCROLLABLE:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = stmt->attr_cursor_scrollable;
if (length_ptr != NULL)
*length_ptr = sizeof (stmt->attr_cursor_scrollable);
break;
case SQL_ATTR_IMP_PARAM_DESC:
if (value_ptr != NULL)
*(ODBC_DESC **) value_ptr = stmt->ipd;
if (length_ptr != NULL)
*length_ptr = sizeof (stmt->ipd);
break;
case SQL_ATTR_IMP_ROW_DESC:
if (value_ptr != NULL)
*(ODBC_DESC **) value_ptr = stmt->ird;
if (length_ptr != NULL)
*length_ptr = sizeof (stmt->ird);
break;
case SQL_ATTR_METADATA_ID:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = stmt->attr_metadata_id;
if (length_ptr != NULL)
*length_ptr = sizeof (stmt->attr_metadata_id);
break;
case SQL_ATTR_PARAM_BIND_OFFSET_PTR:
odbc_get_desc_field (stmt->apd, 0, SQL_DESC_BIND_OFFSET_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_PARAM_BIND_TYPE:
odbc_get_desc_field (stmt->apd, 0, SQL_DESC_BIND_TYPE,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_PARAM_OPERATION_PTR:
odbc_get_desc_field (stmt->apd, 0, SQL_DESC_ARRAY_STATUS_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_PARAM_STATUS_PTR:
odbc_get_desc_field (stmt->ipd, 0, SQL_DESC_ARRAY_STATUS_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_PARAMS_PROCESSED_PTR:
odbc_get_desc_field (stmt->ipd, 0, SQL_DESC_ROWS_PROCESSED_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_PARAMSET_SIZE:
odbc_get_desc_field (stmt->apd, 0, SQL_DESC_ARRAY_SIZE,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_RETRIEVE_DATA:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = SQL_RD_ON;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_ROW_ARRAY_SIZE:
case SQL_ROWSET_SIZE: // for 2.x backward compatiablity
odbc_get_desc_field (stmt->ard, 0, SQL_DESC_ARRAY_SIZE,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_ROW_BIND_OFFSET_PTR:
odbc_get_desc_field (stmt->ard, 0, SQL_DESC_BIND_OFFSET_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_ROW_BIND_TYPE:
odbc_get_desc_field (stmt->ard, 0, SQL_DESC_BIND_TYPE,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_ROW_STATUS_PTR:
odbc_get_desc_field (stmt->ird, 0, SQL_DESC_ARRAY_STATUS_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_ROW_OPERATION_PTR:
odbc_get_desc_field (stmt->ard, 0, SQL_DESC_ARRAY_STATUS_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_ROWS_FETCHED_PTR:
odbc_get_desc_field (stmt->ird, 0, SQL_DESC_ROWS_PROCESSED_PTR,
value_ptr, buffer_length, &tmp_length);
if (length_ptr != NULL)
{
*length_ptr = (SQLINTEGER) tmp_length;
}
break;
case SQL_ATTR_ROW_NUMBER:
if (value_ptr != NULL)
{
if (stmt->current_tpl_pos <= 0)
*(unsigned long *) value_ptr = 0;
else
*(unsigned long *) value_ptr = stmt->current_tpl_pos;
}
if (length_ptr != NULL)
*length_ptr = sizeof (stmt->attr_cursor_scrollable);
break;
case SQL_ATTR_CURSOR_TYPE:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = stmt->attr_cursor_type;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
// SQL_CONCUR_READ_ONLY
case SQL_ATTR_CONCURRENCY:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = stmt->attr_concurrency;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
// Not supported attribute
case SQL_ATTR_CURSOR_SENSITIVITY:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = stmt->attr_cursor_sensitivity;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_ENABLE_AUTO_IPD:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = SQL_FALSE;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_FETCH_BOOKMARK_PTR:
if (value_ptr != NULL)
*((void **) value_ptr) = NULL;
if (length_ptr != NULL)
{
*length_ptr = sizeof (void *);
}
break;
case SQL_ATTR_KEYSET_SIZE:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = 0;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_MAX_LENGTH:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = 0;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_MAX_ROWS:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = 0;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_NOSCAN:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = SQL_NOSCAN_ON;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_QUERY_TIMEOUT:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = 0;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_SIMULATE_CURSOR:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = SQL_SC_NON_UNIQUE;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
case SQL_ATTR_USE_BOOKMARKS:
if (value_ptr != NULL)
*(unsigned long *) value_ptr = stmt->attr_use_bookmark;
if (length_ptr != NULL)
*length_ptr = sizeof (unsigned long);
break;
default:
odbc_set_diag (stmt->diag, "HY092", 0, NULL);
goto error;
}
return ODBC_SUCCESS;
error:
return ODBC_ERROR;
}
/************************************************************************
* name: odbc_set_cursor_name
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC RETCODE
odbc_set_cursor_name (ODBC_STATEMENT * stmt,
char *cursor_name, short name_length)
{
if (cursor_name != NULL)
{
stmt->cursor = UT_MAKE_STRING (cursor_name, name_length);
}
return ODBC_SUCCESS;
}
/************************************************************************
* name: odbc_get_cursor_name
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC RETCODE
odbc_get_cursor_name (ODBC_STATEMENT * stmt,
SQLCHAR * cursor_name,
SQLSMALLINT buffer_length, SQLLEN * name_length_ptr)
{
RETCODE rc, status = ODBC_SUCCESS;
char *pt;
if (stmt->cursor != NULL)
{
pt = stmt->cursor;
}
else
{
pt = "";
}
rc = str_value_assign (pt, cursor_name, buffer_length, name_length_ptr);
if (rc == ODBC_SUCCESS_WITH_INFO)
{
odbc_set_diag (stmt->diag, "01004", 0, NULL);
status = rc;
}
return status;
}
/************************************************************************
* name: odbc_bind_parameter
* arguments:
* returns/side-effects:
* description:
* NOTE:
* column_size에 대해서 고려하지 않고 있음.
************************************************************************/
PUBLIC RETCODE