コード例 #1
0
ファイル: driver_test.php プロジェクト: BackupTheBerlios/zvs
     if (MetabaseReadLOB($clob, $data, 8000) < 0) {
         $error = MetabaseLOBError($clob);
         $success = 0;
         break;
     }
     $value .= $data;
 }
 MetabaseDestroyLOB($clob);
 if ($success) {
     if (strcmp($value, $character_lob["Data"])) {
         $pass = 0;
         echo "FAILED!{$eol}";
         $failed++;
         echo "Test {$test}: retrieved character LOB value (\"" . $value . "\") is different from what was stored (\"" . $character_lob["Data"] . "\"){$eol}";
     } else {
         $blob = MetabaseFetchBLOBResult($database, $result, 0, "picture");
         if ($blob) {
             for ($value = ""; !MetabaseEndOfLOB($blob);) {
                 if (MetabaseReadLOB($blob, $data, 8000) < 0) {
                     $error = MetabaseLOBError($blob);
                     $success = 0;
                     break;
                 }
                 $value .= $data;
             }
             MetabaseDestroyLOB($blob);
             if ($success) {
                 if (strcmp($value, $binary_lob["Data"])) {
                     $pass = 0;
                     echo "FAILED!{$eol}";
                     $failed++;
コード例 #2
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;
 }
コード例 #3
0
ファイル: metabase_lob.php プロジェクト: BackupTheBerlios/zvs
 function Create(&$arguments)
 {
     global $metabase_lobs;
     if (isset($arguments["BufferLength"])) {
         if ($arguments["BufferLength"] <= 0) {
             $this->error = "it was specified an invalid buffer length";
             return 0;
         }
         $this->buffer_length = $arguments["BufferLength"];
     }
     if (isset($arguments["File"])) {
         if (intval($arguments["File"]) == 0) {
             $this->error = "it was specified an invalid output file identifier";
             return 0;
         }
         $this->file = $arguments["File"];
     } else {
         if (isset($arguments["FileName"])) {
             if (!($this->file = fopen($arguments["FileName"], "wb"))) {
                 $this->error = "could not open specified output file (\"" . $arguments["FileName"] . "\")";
                 return 0;
             }
             $this->opened_file = 1;
         } else {
             $this->error = "it was not specified the output file";
             return 0;
         }
     }
     if (isset($arguments["LOB"])) {
         if (!isset($metabase_lobs[$arguments["LOB"]])) {
             $this->Destroy();
             $this->error = "it was specified an invalid input large object identifier";
             return 0;
         }
         $this->input_lob = $arguments["LOB"];
     } else {
         if ($this->database && isset($arguments["Result"]) && isset($arguments["Row"]) && isset($arguments["Field"]) && isset($arguments["Binary"])) {
             if ($arguments["Binary"]) {
                 $this->input_lob = MetabaseFetchBLOBResult($this->database, $arguments["Result"], $arguments["Row"], $arguments["Field"]);
             } else {
                 $this->input_lob = MetabaseFetchCLOBResult($this->database, $arguments["Result"], $arguments["Row"], $arguments["Field"]);
             }
             if ($this->input_lob == 0) {
                 $this->Destroy();
                 $this->error = "could not fetch the input result large object";
                 return 0;
             }
             $this->opened_lob = 1;
         } else {
             $this->Destroy();
             $this->error = "it was not specified the input large object identifier";
             return 0;
         }
     }
     return 1;
 }