Update Sqlite

This commit is contained in:
sunkaixuan
2017-07-09 21:11:32 +08:00
parent c8721af0a8
commit 67075c401a
6 changed files with 60 additions and 14 deletions

View File

@@ -175,7 +175,25 @@ namespace SqlSugar
#region Sqlite Logic
if (this.Context.CurrentConnectionConfig.DbType == DbType.Sqlite)
{
method = isNullableType ? getSqliteTypeNull.MakeGenericMethod(bindPropertyType) : getSqliteType.MakeGenericMethod(bindPropertyType);
if (bindPropertyType == PubConst.IntType)
{
method = isNullableType ? getConvertInt32 : getInt32;
}
else if (bindPropertyType == PubConst.StringType)
{
method = getString;
}
else if (bindPropertyType == PubConst.ByteArrayType)
{
method = getValueMethod;
generator.Emit(OpCodes.Call, method);
generator.Emit(OpCodes.Unbox_Any, bindProperty.PropertyType);
return;
}
else
{
method = isNullableType ? getSqliteTypeNull.MakeGenericMethod(bindPropertyType) : getSqliteType.MakeGenericMethod(bindPropertyType);
}
generator.Emit(OpCodes.Call, method);
return;
};
@@ -254,7 +272,7 @@ namespace SqlSugar
if (method == getValueMethod)
{
generator.Emit(OpCodes.Unbox_Any, bindProperty.PropertyType);
}
}
#endregion
}

View File

@@ -8,6 +8,7 @@ namespace SqlSugar
public static partial class IDataRecordExtensions
{
#region Common Extensions
public static Guid GetStringGuid(this IDataRecord dr, int i)
{
var reval = Guid.Parse(dr.GetValue(i).ToString());
@@ -183,9 +184,27 @@ namespace SqlSugar
return null;
}
#endregion
#region Sqlite Extensions
public static Nullable<T> GetSqliteTypeNull<T>(this IDataReader dr, int i) where T : struct
{
var type = PubMethod.GetUnderType(typeof(T));
if (dr.IsDBNull(i))
{
return null;
}
return SqliteTypeConvert<T>(dr, i, type);
}
public static T GetSqliteType<T>(this IDataReader dr, int i) where T : struct
{
var type = typeof(T);
return SqliteTypeConvert<T>(dr, i, type);
}
private static T SqliteTypeConvert<T>(IDataReader dr, int i, Type type) where T : struct
{
if (type.IsIn(PubConst.IntType))
{
return (T)((object)(dr.GetInt32(i)));
@@ -194,23 +213,29 @@ namespace SqlSugar
{
return (T)Convert.ChangeType(Convert.ToDateTime(dr.GetString(i)), type);
}
else
else if (type == PubConst.DecType)
{
return (T)Convert.ChangeType((dr.GetString(i)), type);
return (T)Convert.ChangeType(dr.GetDecimal(i), type);
}
}
public static T GetSqliteType<T>(this IDataReader dr, int i)
{
var type = typeof(T);
if (type.IsIn(PubConst.IntType))
else if (type == PubConst.DobType)
{
return (T)((object)(dr.GetInt32(i)));
return (T)Convert.ChangeType(dr.GetDouble(i), type);
}
else if (type == PubConst.BoolType)
{
return (T)Convert.ChangeType(dr.GetBoolean(i), type);
}
else if (type == PubConst.GuidType)
{
string guidString = dr.GetString(i);
string changeValue = guidString.IsNullOrEmpty() ? Guid.Empty.ToString() : guidString;
return (T)Convert.ChangeType(Guid.Parse(changeValue), type);
}
else
{
return (T)Convert.ChangeType((dr.GetString(i)), type);
}
}
}
#endregion
}
}

View File

@@ -21,7 +21,7 @@ namespace SqlSugar
{
get
{
return "ORDER BY NOW() ";
return "ORDER BY DATETIME('now') ";
}
}

View File

@@ -91,6 +91,9 @@ namespace SqlSugar
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
this.OutputParameters.Add(sqlParameter);
}
if (sqlParameter.DbType == System.Data.DbType.Guid) {
sqlParameter.DbType = System.Data.DbType.String;
}
++index;
}
return result;

View File

@@ -19,7 +19,7 @@ namespace OrmTest.PerformanceTesting
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
DbType = DbType.Sqlite,
IsAutoCloseConnection = false
});
db.IgnoreColumns.Add("TestId", "Student");