コード例 #1
0
 function execute()
 {
     $definition = $this->tag;
     $source = $definition->attributes()->from;
     $new_name = $definition->attributes()->to;
     $rename_table = DB::newAlterTable($source);
     $rename_table->rename($new_name);
 }
コード例 #2
0
 function execute()
 {
     $definition = $this->tag;
     $table_name = $definition->attributes()->table_name;
     $drop_fields = DB::newAlterTable($table_name);
     foreach ($definition as $tag_name => $tag) {
         $drop_fields->drop_column($tag->attributes()->name);
     }
 }
コード例 #3
0
ファイル: core_db2_test.php プロジェクト: mbcraft/frozen
 function testAlterTable()
 {
     $alter = DB::newAlterTable("another_tab_bites_the_dust");
     $factory = $alter->getFieldFactory();
     $alter->change_column("livello", $factory->create_unsigned_int_32("livello_ext", false));
     $alter->drop_column("nome");
     $alter->add_column($factory->create_text_64("ruolo", true));
     $alter->add_column($factory->create_index("ruolo"));
     $table_description = DB::newTableFieldsDescription("another_tab_bites_the_dust");
     $fields = $table_description->getAllFields();
     $this->assertEqual(count($fields), 3);
     $this->assertTrue(array_key_exists("id", $fields));
     $this->assertTrue(array_key_exists("livello_ext", $fields));
     $this->assertFalse(array_key_exists("nome", $fields));
     $this->assertTrue(array_key_exists("ruolo", $fields));
 }
コード例 #4
0
 function execute()
 {
     $definition = $this->tag;
     $field_factory = __MysqlTableFieldFactory::instance();
     $field_list = array();
     $rename_list = array();
     foreach ($definition as $tag_name => $tag) {
         $attr = $tag->attributes();
         switch ($tag_name) {
             case "primary_key":
             case "unique":
             case "fulltext":
             case "index":
                 $field = $field_factory->{"create_" . $tag_name}($attr->name);
                 break;
             case "autoincrement_id":
                 $field = $field_factory->{"create_" . $tag_name}($attr->name, isset($attr->null) && $attr->null == "true" ? true : false, isset($attr->comment) ? $attr->comment : null, isset($attr->after_col_or_first) ? $attr->after_col_or_first : null, isset($attr->rename_from));
                 break;
             case "external_id":
             case "text_16":
             case "text_32":
             case "text_64":
             case "text_128":
             case "text_512":
             case "text_1024":
             case "text_65k":
             case "text_big":
             case "bool":
             case "unsigned_int_8":
             case "unsigned_int_32":
             case "signed_int_8":
             case "signed_int_32":
             case "double":
             case "numeric":
             case "date":
             case "time":
             case "datetime":
             case "timestamp":
                 $field = $field_factory->{"create_" . $tag_name}($attr->name, isset($attr->null) && $attr->null == "true" ? true : false, isset($attr->comment) ? $attr->comment : null, isset($attr->after_col_or_first) ? $attr->after_col_or_first : null);
                 break;
             default:
                 throw new InvalidParameterException("Il tag : " . $tag_name . " non e' supportato.");
         }
         if (isset($attr->rename_from)) {
             $rename_list["" . $attr->rename_from] = $field;
         } else {
             $field_list[] = $field;
         }
     }
     //Flash::warning(count($rename_list));
     $table_name = $definition->attributes()->table_name;
     $db_desc = DB::newDatabaseDescription();
     //if (count($rename_list)>0 && $db_desc->hasTable($table_name))
     //    throw new IllegalStateException("Non è possibile creare la tabella se ci sono dei rename da effettuare!!");
     //aggiungere controllo su campi già presenti nella tabella e spostarli come change
     if (!$db_desc->hasTable($table_name)) {
         $create_table = DB::newCreateTable($table_name);
         foreach ($field_list as $i => $definition) {
             $create_table->add_column($definition);
         }
         $create_table->exec();
     } else {
         if (count($field_list) > 0 || count($rename_list) > 0) {
             $alter = DB::newAlterTable($table_name);
             foreach ($field_list as $ix => $definition) {
                 $alter->add_column($definition);
             }
             foreach ($rename_list as $old_name => $definition) {
                 $alter->change_column($old_name, $definition);
             }
         } else {
             Flash::warning("No fields found in field list!!");
         }
     }
 }
コード例 #5
0
ファイル: ModulePlug.class.php プロジェクト: mbcraft/frozen
 function rename_table($definition)
 {
     $source = $definition->attributes()->from;
     $new_name = $definition->attributes()->to;
     $rename_table = DB::newAlterTable($source);
     $rename_table->rename($new_name);
 }