<?php
+/**
+ * @ingroup Database
+ * @file
+ */
/**
* This is the Oracle database abstraction layer.
+ * @ingroup Database
*/
-
class ORABlob {
var $mData;
function getData() {
return $this->mData;
}
-};
+}
-/*
- * The oci8 extension is fairly weak and doesn't support oci_num_rows, among
- * other things. We use a wrapper class to handle that and other
+/**
+ * The oci8 extension is fairly weak and doesn't support oci_num_rows, among
+ * other things. We use a wrapper class to handle that and other
* Oracle-specific bits, like converting column names back to lowercase.
+ * @ingroup Database
*/
class ORAResult {
private $rows;
$this->db =& $db;
if (($this->nrows = oci_fetch_all($stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM)) === false) {
$e = oci_error($stmt);
- $db->reportQueryError('', $e['message'], $e['code']);
+ $db->reportQueryError($e['message'], $e['code'], '', __FUNCTION__);
return;
}
}
return $ret;
}
-};
+}
+/**
+ * @ingroup Database
+ */
class DatabaseOracle extends Database {
var $mInsertId = NULL;
var $mLastResult = NULL;
}
$this->mOut =& $wgOut;
$this->mFailFunction = $failFunction;
- $this->mCascadingDeletes = true;
- $this->mCleanupTriggers = true;
- $this->mStrictIPs = true;
$this->mFlags = $flags;
$this->open( $server, $user, $password, $dbName);
}
+ function cascadingDeletes() {
+ return true;
+ }
+ function cleanupTriggers() {
+ return true;
+ }
+ function strictIPs() {
+ return true;
+ }
function realTimestamps() {
return true;
}
-
function implicitGroupby() {
return false;
}
-
+ function implicitOrderby() {
+ return false;
+ }
function searchableIPs() {
return true;
}
function doQuery($sql) {
wfDebug("SQL: [$sql]\n");
- $this->mLastResult = $stmt = oci_parse($this->mConn, $sql);
+ if (!mb_check_encoding($sql)) {
+ throw new MWException("SQL encoding is invalid");
+ }
+
+ if (($this->mLastResult = $stmt = oci_parse($this->mConn, $sql)) === false) {
+ $e = oci_error($this->mConn);
+ $this->reportQueryError($e['message'], $e['code'], $sql, __FUNCTION__);
+ }
+
if (oci_execute($stmt, $this->execFlags()) == false) {
$e = oci_error($stmt);
- $this->reportQueryError($sql, $e['message'], $e['code'], '');
+ $this->reportQueryError($e['message'], $e['code'], $sql, __FUNCTION__);
}
if (oci_statement_type($stmt) == "SELECT")
return new ORAResult($this, $stmt);
if (!is_array($options))
$options = array($options);
- if (in_array('IGNORE', $options))
- $oldIgnore = $this->ignoreErrors(true);
+ #if (in_array('IGNORE', $options))
+ # $oldIgnore = $this->ignoreErrors(true);
# IGNORE is performed using single-row inserts, ignoring errors in each
# FIXME: need some way to distiguish between key collision and other types of error
//$this->ignoreErrors($oldIgnore);
$retVal = true;
- if (in_array('IGNORE', $options))
- $this->ignoreErrors($oldIgnore);
+ //if (in_array('IGNORE', $options))
+ // $this->ignoreErrors($oldIgnore);
return $retVal;
}
// for each value, append ":key"
$first = true;
+ $returning = '';
foreach ($row as $col => $val) {
- if (is_object($val))
+ if (is_object($val)) {
$what = "EMPTY_BLOB()";
- else
+ assert($returning === '');
+ $returning = " RETURNING $col INTO :bval";
+ $blobcol = $col;
+ } else
$what = ":$col";
if ($first)
$sql.= ", $what";
$first = false;
}
- $sql .= ")";
+ $sql .= ") $returning";
$stmt = oci_parse($this->mConn, $sql);
foreach ($row as $col => $val) {
}
}
- if (oci_execute($stmt, $this->execFlags()) === false) {
+ if (($bval = oci_new_descriptor($this->mConn, OCI_D_LOB)) === false) {
+ $e = oci_error($stmt);
+ throw new DBUnexpectedError($this, "Cannot create LOB descriptor: " . $e['message']);
+ }
+
+ if (strlen($returning))
+ oci_bind_by_name($stmt, ":bval", $bval, -1, SQLT_BLOB);
+
+ if (oci_execute($stmt, OCI_DEFAULT) === false) {
$e = oci_error($stmt);
$this->reportQueryError($e['message'], $e['code'], $sql, __METHOD__);
}
+ if (strlen($returning)) {
+ $bval->save($row[$blobcol]->getData());
+ $bval->free();
+ }
+ if (!$this->mTrxLevel)
+ oci_commit($this->mConn);
+
oci_free_statement($stmt);
}
-
+
function tableName( $name ) {
# Replace reserved words with better ones
switch( $name ) {
}
/**
- * ORacle does not have a "USE INDEX" clause, so return an empty string
+ * Oracle does not have a "USE INDEX" clause, so return an empty string
*/
function useIndexClause($index) {
return '';
}
function reportQueryError($error, $errno, $sql, $fname, $tempIgnore = false) {
- # Ignore errors during error handling to avoid infinite recursion
+ # Ignore errors during error handling to avoid infinite
+ # recursion
$ignore = $this->ignoreErrors(true);
++$this->mErrorCount;
if ($ignore || $tempIgnore) {
+echo "error ignored! query = [$sql]\n";
wfDebug("SQL ERROR (ignored): $error\n");
$this->ignoreErrors( $ignore );
}
else {
+echo "error!\n";
$message = "A database error has occurred\n" .
"Query: $sql\n" .
"Function: $fname\n" .
}
function addQuotes( $s ) {
+ global $wgLang;
+ $s = $wgLang->checkTitleEncoding($s);
return "'" . $this->strencode($s) . "'";
}
if ( isset( $options['GROUP BY'] ) ) $preLimitTail .= " GROUP BY {$options['GROUP BY']}";
if ( isset( $options['ORDER BY'] ) ) $preLimitTail .= " ORDER BY {$options['ORDER BY']}";
-
+
if (isset($options['LIMIT'])) {
// $tailOpts .= $this->limitResult('', $options['LIMIT'],
- // isset($options['OFFSET']) ? $options['OFFSET']
+ // isset($options['OFFSET']) ? $options['OFFSET']
// : false);
}
#if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $tailOpts .= ' FOR UPDATE';
#if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $tailOpts .= ' LOCK IN SHARE MODE';
- if ( isset( $noKeyOptions['DISTINCT'] ) && isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT';
+ if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT';
if ( isset( $options['USE INDEX'] ) && ! is_array( $options['USE INDEX'] ) ) {
$useIndex = $this->useIndexClause( $options['USE INDEX'] );
} else {
$useIndex = '';
}
-
+
return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
}
public function setTimeout( $timeout ) {
- /// @fixme no-op
+ // @todo fixme no-op
}
function ping() {
- wfDebug( "Function ping() not written for DatabasePostgres.php yet");
+ wfDebug( "Function ping() not written for DatabaseOracle.php yet");
return true;
}
+ /**
+ * How lagged is this slave?
+ *
+ * @return int
+ */
+ public function getLag() {
+ # Not implemented for Oracle
+ return 0;
+ }
-} // end DatabaseOracle class
+ function setFakeSlaveLag() {}
+ function setFakeMaster() {}
-?>
+ function getDBname() {
+ return $this->mDBname;
+ }
+
+ function getServer() {
+ return $this->mServer;
+ }
+
+} // end DatabaseOracle class