/// <include file='docs/MySqlDataReader.xml' path='docs/GetInt64/*'/> public override Int64 GetInt64(int i) { IMySqlValue v = GetFieldValue(i, true); if (v is MySqlInt64) { return(((MySqlInt64)v).Value); } return((Int64)ChangeType(v, i, typeof(Int64))); }
public override double GetDouble(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, true); if (fieldValue is MySqlDouble) { MySqlDouble num = (MySqlDouble)fieldValue; return(num.Value); } return(Convert.ToDouble(fieldValue.Value)); }
/// <include file='docs/MySqlDataReader.xml' path='docs/GetInt16/*'/> public override Int16 GetInt16(int i) { IMySqlValue v = GetFieldValue(i, true); if (v is MySqlInt16) { return(((MySqlInt16)v).Value); } return((short)ChangeType(v, i, typeof(short))); }
public override string GetString(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, true); if (fieldValue is MySqlBinary) { byte[] value = ((MySqlBinary)fieldValue).Value; return(this.resultSet.Fields[i].Encoding.GetString(value, 0, value.Length)); } return(fieldValue.Value.ToString()); }
public override float GetFloat(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, true); if (fieldValue is MySqlSingle) { MySqlSingle num = (MySqlSingle)fieldValue; return(num.Value); } return(Convert.ToSingle(fieldValue.Value)); }
/// <include file='docs/MySqlDataReader.xml' path='docs/GetUInt64/*'/> public UInt64 GetUInt64(int column) { IMySqlValue v = GetFieldValue(column, true); if (v is MySqlUInt64) { return(((MySqlUInt64)v).Value); } return((UInt64)ChangeType(v, column, typeof(UInt64))); }
public override decimal GetDecimal(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, true); if (fieldValue is MySqlDecimal) { MySqlDecimal num = (MySqlDecimal)fieldValue; return(num.Value); } return(Convert.ToDecimal(fieldValue.Value)); }
public IMySqlValue GetValueObject() { IMySqlValue v = GetIMySqlValue(Type); if (v is MySqlByte && ColumnLength == 1 && MaxLength == 1 && connection.Settings.TreatTinyAsBoolean) { MySqlByte b = (MySqlByte)v; b.TreatAsBoolean = true; v = b; } return(v); }
/// <include file='docs/MySqlDataReader.xml' path='docs/GetString/*'/> public override String GetString(int i) { IMySqlValue val = GetFieldValue(i, true); if (val is MySqlBinary) { byte[] v = ((MySqlBinary)val).Value; return(resultSet.Fields[i].Encoding.GetString(v, 0, v.Length)); } return(val.Value.ToString()); }
public override string GetString(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, true); if (fieldValue is MySqlBinary) { MySqlBinary binary = (MySqlBinary)fieldValue; byte[] bytes = binary.Value; return(this.fields[i].Encoding.GetString(bytes, 0, bytes.Length)); } return(fieldValue.Value.ToString()); }
public ulong GetUInt64(int column) { IMySqlValue fieldValue = this.GetFieldValue(column, true); if (fieldValue is MySqlUInt64) { MySqlUInt64 num = (MySqlUInt64)fieldValue; return(num.Value); } this.connection.UsageAdvisor.Converting(this.command.CommandText, this.fields[column].ColumnName, fieldValue.MySqlTypeName, "UInt64"); return(Convert.ToUInt64(fieldValue.Value)); }
public override long GetInt64(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, true); if (fieldValue is MySqlInt64) { MySqlInt64 num = (MySqlInt64)fieldValue; return(num.Value); } this.connection.UsageAdvisor.Converting(this.command.CommandText, this.fields[i].ColumnName, fieldValue.MySqlTypeName, "Int64"); return(((IConvertible)fieldValue.Value).ToInt64(null)); }
/// <include file='docs/MySqlDataReader.xml' path='docs/GetString/*'/> public override String GetString(int column) { IMySqlValue val = GetFieldValue(column, true); if (val is MySqlBinary) { byte[] v = ((MySqlBinary)val).Value; return(fields[column].Encoding.GetString(v, 0, v.Length)); } return(val.Value.ToString()); }
/// <summary> /// Reads a stream of bytes from the specified column offset into the buffer an array starting at the given buffer offset. /// </summary> /// <param name="i">The zero-based column ordinal. </param> /// <param name="fieldOffset">The index within the field from which to begin the read operation. </param> /// <param name="buffer">The buffer into which to read the stream of bytes. </param> /// <param name="bufferoffset">The index for buffer to begin the read operation. </param> /// <param name="length">The maximum length to copy into the buffer. </param> /// <returns>The actual number of bytes read.</returns> /// <include file='docs/MySqlDataReader.xml' path='MyDocs/MyMembers[@name="GetBytes"]/*'/> public override long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) { if (i >= FieldCount) { throw new IndexOutOfRangeException(); } IMySqlValue val = GetFieldValue(i, false); if (!(val is MySqlBinary) && !(val is MySqlGuid)) { throw new MySqlException("GetBytes can only be called on binary or guid columns"); } byte[] bytes = null; if (val is MySqlBinary) { bytes = ((MySqlBinary)val).Value; } else { bytes = ((MySqlGuid)val).Bytes; } if (buffer == null) { return(bytes.Length); } if (bufferoffset >= buffer.Length || bufferoffset < 0) { throw new IndexOutOfRangeException("Buffer index must be a valid index in buffer"); } if (buffer.Length < (bufferoffset + length)) { throw new ArgumentException("Buffer is not large enough to hold the requested data"); } if (fieldOffset < 0 || ((ulong)fieldOffset >= (ulong)bytes.Length && (ulong)bytes.Length > 0)) { throw new IndexOutOfRangeException("Data index must be a valid index in the field"); } // adjust the length so we don't run off the end if ((ulong)bytes.Length < (ulong)(fieldOffset + length)) { length = (int)((ulong)bytes.Length - (ulong)fieldOffset); } Buffer.BlockCopy(bytes, (int)fieldOffset, buffer, (int)bufferoffset, (int)length); return(length); }
/// <summary> /// Gets the value of the specified column as a byte. /// </summary> /// <param name="i"></param> /// <returns></returns> public override byte GetByte(int i) { IMySqlValue v = GetFieldValue(i, false); if (v is MySqlUByte) { return(((MySqlUByte)v).Value); } else { return((byte)((MySqlByte)v).Value); } }
/// <include file='docs/MySqlDataReader.xml' path='docs/GetInt64/*'/> public override Int64 GetInt64(int i) { IMySqlValue v = GetFieldValue(i, true); if (v is MySqlInt64) { return(((MySqlInt64)v).Value); } connection.UsageAdvisor.Converting(command.CommandText, fields[i].ColumnName, v.MySqlTypeName, "Int64"); return(((IConvertible)v.Value).ToInt64(null)); }
internal void Serialize(MySqlStream stream, bool binary) { IMySqlValue iMySqlValue = MySqlField.GetIMySqlValue(this.mySqlDbType); if (!binary && ((this.paramValue == null) || (this.paramValue == DBNull.Value))) { stream.WriteStringNoNull("NULL"); } else { iMySqlValue.WriteValue(stream, binary, this.paramValue, this.size); } }
internal void Serialize(MySqlStream stream, bool binary) { IMySqlValue v = MySqlField.GetIMySqlValue(mySqlDbType); if (!binary && (paramValue == null || paramValue == DBNull.Value)) { stream.WriteStringNoNull("NULL"); } else { v.WriteValue(stream, binary, paramValue, size); } }
public sbyte GetSByte(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, false); if (fieldValue is MySqlByte) { MySqlByte num = (MySqlByte)fieldValue; return(num.Value); } MySqlByte num2 = (MySqlByte)fieldValue; return(num2.Value); }
public override byte GetByte(int i) { IMySqlValue fieldValue = this.GetFieldValue(i, false); if (fieldValue is MySqlUByte) { MySqlUByte num = (MySqlUByte)fieldValue; return(num.Value); } MySqlByte num2 = (MySqlByte)fieldValue; return((byte)num2.Value); }
/// <include file='docs/MySqlDataReader.xml' path='docs/GetInt32/*'/> public override Int32 GetInt32(int column) { IMySqlValue v = GetFieldValue(column, true); if (v is MySqlInt32) { return(((MySqlInt32)v).Value); } connection.UsageAdvisor.Converting(command.CommandText, fields[column].ColumnName, v.MySqlTypeName, "Int32"); return(((IConvertible)v.Value).ToInt32(null)); }
/// <summary> /// Gets the value of the specified column as a sbyte. /// </summary> /// <param name="i"></param> /// <returns></returns> public sbyte GetSByte(int i) { IMySqlValue v = GetFieldValue(i, false); if (v is MySqlByte) { return(((MySqlByte)v).Value); } else { return((sbyte)((MySqlByte)v).Value); } }
/// <include file='docs/MySqlDataReader.xml' path='docs/GetUInt64/*'/> public UInt64 GetUInt64(int column) { IMySqlValue v = GetFieldValue(column, true); if (v is MySqlUInt64) { return(((MySqlUInt64)v).Value); } connection.UsageAdvisor.Converting(command.CommandText, fields[column].ColumnName, v.MySqlTypeName, "UInt64"); return(Convert.ToUInt64(v.Value)); }
private IMySqlValue GetFieldValue(int index, bool checkNull) { if (index < 0 || index >= this.FieldCount) { this.Throw(new ArgumentException(Resources.InvalidColumnOrdinal)); } IMySqlValue mySqlValue = this.resultSet[index]; if (checkNull && mySqlValue.IsNull) { throw new SqlNullValueException(); } return(mySqlValue); }
public override string GetDataTypeName(int i) { if (!this.isOpen) { this.Throw(new Exception("No current query in data reader")); } if (i >= this.FieldCount) { this.Throw(new IndexOutOfRangeException()); } IMySqlValue mySqlValue = this.resultSet.Values[i]; return(mySqlValue.MySqlTypeName); }
/// <summary> /// Gets a value indicating whether the column contains non-existent or missing values. /// </summary> /// <param name="i"></param> /// <returns></returns> public override bool IsDBNull(int i) { if (!isOpen) { Throw(new Exception("No current query in data reader")); } if (i >= FieldCount) { Throw(new IndexOutOfRangeException()); } IMySqlValue val = GetFieldValue(i, false); return(val.IsNull);//原来调用 GetValue(int i),如果是值类型,并且有值的话,会引起装箱。 }
/// <summary> /// Gets the name of the source data type. /// </summary> /// <param name="i"></param> /// <returns></returns> public override String GetDataTypeName(int i) { if (!isOpen) { throw new Exception("No current query in data reader"); } if (i >= FieldCount) { throw new IndexOutOfRangeException(); } // return the name of the type used on the backend IMySqlValue v = resultSet.Values[i]; return(v.MySqlTypeName); }
public MySqlGeometry GetMySqlGeometry(int i) { try { IMySqlValue v = GetFieldValue(i, false); if (v is MySqlGeometry || v is MySqlBinary) { return(new MySqlGeometry(MySqlDbType.Geometry, (Byte[])v.Value)); } } catch { Throw(new Exception("Can't get MySqlGeometry from value")); } return(new MySqlGeometry(true)); }
public MySqlGeometry GetMySqlGeometry(int i) { try { IMySqlValue fieldValue = this.GetFieldValue(i, false); if (fieldValue is MySqlGeometry || fieldValue is MySqlBinary) { return(new MySqlGeometry(MySqlDbType.Geometry, (byte[])fieldValue.Value)); } } catch { this.Throw(new Exception("Can't get MySqlGeometry from value")); } return(new MySqlGeometry(true)); }
private IMySqlValue GetFieldValue(int index, bool checkNull) { if (index < 0 || index >= FieldCount) { throw new ArgumentException(Resources.InvalidColumnOrdinal); } IMySqlValue v = resultSet[index]; if (checkNull && v.IsNull) { throw new SqlNullValueException(); } return(v); }
private void SetMySqlDbType(MySqlDbType mysql_dbtype) { mySqlDbType = mysql_dbtype; valueObject = MySqlField.GetIMySqlValue(mySqlDbType); switch (mySqlDbType) { case MySqlDbType.NewDecimal: case MySqlDbType.Decimal: dbType = DbType.Decimal; break; case MySqlDbType.Byte: dbType = DbType.SByte; break; case MySqlDbType.UByte: dbType = DbType.Byte; break; case MySqlDbType.Int16: dbType = DbType.Int16; break; case MySqlDbType.UInt16: dbType = DbType.UInt16; break; case MySqlDbType.Int24: case MySqlDbType.Int32: dbType = DbType.Int32; break; case MySqlDbType.UInt24: case MySqlDbType.UInt32: dbType = DbType.UInt32; break; case MySqlDbType.Int64: dbType = DbType.Int64; break; case MySqlDbType.UInt64: dbType = DbType.UInt64; break; case MySqlDbType.Bit: dbType = DbType.UInt64; break; case MySqlDbType.Float: dbType = DbType.Single; break; case MySqlDbType.Double: dbType = DbType.Double; break; case MySqlDbType.Timestamp: case MySqlDbType.DateTime: dbType = DbType.DateTime; break; case MySqlDbType.Date: case MySqlDbType.Newdate: case MySqlDbType.Year: dbType = DbType.Date; break; case MySqlDbType.Time: dbType = DbType.Time; break; case MySqlDbType.Enum: case MySqlDbType.Set: case MySqlDbType.VarChar: dbType = DbType.String; break; case MySqlDbType.TinyBlob: case MySqlDbType.MediumBlob: case MySqlDbType.LongBlob: case MySqlDbType.Blob: dbType = DbType.Object; break; case MySqlDbType.String: dbType = DbType.StringFixedLength; break; case MySqlDbType.Guid: dbType = DbType.Guid; break; } }
private void SetDbType(DbType db_type) { dbType = db_type; switch (dbType) { case DbType.Guid: mySqlDbType = MySqlDbType.Guid; break; case DbType.AnsiString: case DbType.String: mySqlDbType = MySqlDbType.VarChar; break; case DbType.AnsiStringFixedLength: case DbType.StringFixedLength: mySqlDbType = MySqlDbType.String; break; case DbType.Boolean: case DbType.Byte: mySqlDbType = MySqlDbType.UByte; break; case DbType.SByte: mySqlDbType = MySqlDbType.Byte; break; case DbType.Date: mySqlDbType = MySqlDbType.Date; break; case DbType.DateTime: mySqlDbType = MySqlDbType.DateTime; break; case DbType.Time: mySqlDbType = MySqlDbType.Time; break; case DbType.Single: mySqlDbType = MySqlDbType.Float; break; case DbType.Double: mySqlDbType = MySqlDbType.Double; break; case DbType.Int16: mySqlDbType = MySqlDbType.Int16; break; case DbType.UInt16: mySqlDbType = MySqlDbType.UInt16; break; case DbType.Int32: mySqlDbType = MySqlDbType.Int32; break; case DbType.UInt32: mySqlDbType = MySqlDbType.UInt32; break; case DbType.Int64: mySqlDbType = MySqlDbType.Int64; break; case DbType.UInt64: mySqlDbType = MySqlDbType.UInt64; break; case DbType.Decimal: case DbType.Currency: mySqlDbType = MySqlDbType.Decimal; break; case DbType.Object: case DbType.VarNumeric: case DbType.Binary: default: mySqlDbType = MySqlDbType.Blob; break; } valueObject = MySqlField.GetIMySqlValue(mySqlDbType); }
internal void Serialize(MySqlPacket packet, bool binary, MySqlConnectionStringBuilder settings) { if (!binary && (paramValue == null || paramValue == DBNull.Value)) packet.WriteStringNoNull("NULL"); else { if (ValueObject.MySqlDbType == MySqlDbType.Guid) { MySqlGuid g = (MySqlGuid)ValueObject; g.OldGuids = settings.OldGuids; valueObject = g; } ValueObject.WriteValue(packet, binary, paramValue, size); } }
public abstract IMySqlValue ReadColumnValue(int index, MySqlField field, IMySqlValue value);
public override void SkipColumnValue(IMySqlValue valObject) { long length = -1; if (nullMap == null) { length = stream.ReadFieldLength(); if (length == -1) return; } if (length > -1) stream.SkipBytes((int) length); else valObject.SkipValue(stream); }
private object ChangeType(IMySqlValue value, int fieldIndex, Type newType) { #if !CF resultSet.Fields[fieldIndex].AddTypeConversion(newType); #endif return Convert.ChangeType(value.Value, newType, CultureInfo.InvariantCulture); }
public override IMySqlValue ReadColumnValue(int index, MySqlField field, IMySqlValue valObject) { bool flag; long length = -1L; if (this.nullMap != null) { flag = this.nullMap[index + 2]; } else { length = this.stream.ReadFieldLength(); flag = length == -1L; } this.stream.Encoding = field.Encoding; return valObject.ReadValue(this.stream, length, flag); }
public void SkipColumnValue(IMySqlValue valObject) { handler.SkipColumnValue(valObject); }
public IMySqlValue ReadColumnValue(int index, MySqlField field, IMySqlValue value) { return handler.ReadColumnValue(index, field, value); }
public IMySqlValue ReadColumnValue(int index, MySqlField field, IMySqlValue valObject) { packet.Encoding = field.Encoding; packet.Version = version; if (nullMap != null) { return valObject.ReadValue(packet, -1, nullMap[index + 2]); } else { long length = packet.ReadFieldLength(); return valObject.ReadValue(packet, length, length == -1); } }
public IMySqlValue ReadColumnValue(int index, MySqlField field, IMySqlValue valObject) { long length = -1; bool isNull; if (nullMap != null) isNull = nullMap[index + 2]; else { length = packet.ReadFieldLength(); isNull = length == -1; } packet.Encoding = field.Encoding; packet.Version = version; return valObject.ReadValue(packet, length, isNull); }
private object ChangeType(IMySqlValue value, int fieldIndex, Type newType) { return Convert.ChangeType(value.Value, newType, CultureInfo.InvariantCulture); }
public void SkipColumnValue(IMySqlValue valObject) { int length = -1; if (nullMap == null) { length = (int)packet.ReadFieldLength(); if (length == -1) return; } if (length > -1) packet.Position += length; else valObject.SkipValue(packet); }
public override IMySqlValue ReadColumnValue(int index, MySqlField field, IMySqlValue valObject) { long length = -1; bool isNull; if (nullMap != null) isNull = nullMap[index + 2]; else { length = stream.ReadFieldLength(); isNull = length == -1; } stream.Encoding = field.Encoding; return valObject.ReadValue(stream, length, isNull); }
public void SetValueObject(int i, IMySqlValue valueObject) { Debug.Assert(values != null); Debug.Assert(i < values.Length); values[i] = valueObject; }
public abstract void SkipColumnValue(IMySqlValue valObject);
public override void SkipColumnValue(IMySqlValue valObject) { long num = -1L; if (this.nullMap == null) { num = this.stream.ReadFieldLength(); if (num == -1L) { return; } } if (num > -1L) { this.stream.SkipBytes((int) num); } else { valObject.SkipValue(this.stream); } }