From 94e94e0a8566f23d16658a04c55b0bbfdd6689aa Mon Sep 17 00:00:00 2001 From: "godzilla80@gmx.net" <> Date: Sun, 14 Feb 2010 01:22:57 +0000 Subject: Merge Branches & Trunk /trunk:r2680,2692,2707-2736 /branches/3.1:r2682-2686,2694-2702,2705,2738-2762 --- framework/Data/TDbConnection.php | 53 +++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'framework/Data/TDbConnection.php') diff --git a/framework/Data/TDbConnection.php b/framework/Data/TDbConnection.php index 26d61883..4726083c 100644 --- a/framework/Data/TDbConnection.php +++ b/framework/Data/TDbConnection.php @@ -27,10 +27,10 @@ Prado::using('System.Data.TDbCommand'); * specifying {@link setConnectionString ConnectionString}, {@link setUsername Username} * and {@link setPassword Password}. * - * Since 3.1.2, the connection charset can be set (for MySQL and PostgreSQL databases only) + * Since 3.1.2, the connection charset can be set (for MySQL and PostgreSQL databases only) * using the {@link setCharset Charset} property. The value of this property is database dependant. - * e.g. for mysql, you can use 'latin1' for cp1252 West European, 'utf8' for unicode, ... - * + * e.g. for mysql, you can use 'latin1' for cp1252 West European, 'utf8' for unicode, ... + * * The following example shows how to create a TDbConnection instance and establish * the actual connection: * @@ -83,6 +83,12 @@ Prado::using('System.Data.TDbCommand'); */ class TDbConnection extends TComponent { + /** + * + * @since 3.1.7 + */ + const DEFAULT_TRANSACTION_CLASS = 'System.Data.TDbTransaction'; + private $_dsn=''; private $_username=''; private $_password=''; @@ -92,13 +98,19 @@ class TDbConnection extends TComponent private $_pdo=null; private $_transaction; + /** + * @var string + * @since 3.1.7 + */ + private $_transactionClass=self::DEFAULT_TRANSACTION_CLASS; + /** * Constructor. * Note, the DB connection is not established when this connection * instance is created. Set {@link setActive Active} property to true * to establish the connection. * Since 3.1.2, you can set the charset for MySql connection - * + * * @param string The Data Source Name, or DSN, contains the information required to connect to the database. * @param string The user name for the DSN string. * @param string The password for the DSN string. @@ -168,7 +180,7 @@ class TDbConnection extends TComponent { $this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(), $this->getPassword(),$this->_attributes); - // This attribute is only useful for PDO::MySql driver. + // This attribute is only useful for PDO::MySql driver. // Ignore the warning if a driver doesn't understand this. @$this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -194,7 +206,7 @@ class TDbConnection extends TComponent /* * Set the database connection charset. - * Only MySql databases are supported for now. + * Only MySql databases are supported for now. * @since 3.1.2 */ protected function setConnectionCharset() @@ -204,7 +216,7 @@ class TDbConnection extends TComponent switch ($this->_pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) { case 'mysql': - $stmt = $this->_pdo->prepare('SET CHARACTER SET ?'); + $stmt = $this->_pdo->prepare('SET NAMES ?'); break; case 'pgsql': $stmt = $this->_pdo->prepare('SET client_encoding TO ?'); @@ -212,7 +224,7 @@ class TDbConnection extends TComponent } $stmt->execute(array($this->_charset)); } - + /** * @return string The Data Source Name, or DSN, contains the information required to connect to the database. */ @@ -269,7 +281,7 @@ class TDbConnection extends TComponent { return $this->_charset; } - + /** * @param string the charset used for database connection */ @@ -278,7 +290,7 @@ class TDbConnection extends TComponent $this->_charset=$value; $this->setConnectionCharset(); } - + /** * @return PDO the PDO instance, null if the connection is not established yet */ @@ -324,12 +336,31 @@ class TDbConnection extends TComponent if($this->getActive()) { $this->_pdo->beginTransaction(); - return $this->_transaction=new TDbTransaction($this); + return $this->_transaction=Prado::createComponent($this->getTransactionClass(), $this); } else throw new TDbException('dbconnection_connection_inactive'); } + /** + * @return string Transaction class name to be created by calling {@link TDbConnection::beginTransaction}. Defaults to 'System.Data.TDbTransaction'. + * @since 3.1.7 + */ + public function getTransactionClass() + { + return $this->_transactionClass; + } + + + /** + * @param string Transaction class name to be created by calling {@link TDbConnection::beginTransaction}. + * @since 3.1.7 + */ + public function setTransactionClass($value) + { + $this->_transactionClass = (string)$value; + } + /** * Returns the ID of the last inserted row or sequence value. * @param string name of the sequence object (required by some DBMS) -- cgit v1.2.3