public IntPtr GetValuePtr(int ordinal) { object result = DBNull.Value; TDengineMeta meta = _metas[ordinal]; int offset = IntPtr.Size * ordinal; return(Marshal.ReadIntPtr(rowdata, offset)); }
public IntPtr GetValuePtr(int ordinal) { object result = DBNull.Value; TDengineMeta meta = _metas[ordinal]; int offset = (Environment.Is64BitProcess?8:4) * ordinal; return(Marshal.ReadIntPtr(rowdata, offset)); }
/// <summary> /// Gets the data type of the specified column. /// </summary> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The data type of the column.</returns> public override Type GetFieldType(int ordinal) { if (_metas == null || ordinal >= _metas.Count) { throw new InvalidOperationException($"DataReaderClosed{nameof(GetFieldType)}"); } TDengineMeta meta = _metas[ordinal]; Type type = typeof(DBNull); switch ((TDengineDataType)meta.type) { case TDengineDataType.TSDB_DATA_TYPE_BOOL: type = typeof(bool); break; case TDengineDataType.TSDB_DATA_TYPE_TINYINT: type = typeof(byte); break; case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: type = typeof(short); break; case TDengineDataType.TSDB_DATA_TYPE_INT: type = typeof(int); break; case TDengineDataType.TSDB_DATA_TYPE_BIGINT: type = typeof(long); break; case TDengineDataType.TSDB_DATA_TYPE_FLOAT: type = typeof(float); break; case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: type = typeof(double); break; case TDengineDataType.TSDB_DATA_TYPE_BINARY: type = typeof(byte[]); break; case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: type = typeof(long); break; case TDengineDataType.TSDB_DATA_TYPE_NCHAR: type = typeof(string); break; } return(type); }
/// <summary> /// Retrieves data as a Stream. If the reader includes rowid (or any of its aliases), a /// <see cref="TaosBlob"/> is returned. Otherwise, the all of the data is read into memory and a /// <see cref="MemoryStream"/> is returned. /// </summary> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The returned object.</returns> public override Stream GetStream(int ordinal) { MemoryStream result = null; TDengineMeta meta = _metas[ordinal]; int offset = IntPtr.Size * ordinal; IntPtr data = Marshal.ReadIntPtr(rowdata, offset); if (data != IntPtr.Zero) { byte[] bf = new byte[meta.size]; Marshal.Copy(data, bf, 0, meta.size); result = new MemoryStream(bf); } return(result); }
/// <summary> /// Gets the value of the specified column. /// </summary> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The value of the column.</returns> public override object GetValue(int ordinal) { object result = DBNull.Value; TDengineMeta meta = _metas[ordinal]; int offset = IntPtr.Size * ordinal; IntPtr data = Marshal.ReadIntPtr(rowdata, offset); if (data != IntPtr.Zero) { switch ((TDengineDataType)meta.type) { case TDengineDataType.TSDB_DATA_TYPE_BOOL: bool v1 = Marshal.ReadByte(data) == 0 ? false : true; result = v1; break; case TDengineDataType.TSDB_DATA_TYPE_TINYINT: sbyte v2s = (sbyte)Marshal.ReadByte(data); result = v2s; break; case TDengineDataType.TSDB_DATA_TYPE_UTINYINT: byte v2 = Marshal.ReadByte(data); result = v2; break; case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: short v3 = Marshal.ReadInt16(data); result = v3; break; case TDengineDataType.TSDB_DATA_TYPE_USMALLINT: ushort v12 = (ushort)Marshal.ReadInt16(data); result = v12; break; case TDengineDataType.TSDB_DATA_TYPE_INT: int v4 = Marshal.ReadInt32(data); result = v4; break; case TDengineDataType.TSDB_DATA_TYPE_UINT: uint v13 = (uint)Marshal.ReadInt32(data); result = v13; break; case TDengineDataType.TSDB_DATA_TYPE_BIGINT: long v5 = Marshal.ReadInt64(data); result = v5; break; case TDengineDataType.TSDB_DATA_TYPE_UBIGINT: ulong v14 = (ulong)Marshal.ReadInt64(data); result = v14; break; case TDengineDataType.TSDB_DATA_TYPE_FLOAT: float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); result = v6; break; case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); result = v7; break; case TDengineDataType.TSDB_DATA_TYPE_BINARY: { result = Marshal.PtrToStringAnsi(data, meta.size)?.RemoveNull(); } break; case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: { result = GetDateTimeFrom(data); } break; case TDengineDataType.TSDB_DATA_TYPE_NCHAR: { string v10 = string.Empty; if (meta.size > 0) // https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos/issues/99 { byte[] bf = new byte[meta.size]; Marshal.Copy(data, bf, 0, meta.size); if (IsUTF8Bytes(bf) || (bf[0] == 0xEF && bf[1] == 0xBB && bf[2] == 0xBF)) { v10 = System.Text.Encoding.UTF8.GetString(bf)?.RemoveNull(); } else { v10 = System.Text.Encoding.GetEncoding(936).GetString(bf)?.RemoveNull(); } } result = v10; } break; } } else { result = DBNull.Value; } return(result); }
/// <summary> /// Gets the value of the specified column. /// </summary> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The value of the column.</returns> public override object GetValue(int ordinal) { object result = DBNull.Value; TDengineMeta meta = _metas[ordinal]; int offset = IntPtr.Size * ordinal; IntPtr data = Marshal.ReadIntPtr(rowdata, offset); if (data != IntPtr.Zero) { switch ((TDengineDataType)meta.type) { case TDengineDataType.TSDB_DATA_TYPE_BOOL: bool v1 = Marshal.ReadByte(data) == 0 ? false : true; result = v1; break; case TDengineDataType.TSDB_DATA_TYPE_TINYINT: byte v2 = Marshal.ReadByte(data); result = v2; break; case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: short v3 = Marshal.ReadInt16(data); result = v3; break; case TDengineDataType.TSDB_DATA_TYPE_INT: int v4 = Marshal.ReadInt32(data); result = v4; break; case TDengineDataType.TSDB_DATA_TYPE_BIGINT: long v5 = Marshal.ReadInt64(data); result = v5; break; case TDengineDataType.TSDB_DATA_TYPE_FLOAT: float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); result = v6; break; case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); result = v7; break; case TDengineDataType.TSDB_DATA_TYPE_BINARY: { byte[] buffer = new byte[meta.size]; Marshal.Copy(data, buffer, 0, meta.size); result = buffer; } break; case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: long v9 = Marshal.ReadInt64(data); result = v9; break; case TDengineDataType.TSDB_DATA_TYPE_NCHAR: string v10 = Marshal.PtrToStringAnsi(data); result = v10; break; } } else { result = DBNull.Value; } return(result); }
/// <summary> /// Gets the value of the specified column. /// </summary> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The value of the column.</returns> public override object GetValue(int ordinal) { object result = DBNull.Value; TDengineMeta meta = _metas[ordinal]; int offset = IntPtr.Size * ordinal; IntPtr data = Marshal.ReadIntPtr(rowdata, offset); if (data != IntPtr.Zero) { switch ((TDengineDataType)meta.type) { case TDengineDataType.TSDB_DATA_TYPE_BOOL: bool v1 = Marshal.ReadByte(data) == 0 ? false : true; result = v1; break; case TDengineDataType.TSDB_DATA_TYPE_TINYINT: byte v2 = Marshal.ReadByte(data); result = v2; break; case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: short v3 = Marshal.ReadInt16(data); result = v3; break; case TDengineDataType.TSDB_DATA_TYPE_INT: int v4 = Marshal.ReadInt32(data); result = v4; break; case TDengineDataType.TSDB_DATA_TYPE_BIGINT: long v5 = Marshal.ReadInt64(data); result = v5; break; case TDengineDataType.TSDB_DATA_TYPE_FLOAT: float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); result = v6; break; case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); result = v7; break; case TDengineDataType.TSDB_DATA_TYPE_BINARY: { result = Marshal.PtrToStringAnsi(data, meta.size)?.RemoveNull(); } break; case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: var v9 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(Marshal.ReadInt64(data)); result = v9.ToLocalTime(); break; case TDengineDataType.TSDB_DATA_TYPE_NCHAR: string v10 = Marshal.PtrToStringUni(data, meta.size)?.RemoveNull(); result = v10; break; } } else { result = DBNull.Value; } return(result); }