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