public DBCell(string name, DbDataType type, object value, bool isUpdatable = true) { Name = name; Type = type; Value = value; IsUpdatable = isUpdatable; }
public override object GetNewValueForType(DbDataType type) { object newValue; switch (type) { case DbDataType.Int: { newValue = -1; break; } case DbDataType.VarChar: { newValue = ""; break; } case DbDataType.DateTime: { newValue = new DateTime(1753, 1, 1); break; } case DbDataType.Date: { newValue = new DateTime(1753, 1, 1); break; } default: { throw new TypeAccessException(); } } return newValue; }
public override SqlDbType GetTypeAsDBType(DbDataType type) { SqlDbType dbType = SqlDbType.Variant; switch (type) { case DbDataType.Int: { dbType = SqlDbType.Int; break; } case DbDataType.VarChar: { dbType = SqlDbType.VarChar; break; } case DbDataType.DateTime: { dbType = SqlDbType.DateTime; break; } case DbDataType.Date: { dbType = SqlDbType.Date; break; } default: { throw new TypeAccessException(); } } return dbType; }
public static short GetSize(DbDataType dataType) { switch (dataType) { case DbDataType.Array: case DbDataType.Binary: case DbDataType.Text: return 8; case DbDataType.Boolean: case DbDataType.SmallInt: return 2; case DbDataType.Integer: case DbDataType.Float: case DbDataType.Date: case DbDataType.Time: return 4; case DbDataType.BigInt: case DbDataType.Double: case DbDataType.TimeStamp: return 8; case DbDataType.Guid: return 16; default: return 0; } }
public static DbType GetDbTypeFromDbDataType(DbDataType type) { switch (type) { case DbDataType.Array: case DbDataType.Binary: return(DbType.Binary); case DbDataType.Text: case DbDataType.VarChar: case DbDataType.Char: return(DbType.String); case DbDataType.SmallInt: return(DbType.Int16); case DbDataType.Integer: return(DbType.Int32); case DbDataType.BigInt: return(DbType.Int64); case DbDataType.Date: return(DbType.Date); case DbDataType.Time: return(DbType.Time); case DbDataType.TimeStamp: return(DbType.DateTime); case DbDataType.Numeric: case DbDataType.Decimal: return(DbType.Decimal); case DbDataType.Float: return(DbType.Single); case DbDataType.Double: return(DbType.Double); case DbDataType.Guid: return(DbType.Guid); case DbDataType.Boolean: return(DbType.Boolean); default: throw InvalidDataType((int)type); } }
public static Type GetTypeFromDbDataType(DbDataType type) { switch (type) { case DbDataType.Array: return(typeof(System.Array)); case DbDataType.Binary: return(typeof(System.Byte[])); case DbDataType.Text: case DbDataType.Char: case DbDataType.VarChar: return(typeof(System.String)); case DbDataType.Guid: return(typeof(System.Guid)); case DbDataType.SmallInt: return(typeof(System.Int16)); case DbDataType.Integer: return(typeof(System.Int32)); case DbDataType.BigInt: return(typeof(System.Int64)); case DbDataType.Float: return(typeof(System.Single)); case DbDataType.Double: return(typeof(System.Double)); case DbDataType.Numeric: case DbDataType.Decimal: return(typeof(System.Decimal)); case DbDataType.Date: case DbDataType.TimeStamp: return(typeof(System.DateTime)); case DbDataType.Time: return(typeof(System.TimeSpan)); case DbDataType.Boolean: return(typeof(System.Boolean)); default: throw InvalidDataType((int)type); } }
public override void SetParameter(IDbDataParameter parameter, string name, DbDataType dataType, object value) { switch (dataType.DataType) { case DataType.SByte: dataType = dataType.WithDataType(DataType.Int16); if (value is sbyte) { value = (short)(sbyte)value; } break; case DataType.Time: if (value is TimeSpan ts) { value = new DateTime(1900, 1, 1) + ts; } break; case DataType.Xml: dataType = dataType.WithDataType(DataType.NVarChar); if (value is XDocument) { value = value.ToString(); } else if (value is XmlDocument) { value = ((XmlDocument)value).InnerXml; } break; case DataType.Guid: if (value != null) { value = value.ToString(); } dataType = dataType.WithDataType(DataType.Char); parameter.Size = 36; break; case DataType.Undefined: if (value == null) { dataType = dataType.WithDataType(DataType.Char); } break; } base.SetParameter(parameter, "@" + name, dataType, value); }
private DataBaseInfo GetDbInfo(int ID) { IDbLink dal = new DbLink(); DbLinkInfo dlinfo = dal.DbLinkGetInfo(ID); IDataBase dbDal = new CurrencyDal.CodeMaker.DataBase(); string rstmsg = ""; List <string> tableNameList = new List <string>(); string tableName = ""; DbDataTypeEnum dtype = DbDataType.GetDbDataType(dinfo.NameType); if (dtype == DbDataTypeEnum.表) { tableName = dinfo.Name; tableNameList.Add(tableName); } DataBaseInfo dbinfo = dbDal.DataBaseGetInfo(dlinfo, tableNameList, out rstmsg); //DataBaseInfo2 info = new DataBaseInfo2(); //try //{ //switch (dlinfo.DbType) //{ // case 1: // System.Data.Common.DbConnection connSql = new System.Data.SqlClient.SqlConnection(); // connSql.ConnectionString = "Data Source=" + dlinfo.DataSource + ";Initial Catalog=" + dlinfo.DbName + ";User ID=" + dlinfo.UserName + ";Password="******"Data Source=" + dlinfo.DbName + ";User ID=" + dlinfo.UserName + ";Password="******""; // info.GetOracleDb(connOracle); // break; // case 3: // string ConnString = dlinfo.DataSource; // info.LoadFromAccess2000(ConnString); // break; //} //} //catch (Exception ex) //{ // MessageBox.Show("操作失败。" + ex.Message); //} return(dbinfo); }
public static BdpType GetBdpType(DbDataType type) { switch (type) { case DbDataType.Array: return(BdpType.Array); case DbDataType.Binary: return(BdpType.Blob); case DbDataType.SmallInt: return(BdpType.Int16); case DbDataType.Integer: return(BdpType.Int32); case DbDataType.BigInt: return(BdpType.Int64); case DbDataType.Char: case DbDataType.VarChar: return(BdpType.String); case DbDataType.Date: return(BdpType.Date); case DbDataType.Decimal: case DbDataType.Numeric: return(BdpType.Decimal); case DbDataType.Double: return(BdpType.Double); case DbDataType.Float: return(BdpType.Float); case DbDataType.Text: return(BdpType.Blob); case DbDataType.Time: return(BdpType.Time); case DbDataType.TimeStamp: return(BdpType.DateTime); default: return(BdpType.Unknown); } }
public static BdpType GetBdpType(DbDataType type) { switch (type) { case DbDataType.Array: return BdpType.Array; case DbDataType.Binary: return BdpType.Blob; case DbDataType.SmallInt: return BdpType.Int16; case DbDataType.Integer: return BdpType.Int32; case DbDataType.BigInt: return BdpType.Int64; case DbDataType.Char: case DbDataType.VarChar: return BdpType.String; case DbDataType.Date: return BdpType.Date; case DbDataType.Decimal: case DbDataType.Numeric: return BdpType.Decimal; case DbDataType.Double: return BdpType.Double; case DbDataType.Float: return BdpType.Float; case DbDataType.Text: return BdpType.Blob; case DbDataType.Time: return BdpType.Time; case DbDataType.TimeStamp: return BdpType.DateTime; default: return BdpType.Unknown; } }
private static bool IsDateTime(DbDataType dbDataType) { if (dbDataType.DataType.In(DataType.Date, DataType.Time, DataType.DateTime, DataType.DateTime2, DataType.DateTimeOffset, DataType.SmallDateTime, DataType.Timestamp)) { return(true); } if (dbDataType.DataType != DataType.Undefined) { return(false); } return(IsDateTime(dbDataType.SystemType)); }
public SqlField(ColumnDescriptor column) { Type = new DbDataType(column.MemberType, column.DataType, column.DbType, column.Length, column.Precision, column.Scale); Name = column.MemberName; PhysicalName = column.ColumnName; CanBeNull = column.CanBeNull; IsPrimaryKey = column.IsPrimaryKey; PrimaryKeyOrder = column.PrimaryKeyOrder; IsIdentity = column.IsIdentity; IsInsertable = !column.SkipOnInsert; IsUpdatable = !column.SkipOnUpdate; CreateFormat = column.CreateFormat; CreateOrder = column.Order; ColumnDescriptor = column; }
public static DbType GetDbType(DbDataType type) { switch (type) { case DbDataType.Array: case DbDataType.Binary: return(DbType.Binary); case DbDataType.Text: case DbDataType.VarChar: case DbDataType.Char: return(DbType.String); case DbDataType.SmallInt: return(DbType.Int16); case DbDataType.Integer: return(DbType.Int32); case DbDataType.BigInt: return(DbType.Int64); case DbDataType.Date: return(DbType.Date); case DbDataType.Time: return(DbType.Time); case DbDataType.TimeStamp: return(DbType.DateTime); case DbDataType.Numeric: case DbDataType.Decimal: return(DbType.Decimal); case DbDataType.Float: return(DbType.Single); case DbDataType.Double: return(DbType.Double); case DbDataType.Guid: return(DbType.Guid); default: throw new ArgumentException("Invalid data type"); } }
public static string GetSystemDataTypeName(DbDataType dataType) { switch (dataType) { case DbDataType.Array: return("System.Array"); case DbDataType.Binary: return("System.Byte[]"); case DbDataType.Text: case DbDataType.Char: case DbDataType.VarChar: return("System.String"); case DbDataType.Guid: return("System.Guid"); case DbDataType.SmallInt: return("System.Int16"); case DbDataType.Integer: return("System.Int32"); case DbDataType.BigInt: return("System.Int64"); case DbDataType.Float: return("System.Single"); case DbDataType.Double: return("System.Double"); case DbDataType.Numeric: case DbDataType.Decimal: return("System.Decimal"); case DbDataType.Date: case DbDataType.TimeStamp: return("System.DateTime"); case DbDataType.Time: return("System.TimeSpan"); default: return(null); } }
public void AddValue(SqlParameter parameter, object?value, DbDataType dbDataType) { _valuesByParameter ??= new (); var parameterValue = new SqlParameterValue(value, dbDataType); _valuesByParameter.Remove(parameter); _valuesByParameter.Add(parameter, parameterValue); if (parameter.AccessorId != null) { _valuesByAccessor ??= new (); _valuesByAccessor.Remove(parameter.AccessorId.Value); _valuesByAccessor.Add(parameter.AccessorId.Value, parameterValue); } }
public void CreateColumn(string name, DbDataType dataType) { if (_columnDefs.ContainsKey(name)) { throw new NameConflictExc(name); } if (_rows.Count > 0) { //todo throw new FeatureNotSupExc(); } else { _columnDefs.Add(name, dataType); } }
private BulkCopyRowsCopied ProviderSpecificCopyImpl <T>(DataConnection dataConnection, ITable <T> table, BulkCopyOptions options, IEnumerable <T> source) where T : notnull { var connection = _provider.TryGetProviderConnection(dataConnection.Connection, table.DataContext.MappingSchema); if (connection == null) { return(MultipleRowsCopy(table, options, source)); } var sqlBuilder = (BasicSqlBuilder)_provider.CreateSqlBuilder(table.DataContext.MappingSchema); var ed = table.DataContext.MappingSchema.GetEntityDescriptor(typeof(T)); var tableName = GetTableName(sqlBuilder, options, table); var columns = ed.Columns.Where(c => !c.SkipOnInsert || options.KeepIdentity == true && c.IsIdentity).ToArray(); var npgsqlTypes = new NpgsqlProviderAdapter.NpgsqlDbType[columns.Length]; var columnTypes = new DbDataType[columns.Length]; for (var i = 0; i < columns.Length; i++) { columnTypes[i] = columns[i].GetDbDataType(true); var npgsqlType = _provider.GetNativeType(columns[i].DbType, true); if (npgsqlType == null) { var sb = new System.Text.StringBuilder(); sqlBuilder.BuildTypeName(sb, new SqlQuery.SqlDataType(columnTypes[i])); npgsqlType = _provider.GetNativeType(sb.ToString(), true); } if (npgsqlType == null) { throw new LinqToDBException($"Cannot guess PostgreSQL type for column {columns[i].ColumnName}. Specify type explicitly in column mapping."); } npgsqlTypes[i] = npgsqlType.Value; } var fields = string.Join(", ", columns.Select(column => sqlBuilder.ConvertInline(column.ColumnName, ConvertType.NameToQueryField))); var copyCommand = $"COPY {tableName} ({fields}) FROM STDIN (FORMAT BINARY)"; // batch size numbers not based on any strong grounds as I didn't found any recommendations for it var batchSize = Math.Max(10, options.MaxBatchSize ?? 10000); var writer = _provider.Adapter.BeginBinaryImport(connection, copyCommand); return(ProviderSpecificCopySyncImpl(dataConnection, options, source, connection, tableName, columns, columnTypes, npgsqlTypes, copyCommand, batchSize, writer)); }
public static BdpType GetBdpSubType(DbDataType type) { switch (type) { case DbDataType.Binary: return(BdpType.stHBinary); case DbDataType.Char: return(BdpType.stFixed); case DbDataType.Text: return(BdpType.stHMemo); default: return(BdpType.Unknown); } }
/// <summary> /// Translates a native value to a MySql value. /// </summary> public static object TranslateToDb(DbDataType dataType, Type type, object value) { switch (dataType) { case DbDataType.Unknown: return(DBNull.Value); case DbDataType.Boolean: case DbDataType.Char: case DbDataType.UInt8: case DbDataType.SInt8: case DbDataType.UInt16: case DbDataType.SInt16: case DbDataType.UInt24: case DbDataType.SInt24: case DbDataType.UInt32: case DbDataType.SInt32: case DbDataType.UInt64: case DbDataType.SInt64: case DbDataType.Decimal: case DbDataType.Float: case DbDataType.Double: case DbDataType.Text: case DbDataType.Blob: case DbDataType.Enumerated: return(DbTranslation.ScalarToDb(type, value)); case DbDataType.DateTime: return(value); case DbDataType.Timestamp: return(((DateTimeOffset)value).DateTime); case DbDataType.TimeSpan: return(((TimeSpan)value).Ticks); case DbDataType.Records: case DbDataType.Json: return(JsonConvert.SerializeObject(value, Formatting.None)); case DbDataType.Time: case DbDataType.Date: default: throw new NotImplementedException(); } }
public override void SetParameter(IDbDataParameter parameter, string name, DbDataType dataType, object value) { switch (dataType.DataType) { case DataType.DateTimeOffset: if (value is DateTimeOffset) { var dto = (DateTimeOffset)value; var zone = (dto.Offset < TimeSpan.Zero ? "-" : "+") + dto.Offset.ToString("hh\\:mm"); value = _createOracleTimeStampTZ(dto, zone); } break; case DataType.Boolean: dataType = dataType.WithDataType(DataType.Byte); if (value is bool) { value = (bool)value ? (byte)1 : (byte)0; } break; case DataType.Guid: if (value is Guid) { value = ((Guid)value).ToByteArray(); } break; case DataType.Time: // According to http://docs.oracle.com/cd/E16655_01/win.121/e17732/featOraCommand.htm#ODPNT258 // Inference of DbType and OracleDbType from Value: TimeSpan - Object - IntervalDS // if (value is TimeSpan) { dataType = dataType.WithDataType(DataType.Undefined); } break; } if (dataType.DataType == DataType.Undefined && value is string && ((string)value).Length >= 4000) { dataType = dataType.WithDataType(DataType.NText); } base.SetParameter(parameter, name, dataType, value); }
protected override void SetParameterType(IDbDataParameter parameter, DbDataType dataType) { switch (dataType.DataType) { case DataType.Money : _setMoney(parameter) ; return; case DataType.Image : case DataType.Binary : case DataType.VarBinary : _setVarBinary(parameter); return; case DataType.Boolean : _setBoolean(parameter) ; return; case DataType.Xml : _setXml(parameter) ; return; case DataType.Text : case DataType.NText : _setText(parameter) ; return; case DataType.BitArray : _setBit(parameter) ; return; case DataType.Dictionary: _setHstore(parameter) ; return; case DataType.Json : _setJson(parameter) ; return; case DataType.BinaryJson: _setJsonb(parameter) ; return; case DataType.SByte: case DataType.UInt16: case DataType.UInt32: case DataType.UInt64: case DataType.DateTime2: case DataType.DateTimeOffset: case DataType.VarNumeric: case DataType.Decimal: break; default: { if (_setNativeParameterType != null && !string.IsNullOrEmpty(dataType.DbType)) { var nativeType = GetNativeType(dataType.DbType); if (nativeType != null) { _setNativeParameterType(parameter, nativeType); return; } } break; } } base.SetParameterType(parameter, dataType); }
/// <summary> /// 修改字段类型 /// </summary> /// <param name="tablename">表名</param> /// <param name="fieldname">字段名</param> /// <param name="_vartype">字段类型</param> /// <param name="len">长度</param> /// <returns></returns> public string ModifyField(string tablename, string fieldname, DbDataType _vartype, string len) { string lenstr = ""; if (_vartype != DbDataType.INT) { lenstr = "({0})".ToFormat(len); } switch (_DriverType) { case DriverType.mysql: case DriverType.oracle: return("alter table {0} modify column {1} {2}{3};".ToFormat(tablename, fieldname, DataType(_vartype), lenstr)); default: return("alter table {0} alter column {1} {2}{3}".ToFormat(tablename, fieldname, DataType(_vartype), lenstr)); } }
public IntPtr MarshalManagedToNative(Charset charset, object value) { DbField field = new DbField(); ParamDsc descriptor = BuildDescriptor(charset, value); DbDataType type = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType); field.DataType = (short)TypeHelper.GetFbType(type, true); field.SubType = descriptor.SubType; field.DbValue.Value = value; field.Length = descriptor.Length; byte[] buffer = field.DbValue.GetBytes(); descriptor.Data = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, descriptor.Data, buffer.Length); return(MarshalManagedToNative(descriptor)); }
/// <summary> /// Translates a MySql value to a native value. /// </summary> public static object TranslateFromDb(DbDataType dataType, Type type, object value) { switch (dataType) { case DbDataType.Unknown: case DbDataType.Boolean: case DbDataType.Char: case DbDataType.UInt8: case DbDataType.SInt8: case DbDataType.UInt16: case DbDataType.SInt16: case DbDataType.UInt24: case DbDataType.SInt24: case DbDataType.UInt32: case DbDataType.SInt32: case DbDataType.UInt64: case DbDataType.SInt64: case DbDataType.Decimal: case DbDataType.Float: case DbDataType.Double: case DbDataType.Text: case DbDataType.Blob: case DbDataType.Enumerated: return(DbTranslation.ScalarFromDb(type, value)); case DbDataType.DateTime: return(value); case DbDataType.Timestamp: return(new DateTimeOffset((DateTime)value)); case DbDataType.TimeSpan: return(new TimeSpan((long)value)); case DbDataType.Records: case DbDataType.Json: return(JsonConvert.DeserializeObject((string)value, type)); case DbDataType.Time: case DbDataType.Date: default: throw new NotImplementedException(); } }
protected override void SetParameterType(IDbDataParameter parameter, DbDataType dataType) { switch (dataType.DataType) { case DataType.SByte: parameter.DbType = DbType.Int16; break; case DataType.UInt16: parameter.DbType = DbType.Int32; break; case DataType.UInt32: parameter.DbType = DbType.Int64; break; case DataType.UInt64: parameter.DbType = DbType.Decimal; break; case DataType.VarNumeric: parameter.DbType = DbType.Decimal; break; case DataType.Text: case DataType.NText: _setNText(parameter); break; case DataType.Char: case DataType.NChar: _setNChar(parameter); break; case DataType.VarChar: case DataType.NVarChar: _setNVarChar(parameter); break; case DataType.Timestamp: _setTimestamp(parameter); break; case DataType.Binary: _setBinary(parameter); break; case DataType.VarBinary: _setVarBinary(parameter); break; case DataType.Image: _setImage(parameter); break; case DataType.Date: case DataType.DateTime: case DataType.DateTime2: _setDateTime(parameter); break; case DataType.Money: _setMoney(parameter); break; case DataType.Boolean: _setBoolean(parameter); break; default: base.SetParameterType(parameter, dataType); break; } }
public virtual Type ConvertParameterType(Type type, DbDataType dataType) { switch (dataType.DataType) { case DataType.Char: case DataType.NChar: case DataType.VarChar: case DataType.NVarChar: case DataType.Text: case DataType.NText: if (type == typeof(DateTimeOffset)) { return(typeof(string)); } break; case DataType.Image: case DataType.Binary: case DataType.Blob: case DataType.VarBinary: if (type == typeof(Binary)) { return(typeof(byte[])); } break; case DataType.Int64: if (type == typeof(TimeSpan)) { return(typeof(long)); } break; case DataType.Xml: if (type == typeof(XDocument) || type == typeof(XmlDocument)) { return(typeof(string)); } break; } return(type); }
protected override void SetParameterType(IDbDataParameter parameter, DbDataType dataType) { if (parameter is BulkCopyReader.Parameter) { return; } switch (dataType.DataType) { case DataType.Text: _setText(parameter); break; case DataType.Image: _setBlob(parameter); break; case DataType.NText: _setNText(parameter); break; case DataType.Binary: _setVarBinary(parameter); break; } base.SetParameterType(parameter, dataType); }
public DbFieldTypeAttribute(DbDataType dbType, int size) { if (dbType == DbDataType.NONE) { throw new ArgumentException("dbType"); } this.DbType = dbType; if (0 > size) { throw new ArgumentException("size"); } this.Size = size; bool isStrType = SmartCrudHelper.IsStringType(dbType); if (0 == this.Size) { throw new ArgumentException("size"); } }
public static short?GetSize(DbDataType type) { switch (type) { case DbDataType.Array: case DbDataType.Binary: case DbDataType.Text: return(8); case DbDataType.SmallInt: return(2); case DbDataType.Integer: case DbDataType.Float: case DbDataType.Date: case DbDataType.Time: return(4); case DbDataType.BigInt: case DbDataType.Double: case DbDataType.TimeStamp: case DbDataType.Dec16: case DbDataType.TimeTZ: return(8); case DbDataType.Guid: case DbDataType.TimeStampTZEx: case DbDataType.Dec34: case DbDataType.Int128: return(16); case DbDataType.Boolean: return(1); case DbDataType.TimeStampTZ: case DbDataType.TimeTZEx: return(12); default: return(null); } }
protected override void SetParameterType(IDbDataParameter parameter, DbDataType dataType) { switch (dataType.DataType) { case DataType.VarNumeric: parameter.DbType = DbType.Decimal; break; case DataType.UInt16: _setUInt16(parameter); break; case DataType.UInt32: _setUInt32(parameter); break; case DataType.UInt64: _setUInt64(parameter); break; case DataType.Text: _setText(parameter); break; case DataType.NText: _setNText(parameter); break; case DataType.Binary: _setBinary(parameter); break; case DataType.Blob: case DataType.VarBinary: _setVarBinary(parameter); break; case DataType.Image: _setImage(parameter); break; case DataType.Money: _setMoney(parameter); break; case DataType.SmallMoney: _setSmallMoney(parameter); break; case DataType.Date: _setDate(parameter); break; case DataType.Time: _setTime(parameter); break; case DataType.SmallDateTime: _setSmallDateTime(parameter); break; case DataType.Timestamp: _setTimestamp(parameter); break; case DataType.DateTime2: base.SetParameterType(parameter, dataType.WithDataType(DataType.DateTime)); break; default: base.SetParameterType(parameter, dataType); break; } }
private DataBaseInfo GetDbInfo(int DbLinkId) { IDbLink dal = new DbLink(); DbLinkInfo dlinfo = dal.DbLinkGetInfo(DbLinkId); IDataBase dbDal = new CurrencyDal.CodeMaker.DataBase(); string rstmsg = ""; string tableName = ""; List <string> tableNameList = new List <string>(); DbDataTypeEnum dtype = DbDataType.GetDbDataType(dinfo.NameType); if (dtype == DbDataTypeEnum.表) { tableName = dinfo.Name; tableNameList.Add(tableName); } DataBaseInfo dbinfo = dbDal.DataBaseGetInfo(dlinfo, tableNameList, out rstmsg); return(dbinfo); }
public static Type GetCsharpType(this DbDataType type) { switch (type) { case DbDataType.INT: return(typeof(int)); case DbDataType.DOUBLE: return(typeof(double)); case DbDataType.TEXT: return(typeof(string)); case DbDataType.DATETIME: return(typeof(DateTime)); default: throw new FeatureNotSupExc(); } }
protected override void SetParameterType(IDbDataParameter parameter, DbDataType dataType) { switch (dataType.DataType) { case DataType.SByte: dataType = dataType.WithDataType(DataType.Int16); break; case DataType.UInt16: dataType = dataType.WithDataType(DataType.Int32); break; case DataType.UInt32: dataType = dataType.WithDataType(DataType.Int64); break; case DataType.UInt64: dataType = dataType.WithDataType(DataType.Decimal); break; case DataType.VarNumeric: dataType = dataType.WithDataType(DataType.Decimal); break; case DataType.DateTime: case DataType.DateTime2: _setTimeStamp(parameter); return; } base.SetParameterType(parameter, dataType); }
public static string GetTypeNameString(this DbDataType type) { switch (type) { case DbDataType.INT: return("INT"); case DbDataType.DOUBLE: return("DOUBLE"); case DbDataType.TEXT: return("TEXT"); case DbDataType.DATETIME: return("DATETIME"); default: throw new FeatureNotSupExc(); } }
public override Type ConvertParameterType(Type type, DbDataType dataType) { type = base.ConvertParameterType(type, dataType); // native client BulkCopy cannot stand nullable types // AseBulkManager.IsWrongType if (Name == ProviderName.Sybase) { type = type.ToNullableUnderlying(); if (type == typeof(char) || type == typeof(Guid)) { type = typeof(string); } else if (type == typeof(TimeSpan)) { type = typeof(DateTime); } } return(type); }
public static BdpType GetBdpSubType(DbDataType type) { switch (type) { case DbDataType.Binary: return BdpType.stHBinary; case DbDataType.Char: return BdpType.stFixed; case DbDataType.Text: return BdpType.stHMemo; default: return BdpType.Unknown; } }
public abstract object GetNewValueForType(DbDataType type);
public abstract SqlDbType GetTypeAsDBType(DbDataType type);
public static int GetFbType(DbDataType dataType, bool isNullable) { int sqltype = 0; switch (dataType) { case DbDataType.Array: sqltype = IscCodes.SQL_ARRAY; break; case DbDataType.Binary: case DbDataType.Text: sqltype = IscCodes.SQL_BLOB; break; case DbDataType.Char: sqltype = IscCodes.SQL_TEXT; break; case DbDataType.VarChar: sqltype = IscCodes.SQL_VARYING; break; case DbDataType.Boolean: case DbDataType.SmallInt: sqltype = IscCodes.SQL_SHORT; break; case DbDataType.Integer: sqltype = IscCodes.SQL_LONG; break; case DbDataType.BigInt: sqltype = IscCodes.SQL_INT64; break; case DbDataType.Float: sqltype = IscCodes.SQL_FLOAT; break; case DbDataType.Guid: sqltype = IscCodes.SQL_TEXT; break; case DbDataType.Double: sqltype = IscCodes.SQL_DOUBLE; break; case DbDataType.Date: sqltype = IscCodes.SQL_TYPE_DATE; break; case DbDataType.Time: sqltype = IscCodes.SQL_TYPE_TIME; break; case DbDataType.TimeStamp: sqltype = IscCodes.SQL_TIMESTAMP; break; default: throw new ArgumentException("Invalid data type"); } if (isNullable) { sqltype++; } return sqltype; }
public static string GetDataTypeName(DbDataType dataType) { switch (dataType) { case DbDataType.Array: return "ARRAY"; case DbDataType.Binary: return "BLOB"; case DbDataType.Text: return "BLOB SUB_TYPE 1"; case DbDataType.Char: case DbDataType.Guid: return "CHAR"; case DbDataType.VarChar: return "VARCHAR"; case DbDataType.SmallInt: return "SMALLINT"; case DbDataType.Integer: return "INTEGER"; case DbDataType.Float: return "FLOAT"; case DbDataType.Double: return "DOUBLE PRECISION"; case DbDataType.BigInt: return "BIGINT"; case DbDataType.Numeric: return "NUMERIC"; case DbDataType.Decimal: return "DECIMAL"; case DbDataType.Date: return "DATE"; case DbDataType.Time: return "TIME"; case DbDataType.TimeStamp: return "TIMESTAMP"; default: return null; } }
public static string GetSystemDataTypeName(DbDataType dataType) { switch (dataType) { case DbDataType.Array: return "System.Array"; case DbDataType.Binary: return "System.Byte[]"; case DbDataType.Text: case DbDataType.Char: case DbDataType.VarChar: return "System.String"; case DbDataType.Guid: return "System.Guid"; case DbDataType.SmallInt: return "System.Int16"; case DbDataType.Integer: return "System.Int32"; case DbDataType.BigInt: return "System.Int64"; case DbDataType.Float: return "System.Single"; case DbDataType.Double: return "System.Double"; case DbDataType.Numeric: case DbDataType.Decimal: return "System.Decimal"; case DbDataType.Date: case DbDataType.TimeStamp: return "System.DateTime"; case DbDataType.Time: return "System.TimeSpan"; default: return null; } }
/// <summary> /// Convers a <see cref="DbDataType" /> to a corresponding <see cref="Type" />. /// </summary> /// <param name="dataType">The data type.</param> /// <returns>The CLR <see cref="Type" />.</returns> /// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NotSupportedException">The <see cref="DbDataType" /> is not supported.</exception> public Type ConvertToType(DbDataType dataType) { switch (dataType) { case DbDataType.AnsiString: return typeof(string); case DbDataType.Binary: return typeof(byte[]); case DbDataType.Byte: return typeof(byte); case DbDataType.Boolean: return typeof(bool); case DbDataType.Currency: return typeof(double); case DbDataType.Date: return typeof(DateTime); case DbDataType.DateTime: return typeof(DateTime); case DbDataType.Decimal: return typeof(decimal); case DbDataType.Double: return typeof(double); case DbDataType.Guid: return typeof(Guid); case DbDataType.Int16: return typeof(short); case DbDataType.Int32: return typeof(int); case DbDataType.Int64: return typeof(long); case DbDataType.Object: return typeof(object); case DbDataType.SByte: return typeof(sbyte); case DbDataType.Single: return typeof(float); case DbDataType.String: return typeof(string); case DbDataType.Time: return typeof(TimeSpan); case DbDataType.UInt16: return typeof(ushort); case DbDataType.UInt32: return typeof(uint); case DbDataType.UInt64: return typeof(ulong); case DbDataType.VarNumeric: return typeof(decimal); case DbDataType.AnsiStringFixedLength: return typeof(string); case DbDataType.StringFixedLength: return typeof(string); case DbDataType.Xml: return typeof(string); case DbDataType.DateTime2: return typeof(DateTime); case DbDataType.DateTimeOffset: return typeof(DateTimeOffset); default: throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Parameter type \"{0}\" is not supported.", dataType)); } }
/// <summary> /// Converts the specified value. /// </summary> /// <param name="value">The value.</param> /// <param name="destinationType">Type of the destination.</param> /// <returns>The converted object.</returns> private object Convert(object value, DbDataType destinationType) { if (value == null) return DBNull.Value; return SafeTypeConverter.Convert(value, DbTypeConverter.ConvertToType(destinationType)); }
/// <summary> /// Initializes a new instance of the <see cref="StoredProcedureParameterDefinition"/> class. /// </summary> /// <param name="name">The parameter name.</param> /// <param name="dataType">The data type.</param> /// <param name="valueCalculator">The value calculator.</param> public StoredProcedureParameterDefinition(string name, DbDataType dataType, Func<IEditableRoot, object> valueCalculator) { _name = name; _dataType = dataType; _valueCalculator = valueCalculator; }
public static DbType GetDbType(DbDataType type) { switch (type) { case DbDataType.Array: case DbDataType.Binary: return DbType.Binary; case DbDataType.Text: case DbDataType.VarChar: case DbDataType.Char: return DbType.String; case DbDataType.SmallInt: return DbType.Int16; case DbDataType.Integer: return DbType.Int32; case DbDataType.BigInt: return DbType.Int64; case DbDataType.Date: return DbType.Date; case DbDataType.Time: return DbType.Time; case DbDataType.TimeStamp: return DbType.DateTime; case DbDataType.Numeric: case DbDataType.Decimal: return DbType.Decimal; case DbDataType.Float: return DbType.Single; case DbDataType.Double: return DbType.Double; case DbDataType.Guid: return DbType.Guid; case DbDataType.Boolean: return DbType.Boolean; default: throw new ArgumentException("Invalid data type"); } }
/// <summary> /// Converts a <see cref="DbDataType" /> to a corresponding <see cref="DbType" />. /// </summary> /// <param name="dataType">The data type.</param> /// <returns>The <see cref="DbType" />.</returns> public DbType ConvertToDbType(DbDataType dataType) { return (DbType)Enum.Parse(typeof(DbType), dataType.ToString()); }