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
94ba3d35
Commit
94ba3d35
authored
Feb 08, 2014
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-787' into 2.4
parents
1b90a2eb
be2c7033
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+11
-3
ModifyLimitQueryTest.php
...s/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php
+14
-0
No files found.
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
94ba3d35
...
@@ -809,9 +809,17 @@ class SQLServerPlatform extends AbstractPlatform
...
@@ -809,9 +809,17 @@ class SQLServerPlatform extends AbstractPlatform
$query
=
preg_replace
(
'/\s+ORDER\s+BY\s+([^\)]*)/'
,
''
,
$query
);
//Remove ORDER BY from $query
$query
=
preg_replace
(
'/\s+ORDER\s+BY\s+([^\)]*)/'
,
''
,
$query
);
//Remove ORDER BY from $query
$format
=
'SELECT * FROM (%s) AS doctrine_tbl WHERE doctrine_rownum BETWEEN %d AND %d'
;
$format
=
'SELECT * FROM (%s) AS doctrine_tbl WHERE doctrine_rownum BETWEEN %d AND %d'
;
// Pattern to match "main" SELECT ... FROM clause (including nested parentheses in select list).
$selectFromPattern
=
'/^(\s*SELECT\s+(?:\((?>[^()]+)|(?:R)*\)|[^(])+)\sFROM\s/i'
;
if
(
!
$orderBy
)
{
if
(
!
$orderBy
)
{
//Replace only first occurrence of FROM with OVER to prevent changing FROM also in subqueries.
//Replace only "main" FROM with OVER to prevent changing FROM also in subqueries.
$query
=
preg_replace
(
'/\sFROM\s/i'
,
', ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM '
,
$query
,
1
);
$query
=
preg_replace
(
$selectFromPattern
,
'$1, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM '
,
$query
,
1
);
return
sprintf
(
$format
,
$query
,
$start
,
$end
);
return
sprintf
(
$format
,
$query
,
$start
,
$end
);
}
}
...
@@ -853,7 +861,7 @@ class SQLServerPlatform extends AbstractPlatform
...
@@ -853,7 +861,7 @@ class SQLServerPlatform extends AbstractPlatform
//Replace only first occurrence of FROM with $over to prevent changing FROM also in subqueries.
//Replace only first occurrence of FROM with $over to prevent changing FROM also in subqueries.
$over
=
'ORDER BY '
.
implode
(
', '
,
$overColumns
);
$over
=
'ORDER BY '
.
implode
(
', '
,
$overColumns
);
$query
=
preg_replace
(
'/\sFROM\s/i'
,
"
, ROW_NUMBER() OVER (
$over
) AS doctrine_rownum FROM "
,
$query
,
1
);
$query
=
preg_replace
(
$selectFromPattern
,
"$1
, ROW_NUMBER() OVER (
$over
) AS doctrine_rownum FROM "
,
$query
,
1
);
return
sprintf
(
$format
,
$query
,
$start
,
$end
);
return
sprintf
(
$format
,
$query
,
$start
,
$end
);
}
}
...
...
tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php
View file @
94ba3d35
...
@@ -102,6 +102,20 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -102,6 +102,20 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertLimitResult
(
array
(
2
),
$sql
,
1
,
1
);
$this
->
assertLimitResult
(
array
(
2
),
$sql
,
1
,
1
);
}
}
public
function
testModifyLimitQuerySubSelect
()
{
$this
->
_conn
->
insert
(
'modify_limit_table'
,
array
(
'test_int'
=>
1
));
$this
->
_conn
->
insert
(
'modify_limit_table'
,
array
(
'test_int'
=>
2
));
$this
->
_conn
->
insert
(
'modify_limit_table'
,
array
(
'test_int'
=>
3
));
$this
->
_conn
->
insert
(
'modify_limit_table'
,
array
(
'test_int'
=>
4
));
$sql
=
"SELECT *, (SELECT COUNT(*) FROM modify_limit_table) AS cnt FROM modify_limit_table"
;
$this
->
assertLimitResult
(
array
(
4
,
3
,
2
,
1
),
$sql
,
10
,
0
,
false
);
$this
->
assertLimitResult
(
array
(
4
,
3
),
$sql
,
2
,
0
,
false
);
$this
->
assertLimitResult
(
array
(
2
,
1
),
$sql
,
2
,
2
,
false
);
}
public
function
assertLimitResult
(
$expectedResults
,
$sql
,
$limit
,
$offset
,
$deterministic
=
true
)
public
function
assertLimitResult
(
$expectedResults
,
$sql
,
$limit
,
$offset
,
$deterministic
=
true
)
{
{
$p
=
$this
->
_conn
->
getDatabasePlatform
();
$p
=
$this
->
_conn
->
getDatabasePlatform
();
...
...
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