Skip to content

Add Firebird 4 dialect #3166

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

Merged
merged 11 commits into from
Jan 23, 2023
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
4 changes: 4 additions & 0 deletions .github/workflows/NetCoreTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
CONNECTION_STRING: "DataSource=localhost;Database=nhibernate;User=SYSDBA;Password=nhibernate;charset=utf8;"
DB_INIT: |
docker run --name firebird -e EnableWireCrypt=true -e FIREBIRD_USER=nhibernate -e FIREBIRD_PASSWORD=nhibernate -e ISC_PASSWORD=nhibernate -e FIREBIRD_DATABASE=nhibernate -p 3050:3050 -d jacobalberty/firebird:v3.0
- DB: Firebird4
CONNECTION_STRING: "DataSource=localhost;Database=nhibernate;User=SYSDBA;Password=nhibernate;charset=utf8;"
DB_INIT: |
docker run --name firebird -e EnableWireCrypt=true -e FIREBIRD_USER=nhibernate -e FIREBIRD_PASSWORD=nhibernate -e ISC_PASSWORD=nhibernate -e FIREBIRD_DATABASE=nhibernate -p 3050:3050 -d jacobalberty/firebird:v4.0
- DB: MySQL
CONNECTION_STRING: "Server=localhost;Uid=root;Password=nhibernate;Database=nhibernate;Old Guids=True;SslMode=none;"
DB_INIT: |
Expand Down
22 changes: 22 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ environment:
- DB: PostgreSQL
CONNECTION_STRING: Host=localhost;Port=5432;Username=postgres;Password=Password12!;Database=nhibernate;Enlist=true;
- DB: Firebird
- DB: Firebird4
- DB: MySQL
CONNECTION_STRING: Server=127.0.0.1;Uid=root;Pwd=Password12!;Database=nhibernate;Old Guids=True;SslMode=none;CharSet=utf8;
- DB: SQLite
Expand Down Expand Up @@ -38,6 +39,27 @@ before_test:
.\firebird.exe -a
Pop-Location
}
'Firebird4' {
$FireBirdPath = 'C:\firebird'
# Install Firebird
New-Item -ItemType Directory -Force $FireBirdPath > $null
Push-Location $FireBirdPath
Invoke-WebRequest 'https://github.com/FirebirdSQL/firebird/releases/download/v4.0.2/Firebird-4.0.2.2816-0-x64.zip' -OutFile firebird.zip
Unblock-File firebird.zip
7z x firebird.zip
New-Item -ItemType Directory -Force Data
# Declare nhibernate db
Add-Content -Path '.\databases.conf' -Value "`r`nnhibernate = $FireBirdPath\Data\nhibernate.fdb"
# Minimal db settings
Add-Content -Path '.\firebird.conf' -Value "`r`nAuthServer = Srp`r`nAuthClient = Srp`r`nUserManager = Srp`r`nWireCrypt = Enabled"
# Create SYSDBA account
New-Item SYSDBA.sql -Type File
Add-Content -Path '.\SYSDBA.sql' -Value "CREATE USER SYSDBA PASSWORD 'masterkey';`r`nCOMMIT;`r`nQUIT;"
.\isql -user sysdba employee -input SYSDBA.sql
# Start Firebird
.\firebird.exe -a
Pop-Location
}
'MySQL' {
Start-Service 'MySQL57'
# Create nhibernate database (not handled by NHibernate.TestDatabaseSetup.dll)
Expand Down
4 changes: 2 additions & 2 deletions build-common/NHibernate.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Import Condition="Exists('NHibernate.dev.props')" Project="NHibernate.dev.props"/>

<PropertyGroup>
<NhVersion Condition="'$(NhVersion)' == ''" >5.4</NhVersion>
<NhVersion Condition="'$(NhVersion)' == ''" >5.5</NhVersion>
<VersionPatch Condition="'$(VersionPatch)' == ''">0</VersionPatch>
<!-- Clear VersionSuffix for making release and set it to dev for making development builds -->
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
<VersionSuffix Condition="'$(VersionSuffix)' == ''">dev</VersionSuffix>
<LangVersion Condition="'$(MSBuildProjectExtension)' != '.vbproj'">9.0</LangVersion>

<VersionPrefix Condition="'$(VersionPrefix)' == ''">$(NhVersion).$(VersionPatch)</VersionPrefix>
Expand Down
2 changes: 1 addition & 1 deletion lib/teamcity/firebird/firebird_installation.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Installation steps for Firebird for NH TeamCity:

1. Download Firebird (Firebird-3.0.2.32703_0_x64): https://www.firebirdsql.org/en/server-packages/;
1. Download Firebird (Firebird-4.0.2.2816-0-x64): https://www.firebirdsql.org/en/server-packages/;
2. Run the installer AS ADMINISTRATOR... Use the default firebird password when prompted: masterkey.
3. Leave other settings with their defaults.
4. The setup should install Firebird on the machine;
Expand Down
5 changes: 5 additions & 0 deletions psake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Task Set-Configuration {
'connection.driver_class' = 'NHibernate.Driver.FirebirdClientDriver';
'dialect' = 'NHibernate.Dialect.FirebirdDialect'
};
'Firebird4' = @{
'connection.connection_string' = 'DataSource=localhost;Database=nhibernate;User ID=SYSDBA;Password=masterkey;MaxPoolSize=200;';
'connection.driver_class' = 'NHibernate.Driver.FirebirdClientDriver';
'dialect' = 'NHibernate.Dialect.Firebird4Dialect'
};
'MySQL' = @{
'connection.connection_string' = 'Server=127.0.0.1;Uid=root;Pwd=Password12!;Database=nhibernate;Old Guids=True;SslMode=none;';
'connection.driver_class' = 'NHibernate.Driver.MySqlDataDriver';
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<![CDATA[DROP TRIGGER t_iu_part_gen_comp]]>
</drop>
<dialect-scope name="NHibernate.Dialect.FirebirdDialect"/>
<dialect-scope name="NHibernate.Dialect.Firebird4Dialect"/>
</database-object>

</hibernate-mapping>
</hibernate-mapping>
4 changes: 3 additions & 1 deletion src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CREATE GENERATOR MYGENERATOR;
DROP GENERATOR MYGENERATOR;
</drop>
<dialect-scope name="NHibernate.Dialect.FirebirdDialect"/>
<dialect-scope name="NHibernate.Dialect.Firebird4Dialect"/>
</database-object>

<database-object>
Expand All @@ -37,6 +38,7 @@ END
DROP TRIGGER my_entity_BI;
</drop>
<dialect-scope name="NHibernate.Dialect.FirebirdDialect"/>
<dialect-scope name="NHibernate.Dialect.Firebird4Dialect"/>
</database-object>

<database-object>
Expand Down Expand Up @@ -71,4 +73,4 @@ DROP TRIGGER my_entity_BI;
</database-object>


</hibernate-mapping>
</hibernate-mapping>
9 changes: 9 additions & 0 deletions src/NHibernate.Test/TestDialects/Firebird4TestDialect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NHibernate.Test.TestDialects
{
public class Firebird4TestDialect : FirebirdTestDialect
{
public Firebird4TestDialect(Dialect.Dialect dialect) : base(dialect)
{
}
}
}
1 change: 1 addition & 0 deletions src/NHibernate/Async/Type/ByteType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand Down
1 change: 1 addition & 0 deletions src/NHibernate/Async/Type/Int16Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using NHibernate.SqlTypes;
using System.Collections.Generic;
using System.Data;
using System.Numerics;

namespace NHibernate.Type
{
Expand Down
1 change: 1 addition & 0 deletions src/NHibernate/Async/Type/Int32Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using NHibernate.SqlTypes;
using System.Collections.Generic;
using System.Data;
using System.Numerics;

namespace NHibernate.Type
{
Expand Down
1 change: 1 addition & 0 deletions src/NHibernate/Async/Type/Int64Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand Down
1 change: 1 addition & 0 deletions src/NHibernate/Async/Type/UInt16Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand Down
1 change: 1 addition & 0 deletions src/NHibernate/Async/Type/UInt32Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand Down
1 change: 1 addition & 0 deletions src/NHibernate/Async/Type/UInt64Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand Down
15 changes: 15 additions & 0 deletions src/NHibernate/Dialect/Firebird4Dialect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using NHibernate.Dialect.Function;

namespace NHibernate.Dialect
{
public class Firebird4Dialect: FirebirdDialect
{
public override string CurrentTimestampSelectString => "select LOCALTIMESTAMP from RDB$DATABASE";

protected override void RegisterFunctions()
{
base.RegisterFunctions();
RegisterFunction("current_timestamp", new NoArgSQLFunction("localtimestamp", NHibernateUtil.LocalDateTime, false));
}
}
}
15 changes: 1 addition & 14 deletions src/NHibernate/Dialect/FirebirdDialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,6 @@ public override SqlString Render(IList args, ISessionFactoryImplementor factory)
}
}

[Serializable]
private class CurrentTimeStamp : NoArgSQLFunction
{
public CurrentTimeStamp() : base("current_timestamp", NHibernateUtil.LocalDateTime, true)
{
}

public override SqlString Render(IList args, ISessionFactoryImplementor factory)
{
return new SqlString(Name);
}
}

public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
{
return new FirebirdDataBaseSchema(connection);
Expand Down Expand Up @@ -474,7 +461,7 @@ protected virtual void RegisterFunctions()

private void OverrideStandardHQLFunctions()
{
RegisterFunction("current_timestamp", new CurrentTimeStamp());
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.LocalDateTime, false));
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.LocalDate, false));
RegisterFunction("length", new StandardSafeSQLFunction("char_length", NHibernateUtil.Int64, 1));
RegisterFunction("nullif", new StandardSafeSQLFunction("nullif", 2));
Expand Down
14 changes: 12 additions & 2 deletions src/NHibernate/Type/ByteType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand All @@ -23,12 +24,21 @@ public ByteType()

