eZ components PHP Cross Reference Developer Tools

Source: /Database/tests/sqlabstraction/param_values.php - 328 lines - 9648 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
   4   * @license http://ez.no/licenses/new_bsd New BSD License
   5   * @version 1.4.7
   6   * @filesource
   7   * @package Database
   8   * @subpackage Tests
   9   */
  10  
  11  /**
  12   * testing sql abstraction for common rdbms limits
  13   *
  14   * @package Database
  15   * @subpackage Tests
  16   */
  17  class ezcParamValuesTest extends ezcTestCase
  18  {
  19  
  20      protected $boolColumn;
  21      protected $intColumn;
  22      protected $nullColumn;
  23      protected $strColumn;
  24      protected $blobColumn;
  25      protected $clobColumn;
  26  
  27      protected $blob;
  28      protected $clob;
  29  
  30      protected $columnMapping = array(
  31          'bool' => array(
  32              'ezcDbHandlerMysql' => 'boolean',
  33              'ezcDbHandlerOracle' => 'char',
  34              'ezcDbHandlerPgsql' => 'boolean',
  35              'ezcDbHandlerSqlite' => 'integer',
  36              'ezcDbHandlerMssql' => 'integer',
  37          ),
  38          'int' => array(
  39              'ezcDbHandlerMysql' => 'bigint',
  40              'ezcDbHandlerOracle' => 'number',
  41              'ezcDbHandlerPgsql' => 'bigint',
  42              'ezcDbHandlerSqlite' => 'integer',
  43              'ezcDbHandlerMssql' => 'bigint',
  44          ),
  45          'null' => array(
  46              'ezcDbHandlerMysql' => 'bigint',
  47              'ezcDbHandlerOracle' => 'number',
  48              'ezcDbHandlerPgsql' => 'bigint',
  49              'ezcDbHandlerSqlite' => 'integer',
  50              'ezcDbHandlerMssql' => 'bigint',
  51          ),
  52          'str' => array(
  53              'ezcDbHandlerMysql' => 'varchar( 255 )',
  54              'ezcDbHandlerOracle' => 'varchar2( 255 )',
  55              'ezcDbHandlerPgsql' => 'varchar( 255 )',
  56              'ezcDbHandlerSqlite' => 'text',
  57              'ezcDbHandlerMssql' => 'varchar( 255 )',
  58          ),
  59          'blob' => array(
  60              'ezcDbHandlerMysql' => 'longblob',
  61              'ezcDbHandlerOracle' => 'blob',
  62              'ezcDbHandlerPgsql' => 'bytea',
  63              'ezcDbHandlerSqlite' => 'blob',
  64              'ezcDbHandlerMssql' => 'image',
  65          ),
  66          'clob' => array(
  67              'ezcDbHandlerMysql' => 'longtext',
  68              'ezcDbHandlerOracle' => 'clob',
  69              'ezcDbHandlerPgsql' => 'text',
  70              'ezcDbHandlerSqlite' => 'clob',
  71              'ezcDbHandlerMssql' => 'ntext',
  72          ),
  73      );
  74  
  75      public static function suite()
  76      {
  77          return new PHPUnit_Framework_TestSuite( 'ezcParamValuesTest' );
  78      }
  79  
  80      protected function setUp()
  81      {
  82          try {
  83              $db = ezcDbInstance::get();
  84          }
  85          catch ( Exception $e )
  86          {
  87              $this->markTestSkipped();
  88          }
  89  
  90          $this->assertNotNull( $db, 'Database instance is not initialized.' );
  91  
  92          $db->exec( 'CREATE TABLE ' .
  93              $db->quoteIdentifier( __CLASS__ ) . 
  94              '( ' . 
  95                  ( $this->boolColumn = $db->quoteIdentifier( 'bool' ) ) . ' ' . $this->columnMapping['bool'][get_class( $db )] . ' NULL, ' .
  96                  ( $this->intColumn =  $db->quoteIdentifier( 'int' )  ) . ' ' . $this->columnMapping['int' ][get_class( $db )] . ' NULL, ' .
  97                  ( $this->nullColumn = $db->quoteIdentifier( 'null' ) ) . ' ' . $this->columnMapping['null'][get_class( $db )] . ' NULL, ' .
  98                  ( $this->strColumn =  $db->quoteIdentifier( 'str' )  ) . ' ' . $this->columnMapping['str' ][get_class( $db )] . ' NULL, ' .
  99                  ( $this->blobColumn = $db->quoteIdentifier( 'blob' ) ) . ' ' . $this->columnMapping['blob'][get_class( $db )] . ' NULL, ' .
 100                  ( $this->clobColumn = $db->quoteIdentifier( 'clob' ) ) . ' ' . $this->columnMapping['clob'][get_class( $db )] . ' NULL ' .
 101              ')'
 102          );
 103  
 104          // Initialize content
 105          $this->blob = str_repeat( "\x00\x05\x10\x42", 1024 );
 106          $this->clob = str_repeat( "test", 1024 );
 107      }
 108  
 109      protected function tearDown()
 110      {
 111          $db = ezcDbInstance::get();
 112  
 113          $db->exec( 'DROP TABLE ' .
 114              $db->quoteIdentifier( __CLASS__ )
 115          );
 116      }
 117  
 118      public function testBooleanParam()
 119      {
 120          $db = ezcDbInstance::get();
 121  
 122          $query = $db->createInsertQuery();
 123          $query
 124              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 125              ->set( 
 126                  $this->boolColumn,
 127                  $query->bindValue( true ) 
 128              );
 129          $query->prepare()->execute();
 130      }
 131  
 132      public function testBooleanParamForce()
 133      {
 134          $db = ezcDbInstance::get();
 135  
 136          $query = $db->createInsertQuery();
 137          $query
 138              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 139              ->set( 
 140                  $this->boolColumn,
 141                  $query->bindValue( true, null, PDO::PARAM_BOOL ) 
 142              );
 143          $query->prepare()->execute();
 144      }
 145  
 146      public function testBooleanParamForceBroken()
 147      {
 148          $db = ezcDbInstance::get();
 149  
 150          $query = $db->createInsertQuery();
 151          $query
 152              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 153              ->set( 
 154                  $this->boolColumn,
 155                  $query->bindValue( 'some string', null, PDO::PARAM_BOOL ) 
 156              );
 157          $query->prepare()->execute();
 158      }
 159  
 160      public function testIntegerParam()
 161      {
 162          $db = ezcDbInstance::get();
 163  
 164          $query = $db->createInsertQuery();
 165          $query
 166              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 167              ->set( 
 168                  $this->intColumn,
 169                  $query->bindValue( 42 ) 
 170              );
 171          $query->prepare()->execute();
 172      }
 173  
 174      public function testIntegerParamForce()
 175      {
 176          $db = ezcDbInstance::get();
 177  
 178          $query = $db->createInsertQuery();
 179          $query
 180              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 181              ->set( 
 182                  $this->intColumn,
 183                  $query->bindValue( 42, null, PDO::PARAM_INT ) 
 184              );
 185          $query->prepare()->execute();
 186      }
 187  
 188      public function testIntegerParamForceBroken()
 189      {
 190          $db = ezcDbInstance::get();
 191  
 192          $query = $db->createInsertQuery();
 193          $query
 194              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 195              ->set( 
 196                  $this->intColumn,
 197                  $query->bindValue( '42 strings', null, PDO::PARAM_INT ) 
 198              );
 199          $query->prepare()->execute();
 200      }
 201  
 202      public function testStringParam()
 203      {
 204          $db = ezcDbInstance::get();
 205  
 206          $query = $db->createInsertQuery();
 207          $query
 208              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 209              ->set( 
 210                  $this->strColumn,
 211                  $query->bindValue( 'some string' ) 
 212              );
 213          $query->prepare()->execute();
 214      }
 215  
 216      public function testStringParamForce()
 217      {
 218          $db = ezcDbInstance::get();
 219  
 220          $query = $db->createInsertQuery();
 221          $query
 222              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 223              ->set( 
 224                  $this->strColumn,
 225                  $query->bindValue( 'some string', null, PDO::PARAM_INT ) 
 226              );
 227          $query->prepare()->execute();
 228      }
 229  
 230      public function testStringParamForceBroken()
 231      {
 232          $db = ezcDbInstance::get();
 233  
 234          $query = $db->createInsertQuery();
 235          $query
 236              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 237              ->set( 
 238                  $this->strColumn,
 239                  $query->bindValue( true, null, PDO::PARAM_INT ) 
 240              );
 241          $query->prepare()->execute();
 242      }
 243  
 244      public function testClobParam()
 245      {
 246          $db = ezcDbInstance::get();
 247  
 248          $query = $db->createInsertQuery();
 249          $query
 250              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 251              ->set( 
 252                  $this->clobColumn,
 253                  $query->bindValue( $this->clob ) 
 254              );
 255          $query->prepare()->execute();
 256      }
 257  
 258      public function testClobParamForce()
 259      {
 260          $db = ezcDbInstance::get();
 261  
 262          $query = $db->createInsertQuery();
 263          $query
 264              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 265              ->set( 
 266                  $this->clobColumn,
 267                  $query->bindValue( $this->clob, null, PDO::PARAM_LOB ) 
 268              );
 269          $query->prepare()->execute();
 270      }
 271  
 272      public function testClobParamForceBroken()
 273      {
 274          $db = ezcDbInstance::get();
 275  
 276          $query = $db->createInsertQuery();
 277          $query
 278              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 279              ->set( 
 280                  $this->clobColumn,
 281                  $query->bindValue( 42, null, PDO::PARAM_LOB ) 
 282              );
 283          $query->prepare()->execute();
 284      }
 285  
 286      public function testBlobParam()
 287      {
 288          $db = ezcDbInstance::get();
 289  
 290          $query = $db->createInsertQuery();
 291          $query
 292              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 293              ->set( 
 294                  $this->blobColumn,
 295                  $query->bindValue( $this->blob ) 
 296              );
 297          $query->prepare()->execute();
 298      }
 299  
 300      public function testBlobParamForce()
 301      {
 302          $db = ezcDbInstance::get();
 303  
 304          $query = $db->createInsertQuery();
 305          $query
 306              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 307              ->set( 
 308                  $this->blobColumn,
 309                  $query->bindValue( $this->blob, null, PDO::PARAM_LOB ) 
 310              );
 311          $query->prepare()->execute();
 312      }
 313  
 314      public function testBlobParamForceBroken()
 315      {
 316          $db = ezcDbInstance::get();
 317  
 318          $query = $db->createInsertQuery();
 319          $query
 320              ->insertInto( $db->quoteIdentifier( __CLASS__ ) )
 321              ->set( 
 322                  $this->blobColumn,
 323                  $query->bindValue( 42, null, PDO::PARAM_LOB ) 
 324              );
 325          $query->prepare()->execute();
 326      }
 327  }
 328  ?>

title

Description

title

Description

title

Description

title

title

Body