Changeset 57a28e6f20de…
Parent f9c89888f620…
by
Changes to one file · Browse files at 57a28e6f20de Showing diff from parent f9c89888f620 Diff from another changeset...
|
|
@@ -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();
}
|
Loading...