コード例 #1
0
ファイル: mysql5.php プロジェクト: williammoran/DBSteward
 public static function build($output_prefix, $db_doc)
 {
     if (strlen($output_prefix) == 0) {
         throw new exception("mysql5::build() sanity failure: output_prefix is blank");
     }
     // build full db creation script
     $build_file = $output_prefix . '_build.sql';
     dbsteward::notice("Building complete file " . $build_file);
     $build_file_fp = fopen($build_file, 'w');
     if ($build_file_fp === FALSE) {
         throw new exception("failed to open full file " . $build_file . ' for output');
     }
     $build_file_ofs = new output_file_segmenter($build_file, 1, $build_file_fp, $build_file);
     if (count(dbsteward::$limit_to_tables) == 0) {
         $build_file_ofs->write("-- full database definition file generated " . date('r') . "\n");
     }
     // $build_file_ofs->write("START TRANSACTION;\n\n");
     dbsteward::info("Calculating table foreign key dependency order..");
     $table_dependency = xml_parser::table_dependency_order($db_doc);
     // database-specific implementation refers to dbsteward::$new_database when looking up roles/values/conflicts etc
     dbsteward::$new_database = $db_doc;
     // language defintions
     if (dbsteward::$create_languages) {
         foreach ($db_doc->language as $language) {
             dbsteward::warning("Ignoring language {$language['name']} declaration because MySQL does not support languages other than 'sql'");
         }
     }
     if (dbsteward::$only_schema_sql || !dbsteward::$only_data_sql) {
         dbsteward::info("Defining structure");
         mysql5::build_schema($db_doc, $build_file_ofs, $table_dependency);
     }
     if (!dbsteward::$only_schema_sql || dbsteward::$only_data_sql) {
         dbsteward::info("Defining data inserts");
         mysql5::build_data($db_doc, $build_file_ofs, $table_dependency);
     }
     dbsteward::$new_database = NULL;
     // $build_file_ofs->write("COMMIT TRANSACTION;\n\n");
     return $db_doc;
 }
コード例 #2
0
 private function common($xml, $expected)
 {
     $dbs = new SimpleXMLElement($xml);
     $ofs = new mock_output_file_segmenter();
     dbsteward::$new_database = $dbs;
     $table_dependency = xml_parser::table_dependency_order($dbs);
     mysql5::build_data($dbs, $ofs, $table_dependency);
     $actual = $ofs->_get_output();
     // get rid of extra whitespace
     $expected = preg_replace("/^ +/m", "", $expected);
     $expected = trim(preg_replace("/\n+/", "\n", $expected));
     // echo $actual;
     // get rid of comments
     $actual = preg_replace("/\\s*-- .*\$/m", '', $actual);
     // get rid of extra whitespace
     $actual = preg_replace("/^ +/m", "", $actual);
     $actual = trim(preg_replace("/\n+/", "\n", $actual));
     $this->assertEquals($expected, $actual);
 }