Skip to content

Commit 1fd6879

Browse files
authored
Add Firebird 4 dialect (#3166)
* Add Firebird4Dialect * Add Firebird 4.0 test configuration * Add handling of BigInteger to numerical types * Set version 5.5.0-dev
1 parent 04ded09 commit 1fd6879

27 files changed

+183
-39
lines changed

.github/workflows/NetCoreTests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
CONNECTION_STRING: "DataSource=localhost;Database=nhibernate;User=SYSDBA;Password=nhibernate;charset=utf8;"
2121
DB_INIT: |
2222
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
23+
- DB: Firebird4
24+
CONNECTION_STRING: "DataSource=localhost;Database=nhibernate;User=SYSDBA;Password=nhibernate;charset=utf8;"
25+
DB_INIT: |
26+
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
2327
- DB: MySQL
2428
CONNECTION_STRING: "Server=localhost;Uid=root;Password=nhibernate;Database=nhibernate;Old Guids=True;SslMode=none;"
2529
DB_INIT: |

appveyor.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ environment:
77
- DB: PostgreSQL
88
CONNECTION_STRING: Host=localhost;Port=5432;Username=postgres;Password=Password12!;Database=nhibernate;Enlist=true;
99
- DB: Firebird
10+
- DB: Firebird4
1011
- DB: MySQL
1112
CONNECTION_STRING: Server=127.0.0.1;Uid=root;Pwd=Password12!;Database=nhibernate;Old Guids=True;SslMode=none;CharSet=utf8;
1213
- DB: SQLite
@@ -38,6 +39,27 @@ before_test:
3839
.\firebird.exe -a
3940
Pop-Location
4041
}
42+
'Firebird4' {
43+
$FireBirdPath = 'C:\firebird'
44+
# Install Firebird
45+
New-Item -ItemType Directory -Force $FireBirdPath > $null
46+
Push-Location $FireBirdPath
47+
Invoke-WebRequest 'https://github.com/FirebirdSQL/firebird/releases/download/v4.0.2/Firebird-4.0.2.2816-0-x64.zip' -OutFile firebird.zip
48+
Unblock-File firebird.zip
49+
7z x firebird.zip
50+
New-Item -ItemType Directory -Force Data
51+
# Declare nhibernate db
52+
Add-Content -Path '.\databases.conf' -Value "`r`nnhibernate = $FireBirdPath\Data\nhibernate.fdb"
53+
# Minimal db settings
54+
Add-Content -Path '.\firebird.conf' -Value "`r`nAuthServer = Srp`r`nAuthClient = Srp`r`nUserManager = Srp`r`nWireCrypt = Enabled"
55+
# Create SYSDBA account
56+
New-Item SYSDBA.sql -Type File
57+
Add-Content -Path '.\SYSDBA.sql' -Value "CREATE USER SYSDBA PASSWORD 'masterkey';`r`nCOMMIT;`r`nQUIT;"
58+
.\isql -user sysdba employee -input SYSDBA.sql
59+
# Start Firebird
60+
.\firebird.exe -a
61+
Pop-Location
62+
}
4163
'MySQL' {
4264
Start-Service 'MySQL57'
4365
# Create nhibernate database (not handled by NHibernate.TestDatabaseSetup.dll)

build-common/NHibernate.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<Import Condition="Exists('NHibernate.dev.props')" Project="NHibernate.dev.props"/>
33

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

1111
<VersionPrefix Condition="'$(VersionPrefix)' == ''">$(NhVersion).$(VersionPatch)</VersionPrefix>

lib/teamcity/firebird/firebird_installation.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Installation steps for Firebird for NH TeamCity:
33

4-
1. Download Firebird (Firebird-3.0.2.32703_0_x64): https://www.firebirdsql.org/en/server-packages/;
4+
1. Download Firebird (Firebird-4.0.2.2816-0-x64): https://www.firebirdsql.org/en/server-packages/;
55
2. Run the installer AS ADMINISTRATOR... Use the default firebird password when prompted: masterkey.
66
3. Leave other settings with their defaults.
77
4. The setup should install Firebird on the machine;

psake.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Task Set-Configuration {
1414
'connection.driver_class' = 'NHibernate.Driver.FirebirdClientDriver';
1515
'dialect' = 'NHibernate.Dialect.FirebirdDialect'
1616
};
17+
'Firebird4' = @{
18+
'connection.connection_string' = 'DataSource=localhost;Database=nhibernate;User ID=SYSDBA;Password=masterkey;MaxPoolSize=200;';
19+
'connection.driver_class' = 'NHibernate.Driver.FirebirdClientDriver';
20+
'dialect' = 'NHibernate.Dialect.Firebird4Dialect'
21+
};
1722
'MySQL' = @{
1823
'connection.connection_string' = 'Server=127.0.0.1;Uid=root;Pwd=Password12!;Database=nhibernate;Old Guids=True;SslMode=none;';
1924
'connection.driver_class' = 'NHibernate.Driver.MySqlDataDriver';

src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<![CDATA[DROP TRIGGER t_iu_part_gen_comp]]>
7373
</drop>
7474
<dialect-scope name="NHibernate.Dialect.FirebirdDialect"/>
75+
<dialect-scope name="NHibernate.Dialect.Firebird4Dialect"/>
7576
</database-object>
7677

77-
</hibernate-mapping>
78+
</hibernate-mapping>

src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CREATE GENERATOR MYGENERATOR;
2121
DROP GENERATOR MYGENERATOR;
2222
</drop>
2323
<dialect-scope name="NHibernate.Dialect.FirebirdDialect"/>
24+
<dialect-scope name="NHibernate.Dialect.Firebird4Dialect"/>
2425
</database-object>
2526

2627
<database-object>
@@ -37,6 +38,7 @@ END
3738
DROP TRIGGER my_entity_BI;
3839
</drop>
3940
<dialect-scope name="NHibernate.Dialect.FirebirdDialect"/>
41+
<dialect-scope name="NHibernate.Dialect.Firebird4Dialect"/>
4042
</database-object>
4143

4244
<database-object>
@@ -71,4 +73,4 @@ DROP TRIGGER my_entity_BI;
7173
</database-object>
7274

7375

74-
</hibernate-mapping>
76+
</hibernate-mapping>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace NHibernate.Test.TestDialects
2+
{
3+
public class Firebird4TestDialect : FirebirdTestDialect
4+
{
5+
public Firebird4TestDialect(Dialect.Dialect dialect) : base(dialect)
6+
{
7+
}
8+
}
9+
}

src/NHibernate/Async/Type/ByteType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections;
1313
using System.Data;
1414
using System.Data.Common;
15+
using System.Numerics;
1516
using NHibernate.Engine;
1617
using NHibernate.SqlTypes;
1718

src/NHibernate/Async/Type/Int16Type.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using NHibernate.SqlTypes;
1616
using System.Collections.Generic;
1717
using System.Data;
18+
using System.Numerics;
1819

1920
namespace NHibernate.Type
2021
{

src/NHibernate/Async/Type/Int32Type.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using NHibernate.SqlTypes;
1616
using System.Collections.Generic;
1717
using System.Data;
18+
using System.Numerics;
1819

1920
namespace NHibernate.Type
2021
{

src/NHibernate/Async/Type/Int64Type.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections.Generic;
1414
using System.Data;
1515
using System.Data.Common;
16+
using System.Numerics;
1617
using NHibernate.Engine;
1718
using NHibernate.SqlTypes;
1819

src/NHibernate/Async/Type/UInt16Type.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections.Generic;
1414
using System.Data;
1515
using System.Data.Common;
16+
using System.Numerics;
1617
using NHibernate.Engine;
1718
using NHibernate.SqlTypes;
1819

src/NHibernate/Async/Type/UInt32Type.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections.Generic;
1414
using System.Data;
1515
using System.Data.Common;
16+
using System.Numerics;
1617
using NHibernate.Engine;
1718
using NHibernate.SqlTypes;
1819

src/NHibernate/Async/Type/UInt64Type.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections.Generic;
1414
using System.Data;
1515
using System.Data.Common;
16+
using System.Numerics;
1617
using NHibernate.Engine;
1718
using NHibernate.SqlTypes;
1819

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using NHibernate.Dialect.Function;
2+
3+
namespace NHibernate.Dialect
4+
{
5+
public class Firebird4Dialect: FirebirdDialect
6+
{
7+
public override string CurrentTimestampSelectString => "select LOCALTIMESTAMP from RDB$DATABASE";
8+
9+
protected override void RegisterFunctions()
10+
{
11+
base.RegisterFunctions();
12+
RegisterFunction("current_timestamp", new NoArgSQLFunction("localtimestamp", NHibernateUtil.LocalDateTime, false));
13+
}
14+
}
15+
}

src/NHibernate/Dialect/FirebirdDialect.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,6 @@ public override SqlString Render(IList args, ISessionFactoryImplementor factory)
152152
}
153153
}
154154

155-
[Serializable]
156-
private class CurrentTimeStamp : NoArgSQLFunction
157-
{
158-
public CurrentTimeStamp() : base("current_timestamp", NHibernateUtil.LocalDateTime, true)
159-
{
160-
}
161-
162-
public override SqlString Render(IList args, ISessionFactoryImplementor factory)
163-
{
164-
return new SqlString(Name);
165-
}
166-
}
167-
168155
public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
169156
{
170157
return new FirebirdDataBaseSchema(connection);
@@ -474,7 +461,7 @@ protected virtual void RegisterFunctions()
474461

475462
private void OverrideStandardHQLFunctions()
476463
{
477-
RegisterFunction("current_timestamp", new CurrentTimeStamp());
464+
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.LocalDateTime, false));
478465
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.LocalDate, false));
479466
RegisterFunction("length", new StandardSafeSQLFunction("char_length", NHibernateUtil.Int64, 1));
480467
RegisterFunction("nullif", new StandardSafeSQLFunction("nullif", 2));

