Skip to content

Commit 0f0e630

Browse files
committed
tests
1 parent ae7912a commit 0f0e630

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

tests/_support/Database/Migrations/20160428212500_Create_test_tables.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,15 @@ public function up(): void
9191
}
9292

9393
if ($this->db->DBDriver === 'SQLSRV') {
94-
unset($dataTypeFields['type_timestamp']);
94+
unset($dataTypeFields['type_timestamp'], $dataTypeFields['type_blob']);
9595
$dataTypeFields['type_text'] = ['type' => 'NVARCHAR(max)', 'null' => true];
9696
}
9797

9898
if ($this->db->DBDriver === 'Postgre' || $this->db->DBDriver === 'SQLSRV') {
9999
unset(
100100
$dataTypeFields['type_set'],
101101
$dataTypeFields['type_mediumtext'],
102-
$dataTypeFields['type_double'],
103-
$dataTypeFields['type_blob']
102+
$dataTypeFields['type_double']
104103
);
105104
}
106105

tests/system/Database/Live/PreparedQueryTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,32 @@ public function testDeallocatePreparedQueryThenTryToClose(): void
272272

273273
public function testInsertBinaryData(): void
274274
{
275-
if ($this->db->DBDriver === 'Postgre' || $this->db->DBDriver === 'SQLSRV') {
276-
$this->markTestSkipped('Blob not supported for Postgre and SQLSRV.');
275+
$params = [];
276+
if ($this->db->DBDriver === 'SQLSRV') {
277+
$params = [0 => SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY)];
277278
}
278279

279280
$this->query = $this->db->prepare(static fn ($db) => $db->table('type_test')->insert([
280281
'type_blob' => 'binary',
281-
]));
282+
]), $params);
282283

283284
$fileContent = file_get_contents(TESTPATH . '_support/Images/EXIFsamples/landscape_0.jpg');
284285
$this->assertTrue($this->query->execute($fileContent));
285286

286-
$id = $this->db->insertId();
287-
$file = $this->db->table('type_test')->where('id', $id)->get()->getRow();
287+
$id = $this->db->insertId();
288+
$builder = $this->db->table('type_test');
289+
290+
if ($this->db->DBDriver === 'Postgre') {
291+
$file = $builder->select("ENCODE(type_blob, 'base64') AS type_blob")->where('id', $id)->get()->getRow();
292+
$file = base64_decode($file->type_blob, true);
293+
} elseif ($this->db->DBDriver === 'OCI8') {
294+
$file = $builder->select('type_blob')->where('id', $id)->get()->getRow();
295+
$file = $file->type_blob->load();
296+
} else {
297+
$file = $builder->select('type_blob')->where('id', $id)->get()->getRow();
298+
$file = $file->type_blob;
299+
}
288300

289-
$this->assertSame(strlen($fileContent), strlen($file->type_blob));
301+
$this->assertSame(strlen($fileContent), strlen($file));
290302
}
291303
}

0 commit comments

Comments
 (0)