コード例 #1
0
 /** Did the table change schemas? */
 protected static function is_moved_table($schema, $table)
 {
     if (!isset($table['oldSchemaName']) || !mysql5::$use_schema_name_prefix) {
         // no oldSchemaName means it didn't move
         // or, if we're not using prefixes, everything should be in the same "schema", so no
         return false;
     }
     $old_schema = format_table::get_old_table_schema($schema, $table);
     if (is_null($old_schema)) {
         throw new Exception("Table {$schema['name']}.{$table['name']} indicates it was moved from schema {$table['oldSchemaName']}, but no such schema was found!");
     }
     return true;
 }
コード例 #2
0
 public static function update_table_options($ofs1, $ofs3, $old_schema, $old_table, $new_schema, $new_table)
 {
     if (strcasecmp(dbsteward::get_sql_format(), 'mssql10') === 0) {
         dbsteward::warning("mssql10 tableOptions are not implemented yet");
         return;
     }
     if ($new_schema && $new_table) {
         $alter_options = array();
         $create_options = array();
         $drop_options = array();
         $old_options = format_table::get_table_options($old_schema, $old_table);
         $new_options = format_table::get_table_options($new_schema, $new_table);
         // dropped options are those present in the old table, but not in the new
         $drop_options = array_diff_key($old_options, $new_options);
         // added options are those present in the new table but not in the old
         $create_options = array_diff_key($new_options, $old_options);
         // altered options are those present in both but with different values
         $alter_options = array_intersect_ukey($new_options, $old_options, function ($new_key, $old_key) use($new_options, $old_options) {
             if ($new_key == $old_key && strcasecmp($new_options[$new_key], $old_options[$old_key]) !== 0) {
                 return 0;
             } else {
                 return -1;
             }
         });
         static::apply_table_options_diff($ofs1, $ofs3, $new_schema, $new_table, $alter_options, $create_options, $drop_options);
     }
 }
コード例 #3
0
ファイル: dbx.php プロジェクト: williammoran/DBSteward
 /**
  * determine SQL clause expression to match for data_row primary keys
  *
  * @return string
  */
 public static function primary_key_expression($db_doc, $node_schema, $node_table, $data_row_columns, $data_row)
 {
     $primary_keys = format_table::primary_key_columns($node_table);
     $primary_key_index = xml_parser::data_row_overlay_primary_key_index($primary_keys, $data_row_columns, $data_row_columns);
     $primary_key_index = $primary_key_index['base'];
     // figure out the primary key expression
     $primary_key_expression = array();
     foreach ($primary_keys as $primary_column_name) {
         if (!isset($primary_key_index[$primary_column_name])) {
             throw new exception("primary key column named {$primary_column_name} not found in primary_key_index");
         }
         $column_index = $primary_key_index[$primary_column_name];
         // get the type of the column, chasing foreign keys if necessary
         $node_column = dbx::get_table_column($node_table, $primary_column_name);
         $value_type = format_column::column_type($db_doc, $node_schema, $node_table, $node_column, $foreign);
         $primary_key_expression[] = format::get_quoted_column_name($primary_column_name) . ' = ' . format::value_escape($value_type, $data_row->col[$column_index]);
     }
     if (count($primary_key_expression) == 0) {
         throw new exception($node_table['name'] . " primary_key_expression is empty, determinate loop failed");
     }
     return implode(' AND ', $primary_key_expression);
 }
コード例 #4
0
 /**
  * Returns list of constraints that should be added.
  *
  * @param old_table original table
  * @param new_table new table
  * @param type whether primary keys should be processed or other constraints should be processed
  *
  * @return list of constraints that should be added
  */
 protected static function get_new_constraints($old_schema, $old_table, $new_schema, $new_table, $type)
 {
     $list = array();
     if ($new_table != null) {
         if ($old_table == null) {
             foreach (format_constraint::get_table_constraints(dbsteward::$new_database, $new_schema, $new_table, $type) as $constraint) {
                 $list[] = $constraint;
             }
         } else {
             foreach (format_constraint::get_table_constraints(dbsteward::$new_database, $new_schema, $new_table, $type) as $constraint) {
                 $old_constraint = format_constraint::get_table_constraint(dbsteward::$old_database, $old_schema, $old_table, $constraint['name']);
                 if (!format_table::contains_constraint(dbsteward::$old_database, $old_schema, $old_table, $constraint['name']) || !format_constraint::equals($old_constraint, $constraint)) {
                     $list[] = $constraint;
                 }
             }
         }
     }
     return $list;
 }
コード例 #5
0
 /**
  * Returns list of indexes that should be added.
  *
  * @param old_table original table
  * @param new_table new table
  *
  * @return list of indexes that should be added
  */
 public static function get_new_indexes($old_schema, $old_table, $new_schema, $new_table)
 {
     $list = array();
     if ($new_table != null) {
         if ($old_table == null) {
             foreach (format_index::get_table_indexes($new_schema, $new_table) as $index) {
                 $list[] = $index;
             }
         } else {
             foreach (format_index::get_table_indexes($new_schema, $new_table) as $index) {
                 $old_index = format_index::get_table_index($old_schema, $old_table, $index['name']);
                 if (!format_table::contains_index($old_schema, $old_table, $index['name'])) {
                     $list[] = $index;
                 } else {
                     if (!format_index::equals($old_index, $index)) {
                         $list[] = $index;
                     }
                 }
             }
         }
     }
     return $list;
 }