src/NHibernate/Type/ByteType.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Data;
44
using System.Data.Common;
5+
using System.Numerics;
56
using NHibernate.Engine;
67
using NHibernate.SqlTypes;
78

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

2425
public override object Get(DbDataReader rs, int index, ISessionImplementor session)
2526
{
26-
return Convert.ToByte(rs[index]);
27+
return rs[index] switch
28+
{
29+
30+
BigInteger bi => (byte) bi,
31+
var c => Convert.ToByte(c)
32+
};
2733
}
2834

2935
public override object Get(DbDataReader rs, string name, ISessionImplementor session)
3036
{
31-
return Convert.ToByte(rs[name]);
37+
return rs[name] switch
38+
{
39+
BigInteger bi => (byte) bi,
40+
var c => Convert.ToByte(c)
41+
};
3242
}
3343

3444
public override System.Type ReturnedClass

src/NHibernate/Type/DoubleType.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Data;
33
using System.Data.Common;
4+
using System.Numerics;
45
using NHibernate.Engine;
56
using NHibernate.SqlTypes;
67

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

2324
public override object Get(DbDataReader rs, int index, ISessionImplementor session)
2425
{
25-
return Convert.ToDouble(rs[index]);
26+
return rs[index] switch
27+
{
28+
BigInteger bi => (double) bi,
29+
var v => Convert.ToDouble(v)
30+
};
2631
}
2732

