From 434d73535fec033c29b69c1695729053aec2094a Mon Sep 17 00:00:00 2001 From: Boorinio Date: Tue, 13 May 2025 12:18:35 +0300 Subject: [PATCH] Limit query to 50k characters. --- composer.json | 3 ++- src/SqlSegment.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1beb33f..00291d8 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "require": { "php": ">=7.1", - "ext-json": "*" + "ext-json": "*", + "ext-mbstring": "*" }, "autoload": { diff --git a/src/SqlSegment.php b/src/SqlSegment.php index 0c2640f..879513f 100644 --- a/src/SqlSegment.php +++ b/src/SqlSegment.php @@ -84,6 +84,15 @@ public function setDatabaseVersion(string $databaseVersion) return $this; } + private function limitQueryLength(string $query, int $limit = 50000): string + { + if (mb_strwidth($query, 'UTF-8') <= $limit) { + return $query; + } + + return rtrim(mb_strimwidth($query, 0, $limit, '', 'UTF-8')); + } + /** * @param string $driverVersion * @return static @@ -112,7 +121,7 @@ public function setUser(string $user) */ public function setQuery(string $query) { - $this->query = $query; + $this->query = $this->limitQueryLength($query); return $this; }