Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can use database keywords as column names #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public abstract class BaseExpressionProvider : EfCoreMetadataRetriever
/// </summary>
protected virtual char Quote => '\'';

protected virtual char Delimiter => '"';

/// <summary>
/// Mappings between <see cref="Type">CLR Type</see> and SQL column types.
/// Do not ask types directly from this property, use <see cref="GetSqlType"/> instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public virtual SqlBuilder GetInsertStatementBodySql(LambdaExpression insertExpre
if (assignmentParts.Any())
{
sqlResult.Append("(")
.AppendJoin(", ", assignmentParts.Select(x => GetColumnName(x.Key)))
.AppendJoin(", ", assignmentParts.Select(x => $"{Delimiter}{GetColumnName(x.Key)}{Delimiter}"))
.Append(") VALUES (")
.AppendJoin(", ", assignmentParts.Select(x => x.Value.ToString()))
.Append(")");
Expand Down
2 changes: 2 additions & 0 deletions src/Laraue.EfCoreTriggers.MySql/MySqlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public MySqlProvider(IReadOnlyModel model) : base(model)
AddConverter(new MathFloorConverter());
}

protected override char Delimiter => '`';

protected override Dictionary<Type, string> TypeMappings { get; } = new()
{
[typeof(bool)] = "BIT(1)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ public MySqlUnitMathFunctionsTests() : base(new MySqlProvider(new ContextFactory
{
}

public override string ExceptedAbsSql => "INSERT INTO destination_entities (decimal_value) VALUES (ABS(NEW.decimal_value));";
public override string ExceptedAbsSql => "INSERT INTO destination_entities (`decimal_value`) VALUES (ABS(NEW.decimal_value));";

public override string ExceptedAcosSql => "INSERT INTO destination_entities (double_value) VALUES (ACOS(NEW.double_value));";
public override string ExceptedAcosSql => "INSERT INTO destination_entities (`double_value`) VALUES (ACOS(NEW.double_value));";

public override string ExceptedAsinSql => "INSERT INTO destination_entities (double_value) VALUES (ASIN(NEW.double_value));";
public override string ExceptedAsinSql => "INSERT INTO destination_entities (`double_value`) VALUES (ASIN(NEW.double_value));";

public override string ExceptedAtanSql => "INSERT INTO destination_entities (double_value) VALUES (ATAN(NEW.double_value));";
public override string ExceptedAtanSql => "INSERT INTO destination_entities (`double_value`) VALUES (ATAN(NEW.double_value));";

public override string ExceptedAtan2Sql => "INSERT INTO destination_entities (double_value) VALUES (ATAN2(NEW.double_value, NEW.double_value));";
public override string ExceptedAtan2Sql => "INSERT INTO destination_entities (`double_value`) VALUES (ATAN2(NEW.double_value, NEW.double_value));";

public override string ExceptedCeilingSql => "INSERT INTO destination_entities (double_value) VALUES (CEILING(NEW.double_value));";
public override string ExceptedCeilingSql => "INSERT INTO destination_entities (`double_value`) VALUES (CEILING(NEW.double_value));";

public override string ExceptedCosSql => "INSERT INTO destination_entities (double_value) VALUES (COS(NEW.double_value));";
public override string ExceptedCosSql => "INSERT INTO destination_entities (`double_value`) VALUES (COS(NEW.double_value));";

public override string ExceptedExpSql => "INSERT INTO destination_entities (double_value) VALUES (EXP(NEW.double_value));";
public override string ExceptedExpSql => "INSERT INTO destination_entities (`double_value`) VALUES (EXP(NEW.double_value));";

public override string ExceptedFloorSql => "INSERT INTO destination_entities (double_value) VALUES (FLOOR(NEW.double_value));";
public override string ExceptedFloorSql => "INSERT INTO destination_entities (`double_value`) VALUES (FLOOR(NEW.double_value));";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ public MySqlUnitMemberAssignmentFunctionsTests() : base(new MySqlProvider(new Co
{
}

public override string ExceptedEnumValueSql => "INSERT INTO destination_entities (enum_value) VALUES (NEW.enum_value);";
public override string ExceptedEnumValueSql => "INSERT INTO destination_entities (`enum_value`) VALUES (NEW.enum_value);";

public override string ExceptedDecimalAddSql => "INSERT INTO destination_entities (decimal_value) VALUES (NEW.decimal_value + 3);";
public override string ExceptedDecimalAddSql => "INSERT INTO destination_entities (`decimal_value`) VALUES (NEW.decimal_value + 3);";

public override string ExceptedDoubleSubSql => "INSERT INTO destination_entities (double_value) VALUES (NEW.double_value + 3);";
public override string ExceptedDoubleSubSql => "INSERT INTO destination_entities (`double_value`) VALUES (NEW.double_value + 3);";

public override string ExceptedIntMultiplySql => "INSERT INTO destination_entities (int_value) VALUES (NEW.int_value * 2);";
public override string ExceptedIntMultiplySql => "INSERT INTO destination_entities (`int_value`) VALUES (NEW.int_value * 2);";

public override string ExceptedBooleanSql => "INSERT INTO destination_entities (boolean_value) VALUES (NEW.boolean_value is false);";
public override string ExceptedBooleanSql => "INSERT INTO destination_entities (`boolean_value`) VALUES (NEW.boolean_value is false);";

public override string ExceptedNewGuidSql => "INSERT INTO destination_entities (guid_value) VALUES (UUID());";
public override string ExceptedNewGuidSql => "INSERT INTO destination_entities (`guid_value`) VALUES (UUID());";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ public MySqlUnitStringFunctionsTests() : base(new MySqlProvider(new ContextFacto
{
}

public override string ExceptedConcatSql => "INSERT INTO destination_entities (string_field) VALUES (CONCAT(NEW.string_field, 'abc'));";
public override string ExceptedConcatSql => "INSERT INTO destination_entities (`string_field`) VALUES (CONCAT(NEW.string_field, 'abc'));";

public override string ExceptedStringLowerSql => "INSERT INTO destination_entities (string_field) VALUES (LOWER(NEW.string_field));";
public override string ExceptedStringLowerSql => "INSERT INTO destination_entities (`string_field`) VALUES (LOWER(NEW.string_field));";

public override string ExceptedStringUpperSql => "INSERT INTO destination_entities (string_field) VALUES (UPPER(NEW.string_field));";
public override string ExceptedStringUpperSql => "INSERT INTO destination_entities (`string_field`) VALUES (UPPER(NEW.string_field));";

public override string ExceptedStringTrimSql => "INSERT INTO destination_entities (string_field) VALUES (TRIM(NEW.string_field));";
public override string ExceptedStringTrimSql => "INSERT INTO destination_entities (`string_field`) VALUES (TRIM(NEW.string_field));";

public override string ExceptedContainsSql => "INSERT INTO destination_entities (boolean_value) VALUES (INSTR(NEW.string_field, 'abc') > 0);";
public override string ExceptedContainsSql => "INSERT INTO destination_entities (`boolean_value`) VALUES (INSTR(NEW.string_field, 'abc') > 0);";

public override string ExceptedEndsWithSql => "INSERT INTO destination_entities (boolean_value) VALUES (NEW.string_field LIKE CONCAT('%', 'abc'));";
public override string ExceptedEndsWithSql => "INSERT INTO destination_entities (`boolean_value`) VALUES (NEW.string_field LIKE CONCAT('%', 'abc'));";

public override string ExceptedIsNullOrEmptySql => "INSERT INTO destination_entities (boolean_value) VALUES (NEW.string_field IS NULL OR NEW.string_field = '');";
public override string ExceptedIsNullOrEmptySql => "INSERT INTO destination_entities (`boolean_value`) VALUES (NEW.string_field IS NULL OR NEW.string_field = '');";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public class PostgreSqlUnitMathFunctionsTests : UnitMathFunctionsTests
public PostgreSqlUnitMathFunctionsTests() : base(new PostgreSqlProvider(new ContextFactory().CreateDbContext().Model))
{
}
public override string ExceptedAbsSql => "INSERT INTO destination_entities (decimal_value) VALUES (ABS(NEW.decimal_value));";
public override string ExceptedAbsSql => "INSERT INTO destination_entities (\"decimal_value\") VALUES (ABS(NEW.decimal_value));";

public override string ExceptedAcosSql => "INSERT INTO destination_entities (double_value) VALUES (ACOS(NEW.double_value));";
public override string ExceptedAcosSql => "INSERT INTO destination_entities (\"double_value\") VALUES (ACOS(NEW.double_value));";

public override string ExceptedAsinSql => "INSERT INTO destination_entities (double_value) VALUES (ASIN(NEW.double_value));";
public override string ExceptedAsinSql => "INSERT INTO destination_entities (\"double_value\") VALUES (ASIN(NEW.double_value));";

public override string ExceptedAtanSql => "INSERT INTO destination_entities (double_value) VALUES (ATAN(NEW.double_value));";
public override string ExceptedAtanSql => "INSERT INTO destination_entities (\"double_value\") VALUES (ATAN(NEW.double_value));";

public override string ExceptedAtan2Sql => "INSERT INTO destination_entities (double_value) VALUES (ATAN2(NEW.double_value, NEW.double_value));";
public override string ExceptedAtan2Sql => "INSERT INTO destination_entities (\"double_value\") VALUES (ATAN2(NEW.double_value, NEW.double_value));";

public override string ExceptedCeilingSql => "INSERT INTO destination_entities (double_value) VALUES (CEILING(NEW.double_value));";
public override string ExceptedCeilingSql => "INSERT INTO destination_entities (\"double_value\") VALUES (CEILING(NEW.double_value));";

public override string ExceptedCosSql => "INSERT INTO destination_entities (double_value) VALUES (COS(NEW.double_value));";
public override string ExceptedCosSql => "INSERT INTO destination_entities (\"double_value\") VALUES (COS(NEW.double_value));";

public override string ExceptedExpSql => "INSERT INTO destination_entities (double_value) VALUES (EXP(NEW.double_value));";
public override string ExceptedExpSql => "INSERT INTO destination_entities (\"double_value\") VALUES (EXP(NEW.double_value));";

public override string ExceptedFloorSql => "INSERT INTO destination_entities (double_value) VALUES (FLOOR(NEW.double_value));";
public override string ExceptedFloorSql => "INSERT INTO destination_entities (\"double_value\") VALUES (FLOOR(NEW.double_value));";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public class PostgreUnitMemberAssignmentTests : BaseMemberAssignmentUnitTests
public PostgreUnitMemberAssignmentTests() : base(new PostgreSqlProvider(new ContextFactory().CreateDbContext().Model))
{
}
public override string ExceptedEnumValueSql => "INSERT INTO destination_entities (enum_value) VALUES (NEW.enum_value);";
public override string ExceptedEnumValueSql => "INSERT INTO destination_entities (\"enum_value\") VALUES (NEW.enum_value);";

public override string ExceptedDecimalAddSql => "INSERT INTO destination_entities (decimal_value) VALUES (NEW.decimal_value + 3);";
public override string ExceptedDecimalAddSql => "INSERT INTO destination_entities (\"decimal_value\") VALUES (NEW.decimal_value + 3);";

public override string ExceptedDoubleSubSql => "INSERT INTO destination_entities (double_value) VALUES (NEW.double_value + 3);";
public override string ExceptedDoubleSubSql => "INSERT INTO destination_entities (\"double_value\") VALUES (NEW.double_value + 3);";

public override string ExceptedIntMultiplySql => "INSERT INTO destination_entities (int_value) VALUES (NEW.int_value * 2);";
public override string ExceptedIntMultiplySql => "INSERT INTO destination_entities (\"int_value\") VALUES (NEW.int_value * 2);";

public override string ExceptedBooleanSql => "INSERT INTO destination_entities (boolean_value) VALUES (NEW.boolean_value is false);";
public override string ExceptedBooleanSql => "INSERT INTO destination_entities (\"boolean_value\") VALUES (NEW.boolean_value is false);";

public override string ExceptedNewGuidSql => "INSERT INTO destination_entities (guid_value) VALUES (uuid_generate_v4());";
public override string ExceptedNewGuidSql => "INSERT INTO destination_entities (\"guid_value\") VALUES (uuid_generate_v4());";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public class PostgreSqlUnitStringFunctionTests : UnitStringFunctionsTests
public PostgreSqlUnitStringFunctionTests() : base(new PostgreSqlProvider(new ContextFactory().CreateDbContext().Model))
{
}
public override string ExceptedConcatSql => "INSERT INTO destination_entities (string_field) VALUES (CONCAT(NEW.string_field, 'abc'));";
public override string ExceptedConcatSql => "INSERT INTO destination_entities (\"string_field\") VALUES (CONCAT(NEW.string_field, 'abc'));";

public override string ExceptedStringLowerSql => "INSERT INTO destination_entities (string_field) VALUES (LOWER(NEW.string_field));";
public override string ExceptedStringLowerSql => "INSERT INTO destination_entities (\"string_field\") VALUES (LOWER(NEW.string_field));";

public override string ExceptedStringUpperSql => "INSERT INTO destination_entities (string_field) VALUES (UPPER(NEW.string_field));";
public override string ExceptedStringUpperSql => "INSERT INTO destination_entities (\"string_field\") VALUES (UPPER(NEW.string_field));";

public override string ExceptedStringTrimSql => "INSERT INTO destination_entities (string_field) VALUES (BTRIM(NEW.string_field));";
public override string ExceptedStringTrimSql => "INSERT INTO destination_entities (\"string_field\") VALUES (BTRIM(NEW.string_field));";

public override string ExceptedContainsSql => "INSERT INTO destination_entities (boolean_value) VALUES (STRPOS(NEW.string_field, 'abc') > 0);";
public override string ExceptedContainsSql => "INSERT INTO destination_entities (\"boolean_value\") VALUES (STRPOS(NEW.string_field, 'abc') > 0);";

public override string ExceptedEndsWithSql => "INSERT INTO destination_entities (boolean_value) VALUES (NEW.string_field LIKE ('%' || 'abc'));";
public override string ExceptedEndsWithSql => "INSERT INTO destination_entities (\"boolean_value\") VALUES (NEW.string_field LIKE ('%' || 'abc'));";

public override string ExceptedIsNullOrEmptySql => "INSERT INTO destination_entities (boolean_value) VALUES (NEW.string_field IS NULL OR NEW.string_field = '');";
public override string ExceptedIsNullOrEmptySql => "INSERT INTO destination_entities (\"boolean_value\") VALUES (NEW.string_field IS NULL OR NEW.string_field = '');";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ public SqlLiteUnitMathFunctionsTests() : base(new SqlLiteProvider(new ContextFac
{
}

public override string ExceptedAbsSql => "INSERT INTO destination_entities (decimal_value) VALUES (ABS(NEW.decimal_value));";
public override string ExceptedAbsSql => "INSERT INTO destination_entities (\"decimal_value\") VALUES (ABS(NEW.decimal_value));";

public override string ExceptedAcosSql => "INSERT INTO destination_entities (double_value) VALUES (ACOS(NEW.double_value));";
public override string ExceptedAcosSql => "INSERT INTO destination_entities (\"double_value\") VALUES (ACOS(NEW.double_value));";

public override string ExceptedAsinSql => "INSERT INTO destination_entities (double_value) VALUES (ASIN(NEW.double_value));";
public override string ExceptedAsinSql => "INSERT INTO destination_entities (\"double_value\") VALUES (ASIN(NEW.double_value));";

public override string ExceptedAtanSql => "INSERT INTO destination_entities (double_value) VALUES (ATAN(NEW.double_value));";
public override string ExceptedAtanSql => "INSERT INTO destination_entities (\"double_value\") VALUES (ATAN(NEW.double_value));";

public override string ExceptedAtan2Sql => "INSERT INTO destination_entities (double_value) VALUES (ATAN2(NEW.double_value, NEW.double_value));";
public override string ExceptedAtan2Sql => "INSERT INTO destination_entities (\"double_value\") VALUES (ATAN2(NEW.double_value, NEW.double_value));";

public override string ExceptedCeilingSql => "INSERT INTO destination_entities (double_value) VALUES (CEIL(NEW.double_value));";
public override string ExceptedCeilingSql => "INSERT INTO destination_entities (\"double_value\") VALUES (CEIL(NEW.double_value));";

public override string ExceptedCosSql => "INSERT INTO destination_entities (double_value) VALUES (COS(NEW.double_value));";
public override string ExceptedCosSql => "INSERT INTO destination_entities (\"double_value\") VALUES (COS(NEW.double_value));";

public override string ExceptedExpSql => "INSERT INTO destination_entities (double_value) VALUES (EXP(NEW.double_value));";
public override string ExceptedExpSql => "INSERT INTO destination_entities (\"double_value\") VALUES (EXP(NEW.double_value));";

public override string ExceptedFloorSql => "INSERT INTO destination_entities (double_value) VALUES (FLOOR(NEW.double_value));";
public override string ExceptedFloorSql => "INSERT INTO destination_entities (\"double_value\") VALUES (FLOOR(NEW.double_value));";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ public SqlLiteUnitMemberAssignmentTests() : base(new SqlLiteProvider(new Context
{
}

public override string ExceptedEnumValueSql => "INSERT INTO destination_entities (enum_value) VALUES (NEW.enum_value);";
public override string ExceptedEnumValueSql => "INSERT INTO destination_entities (\"enum_value\") VALUES (NEW.enum_value);";

public override string ExceptedDecimalAddSql => "INSERT INTO destination_entities (decimal_value) VALUES (NEW.decimal_value + 3);";
public override string ExceptedDecimalAddSql => "INSERT INTO destination_entities (\"decimal_value\") VALUES (NEW.decimal_value + 3);";

public override string ExceptedDoubleSubSql => "INSERT INTO destination_entities (double_value) VALUES (NEW.double_value + 3);";
public override string ExceptedDoubleSubSql => "INSERT INTO destination_entities (\"double_value\") VALUES (NEW.double_value + 3);";

public override string ExceptedIntMultiplySql => "INSERT INTO destination_entities (int_value) VALUES (NEW.int_value * 2);";
public override string ExceptedIntMultiplySql => "INSERT INTO destination_entities (\"int_value\") VALUES (NEW.int_value * 2);";

public override string ExceptedBooleanSql => "INSERT INTO destination_entities (boolean_value) VALUES (NEW.boolean_value is false);";
public override string ExceptedBooleanSql => "INSERT INTO destination_entities (\"boolean_value\") VALUES (NEW.boolean_value is false);";

public override string ExceptedNewGuidSql => "INSERT INTO destination_entities (guid_value) VALUES (lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab', abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))));";
public override string ExceptedNewGuidSql => "INSERT INTO destination_entities (\"guid_value\") VALUES (lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab', abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))));";

}
}
Loading