示例#1
0
 function DumpDatabase($arguments)
 {
     if (!isset($arguments["Output"])) {
         return "it was not specified a valid output function";
     }
     $output = $arguments["Output"];
     $eol = isset($arguments["EndOfLine"]) ? $arguments["EndOfLine"] : "\n";
     $dump_definition = isset($arguments["Definition"]);
     $sequences = array();
     if (isset($this->database_definition["SEQUENCES"])) {
         for ($error = "", Reset($this->database_definition["SEQUENCES"]), $sequence = 0; $sequence < count($this->database_definition["SEQUENCES"]); Next($this->database_definition["SEQUENCES"]), $sequence++) {
             $sequence_name = Key($this->database_definition["SEQUENCES"]);
             if (isset($this->database_definition["SEQUENCES"][$sequence_name]["on"])) {
                 $table = $this->database_definition["SEQUENCES"][$sequence_name]["on"]["table"];
             } else {
                 $table = "";
             }
             $sequences[$table][] = $sequence_name;
         }
     }
     $previous_database_name = strcmp($this->database_definition["name"], "") ? MetabaseSetDatabase($this->database, $this->database_definition["name"]) : "";
     $output("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>{$eol}");
     $output("<database>{$eol}{$eol} <name>" . $this->database_definition["name"] . "</name>{$eol} <create>" . $this->database_definition["create"] . "</create>{$eol}");
     for ($error = "", Reset($this->database_definition["TABLES"]), $table = 0; $table < count($this->database_definition["TABLES"]); Next($this->database_definition["TABLES"]), $table++) {
         $table_name = Key($this->database_definition["TABLES"]);
         $output("{$eol} <table>{$eol}{$eol}  <name>{$table_name}</name>{$eol}");
         $output("{$eol}  <declaration>{$eol}");
         $fields = $this->database_definition["TABLES"][$table_name]["FIELDS"];
         for (Reset($fields), $field_number = 0; $field_number < count($fields); $field_number++, Next($fields)) {
             $field_name = Key($fields);
             $field = $fields[$field_name];
             if (!isset($field["type"])) {
                 return "it was not specified the type of the field \"{$field_name}\" of the table \"{$table_name}\"";
             }
             $output("{$eol}   <field>{$eol}    <name>{$field_name}</name>{$eol}    <type>" . $field["type"] . "</type>{$eol}");
             switch ($field["type"]) {
                 case "integer":
                     if (isset($field["unsigned"])) {
                         $output("    <unsigned>1</unsigned>{$eol}");
                     }
                     break;
                 case "text":
                 case "clob":
                 case "blob":
                     if (isset($field["length"])) {
                         $output("    <length>" . $field["length"] . "</length>{$eol}");
                     }
                     break;
                 case "boolean":
                 case "date":
                 case "timestamp":
                 case "time":
                 case "float":
                 case "decimal":
                     break;
                 default:
                     return "type \"" . $field["type"] . "\" is not yet supported";
             }
             if (isset($field["notnull"])) {
                 $output("    <notnull>1</notnull>{$eol}");
             }
             if (isset($field["default"])) {
                 $output("    <default>" . $this->EscapeSpecialCharacters($field["default"]) . "</default>{$eol}");
             }
             $output("   </field>{$eol}");
         }
         if (isset($this->database_definition["TABLES"][$table_name]["INDEXES"])) {
             $indexes = $this->database_definition["TABLES"][$table_name]["INDEXES"];
             for (Reset($indexes), $index_number = 0; $index_number < count($indexes); $index_number++, Next($indexes)) {
                 $index_name = Key($indexes);
                 $index = $indexes[$index_name];
                 $output("{$eol}   <index>{$eol}    <name>{$index_name}</name>{$eol}");
                 if (isset($indexes[$index_name]["unique"])) {
                     $output("    <unique>1</unique>{$eol}");
                 }
                 for (Reset($index["FIELDS"]), $field_number = 0; $field_number < count($index["FIELDS"]); $field_number++, Next($index["FIELDS"])) {
                     $field_name = Key($index["FIELDS"]);
                     $field = $index["FIELDS"][$field_name];
                     $output("    <field>{$eol}     <name>{$field_name}</name>{$eol}");
                     if (isset($field["sorting"])) {
                         $output("     <sorting>" . $field["sorting"] . "</sorting>{$eol}");
                     }
                     $output("    </field>{$eol}");
                 }
                 $output("   </index>{$eol}");
             }
         }
         $output("{$eol}  </declaration>{$eol}");
         if ($dump_definition) {
             if (isset($this->database_definition["TABLES"][$table_name]["initialization"])) {
                 $output("{$eol}  <initialization>{$eol}");
                 $instructions = $this->database_definition["TABLES"][$table_name]["initialization"];
                 for (Reset($instructions), $instruction = 0; $instruction < count($instructions); $instruction++, Next($instructions)) {
                     switch ($instructions[$instruction]["type"]) {
                         case "insert":
                             $output("{$eol}   <insert>{$eol}");
                             $fields = $instructions[$instruction]["FIELDS"];
                             for (Reset($fields), $field_number = 0; $field_number < count($fields); $field_number++, Next($fields)) {
                                 $field_name = Key($fields);
                                 $output("{$eol}    <field>{$eol}     <name>{$field_name}</name>{$eol}     <value>" . $this->EscapeSpecialCharacters($fields[$field_name]) . "</value>{$eol}    </field>{$eol}");
                             }
                             $output("{$eol}   </insert>{$eol}");
                             break;
                     }
                 }
                 $output("{$eol}  </initialization>{$eol}");
             }
         } else {
             if (count($this->database_definition["TABLES"][$table_name]["FIELDS"]) == 0) {
                 return "the definition of the table \"{$table_name}\" does not contain any fields";
             }
             if (strcmp($error = $this->GetFields($table_name, $query_fields), "")) {
                 return $error;
             }
             if ($support_summary_functions = MetabaseSupport($this->database, "SummaryFunctions")) {
                 if (($result = MetabaseQuery($this->database, "SELECT COUNT(*) FROM {$table_name}")) == 0) {
                     return MetabaseError($this->database);
                 }
                 $rows = MetabaseFetchResult($this->database, $result, 0, 0);
                 MetabaseFreeResult($this->database, $result);
             }
             if (($result = MetabaseQuery($this->database, "SELECT {$query_fields} FROM {$table_name}")) == 0) {
                 return MetabaseError($this->database);
             }
             if (!$support_summary_functions) {
                 $rows = MetabaseNumberOfRows($this->database, $result);
             }
             if ($rows > 0) {
                 $output("{$eol}  <initialization>{$eol}");
                 for ($row = 0; $row < $rows; $row++) {
                     $output("{$eol}   <insert>{$eol}");
                     for (Reset($fields), $field_number = 0; $field_number < count($fields); $field_number++, Next($fields)) {
                         $field_name = Key($fields);
                         if (!MetabaseResultIsNull($this->database, $result, $row, $field_name)) {
                             $field = $fields[$field_name];
                             $output("{$eol}    <field>{$eol}     <name>{$field_name}</name>{$eol}     <value>");
                             switch ($field["type"]) {
                                 case "integer":
                                 case "text":
                                     $output($this->EscapeSpecialCharacters(MetabaseFetchResult($this->database, $result, $row, $field_name)));
                                     break;
                                 case "clob":
                                     if (!($lob = MetabaseFetchCLOBResult($this->database, $result, $row, $field_name))) {
                                         return MetabaseError($this->database);
                                     }
                                     while (!MetabaseEndOfLOB($lob)) {
                                         if (MetabaseReadLOB($lob, $data, 8000) < 0) {
                                             return MetabaseLOBError($lob);
                                         }
                                         $output($this->EscapeSpecialCharacters($data));
                                     }
                                     MetabaseDestroyLOB($lob);
                                     break;
                                 case "blob":
                                     if (!($lob = MetabaseFetchBLOBResult($this->database, $result, $row, $field_name))) {
                                         return MetabaseError($this->database);
                                     }
                                     while (!MetabaseEndOfLOB($lob)) {
                                         if (MetabaseReadLOB($lob, $data, 8000) < 0) {
                                             return MetabaseLOBError($lob);
                                         }
                                         $output(bin2hex($data));
                                     }
                                     MetabaseDestroyLOB($lob);
                                     break;
                                 case "float":
                                     $output($this->EscapeSpecialCharacters(MetabaseFetchFloatResult($this->database, $result, $row, $field_name)));
                                     break;
                                 case "decimal":
                                     $output($this->EscapeSpecialCharacters(MetabaseFetchDecimalResult($this->database, $result, $row, $field_name)));
                                     break;
                                 case "boolean":
                                     $output($this->EscapeSpecialCharacters(MetabaseFetchBooleanResult($this->database, $result, $row, $field_name)));
                                     break;
                                 case "date":
                                     $output($this->EscapeSpecialCharacters(MetabaseFetchDateResult($this->database, $result, $row, $field_name)));
                                     break;
                                 case "timestamp":
                                     $output($this->EscapeSpecialCharacters(MetabaseFetchTimestampResult($this->database, $result, $row, $field_name)));
                                     break;
                                 case "time":
                                     $output($this->EscapeSpecialCharacters(MetabaseFetchTimeResult($this->database, $result, $row, $field_name)));
                                     break;
                                 default:
                                     return "type \"" . $field["type"] . "\" is not yet supported";
                             }
                             $output("</value>{$eol}    </field>{$eol}");
                         }
                     }
                     $output("{$eol}   </insert>{$eol}");
                 }
                 $output("{$eol}  </initialization>{$eol}");
             }
             MetabaseFreeResult($this->database, $result);
         }
         $output("{$eol} </table>{$eol}");
         if (isset($sequences[$table_name])) {
             for ($sequence = 0; $sequence < count($sequences[$table_name]); $sequence++) {
                 if (!$this->DumpSequence($sequences[$table_name][$sequence], $output, $eol, $dump_definition)) {
                     return MetabaseError($this->database);
                 }
             }
         }
     }
     if (isset($sequences[""])) {
         for ($sequence = 0; $sequence < count($sequences[""]); $sequence++) {
             if (!$this->DumpSequence($sequences[""][$sequence], $output, $eol, $dump_definition)) {
                 return MetabaseError($this->database);
             }
         }
     }
     $output("{$eol}</database>{$eol}");
     if (strcmp($previous_database_name, "")) {
         MetabaseSetDatabase($this->database, $previous_database_name);
     }
     return $error;
 }
示例#2
0
                         MetabaseFreeResult($database, $result);
                     }
                 }
             } else {
                 $success = 0;
             }
             if ($success && $pass) {
                 $passed++;
                 echo "OK.{$eol}";
             }
         }
     } else {
         echo "Transactions are not supported.{$eol}";
     }
 }
 $support_lobs = MetabaseSupport($database, "LOBs");
 if ((isset($tests["lobstorage"]) || isset($tests["lobfiles"]) || isset($tests["lobnulls"])) && $success) {
     if ($support_lobs) {
         $input_file = "lob_test.schema";
         if (!($success = $manager->UpdateDatabase($input_file, $input_file . ".before", $driver_arguments, $database_variables))) {
             $error = $manager->error;
         }
         $debug_output = "";
         if (count($manager->warnings) > 0) {
             $debug_output .= "WARNING:{$eol}" . implode($manager->warnings, "!{$eol}") . $eol;
         }
         if ($manager->database && isset($driver_arguments["CaptureDebug"])) {
             $debug_output .= MetabaseDebugOutput($manager->database);
         }
     } else {
         echo "LOBs are not supported.{$eol}";