private static function initPrimaryKeyFields($raw_class_name) { $table = self::$cachedTables[$raw_class_name]; $table_description = DB::newTableFieldsDescription($table); $pk_fields = $table_description->getPrimaryKeyFields(); self::$cachedPrimaryKeyFields[$raw_class_name] = $pk_fields; }
function execute() { $definition = $this->tag; $table_name = $definition->attributes()->from; $table_desc = DB::newTableFieldsDescription($table_name); $pk_fields = $table_desc->getPrimaryKeyFields(); $delete = DB::newDelete($table_name); $delete->addConditionEquals($pk_fields[0], $definition->attributes()->id); $delete->exec(); }
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)); }
<?php /* This software is released under the BSD license. Full text at project root -> license.txt */ require_once "../init.php"; DB::openDefaultConnection(); $db_description = DB::newDatabaseDescription(); $all_tables = $db_description->getAllTables(); foreach ($all_tables as $table_name) { echo "<br />Tabella : " . $table_name . "<br /><br />"; $fields_description = DB::newTableFieldsDescription($table_name); $all_fields = $fields_description->getAllFields(); echo "<table border='1px'>"; foreach ($all_fields as $field => $props) { echo " <tr>"; echo " <td>"; echo $field; echo " </td>"; echo " </tr>"; } echo "</table>"; } DB::closeConnection();
function testExecute3RenamePrimaryKey() { ModuleUtils::set_modules_path(FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/"); $db_desc = DB::newDatabaseDescription(); $this->assertFalse($db_desc->hasTable("tab_prova"), "La tabella tab_prova e' gia' presente nel database!!"); $plug = new ModulePlug(new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/ecommerce/cart/")); $def = AvailableModules::get_available_module_definition("sample", "sample_01"); $install_data = $def->get_action_data("install"); $plug->execute($install_data); $rename_primary_key_data = $def->get_action_data("rename_primary_key"); $plug->execute($rename_primary_key_data); $table_desc = DB::newTableFieldsDescription("tab_prova"); $this->assertTrue($table_desc->hasField("id_account_rinominato"), "Il campo useless_f1 non e' stato trovato!!"); $uninstall_data = $def->get_action_data("uninstall"); $plug->execute($uninstall_data[0]); $db_desc = DB::newDatabaseDescription(); $this->assertFalse($db_desc->hasTable("tab_prova"), "La tabella tab_prova non e' stata eliminata!!"); ModulePlug::setRootDir("/"); }
public function testTableFieldsDescription() { $direct_sql = DB::newDirectSql(self::$create_table_sql); $direct_sql->exec(); $table_description = DB::newTableFieldsDescription("impiegati"); $fields = $table_description->getAllFields(); $this->assertEqual(count($fields), 4); $this->assertTrue(array_key_exists("id", $fields), "Il campo id non e' stato trovato nella tabella!!"); $this->assertEqual($fields["id"]["type"], "int(11)", "Il tipo del campo non corrisponde!! : " . $fields["id"]["type"]); $this->assertTrue(array_key_exists("livello", $fields), "Il campo livello non e' stato trovato nella tabella!!"); $this->assertTrue(array_key_exists("nome", $fields), "Il campo nome non e' stato trovato nella tabella!!"); $this->assertEqual($fields["nome"]["type"], "varchar(255)", "Il tipo del campo non corrisponde!!"); $this->assertFalse(array_key_exists("ruolo", $fields), "Il campo ruolo e' stato trovato nella tabella!!"); $pk_fields = $table_description->getPrimaryKeyFields(); $this->assertEqual(count($pk_fields), 1); $this->assertEqual($pk_fields[0], "id"); $direct_sql = DB::newDirectSql(self::$drop_table_sql); $direct_sql->exec(); }