Skip to content

Commit ab5c9ff

Browse files
committed
Old methods restored and marked as obsolete
1 parent 83c3c26 commit ab5c9ff

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

src/NHibernate.Test/DialectTest/MsSql2005DialectFixture.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void GetIfExistsDropConstraintTest_without_schema()
199199
string expected = "if exists (select 1 from sys.objects" +
200200
" where object_id = OBJECT_ID(N'[Bar]')" +
201201
" AND parent_object_id = OBJECT_ID('Foo'))";
202-
string ifExistsDropConstraint = dialect.GetIfExistsDropConstraint(foo, "Bar", null);
202+
string ifExistsDropConstraint = dialect.GetIfExistsDropConstraint(foo, "Bar");
203203
System.Console.WriteLine(ifExistsDropConstraint);
204204
Assert.AreEqual(expected, ifExistsDropConstraint);
205205
}
@@ -213,14 +213,41 @@ public void GetIfExistsDropConstraintTest_For_Schema_other_than_dbo()
213213
string expected = "if exists (select 1 from sys.objects" +
214214
" where object_id = OBJECT_ID(N'Other.[Bar]')" +
215215
" AND parent_object_id = OBJECT_ID('Other.Foo'))";
216+
string ifExistsDropConstraint = dialect.GetIfExistsDropConstraint(foo, "Bar");
217+
System.Console.WriteLine(ifExistsDropConstraint);
218+
Assert.AreEqual(expected, ifExistsDropConstraint);
219+
}
220+
221+
222+
[Test]
223+
public void GetIfExistsDropConstraintTest_without_schema_with_schemName_overload()
224+
{
225+
MsSql2005Dialect dialect = new MsSql2005Dialect();
226+
Table foo = new Table("Foo");
227+
string expected = "if exists (select 1 from sys.objects" +
228+
" where object_id = OBJECT_ID(N'[Bar]')" +
229+
" AND parent_object_id = OBJECT_ID('Foo'))";
216230
string ifExistsDropConstraint = dialect.GetIfExistsDropConstraint(foo, "Bar", null);
217231
System.Console.WriteLine(ifExistsDropConstraint);
218232
Assert.AreEqual(expected, ifExistsDropConstraint);
219233
}
220234

235+
[Test]
236+
public void GetIfExistsDropConstraintTest_For_Schema_other_than_dbo_with_schemName_overload()
237+
{
238+
MsSql2005Dialect dialect = new MsSql2005Dialect();
239+
Table foo = new Table("Foo");
240+
foo.Schema = "Other";
241+
string expected = "if exists (select 1 from sys.objects" +
242+
" where object_id = OBJECT_ID(N'Other.[Bar]')" +
243+
" AND parent_object_id = OBJECT_ID('Other.Foo'))";
244+
string ifExistsDropConstraint = dialect.GetIfExistsDropConstraint(foo, "Bar", null);
245+
System.Console.WriteLine(ifExistsDropConstraint);
246+
Assert.AreEqual(expected, ifExistsDropConstraint);
247+
}
221248

222249
[Test]
223-
public void GetIfExistsDropConstraintTest_For_Schema_other_than_dbo_AndInGlobalConfiguration()
250+
public void GetIfExistsDropConstraintTest_For_Schema_other_than_dbo_AndInGlobalConfiguration_with_schemName_overload()
224251
{
225252
MsSql2005Dialect dialect = new MsSql2005Dialect();
226253
Table foo = new Table("Foo");

src/NHibernate/Dialect/Dialect.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,63 @@ public virtual string GetDropForeignKeyConstraintString(string constraintName)
711711
return " drop constraint " + constraintName;
712712
}
713713

