1
0
mirror of synced 2025-01-31 12:32:59 +03:00

Updated oracle and mysql connection drivers

This commit is contained in:
zYne 2006-10-31 09:14:54 +00:00
parent 53e9b06f6c
commit 893b9b0b23
3 changed files with 138 additions and 22 deletions

View File

@ -165,38 +165,79 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return $this->dataDict; 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. * Set the transacton isolation level.
* (implemented by the connection drivers) * (implemented by the connection drivers)
* *
* example:
*
* <code>
* $conn->setTransactionIsolation('READ UNCOMMITTED');
* </code>
*
* @param string standard isolation level * @param string standard isolation level
* READ UNCOMMITTED (allows dirty reads) * READ UNCOMMITTED (allows dirty reads)
* READ COMMITTED (prevents dirty reads) * READ COMMITTED (prevents dirty reads)
* REPEATABLE READ (prevents nonrepeatable reads) * REPEATABLE READ (prevents nonrepeatable reads)
* SERIALIZABLE (prevents phantom 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 * @throws PDOException if something fails at the PDO level
* @return void * @return void
*/ */
public function setTransactionIsolation($isolation) { 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 * 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 * @return string returns the current session transaction isolation level
*/ */
public function getTransactionIsolation() { 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 * query
* queries the database with Doctrine Query Language * queries the database using Doctrine Query Language
* *
* @param string $query DQL query * <code>
* @param array $params query parameters * $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); $parser = new Doctrine_Query($this);
return $parser->query($query, $params); return $parser->query($query, $params);

View File

@ -75,11 +75,18 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
/** /**
* Set the transacton isolation level. * Set the transacton isolation level.
* *
* example :
*
* <code>
* $conn->setTransactionIsolation('READ UNCOMMITTED');
* </code>
*
* @param string standard isolation level * @param string standard isolation level
* READ UNCOMMITTED (allows dirty reads) * READ UNCOMMITTED (allows dirty reads)
* READ COMMITTED (prevents dirty reads) * READ COMMITTED (prevents dirty reads)
* REPEATABLE READ (prevents nonrepeatable reads) * REPEATABLE READ (prevents nonrepeatable reads)
* SERIALIZABLE (prevents phantom reads) * SERIALIZABLE (prevents phantom reads)
*
* @throws Doctrine_Connection_Mysql_Exception if using unknown isolation level * @throws Doctrine_Connection_Mysql_Exception if using unknown isolation level
* @throws PDOException if something fails at the PDO level * @throws PDOException if something fails at the PDO level
* @return void * @return void

View File

@ -30,33 +30,89 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
/** /**
* @var string $driverName the name of this connection driver * @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 * Adds an driver-specific LIMIT clause to the query
* *
* @param string $query * @param string $query query to modify
* @param mixed $limit * @param integer $limit limit the number of rows
* @param mixed $offset * @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)); $e = explode("select ",strtolower($query));
$e2 = explode(" from ",$e[1]); $e2 = explode(" from ",$e[1]);
$fields = $e2[0]; $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; return $query;
} }
/** /**
* Set the transacton isolation level. * Set the transacton isolation level.
* *
* example:
*
* <code>
* $conn->setTransactionIsolation('READ UNCOMMITTED');
* </code>
*
* @param string standard isolation level * @param string standard isolation level
* READ UNCOMMITTED (allows dirty reads) * READ UNCOMMITTED (allows dirty reads)
* READ COMMITTED (prevents dirty reads) * READ COMMITTED (prevents dirty reads)
* REPEATABLE READ (prevents nonrepeatable reads) * REPEATABLE READ (prevents nonrepeatable reads)
* SERIALIZABLE (prevents phantom 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) { switch ($isolation) {
case 'READ UNCOMMITTED': case 'READ UNCOMMITTED':
$isolation = 'READ COMMITTED'; $isolation = 'READ COMMITTED';
@ -66,7 +122,7 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
case 'SERIALIZABLE': case 'SERIALIZABLE':
break; break;
default: 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; $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 * 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 * @return integer
*/ */
public function getNextID($sequence) { public function nextId($sequence) {
$stmt = $this->query("SELECT $sequence.nextval FROM dual"); $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); $data = $stmt->fetch(PDO::FETCH_NUM);
return $data[0]; return $data[0];
} }
} }