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