Update clickhouse

This commit is contained in:
sunkaixuan 2022-08-14 03:18:19 +08:00
parent 31609a18dd
commit f72dbb7a14
2 changed files with 44 additions and 3 deletions

View File

@ -21,12 +21,45 @@ namespace OrmTest
});
//db.DbMaintenance.CreateDatabase();
db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1
db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand();
db.Insertable(new CodeFirstTable1() { Name = "a", Text = "a" }).ExecuteCommand();
var list = db.Queryable<CodeFirstTable1>().ToList();
TestBool(db);
TestGuid(db);
Console.WriteLine("#### CodeFirst end ####");
}
private static void TestGuid(SqlSugarClient db)
{
db.CodeFirst.InitTables<GuidTest>();
db.DbMaintenance.TruncateTable("BoolTest");
var Id = 1;
db.Insertable<GuidTest>(new GuidTest() { A = Guid.Empty, Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<GuidTest>().First().A);
db.Updateable<GuidTest>(new GuidTest() { A = Guid.NewGuid(), Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<GuidTest>().First().A);
}
private static void TestBool(SqlSugarClient db)
{
db.CodeFirst.InitTables<BoolTest>();
db.DbMaintenance.TruncateTable("BoolTest");
var Id = 1;
db.Insertable<BoolTest>(new BoolTest() { A = true, Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<BoolTest>().First().A);
db.Updateable<BoolTest>(new BoolTest() { A = false, Id = Id }).ExecuteCommand();
Console.Write(db.Queryable<BoolTest>().First().A);
}
}
public class GuidTest
{
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
public Guid A { get; set; }
}
public class BoolTest
{
[SugarColumn(IsPrimaryKey =true)]
public long Id { get; set; }
public bool A { get; set; }
}
public class CodeFirstTable1
{
[SugarColumn(IsPrimaryKey = true)]

View File

@ -125,10 +125,18 @@ namespace SqlSugar.ClickHouse
{
dbtype = ClickHouseDbBind.MappingTypesConst.First(it => it.Value == CSharpDataType.@decimal).Key;
}
if (dbtype.ObjToString() == System.Data.DbType.Boolean.ToString())
if (dbtype.ObjToString() == System.Data.DbType.Guid.ToString())
{
dbtype = ClickHouseDbBind.MappingTypesConst.First(it => it.Value == CSharpDataType.Guid).Key;
}
if (param.Value!=null&&param.Value!=DBNull.Value&&dbtype.ObjToString() == System.Data.DbType.Boolean.ToString())
{
sql = sql.Replace(param.ParameterName, param.Value.ObjToBool()?"1":"0");
}
else if (dbtype.ObjToString() == System.Data.DbType.Boolean.ToString())
{
sql = sql.Replace(param.ParameterName, "null");
}
else
{
sql = sql.Replace(param.ParameterName, "{" + newName + ":" + dbtype + "}");