コード例 #1
0
 public static function current()
 {
     if (self::$defs === NULL) {
         self::$defs = new FieldDefinitions();
     }
     return self::$defs;
 }
コード例 #2
0
 /**
  * This function gets the description of a table from the RDBMS and then constructs
  * an array of Fields and returns them as required
  */
 public function setupFields()
 {
     /*if(!$fields = Session::getRegistered($this->table_name.'_field_array'))
       {*/
     try {
         $fields = FieldDefinitions::current()->definitionsForTable($this->table_name);
     } catch (Exception $exc) {
         if (!file_exists($this->fieldCachePath())) {
             $query = SimpleQuery::create('describe ' . $this->table_name);
             $fields = array();
             while ($row = $query->next()) {
                 $type_array = preg_split('/\\(/', $row['Type']);
                 if ($row['Extra'] == 'auto_increment') {
                     $type = 'Field::T_AUTO';
                 } else {
                     if ($row['Key'] == 'PRI') {
                         $type = 'Field::T_PRIMARY_KEY_' . strtoupper($type_array[0]) . '';
                     } else {
                         $type = 'Field::T_' . strtoupper($type_array[0]) . '';
                     }
                 }
                 eval('$field_type = ' . $type . ';');
                 $field = new Field($this->table_name, $row['Field'], $field_type);
                 $fields[$row['Field']] = $field;
                 if ($row['Default'] || !$row['Default'] && is_numeric($row['Default'])) {
                     $field->setValue($row['Default']);
                 }
             }
             @unlink($this->fieldCachePath());
             file_put_contents($this->fieldCachePath(), serialize($fields));
             @chmod($this->fieldCachePath(), 0664);
         } else {
             if (file_exists($this->fieldCachePath())) {
                 $fields = unserialize(file_get_contents($this->fieldCachePath()));
             }
         }
         //Session::register($this->table_name.'_field_array',$fields);
         FieldDefinitions::current()->addDefinitionsForTable($this->table_name, $fields);
     }
     return $fields;
 }