mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 04:23:47 +08:00
Update Core
This commit is contained in:
@@ -26,7 +26,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dic.Add(reader.GetName(i), reader.GetValue(i));
|
var addItem = reader.GetValue(i);
|
||||||
|
if (addItem == DBNull.Value)
|
||||||
|
addItem = null;
|
||||||
|
dic.Add(reader.GetName(i), addItem);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -66,7 +69,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result.Add(reader.GetName(i), reader.GetValue(i));
|
var addItem = reader.GetValue(i);
|
||||||
|
if (addItem == DBNull.Value)
|
||||||
|
addItem = null;
|
||||||
|
result.Add(reader.GetName(i), addItem);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -166,7 +172,10 @@ namespace SqlSugar
|
|||||||
var key = typeName + "." + name;
|
var key = typeName + "." + name;
|
||||||
if (readerValues.ContainsKey(key))
|
if (readerValues.ContainsKey(key))
|
||||||
{
|
{
|
||||||
result.Add(name, readerValues[key]);
|
var addItem = readerValues[key];
|
||||||
|
if (addItem == DBNull.Value)
|
||||||
|
addItem = null;
|
||||||
|
result.Add(name, addItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,12 +201,8 @@ namespace SqlSugar
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T DeserializeObject<T>(string value)
|
public T DeserializeObject<T>(string value)
|
||||||
{
|
{
|
||||||
if (value.IsValuable())
|
|
||||||
{
|
|
||||||
value = value.Replace(":{}", ":null");
|
|
||||||
}
|
|
||||||
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||||
return JsonConvert.DeserializeObject<T>(value,jSetting);
|
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -229,7 +234,10 @@ namespace SqlSugar
|
|||||||
childRow = new Dictionary<string, object>();
|
childRow = new Dictionary<string, object>();
|
||||||
foreach (DataColumn col in table.Columns)
|
foreach (DataColumn col in table.Columns)
|
||||||
{
|
{
|
||||||
childRow.Add(col.ColumnName, row[col]);
|
var addItem = row[col];
|
||||||
|
if (addItem == DBNull.Value)
|
||||||
|
addItem = null;
|
||||||
|
childRow.Add(col.ColumnName, addItem);
|
||||||
}
|
}
|
||||||
deserializeObject.Add(childRow);
|
deserializeObject.Add(childRow);
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,46 @@
|
|||||||
namespace SqlSugar
|
using System;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Linq;
|
||||||
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public interface IDataAdapter
|
public interface IDataAdapter
|
||||||
{
|
{
|
||||||
void Fill(DataSet ds);
|
void Fill(DataSet ds);
|
||||||
}
|
}
|
||||||
|
public partial class SqliteProvider : AdoProvider
|
||||||
|
{
|
||||||
|
public override void ExecuteBefore(string sql, SugarParameter[] parameters)
|
||||||
|
{
|
||||||
|
if (sql.IsValuable() && parameters.IsValuable())
|
||||||
|
{
|
||||||
|
foreach (var parameter in parameters)
|
||||||
|
{
|
||||||
|
//Compatible with.NET CORE parameters case
|
||||||
|
var name = parameter.ParameterName;
|
||||||
|
if (!sql.Contains(name) && Regex.IsMatch(sql, "(" + name + "$)" + "|(" + name + @"[ ,\,])", RegexOptions.IgnoreCase))
|
||||||
|
{
|
||||||
|
parameter.ParameterName = Regex.Match(sql, "(" + name + "$)" + "|(" + name + @"[ ,\,])", RegexOptions.IgnoreCase).Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.IsEnableLogEvent)
|
||||||
|
{
|
||||||
|
Action<string, string> action = LogEventStarting;
|
||||||
|
if (action != null)
|
||||||
|
{
|
||||||
|
if (parameters == null || parameters.Length == 0)
|
||||||
|
{
|
||||||
|
action(sql, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
action(sql, this.Context.RewritableMethods.SerializeObject(parameters.Select(it => new { key = it.ParameterName, value = it.Value.ObjToString() })));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
namespace System.Data.Sqlite {
|
namespace System.Data.Sqlite {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -176,27 +176,32 @@ namespace SqlSugar
|
|||||||
|
|
||||||
}, (cm, key) =>
|
}, (cm, key) =>
|
||||||
{
|
{
|
||||||
string sql = "select * from " + tableName + " limit 0,1";
|
string sql = "PRAGMA table_info(" + tableName + ")";
|
||||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||||
this.Context.Ado.IsEnableLogEvent = false;
|
this.Context.Ado.IsEnableLogEvent = false;
|
||||||
using (DbDataReader reader = (SqliteDataReader)this.Context.Ado.GetDataReader(sql))
|
using (DbDataReader dataReader = (SqliteDataReader)this.Context.Ado.GetDataReader(sql))
|
||||||
{
|
{
|
||||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
|
||||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||||
var schemaTable = reader.GetSchemaTable();
|
while (dataReader.Read())
|
||||||
foreach (DataRow row in schemaTable.Rows)
|
|
||||||
{
|
{
|
||||||
|
var type = dataReader.GetValue(2).ObjToString();
|
||||||
|
var length = 0;
|
||||||
|
if (type.Contains("("))
|
||||||
|
{
|
||||||
|
type = type.Split('(').First();
|
||||||
|
length = type.Split('(').Last().TrimEnd(')').ObjToInt();
|
||||||
|
}
|
||||||
DbColumnInfo column = new DbColumnInfo()
|
DbColumnInfo column = new DbColumnInfo()
|
||||||
{
|
{
|
||||||
TableName = tableName,
|
TableName = tableName,
|
||||||
DataType = row["DataTypeName"].ToString().Trim(),
|
DataType = type,
|
||||||
IsNullable = (bool)row["AllowDBNull"],
|
IsNullable = !dataReader.GetBoolean(3),
|
||||||
IsIdentity = (bool)row["IsAutoIncrement"],
|
IsIdentity = dataReader.GetBoolean(3) && dataReader.GetBoolean(5).ObjToBool() && (type.IsIn("integer", "int", "int32", "int64", "long")),
|
||||||
ColumnDescription = null,
|
ColumnDescription = null,
|
||||||
DbColumnName = row["ColumnName"].ToString(),
|
DbColumnName = dataReader.GetString(1),
|
||||||
DefaultValue = row["defaultValue"].ToString(),
|
DefaultValue = dataReader.GetValue(4).ObjToString(),
|
||||||
IsPrimarykey = (bool)row["IsKey"],
|
IsPrimarykey = dataReader.GetBoolean(5).ObjToBool(),
|
||||||
Length = Convert.ToInt32(row["ColumnSize"])
|
Length = length
|
||||||
};
|
};
|
||||||
result.Add(column);
|
result.Add(column);
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,6 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static string ConnectionString = @"DataSource=D:\MyGit\SqlSugar\Src\Asp.NetCore2\SqlSeverTest\SqliteTest\DataBase\SqlSugar4xTest.sqlite";
|
public static string ConnectionString = @"DataSource=F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\Src\Asp.NetCore2\SqlSeverTest\SqliteTest\DataBase\SqlSugar4xTest.sqlite";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user