OpenSource » Database Migrator » Legacy Migrator
Clone URL:  

Migrator Fixed a bug that caused columns surrounded in the escape sequence (e.g. '[order]') from being found.

Changeset 57a28e6f20de

Parent f9c89888f620

by gareth.farrington

Changes to one file · Browse files at 57a28e6f20de Showing diff from parent f9c89888f620 Diff from another changeset...

 
85
86
87
88
89
90
 
91
92
93
 
112
113
114
 
115
116
117
 
191
192
193
 
 
 
194
195
196
 
292
293
294
295
 
 
 
 
 
 
296
297
298
299
 
 
300
301
302
 
303
304
305
306
307
308
 
309
310
311
312
 
313
314
315
 
453
454
455
456
457
458
459
 
 
460
461
462
463
464
465
466
467
468
469
470
471
 
472
473
474
 
497
498
499
500
501
502
503
504
505
506
507
 
508
509
510
 
85
86
87
 
 
 
88
89
90
91
 
110
111
112
113
114
115
116
 
190
191
192
193
194
195
196
197
198
 
294
295
296
 
297
298
299
300
301
302
303
304
305
 
306
307
308
 
 
309
310
311
312
313
314
315
316
317
318
319
 
320
321
322
323
 
461
462
463
 
 
 
 
464
465
466
467
468
 
469
 
470
471
 
 
 
 
472
473
474
475
 
498
499
500
 
501
502
503
504
505
506
 
507
508
509
510
@@ -85,9 +85,7 @@
  return;   }   - /// - /// Build the cascade string - /// + // Build the cascade string   switch (cascade)   {   case CascadeBehavior.CascadeAll: @@ -112,6 +110,7 @@
  string.Join(",", primaryKeyColumns),   cascadeString));   } +   public override void RemoveForeignKey(string name, string table)   {   if (TableExists(table) && ConstraintExists(name, table)) @@ -191,6 +190,9 @@
  if (!TableExists(table))   return false;   + if (column.StartsWith("[") && column.EndsWith("]")) + column = column.Substring(1, column.Length - 2); +   using (IDataReader reader = ExecuteQuery(string.Format("SELECT TOP 1 * FROM syscolumns WHERE id=object_id('{0}') and name='{1}'", table, column)))   {   return reader.Read(); @@ -292,24 +294,30 @@
  // doesn't seems to do this.   private void DeleteColumnConstraints(string table, string column)   { - string sqlContrainte = + // if the column name was excaped by the caller (e.g. "[order]") then the + // escaping needs to be stripped to pass in to the object_id method + if (column.StartsWith("[") && column.EndsWith("]")) + column = column.Substring(1, column.Length - 2); + + string sqlContraint =   string.Format("SELECT cont.name FROM SYSOBJECTS cont, SYSCOLUMNS col "   + "WHERE cont.parent_obj = col.id "   + "AND col.name = '{1}' AND col.id = object_id('{0}')" - + "AND col.cdefault = cont.id",table, column); + + "AND col.cdefault = cont.id", table, column); +   ArrayList constraints = new ArrayList(); - - using (IDataReader reader = ExecuteQuery(sqlContrainte)) + using (IDataReader reader = ExecuteQuery(sqlContraint))   {   while (reader.Read())   {   constraints.Add(reader.GetString(0));   }   } +   // Can't share the connection so two phase modif   foreach (string constraint in constraints)   { - RemoveForeignKey(constraint, table); + RemoveConstraint(constraint, table);   }   }   @@ -453,22 +461,15 @@
  sqlDefault = string.Format("DEFAULT {0}", ToSqlValue(col.Type, col.DefaultValue));   }   - /// - /// If this is an Identity column and a GUID we will use the NewId - /// function as the default. - /// + // If this is an Identity column and a GUID we will use the NewId + // function as the default.   if((col.ColumnProperty == ColumnProperties.PrimaryKeyWithIdentity   || col.ColumnProperty == ColumnProperties.Identity)   && col.Type == typeof(Guid)){ -   sqlDefault = "DEFAULT NEWID()"; -   }   - - /// - /// Determine if Identity is required - /// + // Determine if Identity is required   if ((col.ColumnProperty == ColumnProperties.PrimaryKeyWithIdentity   || col.ColumnProperty == ColumnProperties.Identity)   && (col.Type == typeof(int) || col.Type == typeof(long))) @@ -497,14 +498,13 @@
  }   }   -   if (type == typeof(string) || (type == typeof(char)) || (type == typeof(DateTime)) || type == typeof(Guid)|| type == typeof(Guid?))   {   if (value == null)   return "null";   return String.Format("'{0}'", value.ToString());   } - else if (type == typeof(int) || type == typeof(Int64) || type == typeof(long) || type == typeof(float) || type == typeof(double)) + else if (type == typeof(int) || type == typeof(Int64) || type == typeof(long) || type == typeof(float) || type == typeof(double) || type == typeof(decimal))   {   return value.ToString();   }