private DataTable GetDataTypes() { DataTable dt = new DataTable("DataTypes"); dt.Columns.Add(new DataColumn("TypeName", typeof(string))); dt.Columns.Add(new DataColumn("ProviderDbType", typeof(int))); dt.Columns.Add(new DataColumn("ColumnSize", typeof(long))); dt.Columns.Add(new DataColumn("CreateFormat", typeof(string))); dt.Columns.Add(new DataColumn("CreateParameters", typeof(string))); dt.Columns.Add(new DataColumn("DataType", typeof(string))); dt.Columns.Add(new DataColumn("IsAutoincrementable", typeof(bool))); dt.Columns.Add(new DataColumn("IsBestMatch", typeof(bool))); dt.Columns.Add(new DataColumn("IsCaseSensitive", typeof(bool))); dt.Columns.Add(new DataColumn("IsFixedLength", typeof(bool))); dt.Columns.Add(new DataColumn("IsFixedPrecisionScale", typeof(bool))); dt.Columns.Add(new DataColumn("IsLong", typeof(bool))); dt.Columns.Add(new DataColumn("IsNullable", typeof(bool))); dt.Columns.Add(new DataColumn("IsSearchable", typeof(bool))); dt.Columns.Add(new DataColumn("IsSearchableWithLike", typeof(bool))); dt.Columns.Add(new DataColumn("IsUnsigned", typeof(bool))); dt.Columns.Add(new DataColumn("MaximumScale", typeof(short))); dt.Columns.Add(new DataColumn("MinimumScale", typeof(short))); dt.Columns.Add(new DataColumn("IsConcurrencyType", typeof(bool))); dt.Columns.Add(new DataColumn("IsLiteralsSupported", typeof(bool))); dt.Columns.Add(new DataColumn("LiteralPrefix", typeof(string))); dt.Columns.Add(new DataColumn("LiteralSuffix", typeof(string))); dt.Columns.Add(new DataColumn("NativeDataType", typeof(string))); // have each one of the types contribute to the datatypes collection MySqlBit.SetDSInfo(dt); MySqlBinary.SetDSInfo(dt); MySqlDateTime.SetDSInfo(dt); MySqlTimeSpan.SetDSInfo(dt); MySqlString.SetDSInfo(dt); MySqlDouble.SetDSInfo(dt); MySqlSingle.SetDSInfo(dt); MySqlByte.SetDSInfo(dt); MySqlInt16.SetDSInfo(dt); MySqlInt32.SetDSInfo(dt); MySqlInt64.SetDSInfo(dt); MySqlDecimal.SetDSInfo(dt); MySqlUByte.SetDSInfo(dt); MySqlUInt16.SetDSInfo(dt); MySqlUInt32.SetDSInfo(dt); MySqlUInt64.SetDSInfo(dt); return(dt); }
/// <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 >= fields.Length) { throw new IndexOutOfRangeException(); } IMySqlValue val = GetFieldValue(i, false); if (!(val is MySqlBinary)) { throw new MySqlException("GetBytes can only be called on binary columns"); } MySqlBinary binary = (MySqlBinary)val; if (buffer == null) { return((long)binary.Value.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)binary.Value.Length && (ulong)binary.Value.Length > 0)) { throw new IndexOutOfRangeException("Data index must be a valid index in the field"); } byte[] bytes = (byte[])binary.Value; // adjust the length so we don't run off the end if ((ulong)binary.Value.Length < (ulong)(fieldOffset + length)) { length = (int)((ulong)binary.Value.Length - (ulong)fieldOffset); } Buffer.BlockCopy(bytes, (int)fieldOffset, buffer, (int)bufferoffset, (int)length); return(length); }
public override long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) { if (i >= this.FieldCount) { this.Throw(new IndexOutOfRangeException()); } IMySqlValue fieldValue = this.GetFieldValue(i, false); if (!(fieldValue is MySqlBinary) && !(fieldValue is MySqlGuid)) { this.Throw(new MySqlException("GetBytes can only be called on binary or guid columns")); } byte[] src = null; if (fieldValue is MySqlBinary) { MySqlBinary binary = (MySqlBinary)fieldValue; src = binary.Value; } else { MySqlGuid guid = (MySqlGuid)fieldValue; src = guid.Bytes; } if (buffer == null) { return((long)src.Length); } if ((bufferoffset >= buffer.Length) || (bufferoffset < 0)) { this.Throw(new IndexOutOfRangeException("Buffer index must be a valid index in buffer")); } if (buffer.Length < (bufferoffset + length)) { this.Throw(new ArgumentException("Buffer is not large enough to hold the requested data")); } if ((fieldOffset < 0L) || ((fieldOffset >= src.Length) && (src.Length > 0L))) { this.Throw(new IndexOutOfRangeException("Data index must be a valid index in the field")); } if (src.Length < (fieldOffset + length)) { length = src.Length - ((int)fieldOffset); } Buffer.BlockCopy(src, (int)fieldOffset, buffer, bufferoffset, length); return((long)length); }
private static MySqlSchemaCollection GetDataTypes() { MySqlSchemaCollection sc = new MySqlSchemaCollection("DataTypes"); sc.AddColumn("TypeName", typeof(string)); sc.AddColumn("ProviderDbType", typeof(int)); sc.AddColumn("ColumnSize", typeof(long)); sc.AddColumn("CreateFormat", typeof(string)); sc.AddColumn("CreateParameters", typeof(string)); sc.AddColumn("DataType", typeof(string)); sc.AddColumn("IsAutoincrementable", typeof(bool)); sc.AddColumn("IsBestMatch", typeof(bool)); sc.AddColumn("IsCaseSensitive", typeof(bool)); sc.AddColumn("IsFixedLength", typeof(bool)); sc.AddColumn("IsFixedPrecisionScale", typeof(bool)); sc.AddColumn("IsLong", typeof(bool)); sc.AddColumn("IsNullable", typeof(bool)); sc.AddColumn("IsSearchable", typeof(bool)); sc.AddColumn("IsSearchableWithLike", typeof(bool)); sc.AddColumn("IsUnsigned", typeof(bool)); sc.AddColumn("MaximumScale", typeof(short)); sc.AddColumn("MinimumScale", typeof(short)); sc.AddColumn("IsConcurrencyType", typeof(bool)); sc.AddColumn("IsLiteralSupported", typeof(bool)); sc.AddColumn("LiteralPrefix", typeof(string)); sc.AddColumn("LiteralSuffix", typeof(string)); sc.AddColumn("NativeDataType", typeof(string)); MySqlBit.SetDSInfo(sc); MySqlBinary.SetDSInfo(sc); MySqlDateTime.SetDSInfo(sc); MySqlTimeSpan.SetDSInfo(sc); MySqlString.SetDSInfo(sc); MySqlDouble.SetDSInfo(sc); MySqlSingle.SetDSInfo(sc); MySqlByte.SetDSInfo(sc); MySqlInt16.SetDSInfo(sc); MySqlInt32.SetDSInfo(sc); MySqlInt64.SetDSInfo(sc); MySqlDecimal.SetDSInfo(sc); MySqlUByte.SetDSInfo(sc); MySqlUInt16.SetDSInfo(sc); MySqlUInt32.SetDSInfo(sc); MySqlUInt64.SetDSInfo(sc); return(sc); }
public IMySqlValue GetValueObject() { IMySqlValue iMySqlValue = GetIMySqlValue(this.Type); if (((iMySqlValue is MySqlByte) && (this.ColumnLength == 1)) && ((this.MaxLength == 1) && this.connection.Settings.TreatTinyAsBoolean)) { MySqlByte num = (MySqlByte)iMySqlValue; num.TreatAsBoolean = true; return(num); } if ((this.Type == MySqlDbType.Binary) && (this.ColumnLength == 0x10)) { MySqlBinary binary = (MySqlBinary)iMySqlValue; binary.IsGuid = true; iMySqlValue = binary; } return(iMySqlValue); }
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; } else if (Type == MySqlDbType.Binary && ColumnLength == 16) { MySqlBinary b = (MySqlBinary)v; b.IsGuid = true; v = b; } return(v); }
public long GetBytes(int i, long dataIndex, byte[] buffer, int bufferIndex, int length) { if (i >= this.fields.Length) { throw new IndexOutOfRangeException(); } MySqlValue fieldValue = this.GetFieldValue(i, false); if (!(fieldValue is MySqlBinary)) { throw new MySqlException("GetBytes can only be called on binary columns"); } MySqlBinary mySqlBinary = (MySqlBinary)fieldValue; if (buffer == null) { return((long)mySqlBinary.Value.Length); } if (bufferIndex >= buffer.Length || bufferIndex < 0) { throw new IndexOutOfRangeException("Buffer index must be a valid index in buffer"); } if (buffer.Length < bufferIndex + length) { throw new ArgumentException("Buffer is not large enough to hold the requested data"); } if (dataIndex >= 0L && (dataIndex < (long)mySqlBinary.Value.Length || (long)mySqlBinary.Value.Length == 0L)) { byte[] value = mySqlBinary.Value; if ((long)mySqlBinary.Value.Length < dataIndex + (long)length) { length = (int)((long)mySqlBinary.Value.Length - dataIndex); } Array.Copy(value, (int)dataIndex, buffer, bufferIndex, length); return((long)length); } throw new IndexOutOfRangeException("Data index must be a valid index in the field"); }