- 增加 ISelect.ToDataTable 系列方法;

- 增加 无参数化命令执行,可配置全局 ICodeFirst.IsNoneCommandParameter、或临时 IInsert/IUpdate.NoneParameter() 便于调试;
- 关闭 自动同步结构功能,避免线上环境误操作;
- 优化 IInsert 批量插入容易导致 values 过多、或参数化过多的问题,5个数据库均已优化;
This commit is contained in:
28810
2019-03-14 02:24:15 +08:00
parent 1fa6c9bfc4
commit abb7402b36
47 changed files with 737 additions and 340 deletions

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -12,24 +13,39 @@ namespace FreeSql.Sqlite.Curd {
: base(orm, commonUtils, commonExpression) {
}
public override long ExecuteIdentity() {
public override int ExecuteAffrows() => base.SplitExecuteAffrows(5000, 999);
public override Task<int> ExecuteAffrowsAsync() => base.SplitExecuteAffrowsAsync(5000, 999);
public override long ExecuteIdentity() => base.SplitExecuteIdentity(5000, 999);
public override Task<long> ExecuteIdentityAsync() => base.SplitExecuteIdentityAsync(5000, 999);
public override List<T1> ExecuteInserted() => base.SplitExecuteInserted(5000, 999);
public override Task<List<T1>> ExecuteInsertedAsync() => base.SplitExecuteInsertedAsync(5000, 999);
internal override long RawExecuteIdentity() {
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return 0;
return long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_transaction, CommandType.Text, string.Concat(sql, "; SELECT last_insert_rowid();"), _params)), out var trylng) ? trylng : 0;
}
async public override Task<long> ExecuteIdentityAsync() {
async internal override Task<long> RawExecuteIdentityAsync() {
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return 0;
return long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_transaction, CommandType.Text, string.Concat(sql, "; SELECT last_insert_rowid();"), _params)), out var trylng) ? trylng : 0;
}
internal override List<T1> RawExecuteInserted() {
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return new List<T1>();
public override List<T1> ExecuteInserted() {
throw new NotImplementedException();
this.ExecuteAffrows();
return _source;
}
public override Task<List<T1>> ExecuteInsertedAsync() {
throw new NotImplementedException();
async internal override Task<List<T1>> RawExecuteInsertedAsync() {
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return new List<T1>();
await this.ExecuteAffrowsAsync();
return _source;
}
}
}

View File

@ -22,10 +22,11 @@ namespace FreeSql.Sqlite {
_commonExpression = commonExpression;
}
public bool IsAutoSyncStructure { get; set; } = true;
public bool IsAutoSyncStructure { get; set; } = false;
public bool IsSyncStructureToLower { get; set; } = false;
public bool IsSyncStructureToUpper { get; set; } = false;
public bool IsConfigEntityFromDbFirst { get; set; } = false;
public bool IsNoneCommandParameter { get; set; } = false;
public bool IsLazyLoading { get; set; } = false;
static object _dicCsToDbLock = new object();

View File

@ -0,0 +1,11 @@
public static class FreeSqlSqliteExtensions {
/// <summary>
/// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换
/// </summary>
/// <param name="that"></param>
/// <param name="args"></param>
/// <returns></returns>
public static string FormatSqlite (this string that, params object[] args) => _sqliteAdo.Addslashes(that, args);
static FreeSql.Sqlite.SqliteAdo _sqliteAdo = new FreeSql.Sqlite.SqliteAdo();
}

View File

@ -15,7 +15,6 @@ namespace FreeSql.Sqlite {
internal override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, Type type, object value) {
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
else if (_orm.CodeFirst.IsSyncStructureToLower) parameterName = parameterName.ToLower();
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
switch (dbtype) {
case DbType.Guid:
@ -29,7 +28,7 @@ namespace FreeSql.Sqlite {
dbtype = DbType.Int64;
break;
}
var ret = new SQLiteParameter { ParameterName = $"@{parameterName}", DbType = dbtype, Value = value };
var ret = new SQLiteParameter { ParameterName = QuoteParamterName(parameterName), DbType = dbtype, Value = value };
_params?.Add(ret);
return ret;
}
@ -63,12 +62,10 @@ namespace FreeSql.Sqlite {
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
internal override string GetNoneParamaterSqlValue(Type type, object value) {
internal override string GetNoneParamaterSqlValue(List<DbParameter> specialParams, Type type, object value) {
if (value == null) return "NULL";
if (type == typeof(byte[])) value = Encoding.UTF8.GetString(value as byte[]);
return FormatSql("{0}", value, 1);
}
internal override string DbName => "Sqlite";
}
}