diff --git a/test/DbTestCase.php b/test/DbTestCase.php index 167ca9f..e7e744b 100644 --- a/test/DbTestCase.php +++ b/test/DbTestCase.php @@ -106,6 +106,31 @@ public function testException(): void } } + public function testBlob(): void + { + $db = static::dbProvider(); + $img = file_get_contents('test/DevTheorem.png'); + + $id = $db->insertRow($this->table, [ + 'name' => 'DevTheorem', + 'dob' => '2024-10-24', + 'weight' => 0.0, + 'is_disabled' => false, + 'photo' => $db->makeBinaryParam($img), + ])->id; + + /** @var array{photo: string|resource} $row */ + $row = $db->selectFrom("SELECT photo FROM {$this->table}") + ->where(['user_id' => $id])->query()->getFirst(); + + if ($db->options->binarySelectedAsStream) { + /** @psalm-suppress PossiblyInvalidArgument */ + $row['photo'] = stream_get_contents($row['photo']); + } + + $this->assertSame(['photo' => $img], $row); + } + public function testIteratorQuery(): void { $peachySql = static::dbProvider(); @@ -124,8 +149,8 @@ public function testIteratorQuery(): void } $ids = $peachySql->insertRows($this->table, $insertColVals)->ids; - $iterator = $peachySql->selectFrom("SELECT * FROM {$this->table}") - ->where(['user_id' => $ids])->query()->getIterator(); + $sql = "SELECT user_id, name, dob, weight, is_disabled, uuid FROM {$this->table}"; + $iterator = $peachySql->selectFrom($sql)->where(['user_id' => $ids])->query()->getIterator(); $this->assertInstanceOf(\Generator::class, $iterator); $colValsCompare = []; diff --git a/test/DevTheorem.png b/test/DevTheorem.png new file mode 100644 index 0000000..cbf74fb Binary files /dev/null and b/test/DevTheorem.png differ diff --git a/test/MssqlDbTest.php b/test/MssqlDbTest.php index 9e44bb7..70bd6ae 100644 --- a/test/MssqlDbTest.php +++ b/test/MssqlDbTest.php @@ -67,12 +67,13 @@ private static function createTestTable(PeachySql $db): void $sql = " DROP TABLE IF EXISTS Users; CREATE TABLE Users ( - user_id INT PRIMARY KEY IDENTITY(1,1) NOT NULL, + user_id INT PRIMARY KEY IDENTITY NOT NULL, name NVARCHAR(50) NOT NULL, dob DATE NOT NULL, weight FLOAT NOT NULL, is_disabled BIT NOT NULL, - uuid BINARY(16) NULL + uuid BINARY(16) NULL, + photo VARBINARY(max) NULL )"; $db->query($sql); diff --git a/test/MysqlDbTest.php b/test/MysqlDbTest.php index 4e4c0fd..2e392c4 100644 --- a/test/MysqlDbTest.php +++ b/test/MysqlDbTest.php @@ -50,7 +50,8 @@ private static function createTestTable(PeachySql $db): void dob DATE NOT NULL, weight DOUBLE NOT NULL, is_disabled BOOLEAN NOT NULL, - uuid BINARY(16) NULL + uuid BINARY(16) NULL, + photo BLOB NULL )"; $db->query("DROP TABLE IF EXISTS Users"); diff --git a/test/PgsqlDbTest.php b/test/PgsqlDbTest.php index add4d46..bdff3fb 100644 --- a/test/PgsqlDbTest.php +++ b/test/PgsqlDbTest.php @@ -56,7 +56,8 @@ private static function createTestTable(PeachySql $db): void dob DATE NOT NULL, weight REAL NOT NULL, is_disabled BOOLEAN NOT NULL, - uuid bytea NULL + uuid bytea NULL, + photo bytea NULL )"; $db->query("DROP TABLE IF EXISTS Users");