xref: /PHP-5.5/ext/oci8/tests/bind_char_2.phpt (revision 8b4890e1)
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 10\.2\./', oci_server_version($c), $matches) !== 1) {
9    if (preg_match('/Release 11\.2\.0\.2/', oci_server_version($c), $matches) !== 2) {
10        die("skip expected output only valid when using Oracle 10gR2 or 11.2.0.2 databases");
11    }
12}
13if (preg_match('/^11\./', oci_client_version()) != 1) {
14    die("skip test expected to work only with Oracle 11g or greater version of client");
15}
16?>
17--ENV--
18NLS_LANG=
19--FILE--
20<?php
21
22require(dirname(__FILE__).'/connect.inc');
23
24// Initialization
25
26$stmtarray = array(
27	"alter session set nls_date_format='YYYY-MM-DD'",
28	"drop table bind_char_tab",
29	"create table bind_char_tab (id number, c1 date)",
30	"insert into bind_char_tab values (1, '2008-04-20')",
31);
32
33oci8_test_sql_execute($c, $stmtarray);
34
35// Run Test
36
37$bv1 = '2008-04-20';
38
39echo "Test 1.1: Type: default.  Length: default\n";
40$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv");
41$r = oci_bind_by_name($s, ":bv", $bv1);
42if ($r)
43   do_e_q($s);
44
45echo "Test 1.2: Type: AFC.  Length: default\n";
46$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
47if ($r)
48   	do_e_q($s);
49
50echo "Test 1.3: Type: AFC:  Length: 0\n";
51$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
52if ($r)
53	do_e_q($s);
54
55echo "Test 1.4: Type: AFC:  Length: strlen\n";
56$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
57if ($r)
58	do_e_q($s);
59
60echo "Test 1.5: Type: AFC.  Length: strlen-1\n";
61$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
62if ($r)
63	do_e_q($s);
64
65echo "Test 1.6: Type: AFC.  Length: strlen+1\n";
66$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
67if ($r)
68	do_e_q($s);
69
70
71function do_e_q($s)
72{
73	echo "  Querying:\n";
74
75	$r = @oci_execute($s);
76	if (!$r) {
77		$m = oci_error($s);
78		echo "    Oci_execute error ORA-".$m['code']." Exiting Query\n";
79		return;
80	}
81	while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) {
82		foreach ($row as $item) {
83			echo "    :" . $item . ":\n";
84		}
85	}
86}
87
88// Cleanup
89$stmtarray = array(
90	"drop table bind_char_tab"
91);
92
93oci8_test_sql_execute($c, $stmtarray);
94
95echo "Done\n";
96
97?>
98--EXPECT--
99Test 1.1: Type: default.  Length: default
100  Querying:
101    :1:
102    :2008-04-20:
103Test 1.2: Type: AFC.  Length: default
104  Querying:
105    :1:
106    :2008-04-20:
107Test 1.3: Type: AFC:  Length: 0
108  Querying:
109    Oci_execute error ORA-1460 Exiting Query
110Test 1.4: Type: AFC:  Length: strlen
111  Querying:
112    :1:
113    :2008-04-20:
114Test 1.5: Type: AFC.  Length: strlen-1
115  Querying:
116    :1:
117    :2008-04-20:
118Test 1.6: Type: AFC.  Length: strlen+1
119  Querying:
120    :1:
121    :2008-04-20:
122Done
123