public override object Get(DbDataReader rs, int index, ISessionImplementor session)
{
return Convert.ToByte(rs[index]);
return rs[index] switch
{

BigInteger bi => (byte) bi,
var c => Convert.ToByte(c)
};
}

public override object Get(DbDataReader rs, string name, ISessionImplementor session)
{
return Convert.ToByte(rs[name]);
return rs[name] switch
{
BigInteger bi => (byte) bi,
var c => Convert.ToByte(c)
};
}

public override System.Type ReturnedClass
Expand Down
13 changes: 11 additions & 2 deletions src/NHibernate/Type/DoubleType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand All @@ -22,12 +23,20 @@ public DoubleType(SqlType sqlType) : base(sqlType) {}

public override object Get(DbDataReader rs, int index, ISessionImplementor session)
{
return Convert.ToDouble(rs[index]);
return rs[index] switch
{
BigInteger bi => (double) bi,
var v => Convert.ToDouble(v)
};
}

public override object Get(DbDataReader rs, string name, ISessionImplementor session)
{
return Convert.ToDouble(rs[name]);
return rs[name] switch
{
BigInteger bi => (double) bi,
var v => Convert.ToDouble(v)
};
}

/// <summary></summary>
Expand Down
13 changes: 11 additions & 2 deletions src/NHibernate/Type/Int16Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NHibernate.SqlTypes;
using System.Collections.Generic;
using System.Data;
using System.Numerics;

