Optimize project catalog

This commit is contained in:
sunkaixuan
2022-03-25 10:39:07 +08:00
parent d6c8b07dae
commit 8a613bc5ac
881 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public class AccessBlukCopy
{
internal List<IGrouping<int, DbColumnInfo>> DbColumnInfoList { get; set; }
internal SqlSugarProvider Context { get; set; }
internal ISqlBuilder Builder { get; set; }
internal InsertBuilder InsertBuilder { get; set; }
internal object[] Inserts { get; set; }
public int ExecuteBulkCopy()
{
throw new NotSupportedException();
}
public async Task<int> ExecuteBulkCopyAsync()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public class AccessBuilder : SqlBuilderProvider
{
public override string SqlTranslationLeft { get { return "["; } }
public override string SqlTranslationRight { get { return "]"; } }
public override string SqlDateNow { get { return " NOW()"; } }
public override string FullSqlDateNow { get { return "SELECT NOW()"; } }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public class AccessDeleteBuilder : DeleteBuilder
{
}
}

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public partial class AccessExpressionContext : ExpressionContext, ILambdaExpressions
{
public SqlSugarProvider Context { get; set; }
public AccessExpressionContext()
{
base.DbMehtods = new AccessMethod();
}
}
public partial class AccessMethod : DefaultDbMethod, IDbMethods
{
public override string ToDate(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CDate({0}) ", parameter.MemberName);
}
public override string ToBool(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CDate({0}) ", parameter.MemberName);
}
public override string ToInt32(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CInt({0}) ", parameter.MemberName);
}
public override string ToString(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" CVar({0}) ", parameter.MemberName);
}
public override string ToDateShort(MethodCallExpressionModel model)
{
var parameter = model.Args[0];
return string.Format(" Format$({0},\"Long Date\") ", parameter.MemberName);
}
public override string DateValue(MethodCallExpressionModel model)
{
var type = "";
if (model.Args[1].MemberValue.ObjToString() == "Day")
{
type = "d";
}
if (model.Args[1].MemberValue.ObjToString() == "Month")
{
type = "m";
}
if (model.Args[1].MemberValue.ObjToString() == "Year")
{
type = "yyyy";
}
if (model.Args[1].MemberValue.ObjToString() == DateType.Minute.ToString())
{
type = "M";
}
if (model.Args[1].MemberValue.ObjToString() == DateType.Second.ToString())
{
type = "s";
}
return "DATEPART(\""+ type + "\", date())";
}
public override string GetRandom()
{
return " rnd() ";
}
public override string GetDate()
{
return " NOW()";
}
public override string HasValue(MethodCallExpressionModel model)
{
if (model.Args[0].Type == UtilConstants.GuidType)
{
var parameter = model.Args[0];
return string.Format("( {0} IS NOT NULL )", parameter.MemberName);
}
else
{
var parameter = model.Args[0];
return string.Format("( {0}<>'' AND {0} IS NOT NULL )", parameter.MemberName);
}
}
}
}

View File

