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
bd319580
Commit
bd319580
authored
Nov 10, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drafting the initial CTI support
parent
c6a0dd65
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
172 additions
and
77 deletions
+172
-77
Connection.php
lib/Doctrine/Connection.php
+3
-3
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+65
-58
Query.php
lib/Doctrine/Query.php
+65
-6
Record.php
lib/Doctrine/Record.php
+20
-9
Table.php
lib/Doctrine/Table.php
+19
-1
No files found.
lib/Doctrine/Connection.php
View file @
bd319580
...
...
@@ -514,15 +514,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$tmp
=
array
();
foreach
(
array_keys
(
$identifier
)
as
$id
)
{
$tmp
[]
=
$id
.
' = ?
'
;
$tmp
[]
=
$id
.
' = ?'
;
}
$query
=
'DELETE FROM '
.
$this
->
conn
->
quoteIdentifier
(
$table
)
.
$this
->
quoteIdentifier
(
$table
)
.
' WHERE '
.
implode
(
' AND '
,
$tmp
);
return
$this
->
conn
->
exec
(
$query
,
array_values
(
$identifier
));
return
$this
->
exec
(
$query
,
array_values
(
$identifier
));
}
/**
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
bd319580
...
...
@@ -267,7 +267,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record
->
preDelete
(
$event
);
$record
->
getTable
()
->
getRecordListener
()
->
preDelete
(
$event
);
$table
=
$record
->
getTable
();
$table
->
getRecordListener
()
->
preDelete
(
$event
);
$state
=
$record
->
state
();
...
...
@@ -277,8 +279,15 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if
(
!
$event
->
skipOperation
)
{
$record
->
state
(
Doctrine_Record
::
STATE_TDIRTY
);
if
(
count
(
$table
->
getOption
(
'joinedParents'
))
>
0
)
{
$this
->
deleteRecord
(
$record
);
foreach
(
$table
->
getOption
(
'joinedParents'
)
as
$parent
)
{
$parentTable
=
$table
->
getConnection
()
->
getTable
(
$parent
);
$this
->
conn
->
delete
(
$parentTable
->
getTableName
(),
$record
->
identifier
());
}
}
$this
->
conn
->
delete
(
$table
->
getTableName
(),
$record
->
identifier
());
$record
->
state
(
Doctrine_Record
::
STATE_TCLEAN
);
}
else
{
...
...
@@ -287,11 +296,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
$
record
->
getTable
()
->
getRecordListener
()
->
postDelete
(
$event
);
$
table
->
getRecordListener
()
->
postDelete
(
$event
);
$record
->
postDelete
(
$event
);
$
record
->
getTable
()
->
removeRecord
(
$record
);
$
table
->
removeRecord
(
$record
);
$this
->
conn
->
commit
();
...
...
@@ -507,8 +516,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
/**
* update
* updates the given record
* updates given record
*
* @param Doctrine_Record $record record to be updated
* @return boolean whether or not the update was successful
...
...
@@ -519,60 +527,49 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record
->
preUpdate
(
$event
);
$record
->
getTable
()
->
getRecordListener
()
->
preUpdate
(
$event
);
$table
=
$record
->
getTable
();
$table
->
getRecordListener
()
->
preUpdate
(
$event
);
if
(
!
$event
->
skipOperation
)
{
$
array
=
$record
->
getPrepared
();
$
identifier
=
$record
->
identifier
();
if
(
empty
(
$array
))
{
return
false
;
}
$set
=
array
();
foreach
(
$array
as
$name
=>
$value
)
{
if
(
$value
instanceof
Doctrine_Expression
)
{
$set
[]
=
$name
.
' = '
.
$value
->
getSql
();
unset
(
$array
[
$name
]);
}
else
{
$set
[]
=
$name
.
' = ?'
;
if
(
count
(
$table
->
getOption
(
'joinedParents'
))
>
0
)
{
$dataSet
=
$this
->
formatDataSet
(
$record
);
$component
=
$table
->
getComponentName
();
$classes
=
$table
->
getOption
(
'joinedParents'
);
$classes
[]
=
$component
;
foreach
(
$record
as
$field
=>
$value
)
{
if
(
$value
instanceof
Doctrine_Record
)
{
if
(
!
$value
->
exists
())
{
$
record
->
save
(
$this
->
conn
);
$
value
->
save
(
);
}
$array
[
$name
]
=
$value
->
getIncremented
();
$record
->
set
(
$name
,
$value
->
getIncremented
());
$record
->
set
(
$field
,
$value
->
getIncremented
());
}
}
}
$params
=
array_values
(
$array
);
$id
=
$record
->
identifier
();
if
(
!
is_array
(
$id
))
{
$id
=
array
(
$id
);
foreach
(
$classes
as
$class
)
{
$parentTable
=
$this
->
conn
->
getTable
(
$class
);
$this
->
conn
->
update
(
$this
->
conn
->
getTable
(
$class
)
->
getTableName
(),
$dataSet
[
$class
],
$identifier
);
}
}
else
{
$array
=
$record
->
getPrepared
();
$this
->
conn
->
update
(
$table
->
getTableName
(),
$array
,
$identifier
);
}
$id
=
array_values
(
$id
);
$params
=
array_merge
(
$params
,
$id
);
$sql
=
'UPDATE '
.
$this
->
conn
->
quoteIdentifier
(
$record
->
getTable
()
->
getTableName
())
.
' SET '
.
implode
(
', '
,
$set
)
.
' WHERE '
.
implode
(
' = ? AND '
,
(
array
)
$record
->
getTable
()
->
getIdentifier
())
.
' = ?'
;
$stmt
=
$this
->
conn
->
prepare
(
$sql
);
$stmt
->
execute
(
$params
);
$record
->
assignIdentifier
(
true
);
}
$
record
->
getTable
()
->
getRecordListener
()
->
postUpdate
(
$event
);
$
table
->
getRecordListener
()
->
postUpdate
(
$event
);
$record
->
postUpdate
(
$event
);
return
true
;
}
/**
* inserts a record into database
*
...
...
@@ -592,24 +589,10 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if
(
!
$event
->
skipOperation
)
{
if
(
count
(
$table
->
getOption
(
'joinedParents'
))
>
0
)
{
$dataSet
=
array
(
);
$dataSet
=
$this
->
formatDataSet
(
$record
);
$component
=
$table
->
getComponentName
();
$array
=
$record
->
getPrepared
();
foreach
(
$table
->
getColumns
()
as
$column
=>
$definition
)
{
if
(
isset
(
$definition
[
'primary'
])
&&
$definition
[
'primary'
])
{
continue
;
}
if
(
isset
(
$definition
[
'owner'
]))
{
$dataSet
[
$definition
[
'owner'
]][
$column
]
=
$array
[
$column
];
}
else
{
$dataSet
[
$component
][
$column
]
=
$array
[
$column
];
}
}
$classes
=
$table
->
getOption
(
'joinedParents'
);
$classes
[]
=
$component
;
...
...
@@ -641,6 +624,30 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return
true
;
}
public
function
formatDataSet
(
Doctrine_Record
$record
)
{
$table
=
$record
->
getTable
();
$dataSet
=
array
();
$component
=
$table
->
getComponentName
();
$array
=
$record
->
getPrepared
();
foreach
(
$table
->
getColumns
()
as
$column
=>
$definition
)
{
if
(
isset
(
$definition
[
'primary'
])
&&
$definition
[
'primary'
])
{
continue
;
}
if
(
isset
(
$definition
[
'owner'
]))
{
$dataSet
[
$definition
[
'owner'
]][
$column
]
=
$array
[
$column
];
}
else
{
$dataSet
[
$component
][
$column
]
=
$array
[
$column
];
}
}
return
$dataSet
;
}
public
function
processSingleInsert
(
Doctrine_Record
$record
)
{
$array
=
$record
->
getPrepared
();
...
...
lib/Doctrine/Query.php
View file @
bd319580
...
...
@@ -453,11 +453,27 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
$sql
=
array
();
foreach
(
$fields
as
$name
)
{
$name
=
$table
->
getColumnName
(
$name
);
if
((
$owner
=
$table
->
getColumnOwner
(
$name
))
!==
null
&&
$owner
!==
$table
->
getComponentName
())
{
$sql
[]
=
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
.
'.'
.
$name
)
.
' AS '
.
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
.
'__'
.
$name
);
$parent
=
$this
->
_conn
->
getTable
(
$owner
);
$name
=
$parent
->
getColumnName
(
$name
);
$parentAlias
=
$this
->
getTableAlias
(
$componentAlias
.
'.'
.
$parent
->
getComponentName
());
$sql
[]
=
$this
->
_conn
->
quoteIdentifier
(
$parentAlias
.
'.'
.
$name
)
.
' AS '
.
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
.
'__'
.
$name
);
}
else
{
$name
=
$table
->
getColumnName
(
$name
);
$sql
[]
=
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
.
'.'
.
$name
)
.
' AS '
.
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
.
'__'
.
$name
);
}
}
$this
->
_neededTables
[]
=
$tableAlias
;
...
...
@@ -1643,8 +1659,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
.
' = '
.
$this
->
_conn
->
quoteIdentifier
(
$foreignAlias
.
'.'
.
$relation
->
getForeign
());
}
}
$queryPart
.=
$this
->
buildInheritanceJoinSql
(
$table
->
getComponentName
(),
$componentAlias
);
$this
->
parts
[
'from'
][
$componentAlias
]
=
$queryPart
;
if
(
!
empty
(
$joinCondition
))
{
$this
->
_pendingJoinConditions
[
$componentAlias
]
=
$joinCondition
;
...
...
@@ -1708,13 +1726,54 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if
(
$this
->
type
===
self
::
SELECT
)
{
$queryPart
.=
' '
.
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
);
}
$this
->
tableAliases
[
$tableAlias
]
=
$componentAlias
;
$queryPart
.=
$this
->
buildInheritanceJoinSql
(
$name
,
$componentAlias
);
$this
->
parts
[
'from'
][]
=
$queryPart
;
$this
->
tableAliases
[
$tableAlias
]
=
$componentAlias
;
$this
->
_aliasMap
[
$componentAlias
]
=
array
(
'table'
=>
$table
,
'map'
=>
null
);
return
$table
;
}
public
function
buildInheritanceJoinSql
(
$name
,
$componentAlias
)
{
// get the connection for the component
$this
->
_conn
=
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$name
);
$table
=
$this
->
_conn
->
getTable
(
$name
);
$tableName
=
$table
->
getTableName
();
// get the short alias for this table
$tableAlias
=
$this
->
getTableAlias
(
$componentAlias
,
$tableName
);
$queryPart
=
''
;
foreach
(
$table
->
getOption
(
'joinedParents'
)
as
$parent
)
{
$parentTable
=
$this
->
_conn
->
getTable
(
$parent
);
$parentAlias
=
$componentAlias
.
'.'
.
$parent
;
// get the short alias for the parent table
$parentTableAlias
=
$this
->
getTableAlias
(
$parentAlias
,
$parentTable
->
getTableName
());
$queryPart
.=
' LEFT JOIN '
.
$this
->
_conn
->
quoteIdentifier
(
$parentTable
->
getTableName
())
.
' '
.
$this
->
_conn
->
quoteIdentifier
(
$parentTableAlias
)
.
' ON '
;
foreach
((
array
)
$table
->
getIdentifier
()
as
$identifier
)
{
$column
=
$table
->
getColumnName
(
$identifier
);
$queryPart
.=
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
)
.
'.'
.
$this
->
_conn
->
quoteIdentifier
(
$column
)
.
' = '
.
$this
->
_conn
->
quoteIdentifier
(
$parentTableAlias
)
.
'.'
.
$this
->
_conn
->
quoteIdentifier
(
$column
);
}
}
return
$queryPart
;
}
/**
* count
...
...
lib/Doctrine/Record.php
View file @
bd319580
...
...
@@ -239,6 +239,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
return
$this
->
_oid
;
}
public
function
oid
()
{
return
$this
->
_oid
;
}
/**
* isValid
...
...
@@ -1041,7 +1045,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* @param Doctrine_Connection $conn optional connection parameter
* @throws Doctrine_Connection_Exception if some of the key values was null
* @throws Doctrine_Connection_Exception if there were no key fields
* @throws
PDOException if something fails at PDO
level
* @throws
Doctrine_Connection_Exception if something fails at database
level
* @return integer number of rows affected
*/
public
function
replace
(
Doctrine_Connection
$conn
=
null
)
...
...
@@ -1066,6 +1070,16 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
return
$a
;
}
public
function
modifiedFields
()
{
$a
=
array
();
foreach
(
$this
->
_modified
as
$k
=>
$v
)
{
$a
[
$v
]
=
$this
->
_data
[
$v
];
}
return
$a
;
}
/**
* getPrepared
...
...
@@ -1472,7 +1486,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
if
(
isset
(
$values
[
$value
]))
{
$this
->
set
(
$value
,
$values
[
$value
]);
}
}
catch
(
Exception
$e
)
{
}
catch
(
Doctrine_
Exception
$e
)
{
// silence all exceptions
}
}
...
...
@@ -1522,12 +1536,6 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
return
$this
->
_node
;
}
public
function
unshiftFilter
(
Doctrine_Record_Filter
$filter
)
{
return
$this
->
_table
->
unshiftFilter
(
$filter
);
}
/**
* revert
* reverts this record to given version, this method only works if versioning plugin
...
...
@@ -1552,7 +1560,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
return
$this
;
}
public
function
unshiftFilter
(
Doctrine_Record_Filter
$filter
)
{
return
$this
->
_table
->
unshiftFilter
(
$filter
);
}
/**
* unlink
* removes links from this record to given records
...
...
lib/Doctrine/Table.php
View file @
bd319580
...
...
@@ -265,7 +265,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
$parent
===
$class
->
getName
())
{
continue
;
}
$ref
=
new
ReflectionClass
(
$parent
);
if
(
$ref
->
isAbstract
())
{
continue
;
}
$table
=
$this
->
_conn
->
getTable
(
$parent
);
$found
=
false
;
...
...
@@ -401,6 +405,20 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
}
}
public
function
getColumnOwner
(
$column
)
{
if
(
isset
(
$this
->
_columns
[
$column
][
'owner'
]))
{
return
$this
->
_columns
[
$column
][
'owner'
];
}
else
{
return
$this
->
getComponentName
();
}
}
public
function
isInheritedColumn
(
$column
)
{
return
(
isset
(
$this
->
_columns
[
$column
][
'owner'
]));
}
public
function
isIdentifier
(
$identifier
)
{
return
(
$identifier
===
$this
->
_identifier
||
...
...
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