function CreateSequence($sequence_name, $sequence, $created_on_table)
 {
     if (!MetabaseSupport($this->database, "Sequences")) {
         return "sequences are not supported";
     }
     MetabaseDebug($this->database, "Create sequence: " . $sequence_name);
     if (!isset($sequence_name) || !strcmp($sequence_name, "")) {
         return "it was not specified a valid sequence name";
     }
     $start = $sequence["start"];
     if (isset($sequence["on"]) && !$created_on_table) {
         $table = $sequence["on"]["table"];
         $field = $sequence["on"]["field"];
         if (MetabaseSupport($this->database, "SummaryFunctions")) {
             $field = "MAX({$field})";
         }
         if (!($result = MetabaseQuery($this->database, "SELECT {$field} FROM {$table}"))) {
             return MetabaseError($this->database);
         }
         if ($rows = MetabaseNumberOfRows($this->database, $result)) {
             for ($row = 0; $row < $rows; $row++) {
                 if (!MetabaseResultIsNull($this->database, $result, $row, 0) && ($value = MetabaseFetchResult($this->database, $result, $row, 0) + 1) > $start) {
                     $start = $value;
                 }
             }
         }
         MetabaseFreeResult($this->database, $result);
     }
     if (!MetabaseCreateSequence($this->database, $sequence_name, $start)) {
         return MetabaseError($this->database);
     }
     return "";
 }
Exemple #2
0
             }
         }
     } else {
         echo "Selecting rows ranges is not supported.{$eol}";
     }
 }
 if (isset($tests["sequences"]) && $success) {
     if (MetabaseSupport($database, "Sequences")) {
         $test = "sequences";
         echo "Testing sequences... ";
         flush();
         $pass = 1;
         for ($start_value = 1; $success && $pass && $start_value < 4; $start_value++) {
             $sequence_name = "test_sequence_{$start_value}";
             MetabaseDropSequence($database, $sequence_name);
             if ($success = MetabaseCreateSequence($database, $sequence_name, $start_value)) {
                 for ($sequence_value = $start_value; $sequence_value < $start_value + 4; $sequence_value++) {
                     if (!($success = MetabaseGetSequenceNextValue($database, $sequence_name, $value))) {
                         break;
                     }
                     if ($value != $sequence_value) {
                         $pass = 0;
                         echo "FAILED!{$eol}";
                         $failed++;
                         echo "Test {$test}: the returned sequence value is {$value} and not {$sequence_value} as expected with sequence start value with {$start_value}{$eol}";
                         break;
                     }
                 }
                 if (!$success) {
                     $error = MetabaseError($database);
                 }