public static void ThrowExceptionForRC(IntPtr _taos) { var te = new TaosException(new TaosErrorResult() { Code = TDengine.ErrorNo(_taos), Error = TDengine.Error(_taos) }); throw te; }
/// <summary> /// Advances to the next row in the result set. /// </summary> /// <returns>true if there are more rows; otherwise, false.</returns> public override bool Read() { if (_closed) { throw new InvalidOperationException($"DataReaderClosed{nameof(Read)}"); } rowdata = TDengine.FetchRows(_taosResult); return(rowdata != IntPtr.Zero); }
internal TaosDataReader(TaosCommand taosCommand, List <TDengineMeta> metas, bool closeConnection) { _taos = taosCommand.Connection._taos; _command = taosCommand; _closeConnection = closeConnection; _fieldCount = TDengine.FieldCount(_taos); _hasRows = TDengine.AffectRows(_taos) > 0; _closed = _closeConnection; _taosResult = TDengine.UseResult(_taos); _metas = metas; }
/// <summary> /// Initializes a new instance of the <see cref="TaosConnection" /> class. /// </summary> public TaosConnection() { if (_dll_isloaded == false) { var libManager = new LibraryManager( new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("taos.dll", Binary(typeof(TaosConnection).Assembly, $"{typeof(TaosConnection).Namespace}.libs.taos_x64.dll"))), new LibraryItem(Platform.Windows, Bitness.x32, new LibraryFile("taos.dll", Binary(typeof(TaosConnection).Assembly, $"{typeof(TaosConnection).Namespace}.libs.taos_x32.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libtaos.so", Binary(typeof(TaosConnection).Assembly, $"{typeof(TaosConnection).Namespace}.libs.libtaos_x64.so")))); libManager.LoadLibraryExplicit = true; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { configDir = "/etc/taos"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { configDir = "C:/TDengine/cfg"; } if (!System.IO.Directory.Exists(configDir)) { configDir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "taos.studio"); } var cfg = new System.IO.FileInfo(System.IO.Path.Combine(configDir, "taos.cfg")); if (!cfg.Directory.Exists) { cfg.Directory.Create(); } if (!cfg.Exists) { System.IO.File.WriteAllBytes(cfg.FullName, Binary(typeof(TaosConnection).Assembly, $"{typeof(TaosConnection).Namespace}.cfg.taos.cfg")); } if ((RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.OSArchitecture == Architecture.X64) || (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X64) || (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X86)) { TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, this.configDir); TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); TDengine.Init(); Process.GetCurrentProcess().Disposed += (object sender, EventArgs e) => { TDengine.Cleanup(); }; _dll_isloaded = true; } else { throw new PlatformNotSupportedException("Only Support Linux X64 And Windows X64/X86"); } } }
internal TaosDataReader(TaosCommand taosCommand, List <TDengineMeta> metas, bool closeConnection, IntPtr res) { _taos = taosCommand.Connection._taos; _command = taosCommand; _closeConnection = closeConnection; _fieldCount = TDengine.FieldCount(res); _hasRows = TDengine.AffectRows(res) > 0; _closed = _closeConnection; _taosResult = res; _metas = metas; _dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); _date_max_1970 = DateTime.MaxValue.Subtract(_dt1970).TotalMilliseconds; }
/// <summary> /// Gets the value of the specified column as a <see cref="TimeSpan" />. /// </summary> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The value of the column.</returns> public virtual TimeSpan GetTimeSpan(int ordinal) { var val = Marshal.ReadInt64(GetValuePtr(ordinal)); var _dateTimePrecision = (TSDB_TIME_PRECISION)TDengine.ResultPrecision(_taosResult); if (_dateTimePrecision == TSDB_TIME_PRECISION.TSDB_TIME_PRECISION_MICRO) { return(TimeSpan.FromMilliseconds(val / 1000)); } else { return(TimeSpan.FromMilliseconds(val)); } }
/// <summary> /// Releases any resources used by the data reader and closes it. /// </summary> /// <param name="disposing"> /// true to release managed and unmanaged resources; false to release only unmanaged resources. /// </param> protected override void Dispose(bool disposing) { if (!disposing) { return; } _command.DataReader = null; _closed = true; if (_closeConnection) { _command.Connection.Close(); } TDengine.FreeResult(_taosResult); }
/// <summary> /// Initializes a new instance of the <see cref="TaosConnection" /> class. /// </summary> public TaosConnection() { if (_dll_isloaded == false) { var accessor = new ResourceAccessor(Assembly.GetExecutingAssembly()); var libManager = new LibraryManager( Assembly.GetExecutingAssembly(), new LibraryItem(Platform.Windows, Bitness.x64, new LibraryFile("taos.dll", accessor.Binary("libs.taos_x64.dll"))), new LibraryItem(Platform.Windows, Bitness.x32, new LibraryFile("taos.dll", accessor.Binary("libs.taos_x32.dll"))), new LibraryItem(Platform.Linux, Bitness.x64, new LibraryFile("libtaos.so", accessor.Binary("libs.libtaos_x64.so")))); libManager.LoadNativeLibrary(false); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { configDir = "/etc/taos"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { configDir = "C:/TDengine/cfg"; } var cfg = new System.IO.FileInfo(System.IO.Path.Combine(configDir, "taos.cfg")); if (!cfg.Directory.Exists) { cfg.Directory.Create(); } if (!cfg.Exists) { System.IO.File.WriteAllBytes(cfg.FullName, accessor.Binary("cfg.taos.cfg")); } if ((RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.OSArchitecture == Architecture.X64) || (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X64) || (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X86)) { TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, this.configDir); TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); TDengine.Init(); _dll_isloaded = true; } else { throw new PlatformNotSupportedException("Only Support Linux X64 And Windows X64/X86"); } } }
private DateTime GetDateTimeFrom(IntPtr data) { var val = Marshal.ReadInt64(data); double tsp; var _dateTimePrecision = (TSDB_TIME_PRECISION)TDengine.ResultPrecision(_taosResult); if (_dateTimePrecision == TSDB_TIME_PRECISION.TSDB_TIME_PRECISION_MICRO) { tsp = (val / 1000); } else { tsp = val; } if (tsp > _date_max_1970) { //fix https://github.com/taosdata/TDengine/issues/3270 tsp /= 1000; } var v9 = _dt1970.AddMilliseconds(tsp); return(v9.ToLocalTime()); }