summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY1
-rw-r--r--framework/Data/TDbConnection.php55
2 files changed, 44 insertions, 12 deletions
diff --git a/HISTORY b/HISTORY
index cfe49b9c..8754d41b 100644
--- a/HISTORY
+++ b/HISTORY
@@ -23,6 +23,7 @@ BUG: TActiveDatePicker js error when date format does not have the 3 elements (C
ENH: Add property ClientScriptManagerClass to TPageService and releated changes in TPage.getClientScript() (Yves)
ENH: Always render clientside counterparts of validation control even if not enabled, but pass-through Enabled property, to allow Enabled/Disable of validator on callback. (Yves)
EHN: Add property TValidationSummary.ScrollToSummary to server-side control since property exists on client-side. (Yves)
+EHN: Add property TransactionClass (defaults to System.Data.TDbTransaction) to TDbConnection and modify beginTransaction() (Yves)
ENH: Issue#215 - Add ClientSide property to TDropContainer (googlenew at pcforum.hu, Christophe)
CHG: Issue#218 - Change URL of Javascript Logger (Christophe)
diff --git a/framework/Data/TDbConnection.php b/framework/Data/TDbConnection.php
index 6b84e1b3..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:
* <code>
@@ -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='';
@@ -93,12 +99,18 @@ class TDbConnection extends TComponent
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.
@@ -167,9 +179,9 @@ class TDbConnection extends TComponent
try
{
$this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(),
- $this->getPassword(),$this->_attributes);
- // This attribute is only useful for PDO::MySql driver.
- // Ignore the warning if a driver doesn't understand this.
+ $this->getPassword(),$this->_attributes);
+ // 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);
$this->_active=true;
@@ -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()
@@ -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,13 +336,32 @@ 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)
* @return string the row ID of the last row inserted, or the last value retrieved from the sequence object