mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-31 15:56:25 +08:00
Update Core
This commit is contained in:
parent
e0e7a5249a
commit
fed097ee39
@ -109,6 +109,9 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
var tableName = GetTableName(entityInfo);
|
||||
this.Context.MappingTables.Add(entityInfo.EntityName,tableName);
|
||||
entityInfo.DbTableName = tableName;
|
||||
entityInfo.Columns.ForEach(it => { it.DbTableName = tableName; });
|
||||
var isAny = this.Context.DbMaintenance.IsAnyTable(tableName);
|
||||
if (isAny)
|
||||
ExistLogic(entityInfo);
|
||||
|
@ -260,7 +260,10 @@ namespace SqlSugar
|
||||
method = isNullableType ? getConvertBoolean : getBoolean;
|
||||
break;
|
||||
case CSharpDataType.@string:
|
||||
CheckType(bind.StringThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||
if (this.Context.CurrentConnectionConfig.DbType != DbType.Oracle)
|
||||
{
|
||||
CheckType(bind.StringThrow, bindProperyTypeName, validPropertyName, propertyName);
|
||||
}
|
||||
method = getString;
|
||||
if (bindProperyTypeName == "guid")
|
||||
{
|
||||
|
@ -302,7 +302,7 @@ namespace SqlSugar
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool CreateIndex(string tableName, string[] columnNames, bool isUnique = false)
|
||||
public virtual bool CreateIndex(string tableName, string[] columnNames, bool isUnique=false)
|
||||
{
|
||||
string sql = string.Format(CreateIndexSql,tableName,string.Join(",",columnNames), string.Join("_", columnNames), isUnique ? "UNIQUE" : "");
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
|
@ -16,6 +16,10 @@ namespace SqlSugar
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
public T End<T>()
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
public class CaseThen
|
||||
{
|
||||
|
@ -45,8 +45,15 @@ namespace SqlSugar
|
||||
{
|
||||
var isFirst = allMethods.First() == methodExp;
|
||||
var isLast = allMethods.Last() == methodExp;
|
||||
var sql = SubTools.GetMethodValue(this.context, methodExp.Arguments[0], this.context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
|
||||
sqls.Add(new KeyValuePair<string, string>(methodExp.Method.Name, sql));
|
||||
if (methodExp.Arguments.Count == 0)
|
||||
{
|
||||
sqls.Add(new KeyValuePair<string, string>(methodExp.Method.Name, "null"));
|
||||
}
|
||||
else
|
||||
{
|
||||
var sql = SubTools.GetMethodValue(this.context, methodExp.Arguments[0], this.context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
|
||||
sqls.Add(new KeyValuePair<string, string>(methodExp.Method.Name, sql));
|
||||
}
|
||||
}
|
||||
var result = this.context.DbMehtods.CaseWhen(sqls);
|
||||
return result;
|
||||
|
@ -420,5 +420,17 @@ namespace SqlSugar
|
||||
var parameter = model.Args[0];
|
||||
return string.Format(" CAST({0} AS VARCHAR(MAX))", parameter.MemberName);
|
||||
}
|
||||
public string BitwiseAnd(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
var parameter2 = model.Args[1];
|
||||
return string.Format(" ({0} & {1}) ", parameter.MemberName, parameter2.MemberName); ;
|
||||
}
|
||||
public string BitwiseInclusiveOR(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
var parameter2 = model.Args[1];
|
||||
return string.Format(" ({0} | {1}) ", parameter.MemberName, parameter2.MemberName); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,5 +65,7 @@ namespace SqlSugar
|
||||
string GetDate();
|
||||
string GetRandom();
|
||||
string CharIndex(MethodCallExpressionModel model);
|
||||
string BitwiseAnd(MethodCallExpressionModel model);
|
||||
string BitwiseInclusiveOR(MethodCallExpressionModel model);
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ namespace SqlSugar
|
||||
{
|
||||
return thisValue.Equals(parameterValue);
|
||||
}
|
||||
public new static bool EqualsNull(object thisValue, object parameterValue)
|
||||
public static bool EqualsNull(object thisValue, object parameterValue)
|
||||
{
|
||||
return thisValue.Equals(parameterValue);
|
||||
}
|
||||
@ -137,5 +137,7 @@ namespace SqlSugar
|
||||
public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");}
|
||||
public static CaseThen IF(bool condition) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int CharIndex(string findChar,string searchValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int BitwiseAnd(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int BitwiseInclusiveOR(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +127,7 @@ namespace SqlSugar
|
||||
copyContext.RefreshMapping = this.RefreshMapping;
|
||||
copyContext.ParameterIndex = this.ParameterIndex;
|
||||
copyContext.PgSqlIsAutoToLower = this.PgSqlIsAutoToLower;
|
||||
copyContext.IsSingle = this.IsSingle;
|
||||
return copyContext;
|
||||
}
|
||||
public ExpressionContext GetCopyContextWithMapping()
|
||||
@ -141,6 +142,7 @@ namespace SqlSugar
|
||||
copyContext.InitMappingInfo = this.InitMappingInfo;
|
||||
copyContext.RefreshMapping = this.RefreshMapping;
|
||||
copyContext.PgSqlIsAutoToLower = this.PgSqlIsAutoToLower;
|
||||
copyContext.IsSingle = this.IsSingle;
|
||||
return copyContext;
|
||||
}
|
||||
#endregion
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@ -61,7 +60,7 @@ namespace SqlSugar
|
||||
if (customAttribute?.IsJson ?? false)
|
||||
{
|
||||
var paramterValue = ExpressionTool.DynamicInvoke(item);
|
||||
var parameterName = AppendParameter(JsonConvert.SerializeObject(paramterValue));
|
||||
var parameterName = AppendParameter(new SerializeService().SerializeObject(paramterValue));
|
||||
this.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
|
||||
|
||||
continue;
|
||||
|
@ -664,6 +664,10 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.GetRandom();
|
||||
case "CharIndex":
|
||||
return this.Context.DbMehtods.CharIndex(model);
|
||||
case "BitwiseAnd":
|
||||
return this.Context.DbMehtods.BitwiseAnd(model);
|
||||
case "BitwiseInclusiveOR":
|
||||
return this.Context.DbMehtods.BitwiseInclusiveOR(model);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -278,14 +278,13 @@ namespace SqlSugar
|
||||
var typeName = tType.Name;
|
||||
if (item.PropertyType.IsClass())
|
||||
{
|
||||
if (readerValues != null &&
|
||||
readerValues.Count == 1 &&
|
||||
readerValues.First().Key == name &&
|
||||
readerValues.First().Value!=null&&
|
||||
readerValues.First().Value.GetType()==UtilConstants.StringType&&
|
||||
Regex.IsMatch(readerValues.First().Value.ObjToString(), @"^\{.+\}$"))
|
||||
if (IsJsonItem(readerValues, name))
|
||||
{
|
||||
result.Add(name, DeserializeObject<Dictionary<string,object>>(readerValues.First().Value.ObjToString()));
|
||||
result.Add(name, DeserializeObject<Dictionary<string, object>>(readerValues.First().Value.ObjToString()));
|
||||
}
|
||||
else if (IsJsonList(readerValues, item))
|
||||
{
|
||||
result.Add(name, DeserializeObject<List<Dictionary<string, object>>>(readerValues[item.Name.ToLower()].ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -336,6 +335,25 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool IsJsonItem(Dictionary<string, object> readerValues, string name)
|
||||
{
|
||||
return readerValues != null &&
|
||||
readerValues.Count == 1 &&
|
||||
readerValues.First().Key == name &&
|
||||
readerValues.First().Value != null &&
|
||||
readerValues.First().Value.GetType() == UtilConstants.StringType &&
|
||||
Regex.IsMatch(readerValues.First().Value.ObjToString(), @"^\{.+\}$");
|
||||
}
|
||||
|
||||
private static bool IsJsonList(Dictionary<string, object> readerValues, PropertyInfo item)
|
||||
{
|
||||
return item.PropertyType.FullName.IsCollectionsList() &&
|
||||
readerValues.ContainsKey(item.Name.ToLower()) &&
|
||||
readerValues[item.Name.ToLower()] != null &&
|
||||
readerValues[item.Name.ToLower()].GetType() == UtilConstants.StringType &&
|
||||
Regex.IsMatch(readerValues[item.Name.ToLower()].ToString(), @"^\[{.+\}]$");
|
||||
}
|
||||
|
||||
private Dictionary<string, object> DataReaderToDynamicList_Part<T>(Dictionary<string, object> readerValues, PropertyInfo item, List<T> reval)
|
||||
{
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
|
@ -92,6 +92,7 @@ namespace SqlSugar
|
||||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@double),
|
||||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@long),
|
||||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@bool),
|
||||
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
|
||||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@decimal),
|
||||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.Single),
|
||||
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
|
||||
|
@ -348,11 +348,11 @@ namespace SqlSugar
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
else
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
() =>
|
||||
{
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||
@ -360,7 +360,7 @@ namespace SqlSugar
|
||||
string sql = "select * from " + SqlBuilder.GetTranslationTableName(tableName) + " WHERE 1=2 ";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
using (DbDataReader reader = (DbDataReader)this.Context.Ado.GetDataReader(sql))
|
||||
using(DbDataReader reader = (DbDataReader) this.Context.Ado.GetDataReader(sql))
|
||||
{
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||
@ -371,8 +371,8 @@ namespace SqlSugar
|
||||
{
|
||||
TableName = tableName,
|
||||
DataType = row["DataType"].ToString().Replace("System.", "").Trim(),
|
||||
IsNullable = (bool)row["AllowDBNull"],
|
||||
IsIdentity = (bool)row["IsIdentity"],
|
||||
IsNullable = (bool) row["AllowDBNull"],
|
||||
IsIdentity = (bool) row["IsIdentity"],
|
||||
ColumnDescription = GetFieldComment(tableName, row["ColumnName"].ToString()),
|
||||
DbColumnName = row["ColumnName"].ToString(),
|
||||
//DefaultValue = row["defaultValue"].ToString(),
|
||||
@ -391,32 +391,32 @@ namespace SqlSugar
|
||||
string cacheKey = "DbMaintenanceProvider.GetPrimaryKeyByTableNames." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
string sql = @" select distinct cu.COLUMN_name KEYNAME from user_cons_columns cu, user_constraints au
|
||||
() =>
|
||||
{
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
string sql = @" select distinct cu.COLUMN_name KEYNAME from user_cons_columns cu, user_constraints au
|
||||
where cu.constraint_name = au.constraint_name
|
||||
and au.constraint_type = 'P' and au.table_name = '" + tableName.ToUpper() + @"'";
|
||||
var pks = this.Context.Ado.SqlQuery<string>(sql);
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
return pks;
|
||||
});
|
||||
var pks = this.Context.Ado.SqlQuery<string>(sql);
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
return pks;
|
||||
});
|
||||
}
|
||||
|
||||
public string GetTableComment(string tableName)
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetTableComment." + tableName;
|
||||
var comments = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
string sql = "SELECT COMMENTS FROM USER_TAB_COMMENTS WHERE TABLE_NAME =@tableName ORDER BY TABLE_NAME";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
var pks = this.Context.Ado.SqlQuery<string>(sql, new { tableName = tableName.ToUpper() });
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
return pks;
|
||||
});
|
||||
() =>
|
||||
{
|
||||
string sql = "SELECT COMMENTS FROM USER_TAB_COMMENTS WHERE TABLE_NAME =@tableName ORDER BY TABLE_NAME";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
var pks = this.Context.Ado.SqlQuery<string>(sql, new { tableName = tableName.ToUpper() });
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
return pks;
|
||||
});
|
||||
return comments.HasValue() ? comments.First() : "";
|
||||
}
|
||||
|
||||
@ -424,15 +424,15 @@ namespace SqlSugar
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetFieldComment." + tableName;
|
||||
var comments = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
string sql = "SELECT TVNAME AS TableName, COLNAME,COMMENT$ AS ColumnDescription from SYSCOLUMNCOMMENTS WHERE TVNAME='"+ tableName.ToUpper() + "' ORDER BY TVNAME";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
var pks = this.Context.Ado.SqlQuery<DbColumnInfo>(sql);
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
return pks;
|
||||
});
|
||||
() =>
|
||||
{
|
||||
string sql = "SELECT TVNAME AS TableName, COLNAME,COMMENT$ AS ColumnDescription from SYSCOLUMNCOMMENTS WHERE TVNAME='" + tableName.ToUpper() + "' ORDER BY TVNAME";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
var pks = this.Context.Ado.SqlQuery<DbColumnInfo>(sql);
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
return pks;
|
||||
});
|
||||
return comments.HasValue() ? comments.First(it => it.DbColumnName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription : "";
|
||||
|
||||
}
|
||||
@ -462,4 +462,4 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
@ -117,6 +117,11 @@ namespace SqlSugar
|
||||
sqlParameter.Size = parameter.Size;
|
||||
sqlParameter.Value = parameter.Value;
|
||||
sqlParameter.DbType = parameter.DbType;
|
||||
if (sqlParameter.DbType == System.Data.DbType.Guid)
|
||||
{
|
||||
sqlParameter.DbType = System.Data.DbType.String;
|
||||
sqlParameter.Value = sqlParameter.Value.ToString();
|
||||
}
|
||||
if (parameter.Direction == 0)
|
||||
{
|
||||
parameter.Direction = ParameterDirection.Input;
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -22,6 +23,8 @@ namespace SqlSugar
|
||||
}
|
||||
public override int ExecuteReturnIdentity()
|
||||
{
|
||||
bool oldIsAuto = AutoBegin();
|
||||
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
@ -31,11 +34,15 @@ namespace SqlSugar
|
||||
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
|
||||
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
|
||||
|
||||
AutoEnd(oldIsAuto);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override long ExecuteReturnBigIdentity()
|
||||
{
|
||||
bool oldIsAuto = AutoBegin();
|
||||
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
@ -43,22 +50,72 @@ namespace SqlSugar
|
||||
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
|
||||
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
|
||||
var count = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 :Convert.ToInt64(GetSeqValue(GetSeqName()));
|
||||
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : Convert.ToInt64(GetSeqValue(GetSeqName()));
|
||||
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
|
||||
|
||||
AutoEnd(oldIsAuto);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async override Task<int> ExecuteReturnIdentityAsync()
|
||||
{
|
||||
bool oldIsAuto = AutoBegin();
|
||||
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
|
||||
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
|
||||
var count = await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : GetSeqValue(GetSeqName()).ObjToInt();
|
||||
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
|
||||
|
||||
AutoEnd(oldIsAuto);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async override Task<long> ExecuteReturnBigIdentityAsync()
|
||||
{
|
||||
bool oldIsAuto = AutoBegin();
|
||||
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
var isDisableMasterSlaveSeparation = this.Context.Ado.IsDisableMasterSlaveSeparation;
|
||||
this.Context.Ado.IsDisableMasterSlaveSeparation = true;
|
||||
var count = await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
var result = (this.GetIdentityKeys().IsNullOrEmpty() || count == 0) ? 0 : Convert.ToInt64(GetSeqValue(GetSeqName()));
|
||||
this.Context.Ado.IsDisableMasterSlaveSeparation = isDisableMasterSlaveSeparation;
|
||||
|
||||
AutoEnd(oldIsAuto);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void AutoEnd(bool oldIsAuto)
|
||||
{
|
||||
if (oldIsAuto)
|
||||
{
|
||||
this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection = oldIsAuto;
|
||||
if (this.Ado.Transaction == null)
|
||||
this.Context.Ado.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private bool AutoBegin()
|
||||
{
|
||||
var oldIsAuto = this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection;
|
||||
if (this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection)
|
||||
{
|
||||
this.Context.Context.CurrentConnectionConfig.IsAutoCloseConnection = false;
|
||||
}
|
||||
|
||||
return oldIsAuto;
|
||||
}
|
||||
private object GetSeqValue(string seqName)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ado.GetScalar(" SELECT " + seqName + ".currval FROM DUAL");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Ado.GetScalar(" SELECT " + seqName + ".nextval FROM DUAL");
|
||||
return Ado.GetScalar(" SELECT " + seqName + ".currval-1 FROM DUAL");
|
||||
}
|
||||
return Ado.GetScalar(" SELECT " + seqName + ".currval FROM DUAL");
|
||||
}
|
||||
protected override void PreToSql()
|
||||
{
|
||||
@ -73,15 +130,15 @@ namespace SqlSugar
|
||||
int seqBeginValue = 0;
|
||||
seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual");
|
||||
//Console.WriteLine(seqBeginValue);
|
||||
var nextLength= insertCount - 1;
|
||||
var nextLength = insertCount - 1;
|
||||
if (nextLength > 0)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine(" select "+ seqName + ".nextval,t.* from (");
|
||||
sb.AppendLine(" select " + seqName + ".nextval,t.* from (");
|
||||
for (int i = 0; i < nextLength; i++)
|
||||
{
|
||||
sb.AppendLine(" select 1 from dual");
|
||||
if (i<(nextLength - 1) )
|
||||
if (i < (nextLength - 1))
|
||||
{
|
||||
sb.AppendLine("union all");
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
@ -14,7 +15,7 @@ namespace SqlSugar
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public OracleExpressionContext()
|
||||
{
|
||||
base.DbMehtods = new OracleMethod();
|
||||
base.DbMehtods = new OracleMethod();
|
||||
}
|
||||
public override string SqlParameterKeyWord
|
||||
{
|
||||
@ -40,6 +41,42 @@ namespace SqlSugar
|
||||
}
|
||||
public partial class OracleMethod : DefaultDbMethod, IDbMethods
|
||||
{
|
||||
private void PageEach<T>(IEnumerable<T> pageItems, int pageSize, Action<List<T>> action)
|
||||
{
|
||||
if (pageItems != null && pageItems.Any())
|
||||
{
|
||||
int totalRecord = pageItems.Count();
|
||||
int pageCount = (totalRecord + pageSize - 1) / pageSize;
|
||||
for (int i = 1; i <= pageCount; i++)
|
||||
{
|
||||
var list = pageItems.Skip((i - 1) * pageSize).Take(pageSize).ToList();
|
||||
action(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override string ContainsArray(MethodCallExpressionModel model)
|
||||
{
|
||||
if (model.Args[0].MemberValue == null)
|
||||
{
|
||||
return base.ContainsArray(model);
|
||||
}
|
||||
var inValueIEnumerable = ((IEnumerable)model.Args[0].MemberValue).Cast<object>().ToArray();
|
||||
if (inValueIEnumerable.Count() < 1000)
|
||||
{
|
||||
return base.ContainsArray(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
string result = "";
|
||||
PageEach(inValueIEnumerable, 999, it =>
|
||||
{
|
||||
model.Args.First().MemberValue = it;
|
||||
result+= (base.ContainsArray(model) + " OR ");
|
||||
|
||||
});
|
||||
return " ( "+result.TrimEnd(' ').TrimEnd('R').TrimEnd('O')+" ) ";
|
||||
}
|
||||
}
|
||||
public override string ToInt64(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
@ -128,6 +165,12 @@ namespace SqlSugar
|
||||
return string.Format(" CAST({0} AS VARCHAR2(4000))", parameter.MemberName);
|
||||
}
|
||||
|
||||
public override string ToDecimal(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format(" CAST({0} AS Number)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public override string ToDate(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
|
@ -51,8 +51,8 @@ namespace SqlSugar
|
||||
WHERE syscolumns.id IN
|
||||
(SELECT id
|
||||
FROM sysobjects
|
||||
WHERE xtype IN('u',
|
||||
'v') )
|
||||
WHERE upper(xtype) IN('U',
|
||||
'V') )
|
||||
AND (systypes.name <> 'sysname')
|
||||
AND sysobjects.name='{0}'
|
||||
AND systypes.name<>'geometry'
|
||||
|
@ -118,7 +118,7 @@ namespace SqlSugar
|
||||
var parameter3 = model.Args[2].MemberValue;
|
||||
if (parameter2.ObjToInt() < 0)
|
||||
{
|
||||
return string.Format(" DATETIME(DATETIME({0}), '+{1} {2}s')", parameter, Math.Abs(parameter2.ObjToInt()), parameter3);
|
||||
return string.Format(" DATETIME(DATETIME({0}), '-{1} {2}s')", parameter, Math.Abs(parameter2.ObjToInt()), parameter3);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -165,7 +165,7 @@ namespace SqlSugar
|
||||
var parameter = model.Args[0].MemberName;
|
||||
var parameter2 = model.Args[1].MemberName;
|
||||
int time = 1;
|
||||
return string.Format(" Cast((JulianDay({0}) - JulianDay({1})) *{2} As INTEGER)=0 ", parameter, parameter2, time);
|
||||
return string.Format(" date({0}, 'localtime', 'start of day')= date({1}, 'localtime', 'start of day') ", parameter, parameter2, time);
|
||||
}
|
||||
public override string DateIsSameByType(MethodCallExpressionModel model)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user