Browse Source

Update Sqlite

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
08a02cf258
  1. 5
      Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs
  2. 22
      Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs
  3. BIN
      Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite
  4. 26
      Src/Asp.Net/SqliteTest/Program.cs
  5. 4
      Src/Asp.Net/SqliteTest/UnitTest/Query/SingleQuery.cs

5
Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs

@ -5,6 +5,8 @@ using System.Text;
using System.Data;
using System.Reflection;
using System.Reflection.Emit;
using System.Text.RegularExpressions;
namespace SqlSugar
{
///<summary>
@ -159,6 +161,9 @@ namespace SqlSugar
MethodInfo method = null;
Type bindPropertyType = PubMethod.GetUnderType(bindProperty, ref isNullableType);
string dbTypeName = DataRecord.GetDataTypeName(ordinal);
if (Regex.IsMatch(dbTypeName, @"\(.+\)")) {
dbTypeName = Regex.Replace(dbTypeName,@"\(.+\)", "");
}
string propertyName = bindProperty.Name;
string validPropertyName = bind.GetPropertyTypeName(dbTypeName);
validPropertyName = validPropertyName == "byte[]" ? "byteArray" : validPropertyName;

22
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

@ -54,6 +54,26 @@ namespace SqlSugar
}
public class SqliteMethod : DefaultDbMethod, IDbMethods
{
public override string Contains(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" ({0} like '%'||{1}||'%') ", parameter.MemberName, parameter2.MemberName);
}
public override string StartsWith(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" ({0} like '%'||{1}) ", parameter.MemberName, parameter2.MemberName);
}
public override string EndsWith(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
var parameter2 = model.Args[1];
return string.Format(" ({0} like {1}||'%') ", parameter.MemberName, parameter2.MemberName);
}
}
}

BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.

26
Src/Asp.Net/SqliteTest/Program.cs

@ -17,19 +17,19 @@ namespace OrmTest
{
static void Main(string[] args)
{
////// /***Unit Test***/
//new Field(1).Init();
//new Where(1).Init();
//new Method(1).Init();
//new JoinQuery(1).Init();
//new SingleQuery(1).Init();
//new SelectQuery(1).Init();
//new AutoClose(1).Init();
//new Insert(1).Init();
//new Delete(1).Init();
//new Update(1).Init();
//new Mapping(1).Init();
//new DataTest(1).Init();
/***Unit Test***/
new Field(1).Init();
new Where(1).Init();
new Method(1).Init();
new JoinQuery(1).Init();
new SingleQuery(1).Init();
new SelectQuery(1).Init();
new AutoClose(1).Init();
new Insert(1).Init();
new Delete(1).Init();
new Update(1).Init();
new Mapping(1).Init();
new DataTest(1).Init();
//// /***Performance Test***/
//// new SqlSugarPerformance(100).Select();

4
Src/Asp.Net/SqliteTest/UnitTest/Query/SingleQuery.cs

@ -95,7 +95,7 @@ namespace OrmTest.UnitTest
.Where(it=>it.Id==1)
.WhereIF(true,it=> SqlFunc.Contains(it.Name,"a"))
.OrderBy(it => it.Id, OrderByType.Desc).Skip((pageIndex - 1) * pageSize).Take(pageSize ).With(SqlWith.NoLock).ToSql();
base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` WHERE ( `ID` = @Id0 ) AND (`Name` like concat('%',@MethodConst1,'%')) ORDER BY `ID` DESC LIMIT 10,10", new List<SugarParameter>() {
base.Check(@"SELECT `ID`,`SchoolId`,`Name`,`CreateTime` FROM `STudent` WHERE ( `ID` = @Id0 ) AND (`Name` like '%'||@MethodConst1||'%') ORDER BY `ID` DESC LIMIT 10,10", new List<SugarParameter>() {
new SugarParameter("@Id0",1),new SugarParameter("@MethodConst1","a")
}, t8.Key, t8.Value,"single t8 Error");
@ -104,7 +104,7 @@ namespace OrmTest.UnitTest
var t9 = db.Queryable<Student>()
.In(1)
.Select(it => new { it.Id, it.Name,x=it.Id }).ToSql();
base.Check("SELECT `ID` AS `Id` , `Name` AS `Name` , `ID` AS `x` FROM `STudent` WHERE `ID` IN (@InPara0) ", new List<SugarParameter>() {
base.Check("SELECT `ID` AS `Id` , `Name` AS `Name` , `ID` AS `x` FROM `STudent` WHERE `Id` IN (@InPara0) ", new List<SugarParameter>() {
new SugarParameter("@InPara0",1) },t9.Key,t9.Value, "single t9 error");
}
}

Loading…
Cancel
Save