Пример #1
0
 /**
  * Molds the table to fit the bean data.
  * Given a property and a value and the bean, this method will
  * adjust the table structure to fit the requirements of the property and value.
  * This may include adding a new column or widening an existing column to hold a larger
  * or different kind of value. This method employs the writer to adjust the table
  * structure in the database. Schema updates are recorded in meta properties of the bean.
  *
  * @param OODBBean $bean     bean to get cast data from and store meta in
  * @param string           $property property to store
  * @param mixed            $value    value to store
  *
  * @return void
  */
 private function moldTable(OODBBean $bean, $property, $value)
 {
     $table = $bean->getMeta('type');
     $columns = $this->writer->getColumns($table);
     if (!in_array($bean->getMeta('type'), $this->chillList)) {
         if ($bean->getMeta("cast.{$property}", -1) !== -1) {
             //check for explicitly specified types
             $cast = $bean->getMeta("cast.{$property}");
             $typeno = $this->getTypeFromCast($cast);
         } else {
             $cast = FALSE;
             $typeno = $this->writer->scanType($value, TRUE);
         }
         if (isset($columns[$this->writer->esc($property, TRUE)])) {
             //Is this property represented in the table ?
             if (!$cast) {
                 //rescan without taking into account special types >80
                 $typeno = $this->writer->scanType($value, FALSE);
             }
             $sqlt = $this->writer->code($columns[$this->writer->esc($property, TRUE)]);
             if ($typeno > $sqlt) {
                 //no, we have to widen the database column type
                 $this->writer->widenColumn($table, $property, $typeno);
                 $bean->setMeta('buildreport.flags.widen', TRUE);
             }
         } else {
             $this->writer->addColumn($table, $property, $typeno);
             $bean->setMeta('buildreport.flags.addcolumn', TRUE);
             $this->processBuildCommands($table, $property, $bean);
         }
     }
 }