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
c24ecd7b
Commit
c24ecd7b
authored
Sep 12, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved nativequery
parent
77fefcbd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
NativeQuery.php
lib/Doctrine/ORM/NativeQuery.php
+92
-0
No files found.
lib/Doctrine/ORM/NativeQuery.php
0 → 100644
View file @
c24ecd7b
<?php
#namespace Doctrine::ORM;
/**
* @todo Migrate the old RawSql to NativeQuery.
* Use JPA/Hibernate NativeQuerys as a role-model.
*/
class
Doctrine_NativeQuery
{
private
static
$_placeHolderPattern
=
'#\{([a-z][a-z0-9_]*)\.(\*|[a-z][a-z0-9_]*)\}#i'
;
private
$_sql
;
private
$_conn
;
private
$_params
=
array
();
private
$_entities
=
array
();
private
$_placeholders
=
array
();
private
$_usedEntityAliases
=
array
();
private
$_usedFields
=
array
();
public
function
__construct
(
$sql
,
Doctrine_Connection
$conn
)
{
$numMatches
=
preg_match_all
(
self
::
$_placeHolderPattern
,
$sql
,
$matches
);
$this
->
_placeHolders
=
$matches
[
0
];
$this
->
_usedEntityAliases
=
$matches
[
1
];
$this
->
_usedFields
=
$matches
[
2
];
$this
->
_sql
=
$sql
;
$this
->
_conn
=
$conn
;
}
private
function
_parse
()
{
// replace placeholders in $sql with generated names
for
(
$i
=
0
;
$i
<
count
(
$this
->
_placeholders
);
$i
++
)
{
$entityClassName
=
$this
->
_entities
[
$this
->
_usedEntityAliases
[
$i
]];
$entityClass
=
$this
->
_conn
->
getClassMetadata
(
$entityClassName
);
$columnName
=
$entityClass
->
getColumnName
(
$this
->
_usedFields
[
$i
]);
$tableName
=
$entityClass
->
getTableName
();
$replacement
=
$tableName
.
'.'
.
$columnName
.
' AS '
.
$this
->
_generateColumnAlias
(
$columnName
,
$tableName
);
$sql
=
str_replace
(
$this
->
_placeholders
[
$i
],
$replacement
,
$sql
);
}
}
private
function
_generateColumnAlias
(
$columnName
,
$tableName
)
{
return
$tableName
.
'__'
.
$columnName
;
}
/*public function addScalar()
{
}*/
public
function
addEntity
(
$alias
,
$className
)
{
$this
->
_entities
[
$alias
]
=
$className
;
}
public
function
addJoin
(
$join
)
{
}
public
function
setParameter
(
$key
,
$value
)
{
$this
->
_params
[
$key
]
=
$value
;
}
public
function
addParameter
(
$value
)
{
$this
->
_params
[]
=
$value
;
}
public
function
execute
(
array
$params
)
{
if
(
$this
->
_entities
)
{
//...
}
else
{
return
$this
->
_conn
->
execute
(
$this
->
_sql
,
array_merge
(
$this
->
_params
,
$params
));
}
}
public
function
executeUpdate
(
array
$params
)
{
return
$this
->
_conn
->
exec
(
$this
->
_sql
,
array_merge
(
$this
->
_params
,
$params
));
}
}
\ No newline at end of file
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