namespace NHibernate.Type
{
Expand All @@ -31,7 +32,11 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
{
try
{
return Convert.ToInt16(rs[index]);
return rs[index] switch
{
BigInteger bi => (short) bi,
var c => Convert.ToInt16(c)
};
}
catch (Exception ex)
{
Expand All @@ -43,7 +48,11 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses
{
try
{
return Convert.ToInt16(rs[name]);
return rs[name]switch
{
BigInteger bi => (short) bi,
var c => Convert.ToInt16(c)
};
}
catch (Exception ex)
{
Expand Down
14 changes: 12 additions & 2 deletions src/NHibernate/Type/Int32Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NHibernate.SqlTypes;
using System.Collections.Generic;
using System.Data;
using System.Numerics;

namespace NHibernate.Type
{
Expand All @@ -27,11 +28,16 @@ public override string Name
}

private static readonly Int32 ZERO = 0;

public override object Get(DbDataReader rs, int index, ISessionImplementor session)
{
try
{
return Convert.ToInt32(rs[index]);
return rs[index] switch
{
BigInteger bi => (int) bi,
var c => Convert.ToInt32(c)
};
}
catch (Exception ex)
{
Expand All @@ -43,7 +49,11 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses
{
try
{
return Convert.ToInt32(rs[name]);
return rs[name] switch
{
BigInteger bi => (int) bi,
var c => Convert.ToInt32(c)
};
}
catch (Exception ex)
{
Expand Down
13 changes: 11 additions & 2 deletions src/NHibernate/Type/Int64Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Numerics;
using NHibernate.Engine;
using NHibernate.SqlTypes;

Expand Down Expand Up @@ -31,7 +32,11 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
{
try
{
return Convert.ToInt64(rs[index]);
return rs[index] switch
{
BigInteger bi => (long) bi,
var c => Convert.ToInt64(c)
};
}
catch (Exception ex)
{
Expand All @@ -43,7 +48,11 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses
{
try
{
return Convert.ToInt64(rs[name]);
return rs[name] switch
{
BigInteger bi => (long) bi,
var c => Convert.ToInt64(c)
};
}
catch (Exception ex)
{
Expand Down
Loading