public void working_with_nullables() { var pst = _db.Query <Post>("select 1 as id, 1 as TopicId").First(); Assert.Equal(1, pst.TopicId); pst = _db.Query <Post>("select 1 as id, null as TopicId").First(); Assert.Null(pst.TopicId); Assert.Equal(0, _db.GetValue <int?>("select 0")); Assert.Null(_db.GetValue <int?>("select null")); }
private string GetConstraintType() { var tp = _db.GetValue <string>( @"select CONSTRAINT_TYPE as Type from information_schema.`TABLE_CONSTRAINTS` where CONSTRAINT_SCHEMA=@0 and CONSTRAINT_NAME=@1 and TABLE_NAME=@2 limit 1", _db.Connection.Database, Item.Name ?? "PRIMARY", Item.TableName); if (tp.IsNullOrEmpty()) { throw new InvalidOperationException("Constraint does not exist"); } switch (tp) { case PrimaryKey: return(PrimaryKey); case "UNIQUE": return(Item.Name); case "FOREIGN KEY": return(tp + " " + Item.Name); } throw new NotSupportedException(); }
public override void ExecuteScalar(BenchmarksContainer bc) { bc.Add(id => { _db.GetValue <string>("select title from sfposts where id=@0", 5); }, "SqlFu scalar"); bc.Add(id => { _db.GetColumnValue <sfPosts, string>(p => p.Title, p => p.Id == 5); }, "SqlFu get scalar expression based"); //bc.Add(id => //{ // _db.ExecuteScalar<int?>("select topicid from sfposts where id=@0 order by id", 5); //}, "SqlFu scalar null to nullable"); //bc.Add(id => //{ // _db.ExecuteScalar<PostType>("select Type from sfposts where id=@0 order by id", 5); //}, "SqlFu scalar enum"); }