mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Update Sqlite Core 2.0
This commit is contained in:
@@ -82,31 +82,6 @@ namespace SqlSugar
|
||||
return method.ReflectedType;
|
||||
}
|
||||
}
|
||||
public static class AdoCore
|
||||
{
|
||||
public static List<DbColumnInfo> GetColumnInfosByTableName(string tableName, DbDataReader dataReader)
|
||||
{
|
||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||
var schemaTable = dataReader.GetSchemaTable();
|
||||
foreach (DataRow row in schemaTable.Rows)
|
||||
{
|
||||
DbColumnInfo column = new DbColumnInfo()
|
||||
{
|
||||
TableName = tableName,
|
||||
DataType = row["DataTypeName"].ToString().Trim(),
|
||||
IsNullable = (bool)row["AllowDBNull"],
|
||||
IsIdentity = (bool)row["IsAutoIncrement"],
|
||||
ColumnDescription = null,
|
||||
DbColumnName = row["ColumnName"].ToString(),
|
||||
DefaultValue = row["defaultValue"].ToString(),
|
||||
IsPrimarykey = (bool)row["IsKey"],
|
||||
Length = Convert.ToInt32(row["ColumnSize"])
|
||||
};
|
||||
result.Add(column);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public static class ReflectionCore
|
||||
{
|
||||
public static Assembly Load(string name)
|
||||
|
@@ -4,7 +4,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data.Sqlite;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
|
@@ -1,42 +0,0 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Data.Sqlite;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Data.Sqlite
|
||||
{
|
||||
public static class AdoCore
|
||||
{
|
||||
public static List<DbColumnInfo> GetColumnInfosByTableName(string tableName, DbDataReader dataReader)
|
||||
{
|
||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
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()
|
||||
{
|
||||
TableName = tableName,
|
||||
DataType = type,
|
||||
IsNullable = !dataReader.GetBoolean(3),
|
||||
IsIdentity = dataReader.GetBoolean(3)&&dataReader.GetBoolean(5).ObjToBool() && (type.IsIn("integer", "int", "int32", "int64", "long")),
|
||||
ColumnDescription = null,
|
||||
DbColumnName = dataReader.GetString(1),
|
||||
DefaultValue =dataReader.GetValue(4).ObjToString(),
|
||||
IsPrimarykey = dataReader.GetBoolean(5).ObjToBool(),
|
||||
Length = length
|
||||
};
|
||||
result.Add(column);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Sqlite;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -176,13 +175,36 @@ namespace SqlSugar
|
||||
|
||||
}, (cm, key) =>
|
||||
{
|
||||
string sql = "select * from " + tableName + " limit 0,1";
|
||||
string sql = "PRAGMA table_info(" + tableName + ")";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
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;
|
||||
return AdoCore.GetColumnInfosByTableName(tableName, reader);
|
||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
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()
|
||||
{
|
||||
TableName = tableName,
|
||||
DataType = type,
|
||||
IsNullable = !dataReader.GetBoolean(3),
|
||||
IsIdentity = dataReader.GetBoolean(3) && dataReader.GetBoolean(5).ObjToBool() && (type.IsIn("integer", "int", "int32", "int64", "long")),
|
||||
ColumnDescription = null,
|
||||
DbColumnName = dataReader.GetString(1),
|
||||
DefaultValue = dataReader.GetValue(4).ObjToString(),
|
||||
IsPrimarykey = dataReader.GetBoolean(5).ObjToBool(),
|
||||
Length = length
|
||||
};
|
||||
result.Add(column);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -3,7 +3,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data.Sqlite;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
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() })));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
|
||||
<PackageReference Include="MySql.Data" Version="6.10.3-rc" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="System.Data.Common" Version="4.3.0" />
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user