714+
715+
/// <summary>
716+
/// The syntax that is used to check if a constraint does not exists before creating it
717+
/// </summary>
718+
/// <param name="table">The table.</param>
719+
/// <param name="name">The name.</param>
720+
/// <returns></returns>
721+
[Obsolete("Can cause issues when a custom schema is defined(https://nhibernate.jira.com/browse/NH-1285). The new overload with the defaultSchema parameter should be used instead")]
722+
public virtual string GetIfNotExistsCreateConstraint(Table table, string name)
723+
{
724+
return "";
725+
}
726+
727+
/// <summary>
728+
/// The syntax that is used to close the if for a constraint exists check, used
729+
/// for dialects that requires begin/end for ifs
730+
/// </summary>
731+
/// <param name="table">The table.</param>
732+
/// <param name="name">The name.</param>
733+
/// <returns></returns>
734+
[Obsolete("Can cause issues when a custom schema is defined(https://nhibernate.jira.com/browse/NH-1285). The new overload with the defaultSchema parameter should be used instead")]
735+
public virtual string GetIfNotExistsCreateConstraintEnd(Table table, string name)
736+
{
737+
return "";
738+
}
739+
740+
/// <summary>
741+
/// The syntax that is used to check if a constraint exists before dropping it
742+
/// </summary>
743+
/// <param name="table">The table.</param>
744+
/// <param name="name">The name.</param>
745+
/// <returns></returns>
746+
[Obsolete("Can cause issues when a custom schema is defined(https://nhibernate.jira.com/browse/NH-1285). The new overload with the defaultSchema parameter should be used instead")]
747+
public virtual string GetIfExistsDropConstraint(Table table, string name)
748+
{
749+
return "";
750+
}
751+
752+
/// <summary>
753+
/// The syntax that is used to close the if for a constraint exists check, used
754+
/// for dialects that requires begin/end for ifs
755+
/// </summary>
756+
/// <param name="table">The table.</param>
757+
/// <param name="name">The name.</param>
758+
/// <returns></returns>
759+
[Obsolete("Can cause issues when a custom schema is defined(https://nhibernate.jira.com/browse/NH-1285). The new overload with the defaultSchema parameter should be used instead")]
760+
public virtual string GetIfExistsDropConstraintEnd(Table table, string name)
761+
{
762+
return "";
763+
}
764+
714765
/// <summary>
715766
/// The syntax that is used to check if a constraint does not exists before creating it
716767
/// </summary>
717768
/// <param name="table">The table.</param>
718769
/// <param name="name">The name.</param>
770+
/// <param name="defaultSchema">The defaultSchema.</param>
719771
/// <returns></returns>
720772
public virtual string GetIfNotExistsCreateConstraint(Table table, string name, string defaultSchema)
721773
{
@@ -728,6 +780,7 @@ public virtual string GetIfNotExistsCreateConstraint(Table table, string name, s
728780
/// </summary>
729781
/// <param name="table">The table.</param>
730782
/// <param name="name">The name.</param>
783+
/// <param name="defaultSchema">The defaultSchema.</param>
731784
/// <returns></returns>
732785
public virtual string GetIfNotExistsCreateConstraintEnd(Table table, string name, string defaultSchema)
733786
{
@@ -739,6 +792,7 @@ public virtual string GetIfNotExistsCreateConstraintEnd(Table table, string name
739792
/// </summary>
740793
/// <param name="table">The table.</param>
741794
/// <param name="name">The name.</param>
795+
/// <param name="defaultSchema">The defaultSchema.</param>
742796
/// <returns></returns>
743797
public virtual string GetIfExistsDropConstraint(Table table, string name, string defaultSchema)
744798
{
@@ -751,6 +805,7 @@ public virtual string GetIfExistsDropConstraint(Table table, string name, string
751805
/// </summary>
752806
/// <param name="table">The table.</param>
753807
/// <param name="name">The name.</param>
808+
/// <param name="defaultSchema">The defaultSchema.</param>
754809
/// <returns></returns>
755810
public virtual string GetIfExistsDropConstraintEnd(Table table, string name, string defaultSchema)
756811
{

0 commit comments

Comments
 (0)