private function getParsedRow($tabrow, $delimiter)
    {
        $xml = <<<XML
<dbsteward>
  <database>
    <role>
      <application>x</application>
      <owner>x</owner>
      <replication>x</replication>
      <readonly>x</readonly>
    </role>
  </database>
  <schema name="public" owner="ROLE_OWNER">
    <table name="tabrowtable" owner="ROLE_OWNER" primaryKey="c1">
      <column name="c1" type="int"/>
      <column name="c2" type="int"/>
      <column name="c3" type="int"/>
      <rows columns="c1,c2,c3">
        <tabrow>{$tabrow}</tabrow>
      </rows>
    </table>
  </schema>
</dbsteward>
XML;
        $doc = simplexml_load_string($xml);
        if ($delimiter !== false) {
            $doc->schema->table->rows['tabrowDelimiter'] = $delimiter;
        }
        $composite = xml_parser::composite_doc(null, $doc);
        $cols = array();
        foreach ($composite->schema->table->rows->row->col as $col) {
            $cols[] = (string) $col;
        }
        return $cols;
    }
Exemplo n.º 2
0
 public function testDefineRows()
 {
     $schema_parent = simplexml_load_string($this->xml_parent);
     $schema_child = simplexml_load_string($this->xml_child);
     $schema_parent_child = simplexml_load_string($this->xml_parent_and_child);
     $schema_grandchild = simplexml_load_string($this->xml_grandchild);
     //  xml_parser::composite_doc($schema_parent, $schema_child);
     //xml_parser::composite_doc($schema_parent, $schema_grandchild);
     xml_parser::composite_doc($schema_parent, $schema_child);
     xml_parser::composite_doc($schema_parent_child, $schema_grandchild);
 }
Exemplo n.º 3
0
 /**
  * @group pgsql8
  */
 public function testTableColumnTypeQuotingPgsql8()
 {
     dbsteward::set_sql_format('pgsql8');
     dbsteward::$quote_all_names = TRUE;
     dbsteward::$single_stage_upgrade = TRUE;
     $doc_empty = simplexml_load_string($this->xml_empty);
     $doc_empty = xml_parser::composite_doc(FALSE, $doc_empty);
     dbsteward::$old_database = $doc_empty;
     $doc = simplexml_load_string($this->xml);
     $doc = xml_parser::composite_doc(FALSE, $doc);
     dbsteward::$new_database = $doc;
     $table_dependency = xml_parser::table_dependency_order($doc);
     //var_dump(xml_parser::format_xml($doc_empty->saveXML()));
     //var_dump(xml_parser::format_xml($doc->saveXML()));
     $schema = $doc->schema;
     $table = $schema->table;
     // make sure the type is named with quoting as part of a definition build
     $expected = "CREATE TYPE \"schema1\".\"enumCamelCaseType\" AS ENUM ('Read','Write','Delete');";
     $mofs = new mock_output_file_segmenter();
     pgsql8::build_schema($doc, $mofs, $table_dependency);
     $actual = trim($mofs->_get_output());
     $this->assertContains($expected, $actual);
     // make sure the type is referred to with quoting in a table creation as part of a definition build
     $expected_column = '"table_shable_mode" "enumCamelCaseType"';
     $this->assertContains($expected_column, $actual);
     // make sure the type is referred to with quoting when generating table create statements
     $expected = '"table_shable_mode" "enumCamelCaseType"';
     $sql = pgsql8_table::get_creation_sql($schema, $table);
     $this->assertContains($expected, $sql);
     // make sure create table quotes the type name
     $expected = '"table_shable_mode" "enumCamelCaseType"';
     $mofs = new mock_output_file_segmenter();
     var_dump(dbx::get_tables($schema));
     pgsql8_diff_tables::diff_tables($mofs, $mofs, NULL, $schema);
     $actual = trim($mofs->_get_output());
     $this->assertContains($expected, $actual);
     // make sure insert statements are made that match the XML definition
     $expected = "INSERT INTO \"schema1\".\"table_shable\" (\"table_shable_id\", \"table_shable_value\", \"table_shable_mode\") VALUES (1, E'shim sham', BETA);";
     $actual = trim(pgsql8_diff_tables::get_data_sql(NULL, NULL, $schema, $table, FALSE));
     $this->assertContains($expected, $actual);
 }
 private function diff($old, $new, $expected1, $expected3, $message = '')
 {
     dbsteward::$old_database = xml_parser::composite_doc(NULL, simplexml_load_string($this->db_doc_xml . $old . '</dbsteward>'));
     dbsteward::$new_database = xml_parser::composite_doc(NULL, simplexml_load_string($this->db_doc_xml . $new . '</dbsteward>'));
     $ofs1 = new mock_output_file_segmenter();
     $ofs3 = new mock_output_file_segmenter();
     mysql5_diff::$old_table_dependency = xml_parser::table_dependency_order(dbsteward::$old_database);
     mysql5_diff::$new_table_dependency = xml_parser::table_dependency_order(dbsteward::$new_database);
     mysql5_diff::update_structure($ofs1, $ofs3);
     $actual1 = trim($ofs1->_get_output());
     $actual3 = trim($ofs3->_get_output());
     $this->assertEquals($expected1, $actual1, "during stage 1: {$message}");
     $this->assertEquals($expected3, $actual3, "during stage 3: {$message}");
 }
Exemplo n.º 5
0
 public function testExceptionIsThrownWithDupes()
 {
     dbsteward::set_sql_format('pgsql8');
     dbsteward::$quote_all_names = TRUE;
     dbsteward::$single_stage_upgrade = TRUE;
     $doc_empty = simplexml_load_string($this->xml_empty);
     $doc_empty = xml_parser::composite_doc(FALSE, $doc_empty);
     dbsteward::$old_database = $doc_empty;
     $doc = simplexml_load_string($this->xml);
     $doc = xml_parser::composite_doc(FALSE, $doc);
     dbsteward::$new_database = $doc;
     $table_dependency = xml_parser::table_dependency_order($doc);
     $schema = $doc->schema;
     $table = $schema->table;
     // make sure the type is named with quoting as part of a definition build
     $mofs = new mock_output_file_segmenter();
     try {
         pgsql8::build_schema($doc, $mofs, $table_dependency);
     } catch (Exception $e) {
         $this->assertContains('duplicate index name', strtolower($e->getMessage()));
         return;
     }
     $this->fail("build_schema did not detect duplicate index names");
 }