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
c6bd1147
Commit
c6bd1147
authored
Oct 31, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Doctrine_Connection
parent
c5f7572c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
40 deletions
+68
-40
Connection.php
lib/Doctrine/Connection.php
+33
-28
Transaction.php
lib/Doctrine/Connection/Transaction.php
+3
-12
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+32
-0
No files found.
lib/Doctrine/Connection.php
View file @
c6bd1147
...
...
@@ -223,16 +223,38 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$query
=
'DELETE FROM '
.
$table
.
' WHERE '
.
implode
(
' AND '
,
$condition
);
$affectedRows
=
$this
->
dbh
->
exec
(
$query
);
$insert
=
implode
(
', '
,
array_keys
(
$values
));
$query
=
'INSERT INTO '
.
$table
.
' ('
.
$insert
.
') VALUES ('
.
substr
(
str_repeat
(
'?, '
,
count
(
$values
)),
0
,
-
2
)
.
')'
;
$stmt
=
$this
->
dbh
->
prepare
(
$query
);
$stmt
->
execute
(
$values
);
$this
->
insert
(
$table
,
$values
);
$affectedRows
++
;
return
$affectedRows
;
}
/**
* Inserts a table row with specified data.
*
* @param string $table The table to insert data into.
* @param array $values An associateve array containing column-value pairs.
* @return boolean
*/
public
function
insert
(
$table
,
array
$values
=
array
())
{
if
(
empty
(
$values
))
return
false
;
// column names are specified as array keys
$cols
=
array_keys
(
$values
);
// build the statement
$query
=
"INSERT INTO
$table
"
.
'('
.
implode
(
', '
,
$cols
)
.
') '
.
'VALUES ('
.
substr
(
str_repeat
(
'?, '
,
count
(
$values
)),
0
,
-
2
)
.
')'
;
// prepare and execute the statement
$stmt
=
$this
->
dbh
->
prepare
(
$query
);
$stmt
->
execute
(
array_values
(
$values
));
return
true
;
}
/**
* returns the next value in the given sequence
*
...
...
@@ -427,36 +449,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* saves all the records from all tables
* this operation is isolated using a transaction
*
* @throws PDOException if something went wrong at database level
* @return void
*/
public
function
flush
()
{
$this
->
beginTransaction
();
$this
->
saveAll
();
$this
->
unitOfWork
->
saveAll
();
$this
->
commit
();
}
/**
* saveAll
* persists all the records from all tables
*
* @return void
*/
private
function
saveAll
()
{
$tree
=
$this
->
unitOfWork
->
buildFlushTree
(
$this
->
tables
);
foreach
(
$tree
as
$name
)
{
$table
=
$this
->
tables
[
$name
];
foreach
(
$table
->
getRepository
()
as
$record
)
{
$this
->
save
(
$record
);
}
}
foreach
(
$tree
as
$name
)
{
$table
=
$this
->
tables
[
$name
];
foreach
(
$table
->
getRepository
()
as
$record
)
{
$this
->
unitOfWork
->
saveAssociations
(
$record
);
}
}
}
/**
* clear
* clears all repositories
...
...
@@ -503,6 +503,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/**
* beginTransaction
* starts a new transaction
*
* this method can be listened by onPreBeginTransaction and onBeginTransaction
* listener methods
*
* @return void
*/
public
function
beginTransaction
()
{
...
...
@@ -579,6 +583,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$record
->
getTable
()
->
getListener
()
->
onDelete
(
$record
);
$this
->
commit
();
return
true
;
}
/**
...
...
lib/Doctrine/Connection/Transaction.php
View file @
c6bd1147
...
...
@@ -282,7 +282,7 @@ class Doctrine_Connection_Transaction implements Countable, IteratorAggregate {
/**
* inserts a record into database
*
* @param Doctrine_Record $record
* @param Doctrine_Record $record
record to be inserted
* @return boolean
*/
public
function
insert
(
Doctrine_Record
$record
)
{
...
...
@@ -298,24 +298,15 @@ class Doctrine_Connection_Transaction implements Countable, IteratorAggregate {
$keys
=
$table
->
getPrimaryKeys
();
$seq
=
$record
->
getTable
()
->
getSequenceName
();
if
(
!
empty
(
$seq
))
{
$id
=
$this
->
getNextID
(
$seq
);
$id
=
$this
->
nextId
(
$seq
);
$name
=
$record
->
getTable
()
->
getIdentifier
();
$array
[
$name
]
=
$id
;
}
$strfields
=
join
(
", "
,
array_keys
(
$array
));
$strvalues
=
substr
(
str_repeat
(
"?, "
,
count
(
$array
)),
0
,
-
2
);
$sql
=
"INSERT INTO "
.
$record
->
getTable
()
->
getTableName
()
.
" ("
.
$strfields
.
") VALUES ("
.
$strvalues
.
")"
;
$stmt
=
$this
->
conn
->
getDBH
()
->
prepare
(
$sql
);
$stmt
->
execute
(
array_values
(
$array
));
$this
->
conn
->
insert
(
$table
->
getTableName
(),
$array
);
if
(
count
(
$keys
)
==
1
&&
$keys
[
0
]
==
$table
->
getIdentifier
())
{
$id
=
$this
->
conn
->
getDBH
()
->
lastInsertID
();
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
c6bd1147
...
...
@@ -142,6 +142,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
* saveRelated
* saves all related records to $record
*
* @throws PDOException if something went wrong at database level
* @param Doctrine_Record $record
*/
public
function
saveRelated
(
Doctrine_Record
$record
)
{
...
...
@@ -185,6 +186,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
* 3, 4 and 5, this method would first destroy the associations to 1 and 2 and then
* save new associations to 4 and 5
*
* @throws PDOException if something went wrong at database level
* @param Doctrine_Record $record
* @return void
*/
...
...
@@ -200,6 +202,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
* deletes all related composites
* this method is always called internally when a record is deleted
*
* @throws PDOException if something went wrong at database level
* @return void
*/
public
function
deleteComposites
(
Doctrine_Record
$record
)
{
...
...
@@ -213,6 +216,35 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
endswitch
;
}
}
/**
* saveAll
* persists all the pending records from all tables
*
* @throws PDOException if something went wrong at database level
* @return void
*/
public
function
saveAll
()
{
// get the flush tree
$tree
=
$this
->
buildFlushTree
(
$this
->
conn
->
getTables
());
// save all records
foreach
(
$tree
as
$name
)
{
$table
=
$this
->
conn
->
getTable
(
$name
);
foreach
(
$table
->
getRepository
()
as
$record
)
{
$this
->
conn
->
save
(
$record
);
}
}
// save all associations
foreach
(
$tree
as
$name
)
{
$table
=
$this
->
conn
->
getTable
(
$name
);
foreach
(
$table
->
getRepository
()
as
$record
)
{
$this
->
saveAssociations
(
$record
);
}
}
}
public
function
getIterator
()
{
}
public
function
count
()
{
}
...
...
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