MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
OCI8Statement.php
Ir para a documentação deste ficheiro.
1
<?php
2
/*
3
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
*
15
* This software consists of voluntary contributions made by many individuals
16
* and is licensed under the LGPL. For more information, see
17
* <http://www.doctrine-project.org>.
18
*/
19
20
namespace
Doctrine\DBAL\Driver\OCI8
;
21
22
use \PDO;
23
30
class
OCI8Statement
implements
\Doctrine\DBAL\Driver\Statement
31
{
33
private
$_sth;
34
private
$_executeMode;
35
private
static
$_PARAM =
':param'
;
36
private
static
$fetchStyleMap = array(
37
PDO::FETCH_BOTH => OCI_BOTH,
38
PDO::FETCH_ASSOC => OCI_ASSOC,
39
PDO::FETCH_NUM => OCI_NUM
40
);
41
private
$_paramMap = array();
42
49
public
function
__construct
($dbh, $statement, $executeMode)
50
{
51
list($statement, $paramMap) =
self::convertPositionalToNamedPlaceholders
($statement);
52
$this->_sth = oci_parse($dbh, $statement);
53
$this->_paramMap = $paramMap;
54
$this->_executeMode = $executeMode;
55
}
56
74
static
public
function
convertPositionalToNamedPlaceholders
($statement)
75
{
76
$count = 1;
77
$inLiteral =
false
;
// a valid query never starts with quotes
78
$stmtLen = strlen($statement);
79
$paramMap = array();
80
for
($i = 0; $i < $stmtLen; $i++) {
81
if
($statement[$i] ==
'?'
&& !$inLiteral) {
82
// real positional parameter detected
83
$paramMap[$count] =
":param$count"
;
84
$len = strlen($paramMap[$count]);
85
$statement = substr_replace($statement,
":param$count"
, $i, 1);
86
$i += $len-1;
// jump ahead
87
$stmtLen = strlen($statement);
// adjust statement length
88
++$count;
89
}
else
if
($statement[$i] ==
"'"
|| $statement[$i] ==
'"'
) {
90
$inLiteral = ! $inLiteral;
// switch state!
91
}
92
}
93
94
return
array($statement, $paramMap);
95
}
96
100
public
function
bindValue
($param, $value, $type =
null
)
101
{
102
return
$this->
bindParam
($param, $value, $type);
103
}
104
108
public
function
bindParam
($column, &$variable, $type =
null
)
109
{
110
$column = isset($this->_paramMap[$column]) ? $this->_paramMap[$column] : $column;
111
112
return
oci_bind_by_name($this->_sth, $column, $variable);
113
}
114
120
public
function
closeCursor
()
121
{
122
return
oci_free_statement($this->_sth);
123
}
124
128
public
function
columnCount
()
129
{
130
return
oci_num_fields($this->_sth);
131
}
132
136
public
function
errorCode
()
137
{
138
$error = oci_error($this->_sth);
139
if
($error !==
false
) {
140
$error = $error[
'code'
];
141
}
142
return
$error;
143
}
144
148
public
function
errorInfo
()
149
{
150
return
oci_error($this->_sth);
151
}
152
156
public
function
execute
($params =
null
)
157
{
158
if
($params) {
159
$hasZeroIndex = isset($params[0]);
160
foreach
($params as $key => $val) {
161
if
($hasZeroIndex && is_numeric($key)) {
162
$this->
bindValue
($key + 1, $val);
163
}
else
{
164
$this->
bindValue
($key, $val);
165
}
166
}
167
}
168
169
$ret = @oci_execute($this->_sth, $this->_executeMode);
170
if
( ! $ret) {
171
throw
OCI8Exception::fromErrorInfo
($this->
errorInfo
());
172
}
173
return
$ret;
174
}
175
179
public
function
fetch
($fetchStyle = PDO::FETCH_BOTH)
180
{
181
if
( ! isset(self::$fetchStyleMap[$fetchStyle])) {
182
throw
new \InvalidArgumentException(
"Invalid fetch style: "
. $fetchStyle);
183
}
184
185
return
oci_fetch_array($this->_sth, self::$fetchStyleMap[$fetchStyle] | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
186
}
187
191
public
function
fetchAll
($fetchStyle = PDO::FETCH_BOTH)
192
{
193
if
( ! isset(self::$fetchStyleMap[$fetchStyle])) {
194
throw
new \InvalidArgumentException(
"Invalid fetch style: "
. $fetchStyle);
195
}
196
197
$result = array();
198
oci_fetch_all($this->_sth, $result, 0, -1,
199
self::$fetchStyleMap[$fetchStyle] | OCI_RETURN_NULLS | OCI_FETCHSTATEMENT_BY_ROW | OCI_RETURN_LOBS);
200
201
return
$result;
202
}
203
207
public
function
fetchColumn
($columnIndex = 0)
208
{
209
$row = oci_fetch_array($this->_sth, OCI_NUM | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
210
return
$row[$columnIndex];
211
}
212
216
public
function
rowCount
()
217
{
218
return
oci_num_rows($this->_sth);
219
}
220
}
Doctrine\DBAL\Driver\OCI8\OCI8Exception\fromErrorInfo
static fromErrorInfo($error)
Definição
OCI8Exception.php:26
Doctrine\DBAL\Driver\OCI8\OCI8Statement
Definição
OCI8Statement.php:31
Doctrine\DBAL\Driver\OCI8\OCI8Statement\columnCount
columnCount()
Definição
OCI8Statement.php:128
Doctrine\DBAL\Driver\OCI8\OCI8Statement\closeCursor
closeCursor()
Definição
OCI8Statement.php:120
Doctrine\DBAL\Driver\OCI8\OCI8Statement\__construct
__construct($dbh, $statement, $executeMode)
Definição
OCI8Statement.php:49
Doctrine\DBAL\Driver\OCI8\OCI8Statement\fetchAll
fetchAll($fetchStyle=PDO::FETCH_BOTH)
Definição
OCI8Statement.php:191
Doctrine\DBAL\Driver\OCI8\OCI8Statement\convertPositionalToNamedPlaceholders
static convertPositionalToNamedPlaceholders($statement)
Definição
OCI8Statement.php:74
Doctrine\DBAL\Driver\OCI8\OCI8Statement\rowCount
rowCount()
Definição
OCI8Statement.php:216
Doctrine\DBAL\Driver\OCI8\OCI8Statement\errorCode
errorCode()
Definição
OCI8Statement.php:136
Doctrine\DBAL\Driver\OCI8\OCI8Statement\bindParam
bindParam($column, &$variable, $type=null)
Definição
OCI8Statement.php:108
Doctrine\DBAL\Driver\OCI8\OCI8Statement\execute
execute($params=null)
Definição
OCI8Statement.php:156
Doctrine\DBAL\Driver\OCI8\OCI8Statement\fetchColumn
fetchColumn($columnIndex=0)
Definição
OCI8Statement.php:207
Doctrine\DBAL\Driver\OCI8\OCI8Statement\errorInfo
errorInfo()
Definição
OCI8Statement.php:148
Doctrine\DBAL\Driver\OCI8\OCI8Statement\bindValue
bindValue($param, $value, $type=null)
Definição
OCI8Statement.php:100
Doctrine\DBAL\Driver\OCI8\OCI8Statement\fetch
fetch($fetchStyle=PDO::FETCH_BOTH)
Definição
OCI8Statement.php:179
Doctrine\DBAL\Driver\Statement
Definição
Statement.php:40
Doctrine\DBAL\Driver\OCI8
Definição
Driver.php:22
classes
extensions
doctrine-dbal
Doctrine
DBAL
Driver
OCI8
OCI8Statement.php
Gerado por
1.10.0