-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NamedSQLQuery ignores query-param type (#3404)
Fixes #3311
- Loading branch information
Showing
7 changed files
with
160 additions
and
8 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/NHibernate.Test/Async/NHSpecificTest/GH3311SqlQueryParam/SqlQueryParamTypeFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Data; | ||
using NHibernate.Dialect; | ||
using NHibernate.SqlTypes; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3311SqlQueryParam | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class SqlQueryParamTypeFixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
var e1 = new Entity {Name = "Bob"}; | ||
session.Save(e1); | ||
|
||
var e2 = new Entity {Name = "Sally"}; | ||
session.Save(e2); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return | ||
//Dialects like SQL Server CE, Firebird don't distinguish AnsiString from String | ||
(Dialect.GetTypeName(new SqlType(DbType.AnsiString)) != Dialect.GetTypeName(new SqlType(DbType.String)) | ||
|| Dialect is SQLiteDialect); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public async Task AppliesParameterTypeFromQueryParamAsync() | ||
{ | ||
using var log = new SqlLogSpy(); | ||
using var s = OpenSession(); | ||
await (s.GetNamedQuery("entityIdByName").SetParameter("name", "Bob").UniqueResultAsync<object>()); | ||
Assert.That(log.GetWholeLog(), Does.Contain("Type: AnsiString")); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/NHibernate.Test/NHSpecificTest/GH3311SqlQueryParam/Entity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3311SqlQueryParam | ||
{ | ||
class Entity | ||
{ | ||
public virtual long Id { get; set; } | ||
public virtual string Name { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/NHibernate.Test/NHSpecificTest/GH3311SqlQueryParam/Mappings.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH3311SqlQueryParam"> | ||
|
||
<class name="Entity"> | ||
<id name="Id" generator="native" /> | ||
<property name="Name" type="AnsiString" /> | ||
</class> | ||
<sql-query name="entityIdByName"> | ||
<query-param name="name" type="AnsiString" /> | ||
select s.Id from Entity s where s.Name = :name | ||
</sql-query> | ||
|
||
</hibernate-mapping> |
50 changes: 50 additions & 0 deletions
50
src/NHibernate.Test/NHSpecificTest/GH3311SqlQueryParam/SqlQueryParamTypeFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Data; | ||
using NHibernate.Dialect; | ||
using NHibernate.SqlTypes; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3311SqlQueryParam | ||
{ | ||
[TestFixture] | ||
public class SqlQueryParamTypeFixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
var e1 = new Entity {Name = "Bob"}; | ||
session.Save(e1); | ||
|
||
var e2 = new Entity {Name = "Sally"}; | ||
session.Save(e2); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return | ||
//Dialects like SQL Server CE, Firebird don't distinguish AnsiString from String | ||
(Dialect.GetTypeName(new SqlType(DbType.AnsiString)) != Dialect.GetTypeName(new SqlType(DbType.String)) | ||
|| Dialect is SQLiteDialect); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public void AppliesParameterTypeFromQueryParam() | ||
{ | ||
using var log = new SqlLogSpy(); | ||
using var s = OpenSession(); | ||
s.GetNamedQuery("entityIdByName").SetParameter("name", "Bob").UniqueResult<object>(); | ||
Assert.That(log.GetWholeLog(), Does.Contain("Type: AnsiString")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters