3 namespace Doctrine\Tests\DBAL\Functional;
5 use Doctrine\DBAL\Types\Type;
6 use Doctrine\DBAL\Connection;
9 require_once __DIR__ . '/../../TestInit.php';
14 class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase
16 public function setUp()
21 /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
22 $table = new \Doctrine\DBAL\Schema\Table("blob_table");
23 $table->addColumn('id', 'integer');
24 $table->addColumn('clobfield', 'text');
25 $table->addColumn('blobfield', 'blob');
26 $table->setPrimaryKey(array('id'));
28 $sm = $this->_conn->getSchemaManager();
29 $sm->createTable($table);
30 } catch(\Exception $e) {
33 $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('blob_table'));
36 public function testInsert()
38 $ret = $this->_conn->insert('blob_table',
39 array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
40 array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
42 $this->assertEquals(1, $ret);
45 public function testSelect()
47 $ret = $this->_conn->insert('blob_table',
48 array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
49 array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
52 $this->assertBlobContains('test');
55 public function testUpdate()
57 $ret = $this->_conn->insert('blob_table',
58 array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
59 array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
62 $this->_conn->update('blob_table',
63 array('blobfield' => 'test2'),
65 array(\PDO::PARAM_LOB, \PDO::PARAM_INT)
68 $this->assertBlobContains('test2');
71 private function assertBlobContains($text)
73 $rows = $this->_conn->fetchAll('SELECT * FROM blob_table');
75 $this->assertEquals(1, count($rows));
76 $row = array_change_key_case($rows[0], CASE_LOWER);
78 $blobValue = Type::getType('blob')->convertToPHPValue($row['blobfield'], $this->_conn->getDatabasePlatform());
80 $this->assertInternalType('resource', $blobValue);
81 $this->assertEquals($text, stream_get_contents($blobValue));