Skip to content

Commit

Permalink
Added support for Dialect 1 in EFCore.
Browse files Browse the repository at this point in the history
Before you start using the DBContext you need to set the Dialect to 1 like

  InterBaseSql.EntityFrameworkCore.InterBase.Storage.Internal.IBSqlGenerationHelper.Dialect = 1;

This will tell the SqlGeneratorHelper to not quote identify things.
  • Loading branch information
jeffovercash committed Apr 17, 2023
1 parent eef670d commit 127427b
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 9 deletions.
4 changes: 2 additions & 2 deletions NETProvider/Demos/EntityCoreExample2/EFCore101.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="InterBaseSql.Data.InterBaseClient" Version="7.13.6" />
<PackageReference Include="InterBaseSql.EntityFrameworkCore.InterBase" Version="7.13.6" />
<PackageReference Include="InterBaseSql.Data.InterBaseClient" Version="7.13.7" />
<PackageReference Include="InterBaseSql.EntityFrameworkCore.InterBase" Version="7.13.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 2 additions & 0 deletions NETProvider/Demos/EntityCoreExample2/EmployeeForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public partial class EmployeeForm : Form
public EmployeeForm()
{
InitializeComponent();
// This is necessary when working with a dialect 1 DB. Setting the dialect must be done before using the DbContext.
InterBaseSql.EntityFrameworkCore.InterBase.Storage.Internal.IBSqlGenerationHelper.Dialect = 1;
}

private void Form1_Load(object sender, EventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
if (!optionsBuilder.IsConfigured)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
optionsBuilder.UseInterBase("data source=localhost;initial catalog=Employee;user id=sysdba;password=masterkey");
optionsBuilder.UseInterBase("data source=localhost;initial catalog=Employee;user id=sysdba;password=masterkey;dialect=1");
}
}

Expand Down
2 changes: 1 addition & 1 deletion NETProvider/Demos/EntityCoreExample2/MyEmployeeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public long GetNextSequenceValue(string genName)
Database.GetDbConnection().Open();
cmd.CommandText = "SELECT gen_id(" + genName + ", 1) from rdb$database";
var obj = cmd.ExecuteScalar();
return (long)obj;
return Convert.ToInt64(obj);
}
}
}
Expand Down
Binary file modified NETProvider/Provider/docs/ADO Driver documentation.docx
Binary file not shown.
2 changes: 1 addition & 1 deletion NETProvider/Provider/src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>7.13.6</VersionPrefix>
<VersionPrefix>7.13.7</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Company>Embarcadero</Company>
<Product>NETProvider</Product>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<Authors>Embarcadero</Authors>
<Company>Embarcadero</Company>
<PackageIcon></PackageIcon>
<AssemblyVersion>7.13.6.0</AssemblyVersion>
<FileVersion>7.13.6.0</FileVersion>
<Version>7.13.6</Version>
<AssemblyVersion>7.13.7.0</AssemblyVersion>
<FileVersion>7.13.7.0</FileVersion>
<Version>7.13.7</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DefineConstants>TRACE</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#Changes for 7.13.7

## IBSqlGeneratorHelper
* Added a static variable called Dialect. It defaults to 3, but when you are working with a Dialcet 1 DB you need to change that static variable to 1.
* Overrode DelimitIdentifier, DelimitIdentifier and DelimitIdentifier to now use the new Dialect variable to determine if the identifier should be double quoted or not.

#Changes for 7.13.6 (updated for EFCore 6.0 and to Fb 9.x)

## added IBDateOnlyTypeMapping.cs, IBRelationalTransaction.cs, IBTimeOnlyTypeMapping.cs, IBTransactionFactory.cs, and IRelationalIBTransaction.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
//$Authors = Jiri Cincura (jiri@cincura.net)

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Migrations;

namespace InterBaseSql.EntityFrameworkCore.InterBase.Storage.Internal;

public class IBSqlGenerationHelper : RelationalSqlGenerationHelper, IIBSqlGenerationHelper
{
public static int Dialect = 3;

public IBSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies)
: base(dependencies)
Expand Down Expand Up @@ -65,4 +71,48 @@ static void EnsureStringLiteralQueryTypeLength(int length)
if (length > IBTypeMappingSource.UnicodeVarcharMaxSize)
throw new ArgumentOutOfRangeException(nameof(length));
}

public static string NotEmpty([NotNull] string? value, string parameterName)
{
if (value is null)
{
NotEmpty(parameterName, nameof(parameterName));

throw new ArgumentNullException(parameterName);
}

if (value.Trim().Length == 0)
{
NotEmpty(parameterName, nameof(parameterName));

throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName));
}

return value;
}
public override string DelimitIdentifier(string identifier)
{
if (Dialect == 3)
return $"\"{EscapeIdentifier(NotEmpty(identifier, nameof(identifier)))}\"";
else
return $"{EscapeIdentifier(NotEmpty(identifier, nameof(identifier)))}";
}

public override void DelimitIdentifier(StringBuilder builder, string identifier)
{
NotEmpty(identifier, nameof(identifier));

if (Dialect == 3)
{
builder.Append('"');
EscapeIdentifier(builder, identifier);
builder.Append('"');
}
else
EscapeIdentifier(builder, identifier);
}

public override string DelimitIdentifier(string name, string? schema)
=> DelimitIdentifier(NotEmpty(name, nameof(name)));

}
2 changes: 1 addition & 1 deletion NETProvider/Provider/src/Perf/Perf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
</ItemGroup>

<ItemGroup Condition="$(Configuration.EndsWith('NuGet'))">
<PackageReference Include="InterBaseSql.Data.InterBaseClient" Version="7.13.6" />
<PackageReference Include="InterBaseSql.Data.InterBaseClient" Version="7.13.7" />
</ItemGroup>
</Project>

0 comments on commit 127427b

Please sign in to comment.