[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/dbal/tests/cases/driver/oci/ -> lmbOciLobTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  require_once(dirname(__FILE__) . '/../DriverInsertTestBase.class.php');
  10  require_once(dirname(__FILE__) . '/fixture.inc.php');
  11  
  12  class lmbOciLobTest extends UnitTestCase
  13  {
  14    function setUp()
  15    {
  16      $this->connection = lmbToolkit :: instance()->getDefaultDbConnection();
  17      DriverOciSetup($this->connection->getConnectionId());
  18      parent::setUp();
  19    }
  20  
  21    function testInsertClob()
  22    {
  23      $value = file_get_contents(dirname(__FILE__) . '/../clob.txt');
  24  
  25      $sql = "
  26          INSERT INTO standard_types (
  27              type_clob,
  28              type_varchar
  29          ) VALUES (
  30              :a:,
  31              :b:
  32          )";
  33      $stmt = $this->connection->newStatement($sql);
  34  
  35      $stmt->setClob('a', $value);
  36      $stmt->set('b', 'junk');
  37      $stmt->execute();
  38  
  39      $stmt = $this->connection->newStatement("SELECT * FROM standard_types");
  40      $record = $stmt->getOneRecord();
  41      $this->assertEqual($record->get('type_clob'), $value);
  42      $this->assertEqual($record->get('type_varchar'), 'junk');
  43    }
  44  
  45    function testInsertBlob()
  46    {
  47      $value = file_get_contents(dirname(__FILE__) . '/../blob.jpg');
  48  
  49      $sql = "
  50          INSERT INTO standard_types (
  51              type_blob,
  52              type_varchar
  53          ) VALUES (
  54              :a:,
  55              :b:
  56          )";
  57      $stmt = $this->connection->newStatement($sql);
  58  
  59      $stmt->setBlob('a', $value);
  60      $stmt->set('b', 'junk');
  61      $stmt->execute();
  62  
  63      $stmt = $this->connection->newStatement("SELECT * FROM standard_types");
  64      $record = $stmt->getOneRecord();
  65      $this->assertEqual($record->get('type_blob'), $value);
  66      $this->assertEqual($record->get('type_varchar'), 'junk');
  67    }
  68  
  69    function testInsertBlobAndClob()
  70    {
  71      $blob = file_get_contents(dirname(__FILE__) . '/../blob.jpg');
  72      $clob = file_get_contents(dirname(__FILE__) . '/../clob.txt');
  73  
  74      $sql = "
  75          INSERT INTO standard_types (
  76              type_blob,
  77              type_varchar,
  78              type_clob
  79          ) VALUES (
  80              :a:,
  81              :b:,
  82              :c:
  83          )";
  84      $stmt = $this->connection->newStatement($sql);
  85  
  86      $stmt->setBlob('a', $blob);
  87      $stmt->set('b', 'junk');
  88      $stmt->setClob('c', $clob);
  89      $stmt->execute();
  90  
  91      $stmt = $this->connection->newStatement("SELECT * FROM standard_types");
  92      $record = $stmt->getOneRecord();
  93      $this->assertEqual($record->get('type_blob'), $blob);
  94      $this->assertEqual($record->get('type_varchar'), 'junk');
  95      $this->assertEqual($record->get('type_clob'), $clob);
  96    }
  97  
  98    function testUpdateClob()
  99    {
 100      $value = file_get_contents(dirname(__FILE__) . '/../clob.txt');
 101  
 102      $sql = "
 103          INSERT INTO standard_types (
 104              type_blob
 105          ) VALUES (
 106              :a:
 107          )";
 108      $stmt = $this->connection->newStatement($sql);
 109  
 110      $stmt->setBlob('a', $value);
 111      $stmt->execute();
 112  
 113      $sql = "
 114          UPDATE standard_types SET
 115              type_clob = :a:,
 116              type_varchar = :b:
 117          ";
 118      $stmt = $this->connection->newStatement($sql);
 119  
 120      $newvalue = substr($value, 0, strlen($value - 30));//checking for truncation
 121  
 122      $stmt->setClob('a', $newvalue);
 123      $stmt->set('b', 'junk');
 124      $stmt->execute();
 125  
 126      $stmt = $this->connection->newStatement("SELECT * FROM standard_types");
 127      $record = $stmt->getOneRecord();
 128      $this->assertEqual($record->get('type_clob'), $newvalue);
 129      $this->assertEqual($record->get('type_varchar'), 'junk');
 130    }
 131  
 132    function testUpdateBlob()
 133    {
 134      $value = file_get_contents(dirname(__FILE__) . '/../blob.jpg');
 135  
 136      $sql = "
 137          INSERT INTO standard_types (
 138              type_blob
 139          ) VALUES (
 140              :type_blob:
 141          )";
 142      $stmt = $this->connection->newStatement($sql);
 143  
 144      $stmt->setBlob('type_blob', $value);
 145      $stmt->execute();
 146  
 147      $sql = "
 148          UPDATE standard_types SET
 149              type_blob = :a:,
 150              type_varchar = :b:
 151          ";
 152      $stmt = $this->connection->newStatement($sql);
 153  
 154      $newvalue = substr($value, 0, strlen($value - 30));//checking for truncation
 155  
 156      $stmt->setBlob('a', $newvalue);
 157      $stmt->set('b', 'junk');
 158      $stmt->execute();
 159  
 160      $stmt = $this->connection->newStatement("SELECT * FROM standard_types");
 161      $record = $stmt->getOneRecord();
 162      $this->assertEqual($record->get('type_blob'), $newvalue);
 163      $this->assertEqual($record->get('type_varchar'), 'junk');
 164    }
 165  
 166    function testUpdateBlobAndClob()
 167    {
 168      $blob = file_get_contents(dirname(__FILE__) . '/../blob.jpg');
 169      $clob = file_get_contents(dirname(__FILE__) . '/../blob.jpg');
 170  
 171      $sql = "
 172          INSERT INTO standard_types (
 173              type_blob,
 174              type_clob
 175          ) VALUES (
 176              :type_blob:,
 177              :type_clob:
 178          )";
 179      $stmt = $this->connection->newStatement($sql);
 180  
 181      $stmt->setBlob('type_blob', $blob);
 182      $stmt->setClob('type_clob', $clob);
 183      $stmt->execute();
 184  
 185      $sql = "
 186          UPDATE standard_types SET
 187              type_blob = :a:,
 188              type_varchar = :b:,
 189              type_clob = :c:
 190          ";
 191      $stmt = $this->connection->newStatement($sql);
 192  
 193      $new_blob = substr($blob, 0, strlen($blob - 30));//checking for truncation
 194      $new_clob = substr($clob, 0, strlen($clob - 30));
 195  
 196      $stmt->setBlob('a', $new_blob);
 197      $stmt->set('b', 'junk');
 198      $stmt->setClob('c', $new_clob);
 199      $stmt->execute();
 200  
 201      $stmt = $this->connection->newStatement("SELECT * FROM standard_types");
 202      $record = $stmt->getOneRecord();
 203      $this->assertEqual($record->get('type_blob'), $new_blob);
 204      $this->assertEqual($record->get('type_varchar'), 'junk');
 205      $this->assertEqual($record->get('type_blob'), $new_clob);
 206    }
 207  }
 208  
 209  ?>


Generated: Mon Sep 8 04:35:41 2008 Cross-referenced by PHPXref 0.7