Beispiel #1
0
 /**
  * Returns an array of names of columns in the metadata table for this
  * table.  The metadata table contains metadata such as state and 
  * translation state for the corresponding records of this table.
  * Fields of this table that are considered to be metadata must begin
  * with two underscores to signify that they are metadata.
  *
  * If no metadata table yet exists, it will be created.
  * @returns array List of column names.
  */
 function getMetadataColumns()
 {
     if (!isset($this->metadataColumns)) {
         $metatablename = $this->tablename . '__metadata';
         $sql = "SHOW COLUMNS FROM `{$metatablename}`";
         $res = mysql_query($sql, $this->db);
         if (!$res || mysql_num_rows($res) == 0) {
             Dataface_MetadataTool::refreshMetadataTable($this->tablename);
             $res = mysql_query($sql, $this->db);
         }
         if (!$res) {
             trigger_error(mysql_error($this->db), E_USER_ERROR);
         }
         if (mysql_num_rows($res) == 0) {
             trigger_error("No metadata table set up for table '{$this->tablename}'", E_USER_ERROR);
         }
         $this->metadataColumns = array();
         while ($row = mysql_fetch_assoc($res)) {
             if (substr($row['Field'], 0, 2) == '__') {
                 $this->metadataColumns[] = $row['Field'];
             }
         }
     }
     return $this->metadataColumns;
 }
Beispiel #2
0
 function test_refreshMetadataTable()
 {
     $app =& Dataface_Application::getInstance();
     $sql = "create table `md_test3` (\n\t\t\t\tfname varchar(32) NOT NULL,\n\t\t\t\tlname varchar(32) NOT NULL,\n\t\t\t\tage int(11) default 10,\n\t\t\t\tprimary key (`fname`,`lname`))";
     $res = xf_db_query($sql, $app->db());
     if (!$res) {
         trigger_error(xf_db_error($app->db()), E_USER_ERROR);
     }
     $mt = new Dataface_MetadataTool('md_test3');
     $this->assertTrue($mt->refreshMetadataTable());
     $this->assertEquals(1, xf_db_num_rows(xf_db_query("show tables like 'md_test3__metadata'", $app->db())));
     $cols = $mt->getColumns(null, false);
     $this->assertEquals(array('fname', 'lname', '__translation_state', '__published_state'), array_keys($cols));
     $mt->fieldDefs['__test_col'] = array('Type' => 'varchar(32)', 'Default' => 'Null', 'Field' => '__test_col');
     $this->assertTrue($mt->refreshMetadataTable());
     $cols = $mt->getColumns(null, false);
     $this->assertEquals(array('fname', 'lname', '__translation_state', '__published_state', '__test_col'), array_keys($cols));
 }