eZ components PHP Cross Reference Developer Tools

Source: /Database/tests/sqlabstraction/rdbms_limits.php - 304 lines - 8803 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 ezcRdbmsLimitTest extends ezcTestCase
  18  {
  19      public static function suite()
  20      {
  21          return new PHPUnit_Framework_TestSuite( 'ezcRdbmsLimitTest' );
  22      }
  23  
  24      protected function setUp()
  25      {
  26          try
  27          {
  28              $db = ezcDbInstance::get();
  29          }
  30          catch ( Exception $e )
  31          {
  32              $this->markTestSkipped();
  33          }
  34  
  35          $this->assertNotNull( $db, 'Database instance is not initialized.' );
  36  
  37      }
  38  
  39      protected function tearDown()
  40      {
  41      }
  42  
  43      public function testLongTableNames()
  44      {
  45          $db = ezcDbInstance::get();
  46          if ( $db->getName() === 'mysql' )
  47          {
  48              self::markTestSkipped( 'Not for MySQL' );
  49          }
  50  
  51          for ( $i = 8; $i <= 256; $i *= 2 )
  52          {
  53              $table = str_pad( 'table', $i, 'very_' );
  54  
  55              try
  56              {
  57                  $db->exec( 'CREATE TABLE ' .
  58                      $db->quoteIdentifier( $table ) . 
  59                      '( ' . $db->quoteIdentifier( $column = 'id' ) . ' int )'
  60                  );
  61  
  62                  $query = $db->createSelectQuery();
  63                  $query->select( $db->quoteIdentifier( $column ) )
  64                        ->from( $db->quoteIdentifier( $table ) );
  65                  $query->prepare()->execute();
  66  
  67                  $db->exec( 'DROP TABLE ' .
  68                      $db->quoteIdentifier( $table )
  69                  );
  70              }
  71              catch ( PDOException $e )
  72              {
  73                  $this->fail( "Failed to use table name with length $i: " . $e->getMessage() );
  74              }
  75          }
  76      }
  77  
  78      public function testLongColumnNames()
  79      {
  80          $db = ezcDbInstance::get();
  81          if ( $db->getName() === 'mysql' )
  82          {
  83              self::markTestSkipped( 'Not for MySQL' );
  84          }
  85  
  86          try
  87          {
  88              $db->exec( 'DROP TABLE ' .
  89                  $db->quoteIdentifier( $table = 'rdbms_test' ) );
  90          }
  91          catch ( Exception $e ) {} // Ignore
  92  
  93          for ( $i = 8; $i <= 256; $i *= 2 )
  94          {
  95              $column = str_pad( 'column', $i, 'very_' );
  96  
  97              try
  98              {
  99                  $db->exec( 'CREATE TABLE ' .
 100                      $db->quoteIdentifier( $table ) . 
 101                      '( ' . $db->quoteIdentifier( $column ) . ' int )'
 102                  );
 103  
 104                  $query = $db->createSelectQuery();
 105                  $query->select( $db->quoteIdentifier( $column ) )
 106                        ->from( $db->quoteIdentifier( $table ) );
 107                  $query->prepare()->execute();
 108  
 109                  $db->exec( 'DROP TABLE ' .
 110                      $db->quoteIdentifier( $table )
 111                  );
 112              }
 113              catch ( PDOException $e )
 114              {
 115                  $this->fail( "Failed to use column name with length $i: " . $e->getMessage() );
 116              }
 117          }
 118      }
 119  
 120      public function testInsertLongText()
 121      {
 122          $db = ezcDbInstance::get();
 123  
 124          try
 125          {
 126              $db->exec( 'DROP TABLE ' .
 127                  $db->quoteIdentifier( $table = 'rdbms_test' ) );
 128          }
 129          catch ( Exception $e ) {} // Ignore
 130  
 131          // Type depends on DB handler
 132          switch ( $class = get_class( $db ) )
 133          {
 134              case 'ezcDbHandlerMysql':
 135              case 'ezcDbHandlerPgsql':
 136                  // Oracle default length for varchar2
 137                  // Also default length in DatabaseSchema
 138                  $type = 'text';
 139                  break;
 140              default:
 141                  $type = 'clob';
 142                  break;
 143          }
 144  
 145          $db->exec( 'CREATE TABLE ' .
 146              $db->quoteIdentifier( $table ) . 
 147              '( ' . $db->quoteIdentifier( $column = 'text' ) . ' ' . $type . ' )' );
 148  
 149          for( $i = 512; $i <= pow( 2, 16 ); $i *= 2 )
 150          {
 151              $text = str_pad( '', $i, 'test ' );
 152  
 153              try
 154              {
 155                  $query = $db->createInsertQuery();
 156                  $query
 157                      ->insertInto( $db->quoteIdentifier( $table ) )
 158                      ->set( $db->quoteIdentifier( $column ), $query->bindValue( $text, null, PDO::PARAM_STR ) );
 159                  $query->prepare()->execute();
 160              }
 161              catch ( PDOException $e )
 162              {
 163                  $this->fail( "Insert of long text failed with $i chars: " . $e->getMessage() );
 164              }
 165          }
 166  
 167          $db->exec( 'DROP TABLE ' .
 168              $db->quoteIdentifier( $table )
 169          );
 170      }
 171  
 172      public function testManyInElements()
 173      {
 174          $db = ezcDbInstance::get();
 175  
 176          try
 177          {
 178              $db->exec( 'DROP TABLE ' .
 179                  $db->quoteIdentifier( $table = 'rdbms_test' ) );
 180          }
 181          catch ( Exception $e ) {} // Ignore
 182  
 183          $db->exec( 'CREATE TABLE ' .
 184              $db->quoteIdentifier( $table ) . 
 185              '( ' . $db->quoteIdentifier( $column = 'id' ) . ' int )' );
 186  
 187          // Insert 10.000 rows...
 188          for ( $i = 0; $i < 10000; $i++ )
 189          {
 190              $query = $db->createInsertQuery();
 191              $query
 192                  ->insertInto( $db->quoteIdentifier( $table ) )
 193                  ->set( $db->quoteIdentifier( $column ), $query->bindValue( $i ) );
 194              $query->prepare()->execute();
 195          }
 196  
 197          // Try some IN statements
 198          for( $i = 512; $i <= pow( 2, 13 ); $i *= 2 )
 199          {
 200              $inValues = array();
 201              for ( $j = 0; $j < $i; ++$j )
 202              {
 203                  $inValues[] = $j;
 204              }
 205  
 206              try
 207              {
 208                  $query = $db->createSelectQuery();
 209                  $query
 210                      ->select( $db->quoteIdentifier( $column ) )
 211                      ->from( $db->quoteIdentifier( $table ) )
 212                      ->where( $query->expr->in(
 213                          $db->quoteIdentifier( $column ),
 214                          $inValues
 215                      ) );
 216                  $statement = $query->prepare();
 217                  $statement->execute();
 218  
 219                  $result = $statement->fetchAll();
 220                  $this->assertEquals(
 221                      count( $result ),
 222                      $i,
 223                      'Count of returned records did not match.'
 224                  );
 225              }
 226              catch ( PDOException $e )
 227              {
 228                  $this->fail( "IN() expression failed with $i values: " . $e->getMessage() );
 229              }
 230          }
 231  
 232          $db->exec( 'DROP TABLE ' .
 233              $db->quoteIdentifier( $table )
 234          );
 235      }
 236  
 237      public function testManyNotInElements()
 238      {
 239          $db = ezcDbInstance::get();
 240  
 241          try
 242          {
 243              $db->exec( 'DROP TABLE ' .
 244                  $db->quoteIdentifier( $table = 'rdbms_test' ) );
 245          }
 246          catch ( Exception $e ) {} // Ignore
 247  
 248          $db->exec( 'CREATE TABLE ' .
 249              $db->quoteIdentifier( $table ) . 
 250              '( ' . $db->quoteIdentifier( $column = 'id' ) . ' int )' );
 251  
 252          // Insert 10.000 rows...
 253          for ( $i = 0; $i < 10000; $i++ )
 254          {
 255              $query = $db->createInsertQuery();
 256              $query
 257                  ->insertInto( $db->quoteIdentifier( $table ) )
 258                  ->set( $db->quoteIdentifier( $column ), $query->bindValue( $i ) );
 259              $query->prepare()->execute();
 260          }
 261  
 262          // Try some IN statements
 263          for( $i = 512; $i <= pow( 2, 13 ); $i *= 2 )
 264          {
 265              $inValues = array();
 266              for ( $j = 0; $j < $i; ++$j )
 267              {
 268                  $inValues[] = $j;
 269              }
 270  
 271              try
 272              {
 273                  $query = $db->createSelectQuery();
 274                  $query
 275                      ->select( $db->quoteIdentifier( $column ) )
 276                      ->from( $db->quoteIdentifier( $table ) )
 277                      ->where( $query->expr->not( 
 278                          $query->expr->in(
 279                              $db->quoteIdentifier( $column ),
 280                              $inValues
 281                          )
 282                      ) );
 283                  $statement = $query->prepare();
 284                  $statement->execute();
 285  
 286                  $result = $statement->fetchAll();
 287                  $this->assertEquals(
 288                      count( $result ),
 289                      10000 - $i,
 290                      'Count of returned records did not match.'
 291                  );
 292              }
 293              catch ( PDOException $e )
 294              {
 295                  $this->fail( "NOT IN() expression failed with $i values: " . $e->getMessage() );
 296              }
 297          }
 298  
 299          $db->exec( 'DROP TABLE ' .
 300              $db->quoteIdentifier( $table )
 301          );
 302      }
 303  }
 304  ?>

title

Description

title

Description

title

Description

title

title

Body