/usr/share/php/propel/adapter/DBOracle.php is in php-propel-runtime 1.6.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | <?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Oracle adapter.
*
* @author David Giffin <david@giffin.org> (Propel)
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Jon S. Stevens <jon@clearink.com> (Torque)
* @author Brett McLaughlin <bmclaugh@algx.net> (Torque)
* @author Bill Schneider <bschneider@vecna.com> (Torque)
* @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
* @version $Revision$
* @package propel.runtime.adapter
*/
class DBOracle extends DBAdapter
{
/**
* This method is called after a connection was created to run necessary
* post-initialization queries or code.
* Removes the charset query and adds the date queries
*
* @see parent::initConnection()
*
* @param PDO $con
* @param array $settings A $PDO PDO connection instance
*/
public function initConnection(PDO $con, array $settings)
{
$con->exec("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
$con->exec("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS'");
if (isset($settings['queries']) && is_array($settings['queries'])) {
foreach ($settings['queries'] as $queries) {
foreach ((array) $queries as $query) {
$con->exec($query);
}
}
}
}
/**
* This method is used to ignore case.
*
* @param string $in The string to transform to upper case.
* @return string The upper case string.
*/
public function toUpperCase($in)
{
return "UPPER(" . $in . ")";
}
/**
* This method is used to ignore case.
*
* @param string $in The string whose case to ignore.
* @return string The string in a case that can be ignored.
*/
public function ignoreCase($in)
{
return "UPPER(" . $in . ")";
}
/**
* Returns SQL which concatenates the second string to the first.
*
* @param string $s1 String to concatenate.
* @param string $s2 String to append.
*
* @return string
*/
public function concatString($s1, $s2)
{
return "CONCAT($s1, $s2)";
}
/**
* Returns SQL which extracts a substring.
*
* @param string $s String to extract from.
* @param integer $pos Offset to start from.
* @param integer $len Number of characters to extract.
*
* @return string
*/
public function subString($s, $pos, $len)
{
return "SUBSTR($s, $pos, $len)";
}
/**
* Returns SQL which calculates the length (in chars) of a string.
*
* @param string $s String to calculate length of.
* @return string
*/
public function strLength($s)
{
return "LENGTH($s)";
}
/**
* @see DBAdapter::applyLimit()
*
* @param string $sql
* @param integer $offset
* @param integer $limit
* @param null|Criteria $criteria
*/
public function applyLimit(&$sql, $offset, $limit, $criteria = null)
{
if (BasePeer::needsSelectAliases($criteria)) {
$crit = clone $criteria;
$selectSql = $this->createSelectSqlPart($crit, $params, true);
$sql = $selectSql . substr($sql, strpos($sql, 'FROM') - 1);
}
$sql = 'SELECT B.* FROM ('
. 'SELECT A.*, rownum AS PROPEL_ROWNUM FROM (' . $sql . ') A '
. ') B WHERE ';
if ($offset > 0) {
$sql .= ' B.PROPEL_ROWNUM > ' . $offset;
if ($limit > 0) {
$sql .= ' AND B.PROPEL_ROWNUM <= ' . ( $offset + $limit );
}
} else {
$sql .= ' B.PROPEL_ROWNUM <= ' . $limit;
}
}
/**
* @return int
*/
protected function getIdMethod()
{
return DBAdapter::ID_METHOD_SEQUENCE;
}
/**
* @param PDO $con
* @param string $name
*
* @throws PropelException
* @return integer
*/
public function getId(PDO $con, $name = null)
{
if ($name === null) {
throw new PropelException("Unable to fetch next sequence ID without sequence name.");
}
$stmt = $con->query("SELECT " . $name . ".nextval FROM dual");
$row = $stmt->fetch(PDO::FETCH_NUM);
return $row[0];
}
/**
* @param string $seed
* @return string
*/
public function random($seed=NULL)
{
return 'dbms_random.value';
}
/**
* Ensures uniqueness of select column names by turning them all into aliases
* This is necessary for queries on more than one table when the tables share a column name
*
* @see http://propel.phpdb.org/trac/ticket/795
*
* @param Criteria $criteria
* @return Criteria The input, with Select columns replaced by aliases
*/
public function turnSelectColumnsToAliases(Criteria $criteria)
{
$selectColumns = $criteria->getSelectColumns();
// clearSelectColumns also clears the aliases, so get them too
$asColumns = $criteria->getAsColumns();
$criteria->clearSelectColumns();
$columnAliases = $asColumns;
// add the select columns back
foreach ($selectColumns as $id => $clause) {
// Generate a unique alias
$baseAlias = "ORA_COL_ALIAS_".$id;
$alias = $baseAlias;
// If it already exists, add a unique suffix
$i = 0;
while (isset($columnAliases[$alias])) {
$i++;
$alias = $baseAlias . '_' . $i;
}
// Add it as an alias
$criteria->addAsColumn($alias, $clause);
$columnAliases[$alias] = $clause;
}
// Add the aliases back, don't modify them
foreach ($asColumns as $name => $clause) {
$criteria->addAsColumn($name, $clause);
}
return $criteria;
}
/**
* @see DBAdapter::bindValue()
* Warning: duplicates logic from OraclePlatform::getColumnBindingPHP().
* Any code modification here must be ported there.
*
* @param PDOStatement $stmt
* @param string $parameter
* @param mixed $value
* @param ColumnMap $cMap
* @param null|integer $position
*
* @return boolean
*/
public function bindValue(PDOStatement $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
{
if ($cMap->isTemporal()) {
$value = $this->formatTemporalValue($value, $cMap);
} elseif ($cMap->getType() == PropelColumnTypes::CLOB_EMU) {
return $stmt->bindParam(':p'.$position, $value, $cMap->getPdoType(), strlen($value));
} elseif (is_resource($value) && $cMap->isLob()) {
// we always need to make sure that the stream is rewound, otherwise nothing will
// get written to database.
rewind($value);
}
return $stmt->bindValue($parameter, $value, $cMap->getPdoType());
}
/**
* Do Explain Plan for query object or query string
*
* @param PropelPDO $con propel connection
* @param ModelCriteria|string $query query the criteria or the query string
* @throws PropelException
* @return PDOStatement A PDO statement executed using the connection, ready to be fetched
*/
public function doExplainPlan(PropelPDO $con, $query)
{
$con->beginTransaction();
if ($query instanceof ModelCriteria) {
$params = array();
$dbMap = Propel::getDatabaseMap($query->getDbName());
$sql = BasePeer::createSelectSql($query, $params);
} else {
$sql = $query;
}
// unique id for the query string
$uniqueId = uniqid('Propel', true);
$stmt = $con->prepare($this->getExplainPlanQuery($sql, $uniqueId));
if ($query instanceof ModelCriteria) {
$this->bindValues($stmt, $params, $dbMap);
}
$stmt->execute();
// explain plan is save in a table, data must be commit
$con->commit();
$stmt = $con->prepare($this->getExplainPlanReadQuery($uniqueId));
$stmt->execute();
return $stmt;
}
/**
* Explain Plan compute query getter
*
* @param string $query query to explain
* @param string $uniqueId query unique id
*
* @return string
*/
public function getExplainPlanQuery($query, $uniqueId)
{
return sprintf('EXPLAIN PLAN SET STATEMENT_ID = \'%s\' FOR %s', $uniqueId, $query);
}
/**
* Explain Plan read query
*
* @param string $uniqueId
* @return string query unique id
*/
public function getExplainPlanReadQuery($uniqueId)
{
return sprintf('SELECT LEVEL, OPERATION, OPTIONS, COST, CARDINALITY, BYTES
FROM PLAN_TABLE CONNECT BY PRIOR ID = PARENT_ID AND PRIOR STATEMENT_ID = STATEMENT_ID
START WITH ID = 0 AND STATEMENT_ID = \'%s\' ORDER BY ID', $uniqueId);
}
}
|