-
Notifications
You must be signed in to change notification settings - Fork 27
/
ibm_db2.c
7895 lines (7220 loc) · 313 KB
/
ibm_db2.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
/*
+----------------------------------------------------------------------+
| Copyright IBM Corporation 2005-2014 |
+----------------------------------------------------------------------+
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you |
| may not use this file except in compliance with the License. You may |
| obtain a copy of the License at |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
+----------------------------------------------------------------------+
| Authors: Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, |
| Dan Scott, Helmut Tessarek, Kellen Bombardier, |
| Tony Cairns, Krishna Raman, Ambrish Bhargava, |
| Rahul Priyadarshi, Praveen Devarao, Calvin Buckley, |
| Kevin Adler, Jesse Gorzinski |
+----------------------------------------------------------------------+
$Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "../ext/standard/info.h"
#include "../ext/standard/php_string.h"
#include "php_ibm_db2.h"
/* This is used so the public header doesn't need to have internal defs */
#include "php_ibm_db2_int.h"
ZEND_DECLARE_MODULE_GLOBALS(ibm_db2)
#define ZEND_FETCH_RESOURCE_NEW(res, stmt_type, stmt, stmt_id, resource_type_name, le_stmt)\
res = (stmt_type) zend_fetch_resource(Z_RES_P(*stmt),resource_type_name,le_stmt);\
if(res == NULL)\
RETURN_FALSE;
#define ZEND_FETCH_RESOURCE_2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1, resource_type2)\
rsrc = (rsrc_type) zend_fetch_resource2(Z_RES_P(*passed_id),resource_type_name,resource_type1,resource_type2); \
if(rsrc == NULL)\
RETURN_FALSE;
#define ZEND_RETURN_STRING(str,val) \
RETVAL_STRING(str); \
efree(str);\
return
#define IBM_DB2_ZEND_GET_TYPE(data) (data)->u1.v.type
#define ZEND_Z_TYPE(entry) IBM_DB2_ZEND_GET_TYPE(&entry)
#define ZEND_Z_TYPE_P(entry) IBM_DB2_ZEND_GET_TYPE(entry)
#define ZEND_Z_TYPE_PP(entry) ZEND_Z_TYPE_P(*entry)
/* True global resources - no need for thread safety here */
static int le_conn_struct, le_stmt_struct, le_pconn_struct;
static void _php_db2_check_sql_errors( SQLHANDLE handle, SQLSMALLINT hType, int rc, int cpy_to_global, char* ret_str, int API, SQLSMALLINT recno);
static void _php_db2_assign_options( void* handle, int type, char* opt_key, zval **data );
static int _php_db2_parse_options( zval* options, int type, void* handle );
static void _php_db2_clear_conn_err_cache();
static void _php_db2_clear_stmt_err_cache();
static void _php_db2_clear_exec_many_err_cache(void* handle);
static void _php_db2_set_decfloat_rounding_mode_client(void* handle);
static int _php_db2_close_now( void* handle, int endpconnect);
static char * _php_db2_instance_name;
static int is_ios, is_zos; /* 1 == TRUE; 0 == FALSE; */
#ifdef PASE /* IBM i specific globals */
static int is_i5_server_mode; /* orig - 1 == TRUE; 0 == FALSE; (IBM i use QSQSRVR proxy for DB2) */
static int is_i5_override_ccsid; /* 1.9.7 - 1 == TRUE; 0 == FALSE; (IBM i force CCSID (DBCS customer UTF-8 issue)); */
static int is_i5_null_in_len; /* 1.9.7 - 1 == TRUE; 0 == FALSE; (IBM i lobs come back +1 (bug)); */
static int is_i5_non_hex_ccsid; /* CB 20200826 - CCSID 65535 is bad news */
#endif /* PASE */
#ifdef PASE /* IBM i reuses handles. Connect close out of sync with le_stmt_struct dtor logic */
#define DB2_I5_MAX_HANDLES 33000
static SQLHANDLE i5_handle_refcount[DB2_I5_MAX_HANDLES];
#endif /* PASE */
/* Defines a linked list structure for error messages */
typedef struct _error_msg_node {
char err_msg[DB2_MAX_ERR_MSG_LEN];
struct _error_msg_node *next;
} error_msg_node;
/* Defines a linked list structure for caching param data */
typedef struct _param_cache_node {
SQLSMALLINT data_type; /* Datatype */
SQLUINTEGER param_size; /* param size */
SQLSMALLINT nullable; /* is Nullable */
SQLSMALLINT scale; /* Decimal scale */
SQLUINTEGER file_options; /* File options if DB2_PARAM_FILE */
SQLINTEGER bind_indicator; /* indicator variable for SQLBindParameter */
SQLINTEGER long_value; /* Value if this is an SQL_C_LONG type */
SQLSMALLINT short_strlen; /* Length of string if this is an SQL_C_STRING type */
int param_num; /* param number in stmt */
int param_type; /* Type of param - INP/OUT/INP-OUT/FILE */
char *varname; /* bound variable name */
zval *value; /* Temp storage value */
struct _param_cache_node *next; /* Pointer to next node */
} param_node;
typedef struct _conn_handle_struct {
SQLHANDLE henv;
SQLHANDLE hdbc;
SQLINTEGER auto_commit;
long c_bin_mode;
long c_case_mode;
long c_cursor_type;
#ifdef PASE /* IBM i overrides php.ini */
long c_i5_dbcs_alloc; /* orig - IBM i 6x space for CCSID<>UTF-8 convert (DBCS customer issue) */
long c_i5_max_pconnect; /* 1.9.7 - IBM i count max usage connection recycle (customer issue months live connection) */
long c_i5_executing; /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
long c_i5_char_trim; /* 2.0.3 - IBM i trim spaces character results (customer size request issue) */
#endif /* PASE */
/* 1.9.7 - IBM i + LUW 10.5 system naming on (*libl)/file.mbr */
long c_i5_sys_naming; /* 1.9.7 - IBM i + LUW DB2 Connect 10.5 system naming (customer *LIBL issues) */
char * c_i5_pending_chglibl; /* 1.9.7 - IBM i + LUW DB2 Connect 10.5 system naming (customer *LIBL issues) */
char * c_i5_pending_chgcurlib; /* 1.9.7 - IBM i + LUW DB2 Connect 10.5 system naming (customer *LIBL issues) */
int handle_active;
SQLSMALLINT error_recno_tracker;
SQLSMALLINT errormsg_recno_tracker;
int flag_pconnect; /* Indicates that this connection is persistent */
int flag_transaction; /* Indicates that transaction is commited */
int expansion_factor; /* Maximum expected expansion factor for the length of mixed character data when converted to the application code page from datavase code page */
} conn_handle;
typedef union {
SQLINTEGER i_val;
SQLDOUBLE d_val;
SQLFLOAT f_val;
SQLREAL r_val;
SQLSMALLINT s_val;
SQLCHAR *str_val;
} db2_row_data_type;
typedef struct {
SQLINTEGER out_length;
db2_row_data_type data;
} db2_row_type;
typedef struct _db2_result_set_info_struct {
SQLCHAR *name;
SQLSMALLINT type;
SQLUINTEGER size;
SQLSMALLINT scale;
SQLSMALLINT nullable;
SQLINTEGER lob_loc;
SQLINTEGER loc_ind;
SQLSMALLINT loc_type;
} db2_result_set_info;
typedef struct _stmt_handle_struct {
SQLHANDLE hdbc;
SQLHANDLE hstmt;
long s_bin_mode;
long cursor_type;
long s_case_mode;
long s_rowcount;
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
conn_handle * s_i5_conn_parent;
#endif /* PASE */
SQLSMALLINT error_recno_tracker;
SQLSMALLINT errormsg_recno_tracker;
/* Parameter Caching variables */
param_node *head_cache_list;
param_node *current_node;
int num_params; /* Number of Params */
int file_param; /* if option passed in is FILE_PARAM */
int num_columns;
db2_result_set_info *column_info;
db2_row_type *row_data;
char *exec_many_err_msg;
int expansion_factor; /* maximum expected expansion factor for the length of mixed character data */
/* when converted to the application code page from the database code page*/
} stmt_handle;
/* equivalent functions on different platforms */
#ifdef PHP_WIN32
#define STRCASECMP stricmp
#else
#define STRCASECMP strcasecmp
#endif
/* {{{ Argument info
*/
#if PHP_MAJOR_VERSION >= 8
#include "ibm_db2_arginfo.h"
#else
#include "ibm_db2_legacy_arginfo.h"
#endif
/* }}} */
/* {{{ ibm_db2_module_entry
*/
zend_module_entry ibm_db2_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"ibm_db2",
ext_functions,
PHP_MINIT(ibm_db2),
PHP_MSHUTDOWN(ibm_db2),
NULL, /* Replace with NULL if there's nothing to do at request start */
PHP_RSHUTDOWN(ibm_db2), /* Replace with NULL if there's nothing to do at request end */
PHP_MINFO(ibm_db2),
#if ZEND_MODULE_API_NO >= 20010901
PHP_IBM_DB2_VERSION, /* Replace with version number for your extension */
#endif
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_IBM_DB2
ZEND_GET_MODULE(ibm_db2)
#endif
/* {{{ PHP_INI
*/
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("ibm_db2.binmode", "1", PHP_INI_ALL, OnUpdateLong,
bin_mode, zend_ibm_db2_globals, ibm_db2_globals)
/* orig - IBM i legacy CRTLIB containers fail under commit control (isolation *NONE) */
STD_PHP_INI_BOOLEAN("ibm_db2.i5_allow_commit", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_allow_commit, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i consultant request php.ini set system naming (customer *LIBL issues) */
STD_PHP_INI_ENTRY("ibm_db2.i5_sys_naming", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_sys_naming, zend_ibm_db2_globals, ibm_db2_globals)
#ifdef PASE /* IBM i ibm_db2.ini options */
/* orig - IBM i 6x space for CCSID<>UTF-8 convert (DBCS customer issue) */
STD_PHP_INI_BOOLEAN("ibm_db2.i5_dbcs_alloc", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_dbcs_alloc, zend_ibm_db2_globals, ibm_db2_globals)
/* orig - IBM i force all connect to pconnect (operator issue) */
STD_PHP_INI_BOOLEAN("ibm_db2.i5_all_pconnect", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_all_pconnect, zend_ibm_db2_globals, ibm_db2_globals)
/* orig - IBM i ignore user id enables no-QSQSRVR job (custom site request) */
STD_PHP_INI_BOOLEAN("ibm_db2.i5_ignore_userid", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_ignore_userid, zend_ibm_db2_globals, ibm_db2_globals)
/* orig - IBM i SQL_ATTR_JOB_SORT_SEQUENCE (customer request DB2 PTF) */
STD_PHP_INI_BOOLEAN("ibm_db2.i5_job_sort", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_job_sort, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i force UTF-8 CCSID (NLS customer issues) */
STD_PHP_INI_ENTRY("ibm_db2.i5_override_ccsid", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_override_ccsid, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i security restrict blank db,uid,pwd (unless customer allow flag) */
STD_PHP_INI_ENTRY("ibm_db2.i5_blank_userid", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_blank_userid, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i consultant request log additional information into php.log */
STD_PHP_INI_ENTRY("ibm_db2.i5_log_verbose", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_log_verbose, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i count max usage connection recycle (customer issue months live connection) */
STD_PHP_INI_ENTRY("ibm_db2.i5_max_pconnect", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_max_pconnect, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i remote persistent connection or long lived local (customer issue dead connection) */
STD_PHP_INI_ENTRY("ibm_db2.i5_check_pconnect", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_check_pconnect, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i consultant request switch subsystem QSQSRVR job (customer workload issues) */
STD_PHP_INI_ENTRY("ibm_db2.i5_servermode_subsystem", NULL, PHP_INI_SYSTEM, OnUpdateString,
i5_servermode_subsystem, zend_ibm_db2_globals, ibm_db2_globals)
/* 1.9.7 - IBM i monitor switch user profile applications (customer security issue) */
STD_PHP_INI_ENTRY("ibm_db2.i5_guard_profile", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_guard_profile, zend_ibm_db2_globals, ibm_db2_globals)
/* 2.0.3 - IBM i trim spaces character results (customer size request issue) */
STD_PHP_INI_BOOLEAN("ibm_db2.i5_char_trim", "0", PHP_INI_SYSTEM, OnUpdateLong,
i5_char_trim, zend_ibm_db2_globals, ibm_db2_globals)
#endif /* PASE */
PHP_INI_ENTRY("ibm_db2.instance_name", NULL, PHP_INI_SYSTEM, NULL)
PHP_INI_END()
/* }}} */
#ifdef PASEDEBUG /* IBM i - debug to error log ... _php_db2_errorlog("inlen=%d",tmp_length) */
static void _php_db2_errorlog(const char * format, ...)
{
char bigbuff[4096];
char * p = (char *) &bigbuff;
va_list args;
va_start(args, format);
vsprintf(p, format, args);
va_end(args);
php_error_docref(NULL, E_WARNING, p);
}
#endif /* PASE */
/* {{{ static int _php_db2_hash_find_ind(const char * varname, int varlen, zval ***bind_data)
*/
static int _php_db2_hash_find_ind(char * varname, int varlen, zval **temp, zval ***bind_data, zend_array ** symbol_table_used)
{
int rc = FAILURE;
zend_array * symbol_table_local; /* php 5.3+, php 7+ */
/* Fetch data from symbol table (local scope) */
symbol_table_local = zend_rebuild_symbol_table();
*temp = zend_hash_str_find_ind(symbol_table_local, varname, varlen );
if (*temp != NULL) {
*bind_data = temp;
*symbol_table_used = symbol_table_local;
rc = SUCCESS;
/* Fetch data from symbol table (global scope ... mmm??) */
} else {
*temp = zend_hash_str_find_ind(&EG(symbol_table), varname, varlen );
if (*temp != NULL) {
*bind_data = temp;
*symbol_table_used = &EG(symbol_table);
rc = SUCCESS;
}
}
return rc;
}
/* }}} */
/* {{{ static void _php_db2_set_symbol(char * varname, zval *var)
*/
static void _php_db2_set_symbol(char * varname, zval *var)
{
zval **bind_data; /* Data value from symbol table */
zval *temp = NULL;
zend_array * symbol_table_used; /* php 5.3+, php 7+ */
if (_php_db2_hash_find_ind(varname, strlen(varname), &temp, &bind_data, &symbol_table_used ) != FAILURE ) {
/* $mydata = 3;
* function callme () {
* global $mydata;
* db2_bind_param( $stmt , 1 , "mydata" , DB2_PARAM_INOUT );
*/
switch(ZEND_Z_TYPE_PP(bind_data)) {
case IS_REFERENCE:
ZVAL_DEREF(*bind_data);
break;
}
zval_ptr_dtor(*bind_data);
ZVAL_COPY_VALUE(*bind_data, var);
}
}
/* }}} */
/* {{{ Murmur hash implementation (for persistent key hash)
*/
static unsigned int _php_db2_MurmurOAAT32 (const char * key)
{
unsigned int h = 3323198485;
for (;*key;++key) {
h ^= *key;
h *= 0x5bd1e995;
h ^= h >> 15;
}
return h;
}
/* }}} */
#ifdef PASE /* IBM i meta change ""->NULL */
static void _php_db2_meta_helper(SQLCHAR **qualifier, size_t *qualifier_len,
SQLCHAR **owner, size_t *owner_len,
SQLCHAR **table, size_t *table_len,
SQLCHAR **column, size_t *column_len)
{
if (qualifier) {
*qualifier=NULL;
*qualifier_len=0;
}
if (owner) {
if (**owner=='\0') {
*owner=NULL;
*owner_len=0;
}
else *owner_len=SQL_NTS;
}
if (table) {
if (**table=='\0') {
*table=NULL;
*table_len=0;
}
else *table_len=SQL_NTS;
}
if (column) {
if (**column=='\0') {
*column=NULL;
*column_len=0;
}
else *column_len=SQL_NTS;
}
}
#endif /* PASE */
#ifdef PASE /* 1.9.7 - IBM i consolidate ifdefs */
SQLRETURN _php_db2_override_SQLSetConnectAttr(
SQLHDBC hdbc,
SQLINTEGER fOption,
SQLPOINTER vParam,
SQLINTEGER fStrLen)
{
int rc = SQL_ERROR;
SQLPOINTER pvParam = vParam;
/* must be 32-bit, or reads first 32-bits in 64-bit word (always 0) */
int iParam = (SQLINTEGER)(intptr_t)vParam;
/* IBM i requires pointer to value;
* LUW supports raw integer (SQL_IS_INTEGER) or pointer (SQL_NTS)
*/
if (fStrLen == SQL_IS_INTEGER) {
pvParam = &iParam;
} else if (fStrLen != SQL_NTS) {
pvParam = &vParam;
}
rc = SQLSetConnectAttr(hdbc, fOption, pvParam, fStrLen);
return rc;
}
SQLRETURN _php_db2_override_SQLSetStmtAttr(
SQLHSTMT hstmt,
SQLINTEGER fOption,
SQLPOINTER vParam,
SQLINTEGER fStrLen)
{
int rc = SQL_ERROR;
SQLPOINTER pvParam = vParam;
/* must be 32-bit, or reads first 32-bits in 64-bit word (always 0) */
int iParam = (SQLINTEGER)(intptr_t)vParam;
/* IBM i requires pointer to value;
* LUW supports raw integer (SQL_IS_INTEGER) or pointer (SQL_NTS)
*/
if (fStrLen == SQL_IS_INTEGER) {
pvParam = &iParam;
} else if (fStrLen != SQL_NTS) {
pvParam = &vParam;
}
rc = SQLSetStmtAttr(hstmt, fOption, pvParam, fStrLen);
return rc;
}
SQLRETURN _php_db2_override_SQLSetEnvAttr(
SQLHENV henv,
SQLINTEGER fOption,
SQLPOINTER vParam,
SQLINTEGER fStrLen)
{
int rc = SQL_ERROR;
SQLPOINTER pvParam = vParam;
/* must be 32-bit, or reads first 32-bits in 64-bit word (always 0) */
int iParam = (SQLINTEGER)(intptr_t)vParam;
/* IBM i requires pointer to value;
* LUW supports raw integer (SQL_IS_INTEGER) or pointer (SQL_NTS)
*/
if (fStrLen == SQL_IS_INTEGER) {
pvParam = &iParam;
} else if (fStrLen != SQL_NTS) {
pvParam = &vParam;
}
rc = SQLSetEnvAttr(henv, fOption, pvParam, fStrLen);
return rc;
}
/* define SQLxxx must appear below override _php_db2_override_SQLxxx*/
#define SQLSetEnvAttr(p1,p2,p3,p4) _php_db2_override_SQLSetEnvAttr(p1,p2,p3,p4)
#define SQLSetConnectAttr(p1,p2,p3,p4) _php_db2_override_SQLSetConnectAttr(p1,p2,p3,p4)
#define SQLSetStmtAttr(p1,p2,p3,p4) _php_db2_override_SQLSetStmtAttr(p1,p2,p3,p4)
#endif /* PASE */
/* {{{ static void php_ibm_db2_init_globals
*/
static void php_ibm_db2_init_globals(zend_ibm_db2_globals *ibm_db2_globals)
{
/* env handle */
ibm_db2_globals->bin_mode = 0;
memset(ibm_db2_globals->__php_conn_err_msg, 0, DB2_MAX_ERR_MSG_LEN);
memset(ibm_db2_globals->__php_stmt_err_msg, 0, DB2_MAX_ERR_MSG_LEN);
memset(ibm_db2_globals->__php_conn_err_state, 0, SQL_SQLSTATE_SIZE + 1);
memset(ibm_db2_globals->__php_stmt_err_state, 0, SQL_SQLSTATE_SIZE + 1);
ibm_db2_globals->i5_allow_commit = 0; /* orig - IBM i legacy CRTLIB containers fail under commit control (isolation *NONE) */
ibm_db2_globals->i5_sys_naming = 0; /* 1.9.7 - IBM i + LUW 10.5 system naming on (*libl)/file.mbr */
#ifdef PASE /* IBM i set default values (ibm_db2 bug long time) */
ibm_db2_globals->i5_dbcs_alloc = 0; /* orig - IBM i 6x space for CCSID<>UTF-8 convert (DBCS customer issue) */
ibm_db2_globals->i5_all_pconnect = 0; /* orig - IBM i force all connect to pconnect (operator issue) */
ibm_db2_globals->i5_ignore_userid = 0; /* orig - IBM i ignore user id enables no-QSQSRVR job (custom site request) */
ibm_db2_globals->i5_job_sort = 0; /* orig - IBM i SQL_ATTR_JOB_SORT_SEQUENCE (customer request DB2 PTF) */
ibm_db2_globals->i5_override_ccsid = 0; /* 1.9.7 - IBM i force UTF-8 CCSID (NLS customer issues) */
ibm_db2_globals->i5_blank_userid = 0; /* 1.9.7 - IBM i security restrict blank db,uid,pwd (unless customer allow flag) */
ibm_db2_globals->i5_log_verbose = 0; /* 1.9.7 - IBM i consultant request log additional information into php.log */
ibm_db2_globals->i5_max_pconnect = 0; /* 1.9.7 - IBM i count max usage connection recycle (customer issue months live connection) */
ibm_db2_globals->i5_check_pconnect = 0; /* 1.9.7 - IBM i remote persistent connection or long lived local (customer issue dead connection) */
ibm_db2_globals->i5_servermode_subsystem = NULL; /* 1.9.7 - IBM i consultant request switch subsystem QSQSRVR job (customer workload issues) */
ibm_db2_globals->i5_guard_profile = 0; /* 1.9.7 - IBM i monitor switch user profile applications (customer security issue) */
ibm_db2_globals->i5_char_trim = 0; /* 2.0.3 - IBM i trim spaces character results (customer size request issue) */
#endif /* PASE */
#ifdef PASE /* IBM i reuses handles. Connect close out of sync with le_stmt_struct dtor logic */
memset(i5_handle_refcount,0,sizeof(i5_handle_refcount));
#endif /* PASE */
}
/* }}} */
#ifdef PASE /* IBM i test helper */
static void _php_db2_i5_test_helper() {
/* IBM i - easy test override ibm_db2.ini */
if (!getenv("IBM_DB_I5_TEST")) return;
if (getenv("IBM_DB_i5_allow_commit")) IBM_DB2_G(i5_allow_commit) = atoi(getenv("IBM_DB_i5_allow_commit"));
if (getenv("IBM_DB_i5_dbcs_alloc")) IBM_DB2_G(i5_dbcs_alloc) = atoi(getenv("IBM_DB_i5_dbcs_alloc"));
if (getenv("IBM_DB_i5_all_pconnect")) IBM_DB2_G(i5_all_pconnect) = atoi(getenv("IBM_DB_i5_all_pconnect"));
if (getenv("IBM_DB_i5_ignore_userid")) IBM_DB2_G(i5_ignore_userid) = atoi(getenv("IBM_DB_i5_ignore_userid"));
if (getenv("IBM_DB_i5_job_sort")) IBM_DB2_G(i5_job_sort) = atoi(getenv("IBM_DB_i5_job_sort"));
if (getenv("IBM_DB_i5_override_ccsid")) IBM_DB2_G(i5_override_ccsid) = atoi(getenv("IBM_DB_i5_override_ccsid"));
if (getenv("IBM_DB_i5_blank_userid")) IBM_DB2_G(i5_blank_userid) = atoi(getenv("IBM_DB_i5_blank_userid"));
if (getenv("IBM_DB_i5_log_verbose")) IBM_DB2_G(i5_log_verbose) = atoi(getenv("IBM_DB_i5_log_verbose"));
if (getenv("IBM_DB_i5_max_pconnect")) IBM_DB2_G(i5_max_pconnect) = atoi(getenv("IBM_DB_i5_max_pconnect"));
if (getenv("IBM_DB_i5_check_pconnect")) IBM_DB2_G(i5_check_pconnect) = atoi(getenv("IBM_DB_i5_check_pconnect"));
if (getenv("IBM_DB_i5_sys_naming")) IBM_DB2_G(i5_sys_naming) = atoi(getenv("IBM_DB_i5_sys_naming"));
if (getenv("IBM_DB_i5_servermode_subsystem")) IBM_DB2_G(i5_servermode_subsystem) = getenv("IBM_DB_i5_servermode_subsystem");
if (getenv("IBM_DB_i5_guard_profile")) IBM_DB2_G(i5_guard_profile) = atoi(getenv("IBM_DB_i5_guard_profile"));
if (getenv("IBM_DB_i5_char_trim")) IBM_DB2_G(i5_char_trim) = atoi(getenv("IBM_DB_i5_char_trim"));
}
#endif /* PASE */
/* {{{ static void _php_db2_free_conn_struct */
static void _php_db2_free_conn_struct(zend_resource *rsrc)
{
int rc;
conn_handle *handle = (conn_handle*) rsrc->ptr;
/* Disconnect from DB. If stmt is allocated, it is freed automatically*/
if ( handle->handle_active ) {
if ( handle->flag_transaction == 1 && handle->auto_commit == 0 ) {
handle->flag_transaction = 0;
rc = SQLEndTran(SQL_HANDLE_DBC, (SQLHDBC)handle->hdbc, SQL_ROLLBACK);
}
rc = SQLDisconnect((SQLHDBC)handle->hdbc);
rc = SQLFreeHandle(SQL_HANDLE_DBC, handle->hdbc);
#ifndef PASE /* IBM i too noisy */
rc = SQLFreeHandle(SQL_HANDLE_ENV, handle->henv);
#endif /* PASE */
}
if ( handle != NULL ) {
if ( handle->flag_pconnect ) {
/* Important to use regular free, we don't want the handled collected by efree */
pefree(handle, 1);
} else {
efree(handle);
}
}
}
/* }}} */
/* {{{ static void _php_db2_free_pconn_struct */
static void _php_db2_free_pconn_struct(zend_resource *rsrc)
{
_php_db2_free_conn_struct(rsrc);
}
/* }}} */
/* {{{ static void _php_db2_free_result_struct(stmt_handle* handle)
*/
static void _php_db2_free_result_struct(stmt_handle* handle)
{
int i;
param_node *curr_ptr = NULL, *prev_ptr = NULL;
if ( handle != NULL ) {
_php_db2_clear_exec_many_err_cache(handle);
/* Free param cache list */
curr_ptr = handle->head_cache_list;
prev_ptr = handle->head_cache_list;
while (curr_ptr != NULL) {
curr_ptr = curr_ptr->next;
if (prev_ptr->varname) {
efree(prev_ptr->varname);
}
if( prev_ptr->param_type != DB2_PARAM_OUT && prev_ptr->param_type != DB2_PARAM_INOUT ) {
if (prev_ptr->value) {
zval_ptr_dtor(prev_ptr->value);
efree(prev_ptr->value);
}
}
efree(prev_ptr);
prev_ptr = curr_ptr;
}
handle->head_cache_list = NULL;
/* free row data cache */
if (handle->row_data) {
for (i=0; i<handle->num_columns;i++) {
switch (handle->column_info[i].type) {
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_UTF8_CHAR:
case SQL_WCHAR:
case SQL_WVARCHAR:
case SQL_GRAPHIC:
case SQL_VARGRAPHIC:
case SQL_LONGVARCHAR:
case SQL_WLONGVARCHAR:
case SQL_LONGVARGRAPHIC:
case SQL_TYPE_DATE:
case SQL_TYPE_TIME:
case SQL_TYPE_TIMESTAMP:
case SQL_DATETIME:
case SQL_BIGINT:
case SQL_DECIMAL:
case SQL_NUMERIC:
case SQL_XML:
case SQL_DECFLOAT:
if ( handle->row_data[i].data.str_val != NULL ) {
efree(handle->row_data[i].data.str_val);
handle->row_data[i].data.str_val = NULL;
}
}
}
efree(handle->row_data);
handle->row_data = NULL;
}
/* free column info cache */
if ( handle->column_info ) {
for (i=0; i<handle->num_columns; i++) {
efree(handle->column_info[i].name);
}
efree(handle->column_info);
handle->column_info = NULL;
handle->num_columns = 0;
}
}
}
/* }}} */
/* {{{ static stmt_handle *_db2_new_stmt_struct(conn_handle* conn_res)
*/
static stmt_handle *_db2_new_stmt_struct(conn_handle* conn_res)
{
stmt_handle *stmt_res;
stmt_res = (stmt_handle *)ecalloc(1, sizeof(stmt_handle));
/* Initialize stmt resource so parsing assigns updated options if needed */
stmt_res->hdbc = conn_res->hdbc;
stmt_res->s_bin_mode = conn_res->c_bin_mode;
stmt_res->cursor_type = conn_res->c_cursor_type;
stmt_res->s_case_mode = conn_res->c_case_mode;
#ifdef PASE /* 1.9.9 - IBM i customer request abandon connection stored proc in MSQW (human response needed) */
stmt_res->s_i5_conn_parent = conn_res;
#endif /* PASE */
stmt_res->expansion_factor = conn_res->expansion_factor;
stmt_res->head_cache_list = NULL;
stmt_res->current_node = NULL;
stmt_res->num_params = 0;
stmt_res->file_param = 0;
stmt_res->column_info = NULL;
stmt_res->num_columns = 0;
stmt_res->error_recno_tracker = 1;
stmt_res->errormsg_recno_tracker = 1;
stmt_res->row_data = NULL;
stmt_res->exec_many_err_msg = NULL;
return stmt_res;
}
/* }}} */
#ifdef PASE /* IBM i reuses handles. Connect close out of sync with le_stmt_struct dtor logic */
/* {{{ static _php_db2_incr_stmt_struct */
static void _php_db2_incr_stmt_struct(stmt_handle *handle)
{
i5_handle_refcount[handle->hstmt]++;
}
/* }}} */
/* {{{ static _php_db2_incr_stmt_struct */
static int _php_db2_decr_stmt_struct(stmt_handle *handle)
{
if (i5_handle_refcount[handle->hstmt] > 0) {
i5_handle_refcount[handle->hstmt]--;
}
return i5_handle_refcount[handle->hstmt];
}
/* }}} */
#endif /* PASE */
/* {{{ static _php_db2_free_stmt_struct */
static void _php_db2_free_stmt_struct(zend_resource *rsrc)
{
int rc;
stmt_handle *handle = (stmt_handle*) rsrc->ptr;
#ifdef PASE /* IBM i reuses handles. Connect close out of sync with le_stmt_struct dtor logic */
if (!_php_db2_decr_stmt_struct(handle)) {
rc = SQLFreeHandle( SQL_HANDLE_STMT, handle->hstmt);
}
#else
rc = SQLFreeHandle( SQL_HANDLE_STMT, handle->hstmt);
#endif /* PASE */
if ( handle ) {
_php_db2_free_result_struct(handle);
efree(handle);
}
}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(ibm_db2)
{
#ifndef PHP_WIN32
/* Declare variables for DB2 instance settings */
char * tmp_name = NULL;
char * instance_name = NULL;
#endif
ZEND_INIT_MODULE_GLOBALS(ibm_db2, php_ibm_db2_init_globals, NULL);
/* IBM i options added to DB2 Connect 10.5 */
/* 1.9.7 - IBM i + LUW 10.5 system naming on (*libl)/file.mbr */
REGISTER_LONG_CONSTANT("DB2_I5_NAMING_ON", SQL_TRUE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_NAMING_OFF", SQL_FALSE, CONST_CS | CONST_PERSISTENT);
/* 1.9.7 - LUW to IBM i need isolation mode *NONE (required non journal CRTLIB) */
REGISTER_LONG_CONSTANT("DB2_I5_TXN_NO_COMMIT", SQL_TXN_NO_COMMIT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_TXN_READ_UNCOMMITTED", SQL_TXN_READ_UNCOMMITTED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_TXN_READ_COMMITTED", SQL_TXN_READ_COMMITTED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_TXN_REPEATABLE_READ", SQL_TXN_REPEATABLE_READ, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_TXN_SERIALIZABLE", SQL_TXN_SERIALIZABLE, CONST_CS | CONST_PERSISTENT);
/* 1.9.7 - LUW to IBM i attributes defined DB2 10.5 */
REGISTER_LONG_CONSTANT("DB2_I5_FMT_ISO", SQL_IBMi_FMT_ISO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_USA", SQL_IBMi_FMT_USA, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_EUR", SQL_IBMi_FMT_EUR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_JIS", SQL_IBMi_FMT_JIS, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_MDY", SQL_IBMi_FMT_MDY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_DMY", SQL_IBMi_FMT_DMY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_YMD", SQL_IBMi_FMT_YMD, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_JUL", SQL_IBMi_FMT_JUL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_JOB", SQL_IBMi_FMT_JOB, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FMT_HMS", SQL_IBMi_FMT_HMS, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_SEP_SLASH", SQL_SEP_SLASH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_SEP_DASH", SQL_SEP_DASH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_SEP_PERIOD", SQL_SEP_PERIOD, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_SEP_COMMA", SQL_SEP_COMMA, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_SEP_BLANK", SQL_SEP_BLANK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_SEP_COLON", SQL_SEP_COLON, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_SEP_JOB", SQL_SEP_JOB, CONST_CS | CONST_PERSISTENT);
#ifdef PASE /* IBM i db2_setoptions */
REGISTER_LONG_CONSTANT("DB2_I5_FETCH_ON", SQL_TRUE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_FETCH_OFF", SQL_FALSE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_JOB_SORT_ON", SQL_JOBRUN_SORT_SEQUENCE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_JOB_SORT_OFF", SQL_HEX_SORT_SEQUENCE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_DBCS_ALLOC_ON", SQL_TRUE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_DBCS_ALLOC_OFF", SQL_FALSE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_FIRST_IO", SQL_FIRST_IO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_ALL_IO", SQL_ALL_IO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_CHAR_TRIM_ON", SQL_TRUE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_I5_CHAR_TRIM_OFF", SQL_FALSE, CONST_CS | CONST_PERSISTENT);
#endif /* PASE */
REGISTER_LONG_CONSTANT("DB2_BINARY", 1, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_CONVERT", 2, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_PASSTHRU", 3, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_SCROLLABLE", DB2_SCROLLABLE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_FORWARD_ONLY", DB2_FORWARD_ONLY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_PARAM_IN", SQL_PARAM_INPUT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_PARAM_OUT", SQL_PARAM_OUTPUT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_PARAM_INOUT", SQL_PARAM_INPUT_OUTPUT, CONST_CS | CONST_PERSISTENT);
/* This number chosen is just a place holder to decide binding function to call */
REGISTER_LONG_CONSTANT("DB2_PARAM_FILE", 11, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_TRUSTED_CONTEXT_ENABLE", SQL_ATTR_USE_TRUSTED_CONTEXT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_AUTOCOMMIT_ON", SQL_AUTOCOMMIT_ON, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_AUTOCOMMIT_OFF", SQL_AUTOCOMMIT_OFF, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_ROWCOUNT_PREFETCH_ON", DB2_ROWCOUNT_PREFETCH_ON, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_ROWCOUNT_PREFETCH_OFF", DB2_ROWCOUNT_PREFETCH_OFF, CONST_CS | CONST_PERSISTENT);
#ifndef PASE /* IBM i unsupported db2_setoptions */
REGISTER_LONG_CONSTANT("DB2_DEFERRED_PREPARE_ON", SQL_DEFERRED_PREPARE_ON, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_DEFERRED_PREPARE_OFF", SQL_DEFERRED_PREPARE_OFF, CONST_CS | CONST_PERSISTENT);
#endif /* PASE */
REGISTER_LONG_CONSTANT("DB2_DOUBLE", SQL_DOUBLE, CONST_CS | CONST_PERSISTENT);
/* This is how CLI defines SQL_C_LONG */
REGISTER_LONG_CONSTANT("DB2_LONG", SQL_INTEGER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_CHAR", SQL_CHAR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_XML", SQL_XML, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_CASE_NATURAL", 0, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_CASE_LOWER", 1, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("DB2_CASE_UPPER", 2, CONST_CS | CONST_PERSISTENT);
REGISTER_INI_ENTRIES();
#ifndef PHP_WIN32
/* Tell DB2 where to find its libraries */
tmp_name = INI_STR("ibm_db2.instance_name");
if (NULL != tmp_name) {
instance_name = (char *)malloc(strlen(DB2_VAR_INSTANCE) + strlen(tmp_name) + 1);
strcpy(instance_name, DB2_VAR_INSTANCE);
strcat(instance_name, tmp_name);
putenv(instance_name);
_php_db2_instance_name = instance_name;
}
#endif
#ifdef _AIX
/* atexit() handler in the DB2/AIX library segfaults in PHP CLI */
/* DB2NOEXITLIST env variable prevents DB2 from invoking atexit() */
putenv("DB2NOEXITLIST=TRUE");
#endif
le_conn_struct = zend_register_list_destructors_ex( _php_db2_free_conn_struct, NULL, DB2_CONN_NAME, module_number);
le_pconn_struct = zend_register_list_destructors_ex(NULL, _php_db2_free_pconn_struct, DB2_PCONN_NAME, module_number);
le_stmt_struct = zend_register_list_destructors_ex( _php_db2_free_stmt_struct, NULL, DB2_STMT_NAME, module_number);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(ibm_db2)
{
UNREGISTER_INI_ENTRIES();
if (NULL != _php_db2_instance_name) {
free(_php_db2_instance_name);
_php_db2_instance_name = NULL;
}
return SUCCESS;
}
/* }}} */
/* {{{ _php_ibm_db2_conn
*/
static int _php_ibm_db2_conn (zend_resource *le)
{
conn_handle *conn_res;
int rc = 0;
/* Fix: #24013 */
if (le->type != le_pconn_struct) {
return ZEND_HASH_APPLY_KEEP;
}
conn_res = (conn_handle *) le->ptr;
if ( conn_res->handle_active ) {
if ( conn_res->flag_transaction == 1 && conn_res->auto_commit == 0 ) {
conn_res->flag_transaction = 0;
rc = SQLEndTran(SQL_HANDLE_DBC, (SQLHDBC)conn_res->hdbc, SQL_ROLLBACK);
if ( rc == SQL_ERROR ) {
_php_db2_check_sql_errors(conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1);
}
}
}
return ZEND_HASH_APPLY_KEEP;
} /* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION (ibm_db2)
{
zend_hash_apply(&EG(persistent_list), (apply_func_t) _php_ibm_db2_conn);
_php_db2_clear_conn_err_cache();
_php_db2_clear_stmt_err_cache();
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(ibm_db2)
{
char opbuffer[32];
php_info_print_table_start();
php_info_print_table_header(2, "IBM Db2 and compatible databases support", "enabled");
php_info_print_table_row(2, "Module release", PHP_IBM_DB2_VERSION);
switch (IBM_DB2_G(bin_mode)) {
case DB2_BINARY:
php_info_print_table_row(2, "Binary data mode (ibm_db2.binmode)", "1 - DB2_BINARY");
break;
case DB2_CONVERT:
php_info_print_table_row(2, "Binary data mode (ibm_db2.binmode)", "2 - DB2_CONVERT");
break;
case DB2_PASSTHRU:
php_info_print_table_row(2, "Binary data mode (ibm_db2.binmode)", "3 - DB2_PASSTHRU");
break;
}
#ifndef PHP_WIN32
php_info_print_table_row(2, "DB2 instance name (ibm_db2.instance_name)", INI_STR("ibm_db2.instance_name"));
#endif
/* 1.9.7 - LUW to IBM i need isolation mode *NONE (required non journal CRTLIB) */
if (IBM_DB2_G(i5_allow_commit) >= 4) {
php_info_print_table_row(2, "Commitment control (ibm_db2.i5_allow_commit)", "4 - DB2_I5_TXN_SERIALIZABLE");
} else if (IBM_DB2_G(i5_allow_commit) >= 3) {
php_info_print_table_row(2, "Commitment control (ibm_db2.i5_allow_commit)", "3 - DB2_I5_TXN_REPEATABLE_READ");
} else if (IBM_DB2_G(i5_allow_commit) >= 2) {
php_info_print_table_row(2, "Commitment control (ibm_db2.i5_allow_commit)", "2 - DB2_I5_TXN_READ_COMMITTED");
} else if (IBM_DB2_G(i5_allow_commit) >= 1) {
php_info_print_table_row(2, "Commitment control (ibm_db2.i5_allow_commit)", "1 - DB2_I5_TXN_READ_UNCOMMITTED");
} else if (IBM_DB2_G(i5_allow_commit) >= 0) {
php_info_print_table_row(2, "Commitment control (ibm_db2.i5_allow_commit)", "0 - DB2_I5_TXN_NO_COMMIT");
}
/* 1.9.7 - IBM i + LUW 10.5 system naming on (*libl)/file.mbr */
if (IBM_DB2_G(i5_sys_naming) > 0) {
php_info_print_table_row(2, "System naming mode (ibm_db2.i5_sys_naming)", "1 - enabled");
} else {
php_info_print_table_row(2, "System naming mode (ibm_db2.i5_sys_naming)", "0 - disabled");
}
#ifdef PASE /* IBM i phpinfo output missing (long time bug) */
/* orig - IBM i 6x space for CCSID<>UTF-8 convert (DBCS customer issue) */
if (IBM_DB2_G(i5_dbcs_alloc) > 0) {
php_info_print_table_row(2, "DBCS extended conversion memory allocations (ibm_db2.i5_dbcs_alloc)", "1 - enabled");
} else {
php_info_print_table_row(2, "DBCS extended conversion memory allocations (ibm_db2.i5_dbcs_alloc)", "0 - disabled");
}
/* orig - IBM i force all connect to pconnect (operator issue) */
if (IBM_DB2_G(i5_all_pconnect) > 0) {
php_info_print_table_row(2, "Force db2_connect to db2_pconnect (ibm_db2.i5_all_pconnect)", "1 - enabled");
} else {
php_info_print_table_row(2, "Force db2_connect to db2_pconnect (ibm_db2.i5_all_pconnect)", "0 - disabled");
}
/* orig - IBM i ignore user id enables no-QSQSRVR job (custom site request) */
if (IBM_DB2_G(i5_ignore_userid) > 0) {
php_info_print_table_row(2, "Ignore userid/password (ibm_db2.i5_ignore_userid)", "1 - enabled");
} else {
php_info_print_table_row(2, "Ignore userid/password (ibm_db2.i5_ignore_userid)", "0 - disabled");
}
/* orig - IBM i SQL_ATTR_JOB_SORT_SEQUENCE (customer request DB2 PTF) */
if (IBM_DB2_G(i5_job_sort) > 0) {
php_info_print_table_row(2, "Job profile sort order (ibm_db2.i5_job_sort)", "1 - enabled");
} else {
php_info_print_table_row(2, "Job profile sort order (ibm_db2.i5_job_sort)", "0 - disabled");
}
/* 1.9.7 - IBM i force UTF-8 CCSID (DBCS customer issue) */
if (IBM_DB2_G(i5_override_ccsid) > 0) {
snprintf(opbuffer, sizeof(opbuffer), "%d - enabled (ccsid)", IBM_DB2_G(i5_override_ccsid));
php_info_print_table_row(2, "Override PASE CCSID (ibm_db2.i5_override_ccsid)", opbuffer);
} else {
php_info_print_table_row(2, "Override PASE CCSID (ibm_db2.i5_override_ccsid)", "0 - disabled");
}
/* 1.9.7 - IBM i security restrict blank db,uid,pwd (unless customer allow flag) */
if (IBM_DB2_G(i5_blank_userid) > 0) {
php_info_print_table_row(2, "Allow blank userid/password (ibm_db2.i5_blank_userid)", "1 - enabled");
} else {
php_info_print_table_row(2, "Allow blank userid/password (ibm_db2.i5_blank_userid)", "0 - disabled");
}
/* 1.9.7 - IBM i consultant request log additional information into php.log */
if (IBM_DB2_G(i5_log_verbose) > 0) {
php_info_print_table_row(2, "DB2 error log verbose (ibm_db2.i5_log_verbose)", "1 - enabled");
} else {
php_info_print_table_row(2, "DB2 error log verbose (ibm_db2.i5_log_verbose)", "0 - disabled");
}
/* 1.9.7 - IBM i count max usage connection recycle (customer issue months live connection) */
if (IBM_DB2_G(i5_max_pconnect) > 0) {
snprintf(opbuffer, sizeof(opbuffer), "%d - enabled (1-99999)", IBM_DB2_G(i5_max_pconnect));
php_info_print_table_row(2, "Max use count db2_pconnect (ibm_db2.i5_max_pconnect)", opbuffer);
} else {
php_info_print_table_row(2, "Max use count db2_pconnect (ibm_db2.i5_max_pconnect)", "0 - disabled");
}
/* 1.9.7 - IBM i remote persistent connection or long lived local (customer issue dead connection) */
if (IBM_DB2_G(i5_check_pconnect) >= 4) {
php_info_print_table_row(2, "Advanced db2_pconnect monitor (ibm_db2.i5_check_pconnect)", "4 - exec/fetch test");
} else if (IBM_DB2_G(i5_check_pconnect) >= 3) {
php_info_print_table_row(2, "Advanced db2_pconnect monitor (ibm_db2.i5_check_pconnect)", "3 - create stmt test");
} else if (IBM_DB2_G(i5_check_pconnect) >= 2) {
php_info_print_table_row(2, "Advanced db2_pconnect monitor (ibm_db2.i5_check_pconnect)", "2 - get conn meta test");
} else {
php_info_print_table_row(2, "Advanced db2_pconnect monitor (ibm_db2.i5_check_pconnect)", "1 - get conn attribute test");
}
/* 1.9.7 - IBM i consultant request switch subsystem QSQSRVR job (customer workload issues) */
php_info_print_table_row(2, "DB2 server mode subsystem (ibm_db2.i5_servermode_subsystem)", INI_STR("ibm_db2.i5_servermode_subsystem"));
/* 1.9.7 - IBM i monitor switch user profile applications (customer security issue) */
if (IBM_DB2_G(i5_guard_profile) > 0) {
php_info_print_table_row(2, "Guard profile (ibm_db2.i5_guard_profile)", "1 - enabled");
} else {
php_info_print_table_row(2, "Guard profile (ibm_db2.i5_guard_profile)", "0 - disabled");
}
/* 2.0.3 - IBM i trim spaces character results (customer size request issue) */
if (IBM_DB2_G(i5_char_trim) > 0) {
php_info_print_table_row(2, "Trim spaces character results (ibm_db2.i5_char_trim)", "1 - enabled");
} else {
php_info_print_table_row(2, "Trim spaces character results (ibm_db2.i5_char_trim)", "0 - disabled");
}
#endif /* PASE */