forked from CUBRID/cubrid-odbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
odbc_diag_record.c
877 lines (778 loc) · 24.2 KB
/
odbc_diag_record.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
/*
* 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 "odbc_portable.h"
#include "odbc_util.h"
#include "sqlext.h"
#include "odbc_diag_record.h"
#include "odbc_env.h"
#include "odbc_connection.h"
#include "odbc_statement.h"
#define ISO_CLASS_ORIGIN "ISO 9075"
#define ODBC_CLASS_ORIGIN "ODBC 3.0"
#define DIAG_PREFIX "[CUBRID][ODBC CUBRID Driver]"
PRIVATE const char *get_diag_message (ODBC_DIAG_RECORD * record);
PRIVATE char *get_diag_subclass_origin (char *sql_state);
PRIVATE void odbc_init_diag (ODBC_DIAG * diag);
PRIVATE void odbc_clear_diag (ODBC_DIAG * diag);
PRIVATE void odbc_init_diag_record (ODBC_DIAG_RECORD * node);
PRIVATE void odbc_clear_diag_record (ODBC_DIAG_RECORD * node);
PRIVATE short is_header_field (short field_id);
PRIVATE ODBC_DIAG_RECORD *find_diag_record (ODBC_DIAG * diag, int rec_number);
PRIVATE char *get_diag_class_origin (char *sql_state);
PRIVATE ODBC_ERROR_MAP odbc_3_0_error_map[] = {
{"01000", "General warning"},
{"01001", "Cursor operation conflict"},
{"01002", "Disconnect error"},
{"01003", "NULL value eliminated in set function"},
{"01004", "String data, right truncated"},
{"01006", "Privilege not revoked"},
{"01007", "Privilege not granted"},
{"01S00", "Invalid connection string attribute"},
{"01S01", "Error in row"},
{"01S02", "Option value changed"},
{"01S06", "Attempt to fetch before the result set retunred the first rowset"},
{"01S07", "Fractional truncation"},
{"01S08", "Error saving File DSN"},
{"01S09", "Invalid keyword"},
{"07001", "Wrong number of parameters"},
{"07002", "COUNT field incorrect"},
{"07005", "Prepared statement not a cursor-specification"},
{"07006", "Restricted data type attribute violation"},
{"07009", "Invalid descriptor index"},
{"07S01", "Invalid use of default parameter"},
{"08001", "Client unable to establish connection"},
{"08002", "Connection name in use"},
{"08003", "Connection does not exist"},
{"08004", "Server rejected the connection"},
{"08007", "Connection failure during transaction"},
{"08S01", "Communication link failure"},
{"21S01", "Insert value list does not match column list"},
{"21S02", "Degree of derived table does not match column list"},
{"22001", "String data, right truncated"},
{"22002", "Indicator variable required but not supplied"},
{"22003", "Numeric value out of range"},
{"22007", "Invalid datetime format"},
{"22008", "Datetime field overflow"},
{"22012", "Division by zero"},
{"22015", "Invalid field overflow"},
{"22018", "Invalid charcter value for cast specification"},
{"22019", "Invalid escape character"},
{"22025", "Invalid escape sequence"},
{"22026", "String data, length mismatch"},
{"23000", "Integrity constraint violation"},
{"24000", "Invalid cursor state"},
{"25000", "Invalid transaction state"},
{"25S01", "Transaction state"},
{"25S02", "Transaction is still active"},
{"25S03", "Transaction is rolled back"},
{"28000", "Invalid authorization specification"},
{"34000", "Invalid cursor name"},
{"3C000", "Duplicate cursor name"},
{"3D000", "Invalid catalog name"},
{"3F000", "Invalid schema name"},
{"40001", "Serialization failure"},
{"40002", "Integrity constraint violation"},
{"40003", "Statement completion unknown"},
{"42000", "Syntax error or access violation"},
{"42S01", "Base table or view already exists"},
{"42S02", "Base table or view not found"},
{"42S11", "Index already exists"},
{"42S12", "Index not found"},
{"42S21", "Column already exists"},
{"42S22", "Column not found"},
{"44000", "WITH CHECK OPTION violation"},
{"HY000", "General error"},
{"HY001", "Memory allocation error"},
{"HY003", "Invalid application buffer type"},
{"HY004", "Invalid SQL data type"},
{"HY007", "Associated statement is not prepared"},
{"HY008", "Operation canceled"},
{"HY009", "Invalid use of null pointer"},
{"HY010", "Function sequence error"},
{"HY011", "Attribute cannot be set now"},
{"HY012", "Invalid transaction operation code"},
{"HY013", "Memory management error"},
{"HY014", "Limit on the number of handles exceeded"},
{"HY015", "No cursor name available"},
{"HY016", "Cannot modify an implementation row descriptor"},
{"HY017", "Invalid use of an automatically allocated descriptor handle"},
{"HY018", "Server declined cancel request"},
{"HY019", "Non-character and non-binary data sent in pieces"},
{"HY020", "Attempt to concatenate a null value"},
{"HY021", "Inconsistent descriptor information"},
{"HY024", "Invalid attribute value"},
{"HY090", "Invalid string or buffer length"},
{"HY091", "Invalid descriptor field identifier"},
{"HY092", "Invalid attribute/option identifier"},
{"HY095", "Function type out of range"},
{"HY096", "Invalid information type"},
{"HY097", "Column type out of range"},
{"HY098", "Scope type out of range"},
{"HY099", "Nullable type out of range"},
{"HY100", "Uniqueness option type out of range"},
{"HY101", "Accuracy option type out of range"},
{"HY103", "Invalid retrieval code"},
{"HY104", "Invalid precision or scale value"},
{"HY105", "Invalid parameter type"},
{"HY106", "Fetch type out of range"},
{"HY107", "Row value out of range"},
{"HY109", "Invalid cursor position"},
{"HY110", "Invalid driver completion"},
{"HY111", "Invalid bookmark value"},
{"HYC00", "Optional feature not implemented"},
{"HYT00", "Timeout expired"},
{"HYT01", "Connection timeout expired"},
{"IM001", "Driver does not support this function"},
{"IM002", "Data source name not found and no default driver specified"},
{"IM003", "Specified driver could not be loaded"},
{"IM004", "Driver's SQLAllocHandle on SQL_HANDLE_ENV failed"},
{"IM005", "Driver's SQLAllocHandle on SQL_HANDLE_DBC failed"},
{"IM006", "Driver's SQLSetConnectAttr failed"},
{"IM007", "No data source or driver specified; dalo prohibited"},
{"IM008", "Dialog failed"},
{"IM009", "Unable to load translation DLL"},
{"IM010", "Data source name too long"},
{"IM011", "Driver name too long"},
{"IM012", "DRIVER keyword syntax error"},
{"IM013", "Trace file error"},
{"IM014", "Invalid name of File DSN"},
{"IM015", "Corrupt file data source"},
{NULL, NULL}
};
/************************************************************************
* name: odbc_alloc_diag
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC ODBC_DIAG *
odbc_alloc_diag (void)
{
ODBC_DIAG *diag = NULL;
diag = UT_ALLOC (sizeof (ODBC_DIAG));
odbc_init_diag (diag);
return diag;
}
/************************************************************************
* name: odbc_free_diag
* arguments:
* option -
* INIT - 초기화
* RESET - member reset
* FREE_MEBER - member만 free
* FREE_ALL - member 및 node free
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC void
odbc_free_diag (ODBC_DIAG * diag, int option)
{
if (diag == NULL)
return;
switch (option)
{
case INIT:
odbc_init_diag (diag);
break;
case RESET:
odbc_clear_diag (diag);
odbc_init_diag (diag);
break;
case FREE_MEMBER:
odbc_clear_diag (diag);
break;
case FREE_ALL:
odbc_clear_diag (diag);
UT_FREE (diag);
break;
}
}
/************************************************************************
* name: odbc_alloc_diag_record
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC ODBC_DIAG_RECORD *
odbc_alloc_diag_record (void)
{
ODBC_DIAG_RECORD *diag_record = NULL;
diag_record = UT_ALLOC (sizeof (ODBC_DIAG_RECORD));
odbc_init_diag_record (diag_record);
return diag_record;
}
/************************************************************************
* name: odbc_free_diag_record
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC void
odbc_free_diag_record (ODBC_DIAG_RECORD * diag_record, int option)
{
if (diag_record == NULL)
return;
switch (option)
{
case INIT:
odbc_init_diag_record (diag_record);
break;
case RESET:
odbc_clear_diag_record (diag_record);
odbc_init_diag_record (diag_record);
break;
case FREE_MEMBER:
odbc_clear_diag_record (diag_record);
break;
case FREE_ALL:
odbc_clear_diag_record (diag_record);
UT_FREE (diag_record);
break;
}
}
PUBLIC void
odbc_free_diag_record_list (ODBC_DIAG_RECORD * diag_record)
{
ODBC_DIAG_RECORD *current, *del;
current = diag_record;
while (current != NULL)
{
del = current;
current = current->next;
odbc_free_diag_record (del, ODBC_DIAG_RECORD_FREE_ALL);
}
}
PUBLIC void
odbc_move_diag (ODBC_DIAG * target_diag, ODBC_DIAG * src_diag)
{
ODBC_DIAG_RECORD *tmp;
if (src_diag == NULL || target_diag == NULL)
return;
tmp = src_diag->record;
if (tmp == NULL)
return;
else
{
while (tmp->next != NULL)
tmp = tmp->next;
}
tmp->next = target_diag->record;
target_diag->record = src_diag->record;
src_diag->record = NULL;
target_diag->rec_number += src_diag->rec_number;
return;
}
/* recored added to head */
PUBLIC void
odbc_set_diag (ODBC_DIAG * diag, char *sql_state, int native_code,
char *message)
{
ODBC_DIAG_RECORD *record = NULL;
int i;
if (diag == NULL)
return;
record = odbc_alloc_diag_record ();
if (record == NULL)
return;
++(diag->rec_number);
record->number = diag->rec_number;
record->sql_state = UT_MAKE_STRING (sql_state, -1);
record->native_code = native_code;
if (message) {
record->message = UT_MAKE_STRING (message, -1);
} else {
for (i = 0; ; i++) {
if (strcmp(odbc_3_0_error_map[i].status, sql_state) == 0 ||
odbc_3_0_error_map[i].status == NULL) {
break;
}
}
record->message = UT_MAKE_STRING (odbc_3_0_error_map[i].msg, -1);
}
record->next = diag->record;
diag->record = record;
}
PUBLIC void
odbc_set_diag_by_cci (ODBC_DIAG * diag, int cci_retval, T_CCI_ERROR *error)
{
ODBC_DIAG_RECORD *record = NULL;
char err_msg[1024] = { 0 };
if (diag == NULL)
return;
record = odbc_alloc_diag_record ();
if (record == NULL)
return;
++(diag->rec_number);
record->number = diag->rec_number;
record->sql_state = UT_MAKE_STRING ("HY000", -1);
if (cci_retval == CCI_ER_DBMS) {
if (error) {
record->native_code = error->err_code;
record->message = UT_MAKE_STRING(error->err_msg, -1);
} else {
record->native_code = CCI_ER_DBMS;
record->message = UT_MAKE_STRING("Unknown DBMS error", -1);
}
} else {
if (cci_get_err_msg(cci_retval, err_msg, sizeof(err_msg)) < 0) {
strncpy(err_msg, "Unknown error", sizeof(err_msg));
}
record->native_code = cci_retval;
record->message = UT_MAKE_STRING(err_msg, -1);
}
record->next = diag->record;
diag->record = record;
}
/************************************************************************
* name: odbc_get_diag_field
* arguments:
* returns/side-effects:
* description:
* NOTE:
* record field의 SQL_DIAG_COLUMN_NUMBER와 SQL_DIAG_ROW_NUMBER는
* 각 data cell에 대한 fetch시 일어나는 error에 관한 정보이다.
* 현재 지원하지 않는다.
************************************************************************/
PUBLIC RETCODE
odbc_get_diag_field (SQLSMALLINT handle_type,
SQLHANDLE handle,
SQLSMALLINT rec_number,
SQLSMALLINT diag_identifier,
SQLPOINTER diag_info_ptr,
SQLSMALLINT buffer_length, SQLLEN *string_length_ptr)
{
ODBC_ENV *env=NULL;
ODBC_DIAG_RECORD *record=NULL;
RETCODE status = ODBC_SUCCESS, rc=-1;
char *pt=NULL;
char empty_str[1] = "";
env = (ODBC_ENV *) handle;
if ((diag_identifier == SQL_DIAG_CURSOR_ROW_COUNT ||
diag_identifier == SQL_DIAG_DYNAMIC_FUNCTION ||
diag_identifier == SQL_DIAG_DYNAMIC_FUNCTION_CODE ||
diag_identifier == SQL_DIAG_ROW_COUNT) &&
handle_type != SQL_HANDLE_STMT)
{
return ODBC_ERROR;
}
if (is_header_field (diag_identifier) == _TRUE_)
{
switch (diag_identifier)
{
/*
case SQL_DIAG_CURSOR_ROW_COUNT:
case SQL_DIAG_ROW_COUNT:
if (diag_info_ptr != NULL)
*(long *) diag_info_ptr =
((ODBC_STATEMENT *) handle)->current_tpl_pos;
if (string_length_ptr != NULL)
{
*string_length_ptr = sizeof (long);
}
break;
*/
case SQL_DIAG_NUMBER:
if (diag_info_ptr != NULL)
*(long *) diag_info_ptr = env->diag->rec_number;
if (string_length_ptr != NULL)
{
*string_length_ptr = sizeof (long);
}
break;
case SQL_DIAG_RETURNCODE:
if (diag_info_ptr != NULL)
*(short *) diag_info_ptr = env->diag->retcode;
if (string_length_ptr != NULL)
{
*string_length_ptr = sizeof (short);
}
break;
default:
return ODBC_ERROR;
}
}
else
{
/* record field */
if (rec_number <= 0 || rec_number > env->diag->rec_number)
{
return ODBC_NO_DATA;
}
record = find_diag_record (env->diag, rec_number);
if (record == NULL)
{
return ODBC_NO_DATA;
}
switch (diag_identifier)
{
case SQL_DIAG_CLASS_ORIGIN:
pt = get_diag_class_origin (record->sql_state);
rc =
str_value_assign (pt, diag_info_ptr, buffer_length,
string_length_ptr);
if (rc == ODBC_SUCCESS_WITH_INFO)
{
status = rc;
}
break;
case SQL_DIAG_COLUMN_NUMBER: /* yet not implemeted */
if (diag_info_ptr != NULL)
*(long *) diag_info_ptr = SQL_COLUMN_NUMBER_UNKNOWN;
if (string_length_ptr != NULL)
{
*string_length_ptr = sizeof (long);
}
break;
case SQL_DIAG_CONNECTION_NAME: /* yet not implemeted */
if (diag_info_ptr && buffer_length > 0)
{
int connhd = -1;
int cci_ret = 0;
T_CCI_ERROR cci_err_buf;
if (handle_type == SQL_HANDLE_DBC)
{
connhd = ((ODBC_CONNECTION *) handle)->connhd;
}
else if (handle_type == SQL_HANDLE_STMT)
{
connhd = ((ODBC_STATEMENT *) handle)->conn->connhd;
}
if (connhd >= 0)
{
cci_ret = cci_get_cas_info(connhd, (char *)diag_info_ptr, 32, &cci_err_buf);
}
if (connhd < 0 || cci_ret < 0)
{
*((char *) diag_info_ptr) = '\0';
*string_length_ptr=0;
}
else
{
*string_length_ptr = strlen((char *)diag_info_ptr);
}
return ODBC_SUCCESS;
}
else
{
return SQL_SUCCESS_WITH_INFO;
}
case SQL_DIAG_MESSAGE_TEXT:
{
char *mesg = NULL;
char diag_prefix[256] = { 0 };
pt = (char *) get_diag_message (record);
if (pt == NULL)
pt = empty_str;
_snprintf (diag_prefix, sizeof(diag_prefix), "%s[%d]",
DIAG_PREFIX, record->native_code);
mesg = UT_MAKE_STRING (diag_prefix, -1);
mesg = UT_APPEND_STRING (mesg, pt, -1);
rc =
str_value_assign (mesg, diag_info_ptr, buffer_length,
string_length_ptr);
if (rc == ODBC_SUCCESS_WITH_INFO)
{
status = rc;
}
NC_FREE (mesg);
}
break;
case SQL_DIAG_NATIVE:
if (diag_info_ptr != NULL)
*(long *) diag_info_ptr = record->native_code;
if (string_length_ptr != NULL)
{
*string_length_ptr = sizeof (long);
}
break;
case SQL_DIAG_ROW_NUMBER: /* yet not implemeted */
if (diag_info_ptr != NULL)
*(long *) diag_info_ptr = SQL_ROW_NUMBER_UNKNOWN;
if (string_length_ptr != NULL)
{
*string_length_ptr = sizeof (long);
}
break;
case SQL_DIAG_SERVER_NAME:
if (handle_type == SQL_HANDLE_ENV)
{
pt = empty_str;
}
else
{
if (handle_type == SQL_HANDLE_DBC)
{
pt = ((ODBC_CONNECTION *) handle)->data_source;
}
else if (handle_type == SQL_HANDLE_STMT)
{
pt = ((ODBC_STATEMENT *) handle)->conn->data_source;
}
else if (handle_type == SQL_HANDLE_DESC)
{
pt = ((ODBC_DESC *) handle)->conn->data_source;
}
rc =
str_value_assign (pt, diag_info_ptr, buffer_length,
string_length_ptr);
if (rc == ODBC_SUCCESS_WITH_INFO)
{
status = rc;
}
}
break;
case SQL_DIAG_SQLSTATE:
if (record->sql_state != NULL)
{
pt = record->sql_state;
}
else
{
pt = empty_str;
}
rc =
str_value_assign (pt, diag_info_ptr, buffer_length,
string_length_ptr);
if (rc == ODBC_SUCCESS_WITH_INFO)
{
status = rc;
}
break;
case SQL_DIAG_SUBCLASS_ORIGIN:
pt = get_diag_subclass_origin (record->sql_state);
if (pt == NULL)
{
pt = empty_str;
}
rc =
str_value_assign (pt, diag_info_ptr, buffer_length,
string_length_ptr);
if (rc == ODBC_SUCCESS_WITH_INFO)
{
status = rc;
}
break;
default:
return ODBC_ERROR;
}
}
return status;
}
/************************************************************************
* name: odbc_get_diag_rec
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
PUBLIC RETCODE
odbc_get_diag_rec (SQLSMALLINT handle_type,
SQLHANDLE *handle,
SQLSMALLINT rec_number,
SQLCHAR *sqlstate,
SQLINTEGER *native_error_ptr,
SQLCHAR *message_text,
SQLSMALLINT buffer_length, SQLLEN *text_length_ptr)
{
RETCODE status = ODBC_SUCCESS, rc;
ODBC_DIAG_RECORD *record;
ODBC_ENV *env;
char *pt;
char *mesg = NULL;
char empty_str[1] = "";
char diag_prefix[256] = { 0 };
env = (ODBC_ENV *) handle;
if (rec_number <= 0)
return ODBC_ERROR;
/* Sequence error record is not implemented */
if (rec_number > env->diag->rec_number)
return ODBC_NO_DATA;
if ((record = find_diag_record (env->diag, rec_number)) == NULL)
{
return ODBC_NO_DATA;
}
if (sqlstate != NULL)
{
strcpy (sqlstate, record->sql_state);
}
if (native_error_ptr != NULL)
{
*native_error_ptr = record->native_code;
}
pt = (char *) get_diag_message (record);
if (pt == NULL)
pt = empty_str;
_snprintf (diag_prefix, sizeof(diag_prefix), "%s[%d]",
DIAG_PREFIX, record->native_code);
mesg = UT_MAKE_STRING (diag_prefix, -1);
mesg = UT_APPEND_STRING (mesg, pt, -1);
rc = str_value_assign (mesg, message_text, buffer_length, text_length_ptr);
if (rc == ODBC_SUCCESS_WITH_INFO)
{
status = rc;
}
NC_FREE (mesg);
return status;
}
PRIVATE const char *
get_diag_message (ODBC_DIAG_RECORD * record)
{
if (record->message != NULL && record->message[0] != '\0')
{
return record->message;
}
else
{
return NULL;
}
}
PRIVATE char *
get_diag_subclass_origin (char *sql_state)
{
if (sql_state == NULL || sql_state[0] == '\0')
{
return NULL;
}
if (strcmp (sql_state, "01S00") == 0 ||
strcmp (sql_state, "01S01") == 0 ||
strcmp (sql_state, "01S02") == 0 ||
strcmp (sql_state, "01S06") == 0 ||
strcmp (sql_state, "01S07") == 0 ||
strcmp (sql_state, "07S01") == 0 ||
strcmp (sql_state, "08S01") == 0 ||
strcmp (sql_state, "21S01") == 0 ||
strcmp (sql_state, "21S02") == 0 ||
strcmp (sql_state, "25S01") == 0 ||
strcmp (sql_state, "25S02") == 0 ||
strcmp (sql_state, "25S03") == 0 ||
strcmp (sql_state, "42S01") == 0 ||
strcmp (sql_state, "42S02") == 0 ||
strcmp (sql_state, "42S11") == 0 ||
strcmp (sql_state, "42S12") == 0 ||
strcmp (sql_state, "42S21") == 0 ||
strcmp (sql_state, "42S22") == 0 ||
strcmp (sql_state, "HY095") == 0 ||
strcmp (sql_state, "HY097") == 0 ||
strcmp (sql_state, "HY098") == 0 ||
strcmp (sql_state, "HY099") == 0 ||
strcmp (sql_state, "HY100") == 0 ||
strcmp (sql_state, "HY101") == 0 ||
strcmp (sql_state, "HY105") == 0 ||
strcmp (sql_state, "HY107") == 0 ||
strcmp (sql_state, "HY109") == 0 ||
strcmp (sql_state, "HY110") == 0 ||
strcmp (sql_state, "HY111") == 0 ||
strcmp (sql_state, "HYT00") == 0 ||
strcmp (sql_state, "HYT01") == 0 ||
strcmp (sql_state, "IM001") == 0 ||
strcmp (sql_state, "IM002") == 0 ||
strcmp (sql_state, "IM003") == 0 ||
strcmp (sql_state, "IM004") == 0 ||
strcmp (sql_state, "IM005") == 0 ||
strcmp (sql_state, "IM006") == 0 ||
strcmp (sql_state, "IM007") == 0 ||
strcmp (sql_state, "IM008") == 0 ||
strcmp (sql_state, "IM010") == 0 ||
strcmp (sql_state, "IM011") == 0 || strcmp (sql_state, "IM012") == 0)
{
return ODBC_CLASS_ORIGIN;
}
return NULL;
}
PRIVATE ODBC_DIAG_RECORD *
find_diag_record (ODBC_DIAG * diag, int rec_number)
{
ODBC_DIAG_RECORD *record = NULL;
record = diag->record;
while (record != NULL)
if (record->number == rec_number)
break;
else
record = record->next;
return record;
}
PRIVATE void
odbc_init_diag (ODBC_DIAG * diag)
{
if (diag == NULL)
return;
memset (diag, 0, sizeof (ODBC_DIAG));
}
PRIVATE void
odbc_clear_diag (ODBC_DIAG * diag)
{
if (diag == NULL)
return;
odbc_free_diag_record_list (diag->record);
}
PRIVATE void
odbc_init_diag_record (ODBC_DIAG_RECORD * node)
{
if (node != NULL)
{
memset (node, 0, sizeof (ODBC_DIAG_RECORD));
}
}
PRIVATE void
odbc_clear_diag_record (ODBC_DIAG_RECORD * node)
{
if (node == NULL)
return;
NC_FREE (node->message);
NC_FREE (node->sql_state);
}
PRIVATE short
is_header_field (short field_id)
{
switch (field_id)
{
case SQL_DIAG_CURSOR_ROW_COUNT:
case SQL_DIAG_DYNAMIC_FUNCTION:
case SQL_DIAG_DYNAMIC_FUNCTION_CODE:
case SQL_DIAG_NUMBER:
case SQL_DIAG_RETURNCODE:
case SQL_DIAG_ROW_COUNT:
return _TRUE_;
default:
return _FALSE_;
}
}
PRIVATE char *
get_diag_class_origin (char *sql_state)
{
if (strncmp (sql_state, "IM", 2) == 0)
return ODBC_CLASS_ORIGIN;
else
return ISO_CLASS_ORIGIN;
}