|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ZendIntegrationTest\Db\Adapter\Driver\Oci8; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Zend\Db\Adapter\Adapter; |
| 7 | +use Zend\Db\Adapter\ParameterContainer; |
| 8 | +use Zend\Db\TableGateway\TableGateway; |
| 9 | + |
| 10 | +class TableGatewayTest extends TestCase |
| 11 | +{ |
| 12 | + use TraitSetup; |
| 13 | + |
| 14 | + /** |
| 15 | + * @see https://github.com/zendframework/zend-db/issues/330 |
| 16 | + */ |
| 17 | + public function testSelectWithEmptyCurrentWithBufferResult() |
| 18 | + { |
| 19 | + $adapter = new Adapter([ |
| 20 | + 'driver' => 'OCI8', |
| 21 | + 'connection_string' => $this->variables['connectionstring'], |
| 22 | + 'username' => $this->variables['username'], |
| 23 | + 'password' => $this->variables['password'], |
| 24 | + 'character_set' => $this->variables['charset'], |
| 25 | + 'options' => ['buffer_results' => true] |
| 26 | + ]); |
| 27 | + $tableGateway = new TableGateway('TEST', $adapter); |
| 28 | + $rowset = $tableGateway->select('ID = 0'); |
| 29 | + |
| 30 | + $this->assertNull($rowset->current()); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @see https://github.com/zendframework/zend-db/issues/330 |
| 35 | + */ |
| 36 | + public function testSelectWithEmptyCurrentWithoutBufferResult() |
| 37 | + { |
| 38 | + $adapter = new Adapter([ |
| 39 | + 'driver' => 'OCI8', |
| 40 | + 'connection_string' => $this->variables['connectionstring'], |
| 41 | + 'username' => $this->variables['username'], |
| 42 | + 'password' => $this->variables['password'], |
| 43 | + 'character_set' => $this->variables['charset'], |
| 44 | + 'options' => ['buffer_results' => false] |
| 45 | + ]); |
| 46 | + $tableGateway = new TableGateway('TEST', $adapter); |
| 47 | + $rowset = $tableGateway->select('ID = 0'); |
| 48 | + |
| 49 | + $this->assertNull($rowset->current()); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @see https://github.com/zendframework/zend-db/pull/396 |
| 54 | + */ |
| 55 | + public function testBlobWithOci8() |
| 56 | + { |
| 57 | + $adapter = new Adapter([ |
| 58 | + 'driver' => 'OCI8', |
| 59 | + 'connection_string' => $this->variables['connectionstring'], |
| 60 | + 'username' => $this->variables['username'], |
| 61 | + 'password' => $this->variables['password'], |
| 62 | + 'character_set' => $this->variables['charset'], |
| 63 | + 'options' => ['buffer_results' => false] |
| 64 | + ]); |
| 65 | + $tableGateway = new TableGateway('TEST', $adapter); |
| 66 | + |
| 67 | + $blob = 'very long sentence that is in fact not very long that tests blob'; |
| 68 | + |
| 69 | + $data = new ParameterContainer(); |
| 70 | + $data->setFromArray(['CONTENT_BLOB' => $blob]); |
| 71 | + $data->offsetSetErrata('CONTENT_BLOB', ParameterContainer::TYPE_BLOB); |
| 72 | + |
| 73 | + $sql = "UPDATE TEST SET CONTENT_BLOB= :CONTENT_BLOB WHERE ID = 1"; |
| 74 | + $stm = $tableGateway->getAdapter()->getDriver()->createStatement($sql); |
| 75 | + $stm->setParameterContainer($data); |
| 76 | + $stm->execute(); |
| 77 | + |
| 78 | + $rowset = $tableGateway->select('ID = 1')->current(); |
| 79 | + |
| 80 | + $this->assertInstanceOf('OCI-Lob', $rowset['CONTENT_BLOB']); |
| 81 | + $value = $rowset['CONTENT_BLOB']->read($rowset['CONTENT_BLOB']->size()); |
| 82 | + $this->assertEquals($blob, $value); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @see https://github.com/zendframework/zend-db/pull/396 |
| 87 | + */ |
| 88 | + public function testClobWithOci8() |
| 89 | + { |
| 90 | + $adapter = new Adapter([ |
| 91 | + 'driver' => 'OCI8', |
| 92 | + 'connection_string' => $this->variables['connectionstring'], |
| 93 | + 'username' => $this->variables['username'], |
| 94 | + 'password' => $this->variables['password'], |
| 95 | + 'character_set' => $this->variables['charset'], |
| 96 | + 'options' => ['buffer_results' => false] |
| 97 | + ]); |
| 98 | + $tableGateway = new TableGateway('TEST', $adapter); |
| 99 | + |
| 100 | + $clob = 'very long sentence that is in fact not very long that tests clob'; |
| 101 | + |
| 102 | + $data = new ParameterContainer(); |
| 103 | + $data->setFromArray(['CONTENT_CLOB' => $clob]); |
| 104 | + $data->offsetSetErrata('CONTENT_CLOB', ParameterContainer::TYPE_CLOB); |
| 105 | + |
| 106 | + $sql = "UPDATE TEST SET CONTENT_CLOB= :CONTENT_CLOB WHERE ID = 1"; |
| 107 | + $stm = $tableGateway->getAdapter()->getDriver()->createStatement($sql); |
| 108 | + $stm->setParameterContainer($data); |
| 109 | + $stm->execute(); |
| 110 | + |
| 111 | + $rowset = $tableGateway->select('ID = 1')->current(); |
| 112 | + |
| 113 | + $this->assertInstanceOf('OCI-Lob', $rowset['CONTENT_CLOB']); |
| 114 | + $value = $rowset['CONTENT_CLOB']->read($rowset['CONTENT_CLOB']->size()); |
| 115 | + $this->assertEquals($clob, $value); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * @see https://github.com/zendframework/zend-db/pull/396 |
| 120 | + */ |
| 121 | + public function testLobWithOci8() |
| 122 | + { |
| 123 | + $adapter = new Adapter([ |
| 124 | + 'driver' => 'OCI8', |
| 125 | + 'connection_string' => $this->variables['connectionstring'], |
| 126 | + 'username' => $this->variables['username'], |
| 127 | + 'password' => $this->variables['password'], |
| 128 | + 'character_set' => $this->variables['charset'], |
| 129 | + 'options' => ['buffer_results' => false] |
| 130 | + ]); |
| 131 | + $tableGateway = new TableGateway('TEST', $adapter); |
| 132 | + |
| 133 | + $clob = 'very long sentence that is in fact not very long that tests lob'; |
| 134 | + |
| 135 | + $data = new ParameterContainer(); |
| 136 | + $data->setFromArray(['CONTENT_CLOB' => $clob]); |
| 137 | + $data->offsetSetErrata('CONTENT_CLOB', ParameterContainer::TYPE_LOB); |
| 138 | + |
| 139 | + $sql = "UPDATE TEST SET CONTENT_CLOB= :CONTENT_CLOB WHERE ID = 2"; |
| 140 | + $stm = $tableGateway->getAdapter()->getDriver()->createStatement($sql); |
| 141 | + $stm->setParameterContainer($data); |
| 142 | + $stm->execute(); |
| 143 | + |
| 144 | + $rowset = $tableGateway->select('ID = 2')->current(); |
| 145 | + |
| 146 | + $this->assertInstanceOf('OCI-Lob', $rowset['CONTENT_CLOB']); |
| 147 | + $value = $rowset['CONTENT_CLOB']->read($rowset['CONTENT_CLOB']->size()); |
| 148 | + $this->assertEquals($clob, $value); |
| 149 | + } |
| 150 | +} |
0 commit comments