Esempio n. 1
0
 /**
  * Get drop SQL suitable for use in an ALTER TABLE statement
  * @param  SimpleXMLElement $node_schema
  * @param  SimpleXMLElement $node_table
  * @param  SimpleXMLElement $node_index
  * @return string
  */
 public static function get_alter_drop_sql($node_schema, $node_table, $node_index)
 {
     return 'DROP INDEX ' . mysql5::get_quoted_object_name($node_index['name']);
 }
 public static function get_constraint_drop_sql($constraint, $with_alter_table = TRUE)
 {
     if (!is_array($constraint)) {
         throw new exception("constraint is not an array?");
     }
     if (strlen($constraint['table_name']) == 0) {
         var_dump(array_keys($constraint));
         throw new exception("table_name is blank");
     }
     // because MySQL refuses to have consistent syntax
     switch (strtoupper($constraint['type'])) {
         case 'CHECK':
             // @TODO: Implement compatibility
             dbsteward::warning("Not dropping constraint '{$constraint['name']}' on table '{$constraint['table_name']}' because MySQL doesn't support the CHECK constraint");
             return "-- Not dropping constraint '{$constraint['name']}' on table '{$constraint['table_name']}' because MySQL doesn't support the CHECK constraint";
             break;
         case 'UNIQUE':
             $drop = "INDEX " . mysql5::get_quoted_object_name($constraint['name']);
             break;
         case 'PRIMARY KEY':
             $drop = "PRIMARY KEY";
             break;
         case 'FOREIGN KEY':
             $drop = "FOREIGN KEY " . mysql5::get_quoted_object_name($constraint['name']);
             break;
         case 'KEY':
             $drop = "KEY " . mysql5::get_quoted_object_name($constraint['name']);
             break;
         default:
             // we shouldn't actually ever get here.
             throw new Exception("Unimplemented MySQL constraint {$constraint['type']}");
     }
     $sql = '';
     if ($with_alter_table) {
         $sql .= "ALTER TABLE " . mysql5::get_fully_qualified_table_name($constraint['schema_name'], $constraint['table_name']) . " ";
     }
     $sql .= "DROP {$drop}";
     if ($with_alter_table) {
         $sql .= ";";
     }
     return $sql;
 }
Esempio n. 3
0
 protected static function map_partition_segments($table_name, $tablePartition, $callback)
 {
     $segs = array();
     foreach ($tablePartition->tablePartitionSegment as $segment) {
         $name = isset($segment['name']) ? trim($segment['name']) : '';
         $value = isset($segment['value']) ? trim($segment['value']) : '';
         if (strlen($name) === 0) {
             throw new exception("No tablePartitionSegment name given for table {$table_name}");
         }
         if (strlen($value) === 0) {
             throw new exception("No tablePartitionSegment value given for tablePartitionSegment {$name} on table {$table_name}");
         }
         $name = mysql5::get_quoted_object_name($name);
         $segs[] = call_user_func($callback, $name, $value);
     }
     if (count($segs) === 0) {
         throw new exception("At least one tablePartitionSegment must be defined for {$type} partition on table {$table_name}");
     }
     return $segs;
 }