mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 02:35:04 +08:00
Update Sqlite
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ORDER BY NOW() ";
|
||||
return "ORDER BY DATETIME('now') ";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
Binary file not shown.
@@ -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");
|
||||
|
Reference in New Issue
Block a user