Exemplo n.º 1
0
 /**
  * for type defintion changes, temporarily change all tables columns that reference the type
  *
  * @param $columns      reference columns returned by reference
  * @param $node_schema
  * @param $node_type
  * @return string DDL
  */
 public static function column_constraint_temporary_drop(&$columns, $node_schema, $node_type)
 {
     $ddl = '';
     for ($i = 0; $i < count(mssql10_diff::$new_table_dependency); $i++) {
         // find the necessary pointers
         $table_item = mssql10_diff::$new_table_dependency[$i];
         if ($table_item['table']['name'] === dbsteward::TABLE_DEPENDENCY_IGNORABLE_NAME) {
             // don't do anything with this table, it is a magic internal DBSteward value
             continue;
         }
         $new_schema = $table_item['schema'];
         $new_table = $table_item['table'];
         foreach (dbx::get_table_columns($new_table) as $new_column) {
             // is the column the passed type?
             $unquoted_type_name = $node_schema['name'] . '.' . $node_type['name'];
             if (strcasecmp($new_column['type'], $unquoted_type_name) == 0) {
                 $ddl .= mssql10_type::get_drop_check_sql($new_schema, $new_table, $new_column, $node_type);
                 // add column to the beginning of the list so it will be done before earlier changes (foreign key ordering)
                 array_unshift($columns, array('alter_column_schema' => $new_schema, 'alter_column_table' => $new_table, 'alter_column_column' => $new_column));
             }
         }
     }
     return $ddl;
 }
Exemplo n.º 2
0
 public static function enum_type_check($db_doc, $node_schema, $node_table, $node_column, &$drop_sql, &$add_sql)
 {
     // if the column type is a defined enum, (re)add a check constraint to enforce the pseudo-enum
     $foreign = array();
     $column_type = mssql10_column::column_type($db_doc, $node_schema, $node_table, $node_column, $foreign, FALSE);
     if (preg_match('/' . dbx::enum_regex($db_doc) . '/i', $column_type) > 0) {
         $type_schema_name = sql_parser::get_schema_name($column_type, $db_doc);
         $type_schema = dbx::get_schema($db_doc, $type_schema_name);
         $node_type = dbx::get_type($type_schema, sql_parser::get_object_name($column_type, $db_doc));
         if (!$node_type) {
             var_dump($node_type);
             throw new exception('failed to find column_type ' . $column_type . ' in type_schema_name ' . $type_schema_name);
         }
         $drop_sql = mssql10_type::get_drop_check_sql($node_schema, $node_table, $node_column, $node_type);
         $add_sql = mssql10_type::get_add_check_sql($node_schema, $node_table, $node_column, $node_type);
         return TRUE;
     }
     return FALSE;
 }