-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Closed
Description
Dapper is throwing an error when I try to use a nullable bool with MySql.
Error parsing column 1 (IsBold=0 - SByte)
It only breaks when a statement follows the null value insert statement.
An additional note, it works fine if I manually change the size of IsBold from tinyint(1) (the default created by BOOLEAN) to 2 or greater.
[Fact]
public void TestSuccess()
{
using (var conn = GetMySqlConnection(true, true, true))
{
try { conn.Execute("drop table boolTest_Test"); } catch { }
conn.Execute("create table boolTest_Test (Id int not null, IsBold BOOLEAN null );");
conn.Execute("insert boolTest_Test (Id, IsBold) values (1,1);");
conn.Execute("insert boolTest_Test (Id, IsBold) values (2,null);");
var rows = conn.Query<BoolTest>("select * from boolTest_Test").ToDictionary(x => x.Id);
Assert.True(rows[1].IsBold);
Assert.Null(rows[2].IsBold);
}
}
[Fact]
public void TestFail()
{
using (var conn = GetMySqlConnection(true, true, true))
{
try { conn.Execute("drop table boolTest_Test"); } catch { }
conn.Execute("create table boolTest_Test (Id int not null, IsBold BOOLEAN null );");
conn.Execute("insert boolTest_Test (Id, IsBold) values (2,null);");
conn.Execute("insert boolTest_Test (Id, IsBold) values (1,1);");
var rows = conn.Query<BoolTest>("select * from boolTest_Test").ToDictionary(x => x.Id);
Assert.True(rows[1].IsBold);
Assert.Null(rows[2].IsBold);
}
}
class BoolTest
{
public int Id { get; set; }
public bool? IsBold { get; set; }
}
Metadata
Metadata
Assignees
Labels
No labels