1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; |
6
|
|
|
use Doctrine\DBAL\ParameterType; |
7
|
|
|
use Doctrine\DBAL\Schema\Table; |
8
|
|
|
use Doctrine\DBAL\Types\Type; |
9
|
|
|
use const CASE_LOWER; |
10
|
|
|
use function array_change_key_case; |
11
|
|
|
use function stream_get_contents; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @group DBAL-6 |
15
|
|
|
*/ |
16
|
|
|
class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase |
17
|
|
|
{ |
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
parent::setUp(); |
21
|
|
|
|
22
|
|
|
if ($this->_conn->getDriver() instanceof PDOSQLSrvDriver) { |
23
|
|
|
$this->markTestSkipped('This test does not work on pdo_sqlsrv driver due to a bug. See: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a755bdd-41e9-45cb-9166-c9da4475bb94/how-to-set-null-for-varbinarymax-using-bindvalue-using-pdosqlsrv?forum=sqldriverforphp'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ |
27
|
|
|
$table = new Table('blob_table'); |
28
|
|
|
$table->addColumn('id', 'integer'); |
29
|
|
|
$table->addColumn('clobfield', 'text'); |
30
|
|
|
$table->addColumn('blobfield', 'blob'); |
31
|
|
|
$table->setPrimaryKey(['id']); |
32
|
|
|
|
33
|
|
|
$sm = $this->_conn->getSchemaManager(); |
34
|
|
|
$sm->dropAndCreateTable($table); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testInsert() |
38
|
|
|
{ |
39
|
|
|
$ret = $this->_conn->insert('blob_table', [ |
40
|
|
|
'id' => 1, |
41
|
|
|
'clobfield' => 'test', |
42
|
|
|
'blobfield' => 'test', |
43
|
|
|
], [ |
44
|
|
|
ParameterType::INTEGER, |
45
|
|
|
ParameterType::STRING, |
46
|
|
|
ParameterType::LARGE_OBJECT, |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
self::assertEquals(1, $ret); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testSelect() |
53
|
|
|
{ |
54
|
|
|
$this->_conn->insert('blob_table', [ |
55
|
|
|
'id' => 1, |
56
|
|
|
'clobfield' => 'test', |
57
|
|
|
'blobfield' => 'test', |
58
|
|
|
], [ |
59
|
|
|
ParameterType::INTEGER, |
60
|
|
|
ParameterType::STRING, |
61
|
|
|
ParameterType::LARGE_OBJECT, |
62
|
|
|
]); |
63
|
|
|
|
64
|
|
|
$this->assertBlobContains('test'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testUpdate() |
68
|
|
|
{ |
69
|
|
|
$this->_conn->insert('blob_table', [ |
70
|
|
|
'id' => 1, |
71
|
|
|
'clobfield' => 'test', |
72
|
|
|
'blobfield' => 'test', |
73
|
|
|
], [ |
74
|
|
|
ParameterType::INTEGER, |
75
|
|
|
ParameterType::STRING, |
76
|
|
|
ParameterType::LARGE_OBJECT, |
77
|
|
|
]); |
78
|
|
|
|
79
|
|
|
$this->_conn->update('blob_table', [ |
80
|
|
|
'blobfield' => 'test2', |
81
|
|
|
], ['id' => 1], [ |
82
|
|
|
ParameterType::LARGE_OBJECT, |
83
|
|
|
ParameterType::INTEGER, |
84
|
|
|
]); |
85
|
|
|
|
86
|
|
|
$this->assertBlobContains('test2'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function assertBlobContains($text) |
90
|
|
|
{ |
91
|
|
|
$rows = $this->_conn->fetchAll('SELECT * FROM blob_table'); |
92
|
|
|
|
93
|
|
|
self::assertCount(1, $rows); |
94
|
|
|
$row = array_change_key_case($rows[0], CASE_LOWER); |
95
|
|
|
|
96
|
|
|
$blobValue = Type::getType('blob')->convertToPHPValue($row['blobfield'], $this->_conn->getDatabasePlatform()); |
97
|
|
|
|
98
|
|
|
self::assertInternalType('resource', $blobValue); |
99
|
|
|
self::assertEquals($text, stream_get_contents($blobValue)); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|