Skip to content
Permalink
Browse files

Fix blob reading in SQLServer

VARBINARY fields in SQLServer come back as hexadecimal encoded strings.
In order for these to be useful, they need to be converted into
resources like other blobby things.

This should fix that AppVeyor builds as well.
  • Loading branch information...
markstory committed May 13, 2015
1 parent c7c32b6 commit 5bd710f200db30f88c9338600472087c7d1b4211
Showing with 7 additions and 0 deletions.
  1. +3 −0 src/Database/Type/BinaryType.php
  2. +4 −0 tests/TestCase/Database/Type/BinaryTypeTest.php
@@ -55,6 +55,9 @@ public function toPHP($value, Driver $driver)
if ($value === null) {
return null;
}
if (is_string($value) && preg_match('/^[a-zA-Z0-9]+$/', $value)) {
$value = pack('H*', $value);
}
if (is_string($value)) {
return fopen('data:text/plain;base64,' . base64_encode($value), 'rb');
}
@@ -46,6 +46,10 @@ public function testToPHP()
{
$this->assertNull($this->type->toPHP(null, $this->driver));
$result = $this->type->toPHP('536F6D652076616C7565', $this->driver);
$this->assertInternalType('resource', $result);
$this->assertSame('Some value', stream_get_contents($result));
$result = $this->type->toPHP('some data', $this->driver);
$this->assertInternalType('resource', $result);

0 comments on commit 5bd710f

Please sign in to comment.
You can’t perform that action at this time.