From 808c270810234222877f0a0567175d7176bd515d Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Wed, 6 May 2015 12:55:39 +0100 Subject: [PATCH] Fix boolean literal replacement in IL-based IMPL; 1.41-beta5 release --- Dapper NET40/SqlMapper.cs | 8 ++++++++ Dapper/project.json | 2 +- Tests/Tests.cs | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Dapper NET40/SqlMapper.cs b/Dapper NET40/SqlMapper.cs index 7848175..01f726b 100644 --- a/Dapper NET40/SqlMapper.cs +++ b/Dapper NET40/SqlMapper.cs @@ -3314,6 +3314,14 @@ internal static IList GetLiteralTokens(string sql) switch (typeCode) { case TypeCode.Boolean: + Label ifTrue = il.DefineLabel(), allDone = il.DefineLabel(); + il.Emit(OpCodes.Brtrue_S, ifTrue); + il.Emit(OpCodes.Ldstr, "0"); + il.Emit(OpCodes.Br_S, allDone); + il.MarkLabel(ifTrue); + il.Emit(OpCodes.Ldstr, "1"); + il.MarkLabel(allDone); + break; case TypeCode.Byte: case TypeCode.SByte: case TypeCode.UInt16: diff --git a/Dapper/project.json b/Dapper/project.json index b9b449f..4cb40c2 100644 --- a/Dapper/project.json +++ b/Dapper/project.json @@ -5,7 +5,7 @@ "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", "summary": "A high performance Micro-ORM", "description": "A high performance Micro-ORM supporting Sql Server, MySQL, Sqlite, SqlCE, Firebird etc..", - "version": "1.41-beta4", + "version": "1.41-beta5", "compile": [ "../Dapper NET40/*.cs", "../Dapper NET45/*.cs" ], "title": "Dapper dot net", "tags": [ "orm", "sql", "micro-orm" ], diff --git a/Tests/Tests.cs b/Tests/Tests.cs index 4686e97..adf95cb 100644 --- a/Tests/Tests.cs +++ b/Tests/Tests.cs @@ -3223,7 +3223,15 @@ public void LiteralReplacementDynamicEnumAndString() y.Equals(123.45M); z.Equals(AnotherEnum.A); } - + + public void LiteralReplacementBoolean() + { + var row = connection.Query("select 42 where 1 = {=val}", new { val = true }).SingleOrDefault(); + row.IsNotNull(); + row.IsEqualTo(42); + row = connection.Query("select 42 where 1 = {=val}", new { val = false }).SingleOrDefault(); + row.IsNull(); + } public void LiteralReplacementWithIn() { var data = connection.Query("select @x where 1 in @ids and 1 ={=a}", -- GitLab