public function export_data($table) { if (!$table) { throw new InvalidParameterException("Il nome della tabella è nullo!"); } $table_desc = new __MysqlTableFieldsDescription($table); $all_fields = $table_desc->getAllFields(); $ss = new __MysqlSelect($table); $all_rows = $ss->exec_fetch_assoc_all(); $xml_builder = new XMLBuilder(); $xml_builder->element("table"); $xml_builder->attribute("name", $table); $xml_builder->forward(); foreach ($all_rows as $row) { $xml_builder->element("row"); $xml_builder->forward(); foreach ($all_fields as $k => $v) { $xml_builder->element("field", $row[$k], true); $xml_builder->attribute("name", $k); } $xml_builder->back(); } return $xml_builder->getXML(); }
public function testImportData() { $this->__dropTable(); $this->__createTable(); $import_path = "/framework/core/tests/db/import_export/import_test.xml"; $f = new File($import_path); $all_import_content = <<<END_OF_DATA <?xml version="1.0" encoding="utf-8"?> <table name="impiegati"> <row> <field name="id">1</field> <field name="nome">Nome della prova</field> <field name="livello">15</field> <field name="data_inserimento">2011/04/06</field> </row> <row> <field name="id">2</field> <field name="nome">Import ME!!</field> <field name="livello">3</field> <field name="data_inserimento">2011-04-03</field> </row> </table> END_OF_DATA; $f->setContent($all_import_content); $importer = new __MysqlTableDataImportExport("impiegati"); $importer->import_data_from_file($import_path); $f->delete(); $ss = new __MysqlSelect("impiegati"); $ss->addConditionEquals("nome", "Import ME!!"); $results = $ss->exec_fetch_assoc_all(); $this->assertEqual(count($results), 1, "Il numero di risultati trovati non corrisponde!!"); if (count($results) == 1) { $result = $results[0]; $this->assertEqual($result["id"], 2, "L'id del dato importato non corrisponde!!"); $this->assertEqual($result["livello"], 3, "Il livello del dato importato non corrisponde!!"); $this->assertEqual($result["data_inserimento"], "2011-04-03", "La data non corrisponde!! : " . $result["data_inserimento"]); } $this->__dropTable(); }
function testAlterView() { $create_view = new __MysqlCreateView("vendite_full"); $t1 = "destinatari"; $t2 = "vendite"; $t3 = "prodotti"; $create_view->addViewField($t1, "nome"); $create_view->addViewField($t1, "cognome"); $create_view->addViewField($t2, "id_vendita"); $create_view->addViewField($t2, "quantita"); $create_view->addViewField($t3, "nome_prodotto"); $create_view->addViewField($t3, "descrizione"); $create_view->addViewField($t3, "prezzo"); $create_view->addJoinFields("vendite", "id_destinatario", "destinatari", "id_destinatario"); $create_view->addJoinFields("vendite", "id_prodotto", "prodotti", "id_prodotto"); $create_view->exec(); $alter_view = new __MysqlAlterView("vendite_full"); $t1 = "destinatari"; $t2 = "vendite"; $t3 = "prodotti"; $alter_view->addViewField($t1, "nome"); $alter_view->addViewField($t1, "cognome"); $alter_view->addViewField($t2, "id_vendita"); $alter_view->addViewField($t2, "quantita"); $alter_view->addViewField($t3, "nome_prodotto"); $alter_view->addJoinFields("vendite", "id_destinatario", "destinatari", "id_destinatario"); $alter_view->addJoinFields("vendite", "id_prodotto", "prodotti", "id_prodotto"); $alter_view->exec(); $sel = new __MysqlSelect("vendite_full"); $sel->add("*"); $all_results = $sel->exec_fetch_assoc_all(); $this->assertEqual(count($all_results), 4, "Il numero di risultati nella query non corrisponde!!"); $this->assertEqual(count($all_results[0]), 5, "Il numero di campi trovati non corrisponde!!"); $drop = new __MysqlDropView("vendite_full"); $drop->exec(); }