Ejemplo n.º 1
0
 function SearchCompleteValues(&$form, $text, &$found)
 {
     $error = '';
     $found = array();
     if (strlen($complete_expression = MetabaseBeginsWith($this->connection, $text)) == 0) {
         return 'it was not possible to build the complete query expression: ' . MetabaseError($this->connection);
     }
     if (!strcmp($complete_values_query = str_replace('{BEGINSWITH}', $complete_expression, $this->complete_values_query), $this->complete_values_query)) {
         return 'the complete values query does not contain the {BEGINSWITH} mark to insert the complete expression';
     }
     if (strlen($text) && $this->complete_values_limit) {
         MetabaseSetSelectedRowRange($this->connection, 0, $this->complete_values_limit);
     }
     if ($r = MetabaseQuery($this->connection, $complete_values_query)) {
         for ($l = 0; !MetabaseEndOfResult($this->connection, $r); $l++) {
             if (!MetabaseFetchResultArray($this->connection, $r, $d, $l)) {
                 $error = 'Could not retrieve the complete values: ' . MetabaseError($this->connection);
                 break;
             }
             $found[$d[0]] = $this->FormatCompleteValue($d);
         }
         MetabaseFreeResult($this->connection, $r);
     } else {
         $error = 'Complete values query execution failed: ' . MetabaseError($this->connection);
     }
     return $error;
 }
