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
4cb332fb
Commit
4cb332fb
authored
Jul 09, 2007
by
hansbrix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added method to properly quote IN (...) strings
Ticket: 383
parent
50b5ecc4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
6 deletions
+40
-6
Query.php
lib/Doctrine/Query.php
+40
-6
No files found.
lib/Doctrine/Query.php
View file @
4cb332fb
...
...
@@ -811,19 +811,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
case
'mysql'
:
// mysql doesn't support LIMIT in subqueries
$list
=
$this
->
_conn
->
execute
(
$subquery
,
$params
)
->
fetchAll
(
Doctrine
::
FETCH_COLUMN
);
$subquery
=
implode
(
', '
,
$list
);
$subquery
=
$this
->
inConditionFromArray
(
$list
);
break
;
case
'pgsql'
:
// pgsql needs special nested LIMIT subquery
$subquery
=
'
SELECT doctrine_subquery_alias.'
.
$table
->
getIdentifier
()
.
' FROM ('
.
$subquery
.
') AS doctrine_subquery_alias
'
;
$subquery
=
'
IN (SELECT doctrine_subquery_alias.'
.
$table
->
getIdentifier
()
.
' FROM ('
.
$subquery
.
') AS doctrine_subquery_alias)
'
;
break
;
}
$field
=
$this
->
getTableAlias
(
$rootAlias
)
.
'.'
.
$table
->
getIdentifier
();
// only append the subquery if it actually contains something
if
(
$subquery
!==
''
)
{
array_unshift
(
$this
->
parts
[
'where'
],
$this
->
_conn
->
quoteIdentifier
(
$field
)
.
' IN ('
.
$subquery
.
')'
);
if
(
$subquery
!==
''
)
{
array_unshift
(
$this
->
parts
[
'where'
],
$this
->
_conn
->
quoteIdentifier
(
$field
)
.
$subquery
);
}
$modifyLimit
=
false
;
...
...
@@ -983,7 +984,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
$subquery
=
implode
(
' '
,
$parts
);
return
$subquery
;
}
/**
...
...
@@ -1273,7 +1273,41 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
return
$this
->
_aliasMap
[
$componentAlias
];
}
}
/**
* inConditionFromArray
*
* explode array into quoted array (quick and dirty)
*
* @param array $values
*
* @return mixed - SQL list of conditions passed, or false if empty
*/
//TODO: check column type instead of first array value?
//TODO: is there cleaner value quoting as part of Doctrine somewhere?
public
function
inConditionFromArray
(
array
$values
)
{
if
(
empty
(
$values
))
return
false
;
$list_values
=
' IN ('
;
// is first value a string? then assume column is.
if
(
is_string
(
$values
[
0
]))
{
foreach
(
$values
as
&
$value
)
{
$value
=
'\''
.
$value
.
'\''
;
}
}
$list_values
.=
implode
(
', '
,
$values
);
$list_values
.=
')'
;
return
$list_values
;
}
/**
* loadRoot
*
...
...
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