2833
public override object Get(DbDataReader rs, string name, ISessionImplementor session)
2934
{
30-
return Convert.ToDouble(rs[name]);
35+
return rs[name] switch
36+
{
37+
BigInteger bi => (double) bi,
38+
var v => Convert.ToDouble(v)
39+
};
3140
}
3241

3342
/// <summary></summary>

src/NHibernate/Type/Int16Type.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NHibernate.SqlTypes;
66
using System.Collections.Generic;
77
using System.Data;
8+
using System.Numerics;
89

910
namespace NHibernate.Type
1011
{
@@ -31,7 +32,11 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
3132
{
3233
try
3334
{
34-
return Convert.ToInt16(rs[index]);
35+
return rs[index] switch
36+
{
37+
BigInteger bi => (short) bi,
38+
var c => Convert.ToInt16(c)
39+
};
3540
}
3641
catch (Exception ex)
3742
{
@@ -43,7 +48,11 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses
4348
{
4449
try
4550
{
46-
return Convert.ToInt16(rs[name]);
51+
return rs[name]switch
52+
{
53+
BigInteger bi => (short) bi,
54+
var c => Convert.ToInt16(c)
55+
};
4756
}
4857
catch (Exception ex)
4958
{

src/NHibernate/Type/Int32Type.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NHibernate.SqlTypes;
66
using System.Collections.Generic;
77
using System.Data;
8+
using System.Numerics;
89

910
namespace NHibernate.Type
1011
{
@@ -27,11 +28,16 @@ public override string Name
2728
}
2829

2930
private static readonly Int32 ZERO = 0;
31+
3032
public override object Get(DbDataReader rs, int index, ISessionImplementor session)
3133
{
3234
try
3335
{
34-
return Convert.ToInt32(rs[index]);
36+
return rs[index] switch
37+
{
38+
BigInteger bi => (int) bi,
39+
var c => Convert.ToInt32(c)
40+
};
3541
}
3642
catch (Exception ex)
3743
{
@@ -43,7 +49,11 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses
4349
{
4450
try
4551
{
46-
return Convert.ToInt32(rs[name]);
52+
return rs[name] switch
53+
{
54+
BigInteger bi => (int) bi,
55+
var c => Convert.ToInt32(c)
56+
};
4757
}
4858
catch (Exception ex)
4959
{

src/NHibernate/Type/Int64Type.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Data;
55
using System.Data.Common;
6+
using System.Numerics;
67
using NHibernate.Engine;
78
using NHibernate.SqlTypes;
89

@@ -31,7 +32,11 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
3132
{
3233
try
3334
{
34-
return Convert.ToInt64(rs[index]);
35+
return rs[index] switch
36+
{
37+
BigInteger bi => (long) bi,
38+
var c => Convert.ToInt64(c)
39+
};
3540
}
3641
catch (Exception ex)
3742
{
@@ -43,7 +48,11 @@ public override object Get(DbDataReader rs, string name, ISessionImplementor ses
4348
{
4449
try
4550
{
46-
return Convert.ToInt64(rs[name]);
51+
return rs[name] switch
52+
{
53+
BigInteger bi => (long) bi,
54+
var c => Convert.ToInt64(c)
55+
};
4756
}
4857
catch (Exception ex)
4958
{

0 commit comments

Comments
 (0)