Skip to content

Commit 4fca7e6

Browse files
committed
abstract isBinary() method
1 parent 0f0e630 commit 4fca7e6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

system/Database/BasePreparedQuery.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,12 @@ public function getErrorMessage(): string
259259
{
260260
return $this->errorString;
261261
}
262+
263+
/**
264+
* Whether the input contain binary data.
265+
*/
266+
protected function isBinary($input): bool
267+
{
268+
return mb_detect_encoding($input, 'UTF-8', true) === false;
269+
}
262270
}

system/Database/Postgre/PreparedQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function _execute(array $data): bool
8888
}
8989

9090
foreach ($data as &$item) {
91-
if (is_string($item) && mb_detect_encoding($item, 'UTF-8', true) === false) {
91+
if (is_string($item) && $this->isBinary($item)) {
9292
$item = pg_escape_bytea($this->db->connID, $item);
9393
}
9494
}

system/Database/SQLite3/PreparedQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function _execute(array $data): bool
7575
$bindType = SQLITE3_INTEGER;
7676
} elseif (is_float($item)) {
7777
$bindType = SQLITE3_FLOAT;
78-
} elseif (is_string($item) && mb_detect_encoding($item, 'UTF-8', true) === false) {
78+
} elseif (is_string($item) && $this->isBinary($item)) {
7979
$bindType = SQLITE3_BLOB;
8080
} else {
8181
$bindType = SQLITE3_TEXT;

0 commit comments

Comments
 (0)