Skip to content

Commit

Permalink
* Disabling filter conditions for MySql due to limited sql syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
artiomchi committed May 21, 2019
1 parent 752d529 commit 6055d7d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/FlexLabs.EntityFrameworkCore.Upsert/HelpLinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ internal class HelpLinks
// Also referenced in the xml comment for UnsupportedExpressionException
// Also referenced in the xml comment for UpsertCommandBuilder.WithFallbackExpressionCompiler
internal const string SupportedExpressions = "https://go.flexlabs.org/upsert.expressions";
internal const string MySQLConditionalUpdate = "https://go.flexlabs.org/upsert.mysql.where";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public override string GenerateCommand(string tableName, ICollection<ICollection
ICollection<(string ColumnName, bool IsNullable)> joinColumns, ICollection<(string ColumnName, IKnownValue Value)> updateExpressions,
KnownExpression updateCondition)
{
if (updateCondition != null)
throw UnsupportedExpressionException.MySQLConditionalUpdate();

var result = new StringBuilder("INSERT ");
if (updateExpressions == null)
result.Append("IGNORE ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ namespace FlexLabs.EntityFrameworkCore.Upsert
/// </summary>
public class UnsupportedExpressionException : Exception
{
private UnsupportedExpressionException(string message, string helpLink = null)
: base(message)
{
HelpLink = helpLink;
}

internal UnsupportedExpressionException(System.Linq.Expressions.Expression expression)
: base("This type of expression is not currently supported: " + expression + ". Simplify the expression, or try a different one. " +
"See " + HelpLinks.SupportedExpressions + " for more details")
{
HelpLink = HelpLinks.SupportedExpressions;
}

internal static UnsupportedExpressionException MySQLConditionalUpdate()
=> new UnsupportedExpressionException("Using conditional updates is not supported in MySQL due to database syntax limitations. " +
"See " + HelpLinks.MySQLConditionalUpdate + " for more details",
HelpLinks.MySQLConditionalUpdate);
}
}
11 changes: 6 additions & 5 deletions test/FlexLabs.EntityFrameworkCore.Upsert.Tests/EF/BasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static BasicTest()

public static readonly List<TestDbContext.DbDriver> DatabaseEngines;
public static IEnumerable<object[]> GetDatabaseEngines() => DatabaseEngines.Select(e => new object[] { e });
public static IEnumerable<object[]> GetDatabaseEnginesExceptMySql() => DatabaseEngines.Where(e => e != TestDbContext.DbDriver.MySQL).Select(e => new object[] { e });

public class Contexts : IDisposable
{
Expand Down Expand Up @@ -1612,7 +1613,7 @@ public void Upsert_ConditionalExpression_UpdateFalse(TestDbContext.DbDriver driv
}
}
[Theory]
[MemberData(nameof(GetDatabaseEngines))]
[MemberData(nameof(GetDatabaseEnginesExceptMySql))]
public void Upsert_UpdateCondition_New(TestDbContext.DbDriver driver)
{
ResetDb(driver);
Expand Down Expand Up @@ -1642,7 +1643,7 @@ public void Upsert_UpdateCondition_New(TestDbContext.DbDriver driver)


[Theory]
[MemberData(nameof(GetDatabaseEngines))]
[MemberData(nameof(GetDatabaseEnginesExceptMySql))]
public void Upsert_UpdateCondition_New_AutoUpdate(TestDbContext.DbDriver driver)
{
ResetDb(driver);
Expand All @@ -1667,7 +1668,7 @@ public void Upsert_UpdateCondition_New_AutoUpdate(TestDbContext.DbDriver driver)
}

[Theory]
[MemberData(nameof(GetDatabaseEngines))]
[MemberData(nameof(GetDatabaseEnginesExceptMySql))]
public void Upsert_UpdateCondition_Update(TestDbContext.DbDriver driver)
{
var dbItem = new TestEntity
Expand Down Expand Up @@ -1715,7 +1716,7 @@ public void Upsert_UpdateCondition_Update(TestDbContext.DbDriver driver)
}

[Theory]
[MemberData(nameof(GetDatabaseEngines))]
[MemberData(nameof(GetDatabaseEnginesExceptMySql))]
public void Upsert_UpdateCondition_AutoUpdate(TestDbContext.DbDriver driver)
{
var dbItem = new TestEntity
Expand Down Expand Up @@ -1759,7 +1760,7 @@ public void Upsert_UpdateCondition_AutoUpdate(TestDbContext.DbDriver driver)
}

[Theory]
[MemberData(nameof(GetDatabaseEngines))]
[MemberData(nameof(GetDatabaseEnginesExceptMySql))]
public void Upsert_UpdateCondition_NoUpdate(TestDbContext.DbDriver driver)
{
var dbItem = new TestEntity
Expand Down

0 comments on commit 6055d7d

Please sign in to comment.