eZ components PHP Cross Reference Developer Tools

Source: /PersistentObject/tests/data/string_identifier/main_table_class.php - 99 lines - 2385 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3  CREATE TABLE main_table
   4  (
   5    id varchar(255),
   6    data varchar(255),
   7    PRIMARY KEY (id)
   8  ) TYPE=InnoDB;
   9  
  10  CREATE TABLE rel
  11  (
  12    id varchar(255),
  13    fk varchar(255),
  14    PRIMARY KEY (id)
  15  ) TYPE=InnoDB;
  16  
  17  CREATE TABLE link
  18  (
  19     main_id varchar(255),
  20     rel_id varchar(255)
  21  ) TYPE=InnoDB;
  22  */
  23  
  24  class MainTable
  25  {
  26      public $id = null;
  27      public $data = null;
  28  
  29      /**
  30       * Inserts some data to use for testing.
  31       */
  32      public static function insertCleanData()
  33      {
  34      }
  35  
  36      /**
  37       * Saves the schema from database to file.
  38       *
  39       * Use this method if you have changed the definition of the persistent object
  40       * and need to update the file on disk.
  41       */
  42      public static function saveSchema()
  43      {
  44          $db = ezcDbInstance::get();
  45          $schema = ezcDbSchema::createFromDb( $db );
  46          $schema->writeToFile( 'array', dirname( __FILE__ ) . '/table.dba' );
  47      }
  48  
  49      /**
  50       * Loads the schema from file into the database.
  51       */
  52      public static function setupTable()
  53      {
  54          $db = ezcDbInstance::get();
  55          // Load schema
  56          $schema = ezcDbSchema::createFromFile( 'array', dirname( __FILE__ ) . '/table.dba' );
  57          $schema->writeToDb( $db );
  58      }
  59  
  60      public static function cleanup()
  61      {
  62          $db = ezcDbInstance::get();
  63          $db->exec( 'DROP TABLE' . $db->quoteIdentifier( 'main_table' ) );
  64          $db->exec( 'DROP TABLE' . $db->quoteIdentifier( 'rel' ) );
  65          $db->exec( 'DROP TABLE' . $db->quoteIdentifier( 'link' ) );
  66          if ( $db->getName() === 'oracle' )
  67          {
  68              $db->exec( "DROP SEQUENCE " . $db->quoteIdentifier( "main_table_id_seq" ) );
  69              $db->exec( "DROP SEQUENCE " . $db->quoteIdentifier( "rel_id_seq" ) );
  70          }
  71      }
  72  
  73      /*
  74      public function saveSqlSchemas()
  75      {
  76          $db = ezcDbInstance::get();
  77          $schema = ezcDbSchema::createFromFile( 'php', dirname( __FILE__ ) . '/persistent_test_object.dba' );
  78          $schema->writeToFile( dirname( __FILE__ ) . '/persistent_test_object-pgsql.sql', 'pgsql-file', 'schema' );
  79      }
  80      */
  81  
  82      public function setState( array $state )
  83      {
  84          foreach ( $state as $key => $value )
  85          {
  86              $this->$key = $value;
  87          }
  88      }
  89  
  90      public function getState()
  91      {
  92          $result = array();
  93          $result['id'] = $this->id;
  94          $result['data'] = $this->data;
  95          return $result;
  96      }
  97  }
  98  
  99  ?>

title

Description

title

Description

title

Description

title

title

Body