@@ -0,0 +1,26 @@
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public class AccessFastBuilder : FastBuilder,IFastBuilder
{
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
{
throw new NotSupportedException();
}
public SqlBulkCopy GetBulkCopyInstance()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public class AccessInsertBuilder : InsertBuilder
{
public override bool IsOleDb { get; set; } = true;
public override string SqlTemplate
{
get
{
if (IsReturnIdentity)
{
return @"INSERT INTO {0}
({1})
VALUES
({2}) ;select @@identity";
}
else
{
return @"INSERT INTO {0}
({1})
VALUES
({2}) ;";
}
}
}
public override string ToSqlString()
{
if (IsNoInsertNull)
{
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList();
}
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
var isSingle = groupList.Count() == 1;
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
if (isSingle)
{
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName));
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
}
else
{
StringBuilder batchInsetrSql = new StringBuilder();
int pageSize = 200;
if (this.EntityInfo.Columns.Count > 30)
{
pageSize = 50;
}
else if (this.EntityInfo.Columns.Count > 20)
{
pageSize = 100;
}
int pageIndex = 1;
int totalRecord = groupList.Count;
int pageCount = (totalRecord + pageSize - 1) / pageSize;
while (pageCount >= pageIndex)
{
batchInsetrSql.AppendFormat(SqlTemplateBatch, GetTableNameString, columnsString);
int i = 0;
foreach (var columns in groupList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList())
{
var isFirst = i == 0;
if (!isFirst)
{
batchInsetrSql.Append(SqlTemplateBatchUnion);
}
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), Builder.GetTranslationColumnName(it.DbColumnName)))));
++i;
}
pageIndex++;
batchInsetrSql.Append("\r\n;\r\n");
}
var result = batchInsetrSql.ToString();
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
{
result += "select SCOPE_IDENTITY();";
}
return result;
}
}
}
}

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public class AccessQueryBuilder : QueryBuilder
{
public override string SqlTemplate
{
get
{
return "SELECT {0}{"+UtilConstants.ReplaceKey+"} FROM {1}{2}{3}{4}";
}
}
public override string ToSqlString()
{
string oldOrderBy = this.OrderByValue;
string externalOrderBy = oldOrderBy;
var isIgnoreOrderBy = this.IsCount && this.PartitionByValue.IsNullOrEmpty();
AppendFilter();
sql = new StringBuilder();
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY now() ";
if (this.PartitionByValue.HasValue())
{
throw new Exception("sqlite no support partition by");
}
var isFirst = (Skip == 0 || Skip == null) && Take == 1 && DisableTop == false;
var isRowNumber = (Skip != null || Take != null) && !isFirst;
var isPage = isRowNumber;
isRowNumber = false;
var oldSkip = Skip;
var oldTake = Take;
Skip = null;
Take = null;
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
string groupByValue = GetGroupByString + HavingInfos;
string orderByValue = (!isRowNumber && this.OrderByValue.HasValue()) ? GetOrderByString : null;
if (isIgnoreOrderBy) { orderByValue = null; }
sql.AppendFormat(SqlTemplate, isFirst ? (" TOP 1 " + GetSelectValue) : GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (isIgnoreOrderBy ? null : rowNumberString) : null);
if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
var result = isFirst ? sql.ToString() : ToPageSql(sql.ToString(), this.Take, this.Skip);
if (ExternalPageIndex > 0)
{
throw new Exception("sqlite no support partition by");
}
this.OrderByValue = oldOrderBy;
if (!string.IsNullOrEmpty(this.Offset))
{
if (this.OrderByValue.IsNullOrEmpty())
{
result += " ORDER BY now() ";
this.OrderByValue = " ORDER BY now() ";
}
result += this.Offset;
}
result = GetSqlQuerySql(result);
if (isPage)
{
var colums=this.Context.EntityMaintenance.GetEntityInfo(this.EntityType).Columns;
if (!colums.Any(x => x.IsPrimarykey))
{
throw new Exception("sqlite page need primary key , entity name: "+ this.EntityName);
}
var pkName =this.Builder.GetTranslationColumnName(colums.Where(x => x.IsPrimarykey).First().DbColumnName);
var takeSql = $@" SELECT { (oldTake == null ? "" : ("Top " + oldTake)) }
*FROM({ result}) ACCTABLE1";
var skipSql = $@"
WHERE {pkName} NOT IN
(SELECT { (oldSkip == null ? "" : ("Top " + oldSkip))} {pkName} FROM ({result}) ACCTABLE2 { this.OrderByValue })";
if (oldSkip == 0)
{
result = takeSql;
}
else
{
result = takeSql+skipSql;
}
}
return result;
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar.Access
{
public class AccessUpdateBuilder : UpdateBuilder
{
protected override string TomultipleSqlString(List<IGrouping<int, DbColumnInfo>> groupList)
{
if (groupList.Count == 0)
{
return null;
}
else if (groupList.GroupBy(it => it.Key).Count() > 1)
{
throw new Exception("access no support batch update");
}
else
{
return ToSingleSqlString(groupList);
}
}
}
}