1--TEST-- 2SELECT oci_bind_by_name with SQLT_AFC aka CHAR and dates 3--EXTENSIONS-- 4oci8 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8require __DIR__.'/connect.inc'; 9// The bind buffer size edge cases seem to change each DB version. 10preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches); 11if (!(isset($matches[0]) && $matches[1] >= 12)) { 12 die("skip expected output only valid when using Oracle 12c database"); 13} 14?> 15--ENV-- 16NLS_LANG=.AL32UTF8 17--FILE-- 18<?php 19 20require __DIR__.'/connect.inc'; 21 22// Initialization 23 24$stmtarray = array( 25 "alter session set nls_date_format='YYYY-MM-DD'", 26 "drop table bind_char_tab", 27 "create table bind_char_tab (id number, c1 date)", 28 "insert into bind_char_tab values (1, '2008-04-20')", 29); 30 31oci8_test_sql_execute($c, $stmtarray); 32 33// Run Test 34 35$bv1 = '2008-04-20'; 36 37echo "Test 1.1: Type: default. Length: default\n"; 38$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv"); 39$r = oci_bind_by_name($s, ":bv", $bv1); 40if ($r) 41 do_e_q($s); 42 43echo "Test 1.2: Type: AFC. Length: default\n"; 44$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC); 45if ($r) 46 do_e_q($s); 47 48echo "Test 1.3: Type: AFC: Length: 0\n"; 49$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC); 50if ($r) 51 do_e_q($s); 52 53echo "Test 1.4: Type: AFC: Length: strlen\n"; 54$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC); 55if ($r) 56 do_e_q($s); 57 58echo "Test 1.5: Type: AFC. Length: strlen-1\n"; 59$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC); 60if ($r) 61 do_e_q($s); 62 63echo "Test 1.6: Type: AFC. Length: strlen+1\n"; 64$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC); 65if ($r) 66 do_e_q($s); 67 68 69function do_e_q($s) 70{ 71 echo " Querying:\n"; 72 73 $r = @oci_execute($s); 74 if (!$r) { 75 $m = oci_error($s); 76 echo " Oci_execute error ORA-".$m['code']." Exiting Query\n"; 77 return; 78 } 79 while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) { 80 foreach ($row as $item) { 81 echo " :" . $item . ":\n"; 82 } 83 } 84} 85 86// Cleanup 87$stmtarray = array( 88 "drop table bind_char_tab" 89); 90 91oci8_test_sql_execute($c, $stmtarray); 92 93echo "Done\n"; 94 95?> 96--EXPECT-- 97Test 1.1: Type: default. Length: default 98 Querying: 99 :1: 100 :2008-04-20: 101Test 1.2: Type: AFC. Length: default 102 Querying: 103 :1: 104 :2008-04-20: 105Test 1.3: Type: AFC: Length: 0 106 Querying: 107 :1: 108 :2008-04-20: 109Test 1.4: Type: AFC: Length: strlen 110 Querying: 111 :1: 112 :2008-04-20: 113Test 1.5: Type: AFC. Length: strlen-1 114 Querying: 115Test 1.6: Type: AFC. Length: strlen+1 116 Querying: 117 :1: 118 :2008-04-20: 119Done 120