Skip to content

Commit 954101c

Browse files
staabmclxmstaab
andauthored
don't report placeholder errors on non-SELECT statements for now (#153)
Co-authored-by: Markus Staab <[email protected]>
1 parent 25e9c67 commit 954101c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/QueryReflection/PlaceholderValidation.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ final class PlaceholderValidation
1313
*/
1414
public function checkErrors(string $queryString, array $parameters): iterable
1515
{
16+
if ('SELECT' !== QueryReflection::getQueryType($queryString)) {
17+
return;
18+
}
19+
1620
$queryReflection = new QueryReflection();
1721
$placeholderCount = $queryReflection->countPlaceholders($queryString);
1822

src/QueryReflection/QueryReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function resolveQueryString(Expr $queryExpr, Scope $scope): ?string
152152
return QuerySimulation::simulateParamValueType($type);
153153
}
154154

155-
private function getQueryType(string $query): ?string
155+
public static function getQueryType(string $query): ?string
156156
{
157157
$query = ltrim($query);
158158

tests/data/syntax-error-in-prepared-statement.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,30 @@ public function arrayParam(Connection $connection)
173173
$query = 'SELECT email FROM ada WHERE adaid IN (:adaids)';
174174
$connection->preparedQuery($query, ['adaids' => [1, 2, 3]]);
175175
}
176+
177+
public function noErrorInBug94(Connection $connection)
178+
{
179+
// XXX with proper sql parsing, we should better detect the placeholders and therefore could validate this query
180+
$sql = "
181+
INSERT IGNORE INTO `s_articles_supplier` (`id`, `name`, `img`, `link`, `changed`) VALUES (:supplierId, 'TestSupplier', '', '', '2019-12-09 10:42:10');
182+
183+
INSERT INTO `s_articles` (`id`, `supplierID`, `name`, `datum`, `taxID`, `changetime`, `pricegroupID`, `pricegroupActive`, `filtergroupID`, `laststock`, `crossbundlelook`, `notification`, `template`, `mode`) VALUES
184+
(:productId, :supplierId, 'SwagTest', '2020-03-20', '1', '2020-03-20 10:42:10', NULL, '0', NULL, '0', '0', '0', '', '0');
185+
186+
INSERT IGNORE INTO `s_order` (`id`, `ordernumber`, `userID`, `invoice_amount`, `invoice_amount_net`, `invoice_shipping`, `invoice_shipping_net`, `ordertime`, `status`, `cleared`, `paymentID`, `transactionID`, `comment`, `customercomment`, `internalcomment`, `net`, `taxfree`, `partnerID`, `temporaryID`, `referer`, `cleareddate`, `trackingcode`, `language`, `dispatchID`, `currency`, `currencyFactor`, `subshopID`, `remote_addr`) VALUES
187+
(:orderId, '29996', 1, 126.82, 106.57, 3.9, 3.28, '2013-07-10 08:17:20', 0, 17, 5, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'EUR', 1, 1, '172.16.10.71');
188+
189+
INSERT IGNORE INTO `s_order_details` (`id`, `orderID`, `ordernumber`, `articleID`, `articleordernumber`, `price`, `quantity`, `name`, `status`, `shipped`, `shippedgroup`, `releasedate`, `modus`, `esdarticle`, `taxID`, `tax_rate`, `config`) VALUES
190+
(15315352, :orderId, '20003', :productId, 'SW10178', 19.95, 1, 'Strandtuch Ibiza', 0, 0, 0, '0000-00-00', 0, 0, 1, 19, ''),
191+
(15315353, :orderId, '20003', 177, 'SW10177', 34.99, 1, 'Strandtuch Stripes für Kinder', 0, 0, 0, '0000-00-00', 0, 0, 1, 19, ''),
192+
(15315354, :orderId, '20003', 173, 'SW10173', 39.99, 1, 'Strandkleid Flower Power', 0, 0, 0, '0000-00-00', 0, 0, 1, 19, ''),
193+
(15315355, :orderId, '20003', 160, 'SW10160.1', 29.99, 1, 'Sommer Sandale Ocean Blue 36', 0, 0, 0, '0000-00-00', 0, 0, 1, 19, ''),
194+
(15315356, :orderId, '20003', 0, 'SHIPPINGDISCOUNT', -2, 1, 'Warenkorbrabatt', 0, 0, 0, '0000-00-00', 4, 0, 0, 19, '');
195+
";
196+
197+
$supplierId = '81729';
198+
$productId = 91829002;
199+
$orderId = 15315351;
200+
$connection->preparedQuery($sql, ['orderId' => $orderId, 'productId' => $productId, 'supplierId' => $supplierId]);
201+
}
176202
}

0 commit comments

Comments
 (0)