Files
SqlSugar/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/SugarParameter.cs

269 lines
7.7 KiB
C#
Raw Normal View History

using System;
2017-01-08 00:16:37 +08:00
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class SugarParameter : DbParameter
{
2018-01-16 14:27:00 +08:00
public bool IsRefCursor { get; set; }
2021-11-08 16:11:45 +08:00
public bool IsClob { get; set; }
2022-08-31 14:56:05 +08:00
public bool IsNvarchar2 { get; set; }
2017-01-08 00:16:37 +08:00
public SugarParameter(string name, object value)
{
this.Value = value;
this.ParameterName = name;
2017-06-16 16:08:32 +08:00
if (value != null)
{
2017-06-16 15:19:11 +08:00
SettingDataType(value.GetType());
}
2017-01-08 00:16:37 +08:00
}
2017-06-01 14:26:49 +08:00
public SugarParameter(string name, object value, Type type)
2017-05-28 11:10:11 +08:00
{
this.Value = value;
this.ParameterName = name;
2017-06-16 15:19:11 +08:00
SettingDataType(type);
}
2018-12-18 17:02:10 +08:00
public SugarParameter(string name, object value, Type type, ParameterDirection direction)
2018-01-29 18:23:57 +08:00
{
this.Value = value;
this.ParameterName = name;
this.Direction = direction;
SettingDataType(type);
}
2018-12-18 17:02:10 +08:00
public SugarParameter(string name, object value, Type type, ParameterDirection direction, int size)
2018-01-29 18:23:57 +08:00
{
this.Value = value;
this.ParameterName = name;
this.Direction = direction;
this.Size = size;
SettingDataType(type);
}
2017-06-16 15:19:11 +08:00
2019-04-28 13:59:07 +08:00
public SugarParameter(string name, object value, System.Data.DbType type)
{
this.Value = value;
this.ParameterName = name;
this.DbType = type;
}
2019-04-28 18:06:16 +08:00
public SugarParameter(string name, DataTable value, string SqlServerTypeName)
2019-04-28 13:59:07 +08:00
{
this.Value = value;
this.ParameterName = name;
this.TypeName = SqlServerTypeName;
}
public SugarParameter(string name, object value, System.Data.DbType type, ParameterDirection direction)
{
this.Value = value;
this.ParameterName = name;
this.Direction = direction;
this.DbType = type;
}
public SugarParameter(string name, object value, System.Data.DbType type, ParameterDirection direction, int size)
{
this.Value = value;
this.ParameterName = name;
this.Direction = direction;
this.Size = size;
this.DbType = type;
}
2017-06-16 15:19:11 +08:00
private void SettingDataType(Type type)
{
2017-08-25 22:22:12 +08:00
if (type == UtilConstants.ByteArrayType)
2017-06-01 14:26:49 +08:00
{
this.DbType = System.Data.DbType.Binary;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.GuidType)
2017-06-01 14:26:49 +08:00
{
this.DbType = System.Data.DbType.Guid;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.IntType)
2017-06-01 14:26:49 +08:00
{
this.DbType = System.Data.DbType.Int32;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.ShortType)
2017-06-16 16:08:32 +08:00
{
this.DbType = System.Data.DbType.Int16;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.LongType)
2017-06-16 16:08:32 +08:00
{
this.DbType = System.Data.DbType.Int64;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.DateType)
2017-06-01 14:26:49 +08:00
{
2017-07-03 00:12:48 +08:00
this.DbType = System.Data.DbType.DateTime;
2017-06-01 14:26:49 +08:00
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.DobType)
2017-06-16 16:08:32 +08:00
{
this.DbType = System.Data.DbType.Double;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.DecType)
2017-06-20 13:11:22 +08:00
{
this.DbType = System.Data.DbType.Decimal;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.ByteType)
2017-06-20 13:11:22 +08:00
{
this.DbType = System.Data.DbType.Byte;
}
2022-10-28 15:12:10 +08:00
else if (type == UtilConstants.SByteType)
{
this.DbType = System.Data.DbType.SByte;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.FloatType)
2017-06-20 13:11:22 +08:00
{
this.DbType = System.Data.DbType.Single;
}
2017-08-25 22:22:12 +08:00
else if (type == UtilConstants.BoolType)
2017-07-06 15:30:44 +08:00
{
this.DbType = System.Data.DbType.Boolean;
}
2017-09-02 11:54:56 +08:00
else if (type == UtilConstants.StringType)
{
this.DbType = System.Data.DbType.String;
}
2018-11-11 20:21:08 +08:00
else if (type == UtilConstants.DateTimeOffsetType)
{
this.DbType = System.Data.DbType.DateTimeOffset;
}
2018-12-18 17:02:10 +08:00
else if (type == UtilConstants.TimeSpanType)
{
2021-09-04 18:30:15 +08:00
this.DbType = System.Data.DbType.Time;
2018-12-18 17:02:10 +08:00
}
2021-11-11 21:05:04 +08:00
else if (type?.Name=="Geometry")
{
this.DbType = System.Data.DbType.Object;
}
2020-12-29 21:32:18 +08:00
else if (type!=null&&type.IsEnum())
2019-04-28 18:06:16 +08:00
{
this.DbType = System.Data.DbType.Int64;
2022-06-14 18:58:01 +08:00
if (Value != null)
{
this.Value = Convert.ToInt64(Value);
}
2019-04-28 18:06:16 +08:00
}
2022-05-31 11:55:15 +08:00
else if (type==UtilConstants.UIntType)
{
this.DbType = System.Data.DbType.UInt32;
}
else if (type == UtilConstants.ULongType)
{
this.DbType = System.Data.DbType.UInt64;
}
2022-11-24 14:22:58 +08:00
else if (type == UtilConstants.UShortType)
{
this.DbType = System.Data.DbType.UInt16;
}
2022-05-31 11:55:15 +08:00
else if (type == UtilConstants.ShortType)
{
this.DbType = System.Data.DbType.UInt16;
}
2017-09-02 11:54:56 +08:00
2017-06-01 14:26:49 +08:00
}
public SugarParameter(string name, object value, bool isOutput)
{
this.Value = value;
this.ParameterName = name;
if (isOutput)
{
2017-05-28 11:10:11 +08:00
this.Direction = ParameterDirection.Output;
}
}
2017-01-08 00:16:37 +08:00
public override System.Data.DbType DbType
{
2017-01-08 00:39:16 +08:00
get; set;
2017-01-08 00:16:37 +08:00
}
public override ParameterDirection Direction
{
2017-01-08 00:39:16 +08:00
get; set;
2017-01-08 00:16:37 +08:00
}
public override bool IsNullable
{
2017-01-08 00:39:16 +08:00
get; set;
2017-01-08 00:16:37 +08:00
}
public override string ParameterName
{
2017-01-08 00:39:16 +08:00
get; set;
2017-01-08 00:16:37 +08:00
}
2017-06-06 17:13:22 +08:00
public int _Size;
2017-01-08 00:16:37 +08:00
public override int Size
{
2017-06-06 17:13:22 +08:00
get
{
if (_Size == 0 && Value != null)
{
2017-08-25 22:22:12 +08:00
var isByteArray = Value.GetType() == UtilConstants.ByteArrayType;
2017-06-08 12:51:56 +08:00
if (isByteArray)
_Size = -1;
2017-06-06 17:13:22 +08:00
else
{
2017-06-08 12:51:56 +08:00
var length = Value.ToString().Length;
_Size = length < 4000 ? 4000 : -1;
2017-06-06 17:13:22 +08:00
}
}
if (_Size == 0)
_Size = 4000;
return _Size;
}
set
{
_Size = value;
}
2017-01-08 00:16:37 +08:00
}
public override string SourceColumn
{
2017-01-08 00:39:16 +08:00
get; set;
2017-01-08 00:16:37 +08:00
}
public override bool SourceColumnNullMapping
{
2017-01-08 00:39:16 +08:00
get; set;
2017-01-08 00:16:37 +08:00
}
2017-01-08 00:39:16 +08:00
public string UdtTypeName
{
get;
set;
}
2017-01-08 00:16:37 +08:00
public override object Value
{
2017-01-08 00:39:16 +08:00
get; set;
2017-01-08 00:16:37 +08:00
}
2017-01-14 20:53:04 +08:00
public Dictionary<string, object> TempDate
{
get; set;
}
2017-06-21 17:54:53 +08:00
/// <summary>
/// 如果类库是.NET 4.5请删除该属性
/// If the SqlSugar library is.NET 4.5, delete the property
/// </summary>
2017-05-22 10:17:30 +08:00
public override DataRowVersion SourceVersion
{
2017-06-01 14:26:49 +08:00
get; set;
2017-05-22 10:17:30 +08:00
}
2017-01-08 00:16:37 +08:00
public override void ResetDbType()
{
this.DbType = System.Data.DbType.String;
}
2019-04-28 13:59:07 +08:00
public string TypeName { get; set; }
2020-10-02 13:54:49 +08:00
public bool IsJson { get; set; }
2020-10-13 17:44:25 +08:00
public bool IsArray { get; set; }
2017-01-08 00:16:37 +08:00
}
}