Skip to content

Commit 76fea3a

Browse files
staabmclxmstaab
andauthored
support queries which acquire read locks (#179)
Co-authored-by: Markus Staab <[email protected]>
1 parent 47d8cce commit 76fea3a

File tree

5 files changed

+363
-3
lines changed

5 files changed

+363
-3
lines changed

.phpstan-dba.cache

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpunit-phpstan-dba.cache

Lines changed: 143 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QueryReflection/QuerySimulation.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,23 @@ public static function simulate(string $queryString): ?string
112112

113113
private static function stripTraillingLimit(string $queryString): ?string
114114
{
115+
// XXX someday we will use a proper SQL parser,
115116
$queryString = rtrim($queryString, ';');
116117

118+
// strip trailling FOR UPDATE/FOR SHARE
119+
$queryString = preg_replace('/(.*)FOR (UPDATE|SHARE)\s*$/i', '$1', $queryString);
120+
121+
if (null === $queryString) {
122+
throw new ShouldNotHappenException('Could not strip trailling FOR UPDATE/SHARE from query');
123+
}
124+
117125
// strip trailling OFFSET
118126
$queryString = preg_replace('/(.*)OFFSET\s+["\']?\d+["\']?\s*$/i', '$1', $queryString);
119127

120128
if (null === $queryString) {
121-
throw new ShouldNotHappenException('Could not strip trailing offset from query');
129+
throw new ShouldNotHappenException('Could not strip trailing OFFSET from query');
122130
}
123131

124-
// XXX someday we will use a proper SQL parser,
125-
// which would also allow us to support even more complex expressions like SELECT .. LIMIT X, Y FOR UPDATE
126132
return preg_replace('/\s*LIMIT\s+["\']?\d+["\']?\s*(,\s*["\']?\d*["\']?)?\s*$/i', '', $queryString);
127133
}
128134
}

0 commit comments

Comments
 (0)