|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jpina\Oci8; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Oci8Statement |
|
7
|
|
|
* @package Jpina\Oci8 |
|
8
|
|
|
* @see http://php.net/manual/en/book.oci8.php |
|
9
|
|
|
*/ |
|
10
|
|
|
class Oci8Statement extends AbstractOci8Base implements Oci8StatementInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var resource */ |
|
13
|
|
|
protected $resource; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Statement constructor |
|
17
|
|
|
* @param resource $resource |
|
18
|
|
|
* @throws \Jpina\Oci8\Oci8Exception |
|
19
|
|
|
*/ |
|
20
|
53 |
|
public function __construct($resource) |
|
21
|
|
|
{ |
|
22
|
53 |
|
if (!is_resource($resource) || get_resource_type($resource) !== 'oci8 statement') { |
|
23
|
1 |
|
throw new Oci8Exception('resource is not an oci8 statement', 0, E_ERROR, __FILE__, __LINE__); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
52 |
|
$this->resource = $resource; |
|
27
|
52 |
|
} |
|
28
|
|
|
|
|
29
|
2 |
|
public function bindArrayByName($name, &$varArray, $maxTableLength, $maxItemLength = -1, $type = SQLT_AFC) |
|
30
|
|
|
{ |
|
31
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
32
|
2 |
|
$isSuccess = oci_bind_array_by_name($this->resource, $name, $varArray, $maxTableLength, $maxItemLength, $type); |
|
33
|
1 |
|
restore_error_handler(); |
|
34
|
1 |
|
return $isSuccess; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
3 |
View Code Duplication |
public function bindByName($bvName, &$variable, $maxLength = -1, $type = SQLT_CHR) |
|
38
|
|
|
{ |
|
39
|
3 |
|
set_error_handler(static::getErrorHandler()); |
|
40
|
3 |
|
$isSuccess = oci_bind_by_name($this->resource, $bvName, $variable, $maxLength, $type); |
|
41
|
1 |
|
restore_error_handler(); |
|
42
|
1 |
|
return $isSuccess; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
public function cancel() |
|
46
|
|
|
{ |
|
47
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
48
|
2 |
|
$isSuccess = oci_cancel($this->resource); |
|
49
|
1 |
|
restore_error_handler(); |
|
50
|
1 |
|
return $isSuccess; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
4 |
|
public function defineByName($columnName, &$variable, $type = SQLT_CHR) |
|
54
|
|
|
{ |
|
55
|
4 |
|
set_error_handler(static::getErrorHandler()); |
|
56
|
4 |
|
$isSuccess = oci_define_by_name($this->resource, $columnName, $variable, $type); |
|
57
|
3 |
|
restore_error_handler(); |
|
58
|
3 |
|
return $isSuccess; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
32 |
|
public function execute($mode = OCI_COMMIT_ON_SUCCESS) |
|
62
|
|
|
{ |
|
63
|
32 |
|
set_error_handler(static::getErrorHandler()); |
|
64
|
32 |
|
$isSuccess = oci_execute($this->resource, $mode); |
|
65
|
31 |
|
restore_error_handler(); |
|
66
|
31 |
|
return $isSuccess; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
public function fetchAll(&$output, $skip = 0, $maxRows = -1, $flags = 0) |
|
70
|
|
|
{ |
|
71
|
2 |
|
if (empty($flags)) { |
|
72
|
2 |
|
$flags = OCI_FETCHSTATEMENT_BY_COLUMN | OCI_ASSOC; |
|
73
|
2 |
|
} |
|
74
|
|
|
|
|
75
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
76
|
2 |
|
$numRows = oci_fetch_all($this->resource, $output, $skip, $maxRows, $flags); |
|
77
|
1 |
|
restore_error_handler(); |
|
78
|
1 |
|
return $numRows; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
9 |
|
public function fetchArray($mode = OCI_BOTH) |
|
82
|
|
|
{ |
|
83
|
9 |
|
set_error_handler(static::getErrorHandler()); |
|
84
|
9 |
|
$row = oci_fetch_array($this->resource, $mode); |
|
85
|
6 |
|
restore_error_handler(); |
|
86
|
6 |
|
return $row; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
7 |
|
public function fetchAssoc() |
|
90
|
|
|
{ |
|
91
|
7 |
|
set_error_handler(static::getErrorHandler()); |
|
92
|
7 |
|
$row = oci_fetch_assoc($this->resource); |
|
93
|
6 |
|
restore_error_handler(); |
|
94
|
6 |
|
return $row; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
public function fetchObject() |
|
98
|
|
|
{ |
|
99
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
100
|
2 |
|
$row = oci_fetch_object($this->resource); |
|
101
|
1 |
|
restore_error_handler(); |
|
102
|
1 |
|
return $row; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
2 |
|
public function fetchRow() |
|
106
|
|
|
{ |
|
107
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
108
|
2 |
|
$row = oci_fetch_row($this->resource); |
|
109
|
1 |
|
restore_error_handler(); |
|
110
|
1 |
|
return $row; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
4 |
|
public function fetch() |
|
114
|
|
|
{ |
|
115
|
4 |
|
set_error_handler(static::getErrorHandler()); |
|
116
|
4 |
|
$isSuccess = oci_fetch($this->resource); |
|
117
|
3 |
|
restore_error_handler(); |
|
118
|
3 |
|
return $isSuccess; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
18 |
|
public function getField($field) |
|
122
|
|
|
{ |
|
123
|
18 |
|
set_error_handler(static::getErrorHandler()); |
|
124
|
18 |
|
$name = oci_field_name($this->resource, $field); |
|
125
|
17 |
|
$precision = oci_field_precision($this->resource, $field); |
|
126
|
17 |
|
$scale = oci_field_scale($this->resource, $field); |
|
127
|
17 |
|
$size = oci_field_size($this->resource, $field); |
|
128
|
17 |
|
$rawType = oci_field_type_raw($this->resource, $field); |
|
129
|
17 |
|
$type = oci_field_type($this->resource, $field); |
|
130
|
17 |
|
$value = oci_field_is_null($this->resource, $field) ? null : oci_result($this->resource, $field); |
|
131
|
17 |
|
$field = new Oci8Field($name, $value, $size, $precision, $scale, $type, $rawType); |
|
132
|
17 |
|
restore_error_handler(); |
|
133
|
|
|
|
|
134
|
17 |
|
return $field; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
18 |
View Code Duplication |
public function free() |
|
138
|
|
|
{ |
|
139
|
18 |
|
$isSuccess = false; |
|
140
|
18 |
|
set_error_handler(static::getErrorHandler()); |
|
141
|
18 |
|
if ($this->resource) { |
|
142
|
18 |
|
$isSuccess = oci_free_statement($this->resource); |
|
143
|
18 |
|
} |
|
144
|
18 |
|
restore_error_handler(); |
|
145
|
|
|
|
|
146
|
18 |
|
if ($isSuccess) { |
|
147
|
18 |
|
$this->resource = null; |
|
148
|
18 |
|
} |
|
149
|
18 |
|
return $isSuccess; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
1 |
View Code Duplication |
public function getImplicitResultset() |
|
153
|
|
|
{ |
|
154
|
1 |
|
$resultset = false; |
|
155
|
1 |
|
set_error_handler(static::getErrorHandler()); |
|
156
|
1 |
|
$resource = oci_get_implicit_resultset($this->resource); |
|
157
|
1 |
|
if ($resource) { |
|
158
|
|
|
$resultset = new static($resource); |
|
159
|
|
|
} |
|
160
|
1 |
|
restore_error_handler(); |
|
161
|
1 |
|
return $resultset; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
2 |
|
public function getNumFields() |
|
165
|
|
|
{ |
|
166
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
167
|
2 |
|
$numFields = oci_num_fields($this->resource); |
|
168
|
1 |
|
restore_error_handler(); |
|
169
|
1 |
|
return $numFields; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
2 |
|
public function getNumRows() |
|
173
|
|
|
{ |
|
174
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
175
|
2 |
|
$numRows = oci_num_rows($this->resource); |
|
176
|
1 |
|
restore_error_handler(); |
|
177
|
1 |
|
return $numRows; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
2 |
|
public function setPrefetch($rows) |
|
181
|
|
|
{ |
|
182
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
183
|
2 |
|
$isSuccess = oci_set_prefetch($this->resource, $rows); |
|
184
|
1 |
|
restore_error_handler(); |
|
185
|
1 |
|
return $isSuccess; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
2 |
|
public function getType() |
|
189
|
|
|
{ |
|
190
|
2 |
|
set_error_handler(static::getErrorHandler()); |
|
191
|
2 |
|
$type = oci_statement_type($this->resource); |
|
192
|
1 |
|
restore_error_handler(); |
|
193
|
1 |
|
return $type; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|