1--TEST--
2SELECT oci_bind_by_name with SQLT_AFC aka CHAR and dates
3--SKIPIF--
4<?php
5if (!extension_loaded('oci8')) die ("skip no oci8 extension");
6require(dirname(__FILE__)."/connect.inc");
7// The bind buffer size edge cases seem to change each DB version.
8if (preg_match('/Release 11\.1\./', oci_server_version($c), $matches) !== 1) {
9    if (preg_match('/Release 11\.2\.0\.3/', oci_server_version($c), $matches) !== 1) {
10        die("skip expected output only valid when using Oracle 11gR1 or 11.2.0.3 databases");
11    }
12}
13?>
14--ENV--
15NLS_LANG=
16--FILE--
17<?php
18
19require(dirname(__FILE__).'/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    Oci_execute error ORA-1460 Exiting Query
107Test 1.4: Type: AFC:  Length: strlen
108  Querying:
109    :1:
110    :2008-04-20:
111Test 1.5: Type: AFC.  Length: strlen-1
112  Querying:
113    Oci_execute error ORA-1460 Exiting Query
114Test 1.6: Type: AFC.  Length: strlen+1
115  Querying:
116    :1:
117    :2008-04-20:
118Done
119