Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
8eef3f44
Commit
8eef3f44
authored
Jun 11, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated doc blocks, added savepoint as optional transaction parameter
parent
8573d33f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
124 additions
and
47 deletions
+124
-47
Connection.php
lib/Doctrine/Connection.php
+92
-32
Export.php
lib/Doctrine/Export.php
+3
-3
Mysql.php
lib/Doctrine/Export/Mysql.php
+1
-1
Sqlite.php
lib/Doctrine/Export/Sqlite.php
+1
-1
Table.php
lib/Doctrine/Table.php
+1
-1
Transaction.php
lib/Doctrine/Transaction.php
+26
-9
No files found.
lib/Doctrine/Connection.php
View file @
8eef3f44
...
...
@@ -113,7 +113,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
'import'
=>
false
,
'sequence'
=>
false
,
'unitOfWork'
=>
false
,
'formatter'
=>
false
'formatter'
=>
false
,
'util'
=>
false
,
);
/**
* @var array $properties an array of connection properties
...
...
@@ -233,6 +234,59 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
return
$this
->
dbh
;
}
/**
* connect
* connects into database
*
* @return boolean
*/
public
function
connect
()
{
/**
if ($this->isConnected) {
return false;
}
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::CONNECT);
$this->listener->onPreConnect($event);
$e = explode(':', $this->options['dsn']);
$found = false;
if (extension_loaded('pdo')) {
if (in_array($e[0], PDO::getAvailableDrivers())) {
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$found = true;
}
}
if ( ! $found) {
$class = 'Doctrine_Adapter_' . ucwords($e[0]);
if (class_exists($class)) {
$this->dbh = new $class($this->options['dsn'], $this->options['username'], $this->options['password']);
} else {
throw new Doctrine_Connection_Exception("Couldn't locate driver named " . $e[0]);
}
}
foreach($this->pendingAttributes as $attr => $value) {
// some drivers don't support setting this so we just skip it
if($attr == Doctrine::ATTR_DRIVER_NAME) {
continue;
}
$this->dbh->setAttribute($attr, $value);
}
$this->isConnected = true;
$this->listener->onConnect($event);
return true;
*/
}
/**
* converts given driver name
*
...
...
@@ -762,17 +816,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* addTable
* adds a Doctrine_Table object into connection registry
*
* @param $
objTable
a Doctrine_Table object to be added into registry
* @param $
table
a Doctrine_Table object to be added into registry
* @return boolean
*/
public
function
addTable
(
Doctrine_Table
$
objT
able
)
public
function
addTable
(
Doctrine_Table
$
t
able
)
{
$name
=
$
objT
able
->
getComponentName
();
$name
=
$
t
able
->
getComponentName
();
if
(
isset
(
$this
->
tables
[
$name
]))
{
return
false
;
}
$this
->
tables
[
$name
]
=
$
objT
able
;
$this
->
tables
[
$name
]
=
$
t
able
;
return
true
;
}
/**
...
...
@@ -850,40 +904,55 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
/**
* beginTransaction
*
starts a new transaction
*
Start a transaction or set a savepoint.
*
*
this method can be listened by onPreBeginTransaction and onBeginT
ransaction
*
listener methods
*
if trying to set a savepoint and there is no active t
ransaction
*
a new transaction is being started
*
* @return void
* Listeners: onPreTransactionBegin, onTransactionBegin
*
* @param string $savepoint name of a savepoint to set
* @throws Doctrine_Transaction_Exception if the transaction fails at database level
* @return integer current transaction nesting level
*/
public
function
beginTransaction
()
public
function
beginTransaction
(
$savepoint
=
null
)
{
$this
->
transaction
->
beginTransaction
();
$this
->
transaction
->
beginTransaction
(
$savepoint
);
}
/**
* commits the current transaction
* if lockmode is optimistic this method starts a transaction
* and commits it instantly
* commit
* Commit the database changes done during a transaction that is in
* progress or release a savepoint. This function may only be called when
* auto-committing is disabled, otherwise it will fail.
*
* @return void
* Listeners: onPreTransactionCommit, onTransactionCommit
*
* @param string $savepoint name of a savepoint to release
* @throws Doctrine_Transaction_Exception if the transaction fails at PDO level
* @throws Doctrine_Validator_Exception if the transaction fails due to record validations
* @return boolean false if commit couldn't be performed, true otherwise
*/
public
function
commit
()
public
function
commit
(
$savepoint
=
null
)
{
$this
->
transaction
->
commit
();
$this
->
transaction
->
commit
(
$savepoint
);
}
/**
* rollback
* rolls back all transactions
* Cancel any database changes done during a transaction or since a specific
* savepoint that is in progress. This function may only be called when
* auto-committing is disabled, otherwise it will fail. Therefore, a new
* transaction is implicitly started after canceling the pending changes.
*
* this method
also listens to
onPreTransactionRollback and onTransactionRollback
* eventlisteners
* this method
can be listened with
onPreTransactionRollback and onTransactionRollback
* eventlistener
method
s
*
* @return void
* @param string $savepoint name of a savepoint to rollback to
* @throws Doctrine_Transaction_Exception if the rollback operation fails at database level
* @return boolean false if rollback couldn't be performed, true otherwise
*/
public
function
rollback
()
public
function
rollback
(
$savepoint
=
null
)
{
$this
->
transaction
->
rollback
();
$this
->
transaction
->
rollback
(
$savepoint
);
}
/**
* returns a string representation of this object
...
...
@@ -893,14 +962,5 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
return
Doctrine_Lib
::
getConnectionAsString
(
$this
);
}
/**
* Enter description here...
*
* @param unknown_type $name
*/
public
function
getIndexName
(
$name
)
{
return
$this
->
formatter
->
getIndexName
(
$name
);
}
}
lib/Doctrine/Export.php
View file @
8eef3f44
...
...
@@ -66,7 +66,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public
function
dropIndex
(
$table
,
$name
)
{
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getIndexName
(
$name
),
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
),
true
);
return
$this
->
conn
->
exec
(
'DROP INDEX '
.
$name
);
}
/**
...
...
@@ -80,7 +80,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
public
function
dropConstraint
(
$table
,
$name
,
$primary
=
false
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getIndexName
(
$name
),
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
),
true
);
return
$this
->
conn
->
exec
(
'ALTER TABLE '
.
$table
.
' DROP CONSTRAINT '
.
$name
);
}
/**
...
...
@@ -226,7 +226,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
public
function
createConstraint
(
$table
,
$name
,
$definition
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getIndexName
(
$name
),
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
),
true
);
$query
=
'ALTER TABLE '
.
$table
.
' ADD CONSTRAINT '
.
$name
;
if
(
!
empty
(
$definition
[
'primary'
]))
{
$query
.=
' PRIMARY KEY'
;
...
...
lib/Doctrine/Export/Mysql.php
View file @
8eef3f44
...
...
@@ -579,7 +579,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
public
function
dropIndex
(
$table
,
$name
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getIndexName
(
$name
),
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
),
true
);
return
$this
->
conn
->
exec
(
'DROP INDEX '
.
$name
.
' ON '
.
$table
);
}
/**
...
...
lib/Doctrine/Export/Sqlite.php
View file @
8eef3f44
...
...
@@ -68,7 +68,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
public
function
createIndexSql
(
$table
,
$name
,
array
$definition
)
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
getIndexName
(
$name
);
$name
=
$this
->
conn
->
formatter
->
getIndexName
(
$name
);
$query
=
'CREATE INDEX '
.
$name
.
' ON '
.
$table
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationList
(
$definition
[
'fields'
])
.
')'
;
...
...
lib/Doctrine/Table.php
View file @
8eef3f44
...
...
@@ -462,7 +462,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public
function
addIndex
(
$index
,
array
$definition
)
{
$index
=
$this
->
conn
->
getIndexName
(
$index
);
$index
=
$this
->
conn
->
formatter
->
getIndexName
(
$index
);
$this
->
options
[
'indexes'
][
$index
]
=
$definition
;
}
/**
...
...
lib/Doctrine/Transaction.php
View file @
8eef3f44
...
...
@@ -207,10 +207,13 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
* Listeners: onPreTransactionBegin, onTransactionBegin
*
* @param string $savepoint name of a savepoint to set
* @throws Doctrine_Transaction_Exception if the transaction fails at database level
* @return integer current transaction nesting level
*/
public
function
beginTransaction
(
$savepoint
=
null
)
{
$this
->
conn
->
connect
();
if
(
!
is_null
(
$savepoint
))
{
$this
->
beginTransaction
();
...
...
@@ -221,7 +224,11 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
if
(
$this
->
transactionLevel
==
0
)
{
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreTransactionBegin
(
$this
->
conn
);
$this
->
conn
->
getDbh
()
->
beginTransaction
();
try
{
$this
->
conn
->
getDbh
()
->
beginTransaction
();
}
catch
(
Exception
$e
)
{
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
}
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionBegin
(
$this
->
conn
);
}
...
...
@@ -240,14 +247,17 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
* Listeners: onPreTransactionCommit, onTransactionCommit
*
* @param string $savepoint name of a savepoint to release
* @throws Doctrine_Transaction_Exception if the transaction fails at
PDO
level
* @throws Doctrine_Transaction_Exception if the transaction fails at
database
level
* @throws Doctrine_Validator_Exception if the transaction fails due to record validations
* @return boolean false if commit couldn't be performed, true otherwise
*/
public
function
commit
(
$savepoint
=
null
)
{
if
(
$this
->
transactionLevel
==
0
)
$this
->
conn
->
connect
();
if
(
$this
->
transactionLevel
==
0
)
{
return
false
;
}
if
(
!
is_null
(
$savepoint
))
{
$this
->
transactionLevel
=
$this
->
removeSavePoints
(
$savepoint
);
...
...
@@ -263,7 +273,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
}
catch
(
Exception
$e
)
{
$this
->
rollback
();
throw
new
Doctrine_Transaction_Exception
(
$e
->
__toString
());
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
}
if
(
!
empty
(
$this
->
invalid
))
{
$this
->
rollback
();
...
...
@@ -299,16 +309,20 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
* auto-committing is disabled, otherwise it will fail. Therefore, a new
* transaction is implicitly started after canceling the pending changes.
*
* this method
listens to
onPreTransactionRollback and onTransactionRollback
* this method
can be listened with
onPreTransactionRollback and onTransactionRollback
* eventlistener methods
*
* @param string $savepoint name of a savepoint to rollback to
* @param string $savepoint name of a savepoint to rollback to
* @throws Doctrine_Transaction_Exception if the rollback operation fails at database level
* @return boolean false if rollback couldn't be performed, true otherwise
*/
public
function
rollback
(
$savepoint
=
null
)
{
if
(
$this
->
transactionLevel
==
0
)
$this
->
conn
->
connect
();
if
(
$this
->
transactionLevel
==
0
)
{
return
false
;
}
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onPreTransactionRollback
(
$this
->
conn
);
...
...
@@ -321,8 +335,11 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
$this
->
deteles
=
array
();
$this
->
transactionLevel
=
0
;
$this
->
conn
->
getDbh
()
->
rollback
();
try
{
$this
->
conn
->
getDbh
()
->
rollback
();
}
catch
(
Exception
$e
)
{
throw
new
Doctrine_Transaction_Exception
(
$e
->
getMessage
());
}
}
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onTransactionRollback
(
$this
->
conn
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment