/// <summary> /// 生成一个Parameter对象 /// </summary> /// <param name="parameter"></param> /// <param name="parameterName"></param> /// <param name="dbType"></param> /// <param name="size"></param> /// <param name="direction"></param> /// <param name="nullable"></param> /// <param name="sourceColumn"></param> /// <remarks> /// 面向批量处理增加的方法 /// added by wangxiang . May 21, 2008 /// </remarks> protected override void ConfigureParameter(DbParameter parameter, string parameterName, DbType dbType, int size, ParameterDirection direction, bool nullable, string sourceColumn) { SqlParameter param = parameter as SqlParameter; param.ParameterName = parameterName; if (dbType.Equals(DbType.Object)) { param.SqlDbType = SqlDbType.Image; } else { param.DbType = dbType; } param.Size = size; param.Direction = direction; param.IsNullable = nullable; param.SourceColumn = sourceColumn; }
/// <devdoc> /// Create a parameter. /// </devdoc> private SqlParameter CreateParameter(string name, DbType type, int size, ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value) { SqlParameter param = this.command.CreateParameter(); param.ParameterName = BuildParameterName(name); if ((type.Equals(DbType.Object)) && (value is byte[])) { param.SqlDbType = SqlDbType.Image; } else { param.DbType = type; } param.Size = size; param.Direction = direction; param.IsNullable = nullable; param.Precision = precision; param.Scale = scale; param.SourceColumn = sourceColumn; param.SourceVersion = sourceVersion; param.Value = (value == null) ? DBNull.Value : value; return(param); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (this == obj) { return(true); } ColumnAttribute other = obj as ColumnAttribute; if (other == null) { return(false); } bool lEquals = true; lEquals &= NullHelper.Equals(name, other.name); lEquals &= dbType.Equals(other.dbType); lEquals &= Nullable.Equals(other.nullable); lEquals &= NullHelper.Equals(selectCast, other.selectCast); lEquals &= NullHelper.Equals(updateCast, other.updateCast); return(lEquals); }
/// <summary> /// 生成一个Parameter对象,同时为期赋值 /// </summary> protected override void ConfigureParameter(DbParameter parameter, string parameterName, DbType dbType, int size, ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value) { SqlParameter param = parameter as SqlParameter; param.ParameterName = parameterName; if ((dbType.Equals(DbType.Object)) && (value is byte[])) { param.SqlDbType = SqlDbType.Image; } else { param.DbType = dbType; } param.Size = size; param.Direction = direction; param.IsNullable = nullable; param.Precision = precision; param.Scale = scale; param.SourceColumn = sourceColumn; param.SourceVersion = sourceVersion; param.Value = (value == null) ? DBNull.Value : value; }
protected override bool Execute() {//* ActiveObject = GetName(); if (column == null) { column = AddColumn(table); } SetAttributeValue(column, "Name", ColumnName); if (ColumnName.IndexOfAny(new[] { '#', '*', '.' }) > -1) { SetAttributeValue(column, "Member", ColumnName.Replace("#", "_").Replace(".", "_").Replace("*", "_")); } else { SetAttributeValue(column, "Member", null); } if (!string.IsNullOrEmpty(DataType)) { SetAttributeValue(column, "Type", DataType); if (DataType == "timestamp") { SetAttributeValue(column, "IsVersion", "true"); } else { SetAttributeValue(column, "IsVersion", null); } if (DbType.Equals("varbinary(max)", StringComparison.OrdinalIgnoreCase)) { SetAttributeValue(column, "IsDelayLoaded", "true"); SetAttributeValue(column, "UpdateCheck", "Never"); } if (DbType.Equals("xml", StringComparison.OrdinalIgnoreCase)) { SetAttributeValue(column, "UpdateCheck", "Never"); } } if (!string.IsNullOrEmpty(DbType)) { SetAttributeValue(column, "DbType", DbType); } SetAttributeValue(column, "CanBeNull", (!Mandatory).ToString().ToLower()); if (ComputeInDataBase) { SetAttributeValue(column, "IsDbGenerated", "true"); } else { SetAttributeValue(column, "IsDbGenerated", null); } // SetAttributeValue(column, "IsPrimaryKey", IsPrimaryKey.ToString());*/ return(true); }
public override string typeOfDbType(DbType dbType) { foreach (string typeName in DataTypeDict.Keys) { DataTypeMap dtm = DataTypeDict[typeName]; if (dbType.Equals(dtm.DbType)) { return(typeName); } } throw new Exception(string.Format(Lang.DatabaseNotSuportsDataType, dbType.ToString())); }
public static IDbDataParameter AddParameter(this IDbCommand command, object value, DbType type, string name, bool isUotput = false) { IDbDataParameter parameter = command.CreateParameter(); parameter.Value = value ?? DBNull.Value; parameter.DbType = type; parameter.ParameterName = name; if (isUotput) { parameter.Direction = ParameterDirection.Output; if (type.Equals(DbType.String)) { parameter.Size = 350; } if (type.Equals(DbType.Xml)) { parameter.Size = int.MaxValue; } } command.Parameters.Add(parameter); return(parameter); }
public bool Equals(SqlType rhsSqlType) { if (rhsSqlType == null) { return(false); } if (LengthDefined) { return((DbType.Equals(rhsSqlType.DbType)) && (Length == rhsSqlType.Length)); } if (PrecisionDefined) { return((DbType.Equals(rhsSqlType.DbType)) && (Precision == rhsSqlType.Precision) && (Scale == rhsSqlType.Scale)); } return(DbType.Equals(rhsSqlType.DbType)); }
/// <summary> /// 将SqlDbType类型转换为Net /// </summary> /// <param name="theType">待转换类型</param> /// <returns></returns> public static Type GetNetType(DbType theType) { if (theType.Equals(DbType.Binary)) { return(typeof(byte[])); } switch (theType) { case DbType.Boolean: return(typeof(bool)); case DbType.Byte: return(typeof(byte)); case DbType.DateTime: return(typeof(DateTime)); case DbType.DateTime2: return(typeof(DateTime)); case DbType.DateTimeOffset: return(typeof(DateTime)); case DbType.Decimal: return(typeof(decimal)); case DbType.Double: return(typeof(double)); case DbType.Int32: return(typeof(int)); case DbType.Int64: return(typeof(long)); case DbType.Single: return(typeof(float)); case DbType.String: return(typeof(string)); default: return(typeof(string)); } }
private static List <DataListColumn> getColumns(List <FieldDef> fields) { List <DataListColumn> ret = new List <DataListColumn>(); foreach (FieldDef col in fields) { DbType type = DatabaseAdmin.getInstance().getDbType(col.Type); if (type.Equals(DbType.Binary)) { continue; } DataListColumn listCol = new DataListColumn(); string fldName = col.Name; listCol.field = fldName; listCol.title = col.Title; listCol.resizable = true; listCol.hidden = false; listCol.editor = "text"; ret.Add(listCol); } return(ret); }
void Upgrade(Metadata <T> masters) { if (!Key.Equals(masters.Key)) { throw new InvalidOperationException("Incompatible table storage"); } var local = new HashSet <MemberMap <T> >(_members.Values); var all = new List <MemberMap <T> >(local); // transfer ids from master members foreach (var master in masters._members.Values) { var m = master; var existing = local.FirstOrDefault(i => i.Name == m.Name && i.DbType.Equals(m.DbType)); if (existing != null) { existing.Id = master.Id; local.Remove(existing); } else { all.Add(master); } } // assign free ids to rest new members var id = masters._members.Values.Max(i => i.Id); foreach (var i in local) { i.Id = ++id; } // rebuild dictionary _members = all.ToDictionary(i => i.Id); Prepare(); }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { bool equals = false; SqlType rhsSqlType; // Step1: Perform an equals test if (obj == this) { return(true); } // Step 2: Instance of check rhsSqlType = obj as SqlType; if (rhsSqlType == null) { return(false); } //Step 3: Check each important field if (LengthDefined) { equals = (DbType.Equals(rhsSqlType.DbType)) && (Length == rhsSqlType.Length); } else if (PrecisionDefined) { equals = (DbType.Equals(rhsSqlType.DbType)) && (Precision == rhsSqlType.Precision) && (Scale == rhsSqlType.Scale); } else { equals = (DbType.Equals(rhsSqlType.DbType)); } return(equals); }
public override void AdjustParameter(DbParameter param) { OdbcParameter odbcParam = (OdbcParameter)param; object value = param.Value; DbType type = param.DbType; if (value == null || value == DBNull.Value) { odbcParam.Value = DBNull.Value; if (odbcParam.DbType != DbType.Binary && odbcParam.DbType != DbType.Int32) { odbcParam.OdbcType = OdbcType.NVarChar; } return; } if (value.GetType().IsEnum) { odbcParam.OdbcType = OdbcType.Int; return; } if (value.GetType() == typeof(byte[])) { odbcParam.OdbcType = OdbcType.VarBinary; return; } if (value.GetType() == typeof(Guid)) { odbcParam.OdbcType = OdbcType.VarChar; odbcParam.Value = value.ToString(); return; } if (value.GetType() == typeof(Byte) || value.GetType() == typeof(SByte) || value.GetType() == typeof(Int16) || value.GetType() == typeof(Int32) || value.GetType() == typeof(Int64) || value.GetType() == typeof(UInt16) || value.GetType() == typeof(UInt32) || value.GetType() == typeof(UInt64)) { odbcParam.OdbcType = OdbcType.BigInt; return; } if (value.GetType() == typeof(Single) || value.GetType() == typeof(Double)) { odbcParam.OdbcType = OdbcType.Double; return; } if (value.GetType() == typeof(Boolean)) { odbcParam.OdbcType = OdbcType.Bit; odbcParam.Value = (((bool)value) ? 1 : 0); return; } if (value.GetType() == typeof(Char)) { odbcParam.OdbcType = OdbcType.NVarChar; return; } if (value.GetType() == typeof(Decimal)) { odbcParam.OdbcType = OdbcType.Decimal; return; } //datetime is special here if (value.GetType() == typeof(DateTime) || type.Equals(DbType.DateTime) || type.Equals(DbType.Date) || type.Equals(DbType.Time)) { odbcParam.OdbcType = OdbcType.NText; odbcParam.Value = value.ToString(); return; } if (value.GetType() == typeof(string)) { odbcParam.OdbcType = OdbcType.NVarChar; if (value.ToString().Length > 2000) { odbcParam.OdbcType = OdbcType.NText; } return; } //by default, threat as string odbcParam.OdbcType = OdbcType.NText; odbcParam.Value = Rock.Orm.Common.SerializationManager.Serialize(value); }
/// <summary> /// Adjust Db Parameter value /// </summary> /// <param name="param"></param> public override void AdjustParameter(DbParameter param) { OleDbParameter oleDbParam = (OleDbParameter)param; object value = param.Value; DbType type = param.DbType; if (value == null || value == DBNull.Value) { oleDbParam.Value = DBNull.Value; if (oleDbParam.DbType != DbType.Binary && oleDbParam.DbType != DbType.Int32) { oleDbParam.OleDbType = OleDbType.VarWChar; } return; } if (value.GetType().IsEnum) { oleDbParam.OleDbType = OleDbType.Integer; return; } if (value.GetType() == typeof(byte[])) { oleDbParam.OleDbType = OleDbType.LongVarBinary; return; } if (value.GetType() == typeof(Guid)) { oleDbParam.OleDbType = OleDbType.VarChar; oleDbParam.Value = value.ToString(); return; } if (value.GetType() == typeof(Byte) || value.GetType() == typeof(SByte) || value.GetType() == typeof(Int16) || value.GetType() == typeof(Int32) || value.GetType() == typeof(Int64) || value.GetType() == typeof(UInt16) || value.GetType() == typeof(UInt32) || value.GetType() == typeof(UInt64)) { oleDbParam.OleDbType = OleDbType.Integer; return; } if (value.GetType() == typeof(Single) || value.GetType() == typeof(Double)) { oleDbParam.OleDbType = OleDbType.Double; return; } if (value.GetType() == typeof(Boolean)) { oleDbParam.OleDbType = OleDbType.Boolean; return; } if (value.GetType() == typeof(Char)) { oleDbParam.OleDbType = OleDbType.WChar; return; } if (value.GetType() == typeof(Decimal)) { oleDbParam.OleDbType = OleDbType.Decimal; return; } //datetime is special here if (value.GetType() == typeof(DateTime) || type.Equals(DbType.DateTime) || type.Equals(DbType.Date) || type.Equals(DbType.Time)) { oleDbParam.OleDbType = OleDbType.LongVarWChar; oleDbParam.Value = value.ToString(); return; } if (value.GetType() == typeof(string)) { oleDbParam.OleDbType = OleDbType.VarWChar; if (value.ToString().Length > 2000) { oleDbParam.OleDbType = OleDbType.LongVarWChar; } return; } //by default, threat as string oleDbParam.OleDbType = OleDbType.LongVarWChar; oleDbParam.Value = NBear.Common.SerializationManager.Serialize(value); }
/// <devdoc> /// Create a parameter. /// </devdoc> private SqlParameter CreateParameter(string name, DbType type, int size, ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value) { SqlParameter param = this.command.CreateParameter(); param.ParameterName = BuildParameterName(name); if ((type.Equals(DbType.Object)) && (value is byte[])) { param.SqlDbType = SqlDbType.Image; } else { param.DbType = type; } param.Size = size; param.Direction = direction; param.IsNullable = nullable; param.Precision = precision; param.Scale = scale; param.SourceColumn = sourceColumn; param.SourceVersion = sourceVersion; param.Value = (value == null) ? DBNull.Value : value; return param; }
///<inheritdoc/> public bool Equals(DataType other) { return(DbType.Equals(other.DbType, StringComparison.InvariantCultureIgnoreCase) && SystemType == other.SystemType); }
public static DbParameter buildParm(string parmName, object value, ParameterDirection parmDirection, DbType dbType, int size) { switch (DatabaseProvider) { case "MySql.Data.MySqlClient": MySqlParameter parm = new MySqlParameter(parmName, dbType.Equals(DbType.String)?MySql.Data.MySqlClient.MySqlDbType.String:( dbType.Equals(DbType.Object)?MySql.Data.MySqlClient.MySqlDbType.Text:( dbType.Equals(DbType.Int32)?MySqlDbType.Int32:( dbType.Equals(DbType.Double)?MySqlDbType.Double:( dbType.Equals(DbType.DateTime)?MySqlDbType.DateTime:( dbType.Equals(DbType.Boolean)?MySqlDbType.Bit:( dbType.Equals(DbType.UInt32)?MySqlDbType.UInt32:( dbType.Equals(DbType.Decimal)?MySqlDbType.Decimal:( MySqlDbType.String ))))))))); parm.Value = value; parm.Direction = parmDirection; return(parm); case "System.Data.SqlClient": SqlParameter parm2 = new SqlParameter(parmName, dbType.Equals(DbType.String) ? SqlDbType.VarChar : ( dbType.Equals(DbType.Object) ? SqlDbType.Text : ( dbType.Equals(DbType.Int32) ? SqlDbType.Int : ( dbType.Equals(DbType.Double) ? SqlDbType.BigInt : ( dbType.Equals(DbType.DateTime) ? SqlDbType.DateTime : ( dbType.Equals(DbType.Boolean) ? SqlDbType.Bit : ( dbType.Equals(DbType.UInt32) ? SqlDbType.Int : ( dbType.Equals(DbType.Decimal) ? SqlDbType.Decimal : ( SqlDbType.VarChar ))))))))); parm2.Value = value; parm2.Direction = parmDirection; if (size != CommonRoutines.NULL_INT) { parm2.Size = size; } return(parm2); default: throw new Exception("buildParm(..) not supported for this Database Provider: " + DatabaseProvider); } }
private bool Equals(SQLiteDbParameterValue other) { return (_dbType.Equals(other._dbType) && Equals(_value, other._value)); }
/// <summary> /// Adjust common Parameter db type to the specified MySql Parameter db type. /// </summary> public override void AdjustParameter(DbParameter param) { MySqlParameter mySqlParam = (MySqlParameter)param; object value = param.Value; DbType type = param.DbType; if (value == null || value == DBNull.Value) { mySqlParam.Value = DBNull.Value; if (mySqlParam.DbType != DbType.Binary && mySqlParam.DbType != DbType.Int32) { mySqlParam.MySqlDbType = MySqlDbType.VarChar; } return; } if (value.GetType().IsEnum) { mySqlParam.MySqlDbType = MySqlDbType.Enum; return; } if (value.GetType() == typeof(byte[])) { mySqlParam.MySqlDbType = MySqlDbType.VarBinary; return; } if (value.GetType() == typeof(Guid)) { mySqlParam.MySqlDbType = MySqlDbType.VarChar; mySqlParam.Value = value.ToString(); return; } if (value.GetType() == typeof(Byte) || value.GetType() == typeof(SByte) || value.GetType() == typeof(Int16) || value.GetType() == typeof(Int32) || value.GetType() == typeof(Int64) || value.GetType() == typeof(UInt16) || value.GetType() == typeof(UInt32) || value.GetType() == typeof(UInt64)) { mySqlParam.MySqlDbType = MySqlDbType.Int32; return; } if (value.GetType() == typeof(Single) || value.GetType() == typeof(Double)) { mySqlParam.MySqlDbType = MySqlDbType.Float; return; } if (value.GetType() == typeof(Boolean)) { mySqlParam.MySqlDbType = MySqlDbType.Bit; mySqlParam.Value = (((bool)value) ? 1 : 0); return; } if (value.GetType() == typeof(Char)) { mySqlParam.MySqlDbType = MySqlDbType.VarChar; return; } if (value.GetType() == typeof(Decimal)) { mySqlParam.MySqlDbType = MySqlDbType.Decimal; return; } //datetime is special here if (value.GetType() == typeof(DateTime) || type.Equals(DbType.DateTime) || type.Equals(DbType.Date) || type.Equals(DbType.Time)) { mySqlParam.MySqlDbType = MySqlDbType.Datetime; mySqlParam.Value = value; return; } if (value.GetType() == typeof(string)) { mySqlParam.MySqlDbType = MySqlDbType.VarChar; if (value.ToString().Length > 2000) { mySqlParam.MySqlDbType = MySqlDbType.Text; } return; } //by default, threat as string and then Serialize it a string. mySqlParam.MySqlDbType = MySqlDbType.Text; mySqlParam.Value = SerializationManager.Serialize(mySqlParam.Value); }