File: lob_029.phpt

package info (click to toggle)
php5 5.3.3-7%2Bsqueeze17
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 122,824 kB
  • ctags: 55,742
  • sloc: ansic: 633,963; php: 19,620; sh: 11,344; xml: 5,816; cpp: 2,400; yacc: 1,745; exp: 1,514; makefile: 1,019; pascal: 623; awk: 537; sql: 22
file content (125 lines) | stat: -rw-r--r-- 3,074 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
--TEST--
reading/writing BFILE LOBs
--SKIPIF--
<?php if (!extension_loaded('oci8')) die("skip no oci8 extension");
include "details.inc";
if (empty($oracle_on_localhost)) die("skip this test won't work with remote Oracle");
?>
--FILE--
<?php

require dirname(__FILE__).'/connect.inc';

$realdirname = dirname(__FILE__);
$realfilename1 = "oci8bfiletest1.txt";
$fullname1 = $realdirname."/".$realfilename1;
$realfilename2 = "oci8bfiletest2.txt";
$fullname2 = $realdirname."/".$realfilename2;
$realfilename3 = "oci8bfiletest3.txt";
$fullname3 = $realdirname."/".$realfilename3;

// Setup
$s = oci_parse($c, "drop table FileTest");
@oci_execute($s);

$s = oci_parse($c, "drop directory TestDir");
@oci_execute($s);

$s = oci_parse($c, "create directory TestDir as '$realdirname'");
oci_execute($s);

file_put_contents($fullname1, 'Some text in the bfile 1');
file_put_contents($fullname2, 'Some text in the bfile 2');
file_put_contents($fullname3, 'Some text in the bfile 3');

$s = oci_parse($c, "create table FileTest (FileNum number, FileDesc varchar2(30), Image bfile)");
oci_execute($s);

$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (1, 'Description 1', bfilename('TESTDIR', '$realfilename1'))");
oci_execute($s);

$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (2, 'Description 2', bfilename('TESTDIR', '$realfilename2'))");
oci_execute($s);

$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (3, 'Description 3', bfilename('TESTDIR', '$realfilename3'))");
oci_execute($s);

// Run tests

echo "Test 1. Check how many rows in the table\n";

$s = oci_parse($c, "select count(*) numrows from FileTest");
oci_execute($s);
oci_fetch_all($s, $res);
var_dump($res);

echo "Test 2\n";
$s = oci_parse($c, "select * from FileTest order by FileNum");
oci_execute($s);
oci_fetch_all($s, $res);
var_dump($res);

echo "Test 3\n";
$d = oci_new_descriptor($c, OCI_D_FILE);

$s = oci_parse($c, "insert into FileTest (FileNum, FileDesc, Image) values (2, 'Description 2', bfilename('TESTDIR', '$realfilename1')) returning Image into :im");
oci_bind_by_name($s, ":im", $d, -1, OCI_B_BFILE);
oci_execute($s);

$r = $d->read(40);
var_dump($r);

unlink($fullname1);
unlink($fullname2);
unlink($fullname3);

$s = oci_parse($c, "drop table FileTest");
oci_execute($s);

$s = oci_parse($c, "drop directory TestDir");
oci_execute($s);

echo "Done\n";
?>
--EXPECTF-- 
Test 1. Check how many rows in the table
array(1) {
  ["NUMROWS"]=>
  array(1) {
    [0]=>
    string(1) "3"
  }
}
Test 2
array(3) {
  ["FILENUM"]=>
  array(3) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "2"
    [2]=>
    string(1) "3"
  }
  ["FILEDESC"]=>
  array(3) {
    [0]=>
    string(13) "Description 1"
    [1]=>
    string(13) "Description 2"
    [2]=>
    string(13) "Description 3"
  }
  ["IMAGE"]=>
  array(3) {
    [0]=>
    string(24) "Some text in the bfile 1"
    [1]=>
    string(24) "Some text in the bfile 2"
    [2]=>
    string(24) "Some text in the bfile 3"
  }
}
Test 3
string(24) "Some text in the bfile 1"
Done