Updated oracle and mysql connection drivers
This commit is contained in:
parent
53e9b06f6c
commit
893b9b0b23
@ -165,38 +165,79 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
return $this->dataDict;
|
||||
}
|
||||
/**
|
||||
* returns the next value in the given sequence
|
||||
*
|
||||
* @param string $sequence
|
||||
* @throws PDOException if something went wrong at database level
|
||||
* @return integer
|
||||
*/
|
||||
public function nextId($sequence) {
|
||||
throw new Doctrine_Connection_Exception('NextId() for sequences not supported by this driver.');
|
||||
}
|
||||
/**
|
||||
* Set the charset on the current connection
|
||||
*
|
||||
* @param string charset
|
||||
* @param resource connection handle
|
||||
*
|
||||
* @throws Doctrine_Connection_Exception if the feature is not supported by the driver
|
||||
* @return true on success, MDB2 Error Object on failure
|
||||
*/
|
||||
public function setCharset($charset) {
|
||||
throw new Doctrine_Connection_Exception('Altering charset not supported by this driver.');
|
||||
}
|
||||
/**
|
||||
* setTransactionIsolation
|
||||
*
|
||||
* Set the transacton isolation level.
|
||||
* (implemented by the connection drivers)
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* <code>
|
||||
* $conn->setTransactionIsolation('READ UNCOMMITTED');
|
||||
* </code>
|
||||
*
|
||||
* @param string standard isolation level
|
||||
* READ UNCOMMITTED (allows dirty reads)
|
||||
* READ COMMITTED (prevents dirty reads)
|
||||
* REPEATABLE READ (prevents nonrepeatable reads)
|
||||
* SERIALIZABLE (prevents phantom reads)
|
||||
*
|
||||
* @throws Doctrine_Connection_Exception if the feature is not supported by the driver
|
||||
* @throws PDOException if something fails at the PDO level
|
||||
* @return void
|
||||
*/
|
||||
public function setTransactionIsolation($isolation) {
|
||||
throw new Doctrine_Connection_Exception('Transaction isolation levels not supported by this database driver.');
|
||||
throw new Doctrine_Connection_Exception('Transaction isolation levels not supported by this driver.');
|
||||
}
|
||||
|
||||
/**
|
||||
* getTransactionIsolation
|
||||
*
|
||||
* @throws Doctrine_Connection_Exception if the feature is not supported by the driver
|
||||
* @throws PDOException if something fails at the PDO level
|
||||
* @return string returns the current session transaction isolation level
|
||||
*/
|
||||
public function getTransactionIsolation() {
|
||||
throw new Doctrine_Connection_Exception('Fetching transaction isolation level not supported by this database driver.');
|
||||
throw new Doctrine_Connection_Exception('Fetching transaction isolation level not supported by this driver.');
|
||||
}
|
||||
/**
|
||||
* query
|
||||
* queries the database with Doctrine Query Language
|
||||
* queries the database using Doctrine Query Language
|
||||
*
|
||||
* @param string $query DQL query
|
||||
* @param array $params query parameters
|
||||
* <code>
|
||||
* $users = $conn->query('SELECT u.* FROM User u');
|
||||
*
|
||||
* $users = $conn->query('SELECT u.* FROM User u WHERE u.name LIKE ?', array('someone'));
|
||||
* </code>
|
||||
*
|
||||
* @param string $query DQL query
|
||||
* @param array $params query parameters
|
||||
* @see Doctrine_Query
|
||||
* @return Doctrine_Collection Collection of Doctrine_Record objects
|
||||
*/
|
||||
final public function query($query,array $params = array()) {
|
||||
public function query($query, array $params = array()) {
|
||||
$parser = new Doctrine_Query($this);
|
||||
|
||||
return $parser->query($query, $params);
|
||||
|
@ -75,11 +75,18 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
||||
/**
|
||||
* Set the transacton isolation level.
|
||||
*
|
||||
* example :
|
||||
*
|
||||
* <code>
|
||||
* $conn->setTransactionIsolation('READ UNCOMMITTED');
|
||||
* </code>
|
||||
*
|
||||
* @param string standard isolation level
|
||||
* READ UNCOMMITTED (allows dirty reads)
|
||||
* READ COMMITTED (prevents dirty reads)
|
||||
* REPEATABLE READ (prevents nonrepeatable reads)
|
||||
* SERIALIZABLE (prevents phantom reads)
|
||||
*
|
||||
* @throws Doctrine_Connection_Mysql_Exception if using unknown isolation level
|
||||
* @throws PDOException if something fails at the PDO level
|
||||
* @return void
|
||||
|
@ -30,33 +30,89 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
|
||||
/**
|
||||
* @var string $driverName the name of this connection driver
|
||||
*/
|
||||
protected $driverName = 'Oracle';
|
||||
protected $driverName = 'Oracle';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->supported = array(
|
||||
'sequences' => true,
|
||||
'indexes' => true,
|
||||
'summary_functions' => true,
|
||||
'order_by_text' => true,
|
||||
'current_id' => true,
|
||||
'affected_rows' => true,
|
||||
'transactions' => true,
|
||||
'savepoints' => true,
|
||||
'limit_queries' => true,
|
||||
'LOBs' => true,
|
||||
'replace' => 'emulated',
|
||||
'sub_selects' => true,
|
||||
'auto_increment' => false, // implementation is broken
|
||||
'primary_key' => true,
|
||||
'result_introspection' => true,
|
||||
'prepared_statements' => true,
|
||||
'identifier_quoting' => true,
|
||||
'pattern_escaping' => true,
|
||||
);
|
||||
|
||||
$this->options['DBA_username'] = false;
|
||||
$this->options['DBA_password'] = false;
|
||||
$this->options['database_name_prefix'] = false;
|
||||
$this->options['emulate_database'] = true;
|
||||
$this->options['default_tablespace'] = false;
|
||||
$this->options['default_text_field_length'] = 2000;
|
||||
$this->options['result_prefetching'] = false;
|
||||
}
|
||||
/**
|
||||
* Adds an driver-specific LIMIT clause to the query
|
||||
*
|
||||
* @param string $query
|
||||
* @param mixed $limit
|
||||
* @param mixed $offset
|
||||
* @param string $query query to modify
|
||||
* @param integer $limit limit the number of rows
|
||||
* @param integer $offset start reading from given offset
|
||||
* @return string the modified query
|
||||
*/
|
||||
public function modifyLimitQuery($query,$limit,$offset) {
|
||||
public function modifyLimitQuery($query, $limit, $offset) {
|
||||
/**
|
||||
$e = explode("select ",strtolower($query));
|
||||
$e2 = explode(" from ",$e[1]);
|
||||
$fields = $e2[0];
|
||||
|
||||
$query = "SELECT $fields FROM (SELECT rownum as linenum, $fields FROM ($query) WHERE rownum <= ($offset + $limit)) WHERE linenum >= ".++$offset;
|
||||
*/
|
||||
if (preg_match('/^\s*SELECT/i', $query)) {
|
||||
if ( ! preg_match('/\sFROM\s/i', $query)) {
|
||||
$query .= " FROM dual";
|
||||
}
|
||||
if ($limit > 0) {
|
||||
// taken from http://svn.ez.no/svn/ezcomponents/packages/Database
|
||||
$max = $offset + $limit;
|
||||
if ($offset > 0) {
|
||||
$min = $offset + 1;
|
||||
$query = 'SELECT * FROM (SELECT a.*, ROWNUM dctrn_rownum FROM (' . $query
|
||||
. ') a WHERE ROWNUM <= ' . $max . ') WHERE dctrn_rownum >= ' . $min;
|
||||
} else {
|
||||
$query = 'SELECT a.* FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
/**
|
||||
* Set the transacton isolation level.
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* <code>
|
||||
* $conn->setTransactionIsolation('READ UNCOMMITTED');
|
||||
* </code>
|
||||
*
|
||||
* @param string standard isolation level
|
||||
* READ UNCOMMITTED (allows dirty reads)
|
||||
* READ COMMITTED (prevents dirty reads)
|
||||
* REPEATABLE READ (prevents nonrepeatable reads)
|
||||
* SERIALIZABLE (prevents phantom reads)
|
||||
* @return mixed MDB2_OK on success, a MDB2 error on failure
|
||||
* @throws PDOException if something fails at the PDO level
|
||||
* @return void
|
||||
*/
|
||||
function setTransactionIsolation($isolation) {
|
||||
public function setTransactionIsolation($isolation) {
|
||||
switch ($isolation) {
|
||||
case 'READ UNCOMMITTED':
|
||||
$isolation = 'READ COMMITTED';
|
||||
@ -66,7 +122,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
|
||||
case 'SERIALIZABLE':
|
||||
break;
|
||||
default:
|
||||
throw new Doctrine_Connection_Oracle_Exception('Isolation level ' . $isolation . 'is not supported.');
|
||||
throw new Doctrine_Connection_Oracle_Exception('Isolation level ' . $isolation . ' is not supported.');
|
||||
}
|
||||
|
||||
$query = 'ALTER SESSION ISOLATION LEVEL ' . $isolation;
|
||||
@ -74,16 +130,28 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
|
||||
}
|
||||
/**
|
||||
* returns the next value in the given sequence
|
||||
* @param string $sequence
|
||||
*
|
||||
* @param string $sequence name of the sequence
|
||||
* @throws PDOException if something went wrong at database level
|
||||
* @return integer
|
||||
*/
|
||||
public function getNextID($sequence) {
|
||||
$stmt = $this->query("SELECT $sequence.nextval FROM dual");
|
||||
public function nextId($sequence) {
|
||||
$stmt = $this->query('SELECT ' . $sequence . '.nextval FROM dual');
|
||||
$data = $stmt->fetch(PDO::FETCH_NUM);
|
||||
return $data[0];
|
||||
}
|
||||
/**
|
||||
* Returns the current id of a sequence
|
||||
*
|
||||
* @param string $sequence name of the sequence
|
||||
* @throws PDOException if something went wrong at database level
|
||||
* @return mixed id
|
||||
*/
|
||||
public function currId($sequence) {
|
||||
$sequence = $this->quoteIdentifier($this->getSequenceName($sequence), true);
|
||||
$stmt = $this->query('SELECT ' . $sequence . '.currval FROM dual');
|
||||
$data = $stmt->fetch(PDO::FETCH_NUM);
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user