コード例 #1
0
 function CreateTable($table_name, $table)
 {
     MetabaseDebug($this->database, "Create table: " . $table_name);
     if (!MetabaseCreateTable($this->database, $table_name, $table["FIELDS"])) {
         return MetabaseError($this->database);
     }
     $success = 1;
     $error = "";
     if (isset($table["initialization"])) {
         $instructions = $table["initialization"];
         for (Reset($instructions), $instruction = 0; $success && $instruction < count($instructions); $instruction++, Next($instructions)) {
             switch ($instructions[$instruction]["type"]) {
                 case "insert":
                     $fields = $instructions[$instruction]["FIELDS"];
                     for ($query_fields = $query_values = "", Reset($fields), $field_number = 0; $field_number < count($fields); $field_number++, Next($fields)) {
                         if ($field_number > 0) {
                             $query_fields .= ",";
                             $query_values .= ",";
                         }
                         $field_name = Key($fields);
                         $field = $table["FIELDS"][$field_name];
                         if (strcmp($error = $this->GetField($field, $field_name, 0, $query), "")) {
                             return $error;
                         }
                         $query_fields .= $query;
                         $query_values .= "?";
                     }
                     if ($success = $prepared_query = MetabasePrepareQuery($this->database, "INSERT INTO {$table_name} ({$query_fields}) VALUES ({$query_values})")) {
                         for ($lobs = array(), Reset($fields), $field_number = 0; $field_number < count($fields); $field_number++, Next($fields)) {
                             $field_name = Key($fields);
                             $field = $table["FIELDS"][$field_name];
                             if (strcmp($error = $this->GetField($field, $field_name, 0, $query), "")) {
                                 return $error;
                             }
                             switch ($field["type"]) {
                                 case "integer":
                                     $success = MetabaseQuerySetInteger($this->database, $prepared_query, $field_number + 1, intval($fields[$field_name]));
                                     break;
                                 case "text":
                                     $success = MetabaseQuerySetText($this->database, $prepared_query, $field_number + 1, $fields[$field_name]);
                                     break;
                                 case "clob":
                                     $lob_definition = array("Database" => $this->database, "Error" => "", "Data" => $fields[$field_name]);
                                     $lob = count($lobs);
                                     if (!($success = MetabaseCreateLOB($lob_definition, $lobs[$lob]))) {
                                         $error = $lob_definition["Error"];
                                         break;
                                     }
                                     $success = MetabaseQuerySetCLOB($this->database, $prepared_query, $field_number + 1, $lobs[$lob], $field_name);
                                     break;
                                 case "blob":
                                     $lob_definition = array("Database" => $this->database, "Error" => "", "Data" => $fields[$field_name]);
                                     $lob = count($lobs);
                                     if (!($success = MetabaseCreateLOB($lob_definition, $lobs[$lob]))) {
                                         $error = $lob_definition["Error"];
                                         break;
                                     }
                                     $success = MetabaseQuerySetBLOB($this->database, $prepared_query, $field_number + 1, $lobs[$lob], $field_name);
                                     break;
                                 case "boolean":
                                     $success = MetabaseQuerySetBoolean($this->database, $prepared_query, $field_number + 1, intval($fields[$field_name]));
                                     break;
                                 case "date":
                                     $success = MetabaseQuerySetDate($this->database, $prepared_query, $field_number + 1, $fields[$field_name]);
                                     break;
                                 case "timestamp":
                                     $success = MetabaseQuerySetTimestamp($this->database, $prepared_query, $field_number + 1, $fields[$field_name]);
                                     break;
                                 case "time":
                                     $success = MetabaseQuerySetTime($this->database, $prepared_query, $field_number + 1, $fields[$field_name]);
                                     break;
                                 case "float":
                                     $success = MetabaseQuerySetFloat($this->database, $prepared_query, $field_number + 1, doubleval($fields[$field_name]));
                                     break;
                                 case "decimal":
                                     $success = MetabaseQuerySetDecimal($this->database, $prepared_query, $field_number + 1, $fields[$field_name]);
                                     break;
                                 default:
                                     $error = "type \"" . $field["type"] . "\" is not yet supported";
                                     $success = 0;
                                     break;
                             }
                             if (!$success && $error == "") {
                                 $error = MetabaseError($this->database);
                                 break;
                             }
                         }
                         if ($success && !($success = MetabaseExecuteQuery($this->database, $prepared_query))) {
                             $error = MetabaseError($this->database);
                         }
                         for ($lob = 0; $lob < count($lobs); $lob++) {
                             MetabaseDestroyLOB($lobs[$lob]);
                         }
                         MetabaseFreePreparedQuery($this->database, $prepared_query);
                     } else {
                         $error = MetabaseError($this->database);
                     }
                     break;
             }
         }
     }
     if ($success && isset($table["INDEXES"])) {
         if (!MetabaseSupport($this->database, "Indexes")) {
             return "indexes are not supported";
         }
         $indexes = $table["INDEXES"];
         for ($index = 0, Reset($indexes); $index < count($indexes); Next($indexes), $index++) {
             if (!MetabaseCreateIndex($this->database, $table_name, Key($indexes), $indexes[Key($indexes)])) {
                 $error = MetabaseError($this->database);
                 $success = 0;
                 break;
             }
         }
     }
     if (!$success) {
         if (!MetabaseDropTable($this->database, $table_name)) {
             $error = "could not initialize the table \"{$table_name}\" ({$error}) and then could not drop the table (" . MetabaseError($this->database) . ")";
         }
     }
     return $error;
 }
コード例 #2
0
 function FetchLOBResult($result, $row, $field)
 {
     $lob = count($this->lobs) + 1;
     $this->lobs[$lob] = array("Result" => $result, "Row" => $row, "Field" => $field, "Position" => 0);
     $character_lob = array("Database" => $this->database, "Error" => "", "Type" => "resultlob", "ResultLOB" => $lob);
     if (!MetabaseCreateLOB($character_lob, $clob)) {
         return $this->SetError("Fetch LOB result", $character_lob["Error"]);
     }
     return $clob;
 }
コード例 #3
0
ファイル: driver_test.php プロジェクト: BackupTheBerlios/zvs
         }
         fclose($file);
     } else {
         $success = 0;
         $error = "could not reopen the character lob data file";
     }
 }
 if ($success) {
     if (strcmp($value, $character_data)) {
         $pass = 0;
         echo "FAILED!{$eol}";
         $failed++;
         echo "Test {$test}: retrieved character LOB value (\"" . $value . "\") is different from what was stored (\"" . $character_data . "\"){$eol}";
     } else {
         $binary_lob = array("Type" => "outputfile", "Database" => $database, "Result" => $result, "Row" => 0, "Field" => "picture", "Binary" => 1, "Error" => "", "FileName" => $binary_data_file, "BufferLength" => 32);
         if ($success = MetabaseCreateLOB($binary_lob, $blob)) {
             if (MetabaseReadLOB($blob, $data, 0) < 0) {
                 $error = MetabaseLOBError($clob);
                 $success = 0;
             }
             MetabaseDestroyLOB($blob);
             if ($success) {
                 if ($file = fopen($binary_data_file, "rb")) {
                     if (GetType($value = fread($file, filesize($binary_data_file))) != "string") {
                         $success = 0;
                         $error = "could not read from the binary lob data file";
                     }
                     fclose($file);
                 } else {
                     $success = 0;
                     $error = "could not reopen the binary lob data file";