Ejemplo n.º 2
0
 function GetGroups(&$g)
 {
     if (strlen($this->groups_query) == 0) {
         return "it was not specified a valid query to retrieve all the options groups";
     }
     $g = array();
     if (isset($this->default_option)) {
         $g[] = $this->default_option;
     }
     $error = "";
     if ($r = MetabaseQuery($this->connection, $this->groups_query)) {
         for ($l = 0; !MetabaseEndOfResult($this->connection, $r); $l++) {
             if (!MetabaseFetchResultArray($this->connection, $r, $d, $l)) {
                 $error = "Could not retrieve the options group: " . MetabaseError($this->connection);
                 break;
             }
             $g[] = $d[0];
         }
         if (count($g) == 0 && strlen($error) == 0) {
             $error = "there are no group options";
         }
         MetabaseFreeResult($this->connection, $r);
     } else {
         $error = "Groups query execution failed: " . MetabaseError($this->connection);
     }
     if (strlen($error)) {
         unset($g);
     }
     return $error;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 function freeResults()
 {
     $success = @MetabaseFreeResult($this->db, $this->result);
     if ($success == true) {
         return true;
     } else {
         $this->error = $success;
         return false;
     }
 }
Ejemplo n.º 5
0
                 $success = 0;
             } else {
                 if (MetabaseEndOfResult($database, $result)) {
                     $pass = 0;
                     echo "FAILED!{$eol}";
                     $failed++;
                     echo "Test {$test}: the query result seem to have reached the end of result too soon.{$eol}";
                 } else {
                     if (!MetabaseResultIsNull($database, $result, 0, $field = "document") || !MetabaseResultIsNull($database, $result, 0, $field = "picture")) {
                         $pass = 0;
                         echo "FAILED!{$eol}";
                         $failed++;
                         echo "Test {$test}: a query result large object column is not NULL unlike what was expected{$eol}";
                     }
                 }
                 MetabaseFreeResult($database, $result);
             }
         } else {
             $success = 0;
         }
     }
     if ($success && $pass) {
         $passed++;
         echo "OK.{$eol}";
     }
 }
 if (!$success && !strcmp($error, "")) {
     $error = MetabaseError($database);
 }
 if (isset($driver_arguments["CaptureDebug"])) {
     $debug_output .= MetabaseDebugOutput($database);
Ejemplo n.º 6
0
 /**
  * Booking::showPossibleEscorts()
  * 
  * show all guest who have a booking with a guest without actual escorts
  * 
  * @param int $bookingdetailid booking detail id
  * @param int $guestid guest id
  * @return array guest data
  * @access public 
  * @since 2004-06-27
  * @author Christian Ehret <*****@*****.**> 
  */
 function showPossibleEscorts($bookingdetailid, $guestid)
 {
     global $gDatabase, $tbl_guest, $tbl_address, $tbl_guest_address, $tbl_booking_detail_guest, $tbl_country, $errorhandler, $request;
     $guest = array();
     $exclguest = array();
     $query = "SELECT pk_fk_guest_id FROM {$tbl_booking_detail_guest} WHERE pk_fk_booking_detail_id = {$bookingdetailid}";
     $result = MetabaseQuery($gDatabase, $query);
     if (!$result) {
         $errorhandler->display('SQL', 'Booking::showPossibleEscorts()', $query);
     } else {
         $row = 0;
         for ($row = 0; ($eor = MetabaseEndOfResult($gDatabase, $result)) == 0; ++$row) {
             $exclguest[$row] = MetabaseFetchResult($gDatabase, $result, $row, 0);
         }
     }
     MetabaseFreeResult($gDatabase, $result);
     $query = "( \n\t\t\t\t\tSELECT DISTINCT b.fk_guest_id AS pk_guest_id, g.lastname AS lastname, \n\t\t\t\t\t\tg.firstname AS firstname, a.city AS city, c.country_de  AS country_de \n\t\t\t\t\tFROM zvs_booking_detail_guest bdg \n\t\t\t\t\tLEFT JOIN zvs_booking_detail bd ON bdg.pk_fk_booking_detail_id = bd.pk_booking_detail_id \n\t\t\t\t\tLEFT JOIN zvs_booking b ON bd.fk_booking_id = b.pk_booking_id \n\t\t\t\t\tLEFT JOIN zvs_guest g ON b.fk_guest_id = g.pk_guest_id \n\t\t\t\t  LEFT JOIN {$tbl_guest_address} ga ON g.pk_guest_id = ga.pk_fk_guest_id \n\t\t\t\t  \t\t\t\t\t\t\tAND ga.default_address = " . MetabaseGetBooleanFieldValue($gDatabase, true) . "\t\t\t\t  \n\t\t\t\t  LEFT JOIN {$tbl_address} a ON a.pk_address_id = ga.pk_fk_address_id\n\t              LEFT JOIN {$tbl_country} c ON c.pk_country_id = a.fk_country_id \t\t\t\t\t\n\t\t\t\t\tWHERE bdg.pk_fk_guest_id =  {$guestid} \n\t\t\t\t\t\tAND b.fk_guest_id != {$guestid} \n\t\t\t\t";
     if (count($exclguest > 0)) {
         $query .= " AND g.pk_guest_id ";
         if (count($exclguest) > 1) {
             $query .= " NOT IN (";
             for ($i = 0; $i < count($exclguest); $i++) {
                 if ($i != 0) {
                     $query .= ", ";
                 }
                 $query .= $exclguest[$i];
             }
             $query .= ") ";
         } else {
             $query .= "<> {$exclguest['0']} ";
         }
     }
     $query .= "\tGROUP BY pk_guest_id \t\t\t\t\t\n\t\t\t\t  ) UNION ( \n\t\t\t\t    SELECT DISTINCT bdg2.pk_fk_guest_id AS pk_guest_id, g.lastname AS lastname, \n\t\t\t\t\t\tg.firstname AS firstname, a.city AS city, c.country_de  AS country_de\n\t\t\t\t\tFROM zvs_booking_detail_guest bdg \n\t\t\t\t\tLEFT JOIN zvs_booking_detail bd ON bdg.pk_fk_booking_detail_id = bd.pk_booking_detail_id \n\t\t\t\t\tLEFT JOIN zvs_booking b ON bd.fk_booking_id = b.pk_booking_id \n\t\t\t\t\tLEFT JOIN zvs_booking_detail bd2 ON b.pk_booking_id = bd2.fk_booking_id \n\t\t\t\t\tLEFT JOIN zvs_booking_detail_guest bdg2 ON bd2.pk_booking_detail_id = bdg2.pk_fk_booking_detail_id \n\t\t\t\t\tLEFT JOIN zvs_guest g ON bdg2.pk_fk_guest_id = g.pk_guest_id \n\t\t\t\t  LEFT JOIN {$tbl_guest_address} ga ON g.pk_guest_id = ga.pk_fk_guest_id \n\t\t\t\t  \tAND ga.default_address = " . MetabaseGetBooleanFieldValue($gDatabase, true) . "\n\t\t\t\t  LEFT JOIN {$tbl_address} a ON a.pk_address_id = ga.pk_fk_address_id\n\t              LEFT JOIN {$tbl_country} c ON c.pk_country_id = a.fk_country_id \t\t\t\t\t\n\t\t\t\t\tWHERE bdg.pk_fk_guest_id =  {$guestid} \n\t\t\t\t\t\t AND bdg2.pk_fk_guest_id != {$guestid} \n\t\t\t\t";
     if (count($exclguest > 0)) {
         $query .= " AND g.pk_guest_id ";
         if (count($exclguest) > 1) {
             $query .= " NOT IN (";
             for ($i = 0; $i < count($exclguest); $i++) {
                 if ($i != 0) {
                     $query .= ", ";
                 }
                 $query .= $exclguest[$i];
             }
             $query .= " ) ";
         } else {
             $query .= "<> {$exclguest['0']} ";
         }
     }
     $query .= " GROUP BY pk_guest_id \n\t\t\t\t) \n\t\t\t\tORDER BY lastname, firstname ";
     $result = MetabaseQuery($gDatabase, $query);
     if (!$result) {
         $errorhandler->display('SQL', 'Booking::showPossibleEscorts()', $query);
     } else {
         $row = 0;
         for ($row = 0; $row < MetabaseNumberOfRows($gDatabase, $result); ++$row) {
             $color = 0;
             if ($row % 2 != 0) {
                 $color = 1;
             }
             $guest[$row] = array('guestid' => MetabaseFetchResult($gDatabase, $result, $row, 0), 'firstname' => MetabaseFetchResult($gDatabase, $result, $row, 2), 'lastname' => MetabaseFetchResult($gDatabase, $result, $row, 1), 'city' => MetabaseFetchResult($gDatabase, $result, $row, 3), 'country_name' => MetabaseFetchResult($gDatabase, $result, $row, 4), 'color' => $color);
         }
     }
     return $guest;
 }