├── src ├── resource │ └── logo.jpg ├── TMQ │ ├── MessageComponentType.cs │ ├── IHeader.cs │ ├── IDeserializer.cs │ ├── Header.cs │ ├── SerializationContext.cs │ ├── DictionaryDeserializer.cs │ ├── ITMQRows.cs │ ├── IConsumer.cs │ ├── ReferenceDeserializer.cs │ ├── ConsumerBuilder.cs │ ├── WebSocket │ │ └── TMQWSRows.cs │ ├── Headers.cs │ ├── ConsumeResult.cs │ └── Native │ │ └── TMQNativeRows.cs ├── Driver │ ├── Impl │ │ └── WebSocketMethods │ │ │ ├── Protocol │ │ │ ├── WSVersionReq.cs │ │ │ ├── WSTMQCommitReq.cs │ │ │ ├── WSTMQListTopicsReq.cs │ │ │ ├── WSTMQUnsubscribeReq.cs │ │ │ ├── WSFetchReq.cs │ │ │ ├── WSQueryReq.cs │ │ │ ├── WSStmt2ExecReq.cs │ │ │ ├── WSStmt2CloseReq.cs │ │ │ ├── WSFetchBlockReq.cs │ │ │ ├── WSFreeResultReq.cs │ │ │ ├── WSStmt2UseResultReq.cs │ │ │ ├── WSTMQFetchReq.cs │ │ │ ├── WSTMQTopicVgroupId.cs │ │ │ ├── WSTMQFetchBlockReq.cs │ │ │ ├── WSTMQGetTopicAssignmentReq.cs │ │ │ ├── WSTMQCommittedReq.cs │ │ │ ├── WSTMQPollReq.cs │ │ │ ├── WSTMQPositionReq.cs │ │ │ ├── WSStmt2InitReq.cs │ │ │ ├── WSStmt2PrepareReq.cs │ │ │ ├── WSTMQOffsetSeekReq.cs │ │ │ ├── WSTMQCommitOffsetReq.cs │ │ │ ├── WSSchemalessReq.cs │ │ │ ├── WSConnResp.cs │ │ │ ├── WSSchemalessResp.cs │ │ │ ├── WSTMQUnsubscribeResp.cs │ │ │ ├── WSTMQOffsetSeekResp.cs │ │ │ ├── WSTMQSubscribeResp.cs │ │ │ ├── WSConnReq.cs │ │ │ ├── WSStmt2BindResp.cs │ │ │ ├── WSStmt2InitResp.cs │ │ │ ├── WSTMQCommitResp.cs │ │ │ ├── WSVersionResp.cs │ │ │ ├── WSTMQPositionResp.cs │ │ │ ├── WSTMQCommittedResp.cs │ │ │ ├── WSTMQListTopicsResp.cs │ │ │ ├── IWSResultResp.cs │ │ │ ├── WSTMQCommitOffsetResp.cs │ │ │ ├── WSStmt2ExecResp.cs │ │ │ ├── WSFetchResp.cs │ │ │ ├── WSBaseResp.cs │ │ │ ├── WSTMQGetTopicAssignmentResp.cs │ │ │ ├── WSTMQPollResp.cs │ │ │ ├── WSStmt2UseResultResp.cs │ │ │ ├── WSTMQFetchResp.cs │ │ │ ├── WSQueryResp.cs │ │ │ ├── WSStmt2PrepareResp.cs │ │ │ └── WSTMQSubscribeReq.cs │ │ │ └── Schemaless.cs │ ├── Client │ │ ├── DbDriver.cs │ │ ├── AbstractStmtResult.cs │ │ ├── AbstractStmtAddBatch.cs │ │ ├── AbstractStmtTableName.cs │ │ └── Native │ │ │ └── NativeRows.cs │ ├── ITDengineClient.cs │ ├── IRows.cs │ ├── TDengineError.cs │ ├── TDengineVersion.cs │ └── ReqId.cs ├── Data │ └── Client │ │ ├── TDengineConnectionStringBuilder.cs │ │ └── TDengineFactory.cs └── TDengine.csproj ├── .github └── workflows │ ├── taos.cfg │ └── taosadapter.toml ├── examples ├── WindowsFormsApp4.8 │ ├── App.config │ ├── Properties │ │ ├── Settings.settings │ │ ├── AssemblyInfo.cs │ │ ├── Settings.Designer.cs │ │ └── Resources.Designer.cs │ ├── Program.cs │ └── Form1.cs ├── WSADO │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── WSADO.csproj ├── WSSeek │ ├── Properties │ │ └── AssemblyInfo.cs │ └── WSSeek.csproj ├── WSStmt │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── WSStmt.csproj ├── WSQuery │ ├── Properties │ │ └── AssemblyInfo.cs │ └── WSQuery.csproj ├── NativeADO │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── NativeADO.csproj ├── NativeSeek │ ├── Properties │ │ └── AssemblyInfo.cs │ └── NativeSeek.csproj ├── NativeStmt │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── NativeStmt.csproj ├── AllTypeStmt │ ├── Properties │ │ └── AssemblyInfo.cs │ └── AllTypeStmt.csproj ├── NativeQuery │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── NativeQuery.csproj │ └── Query.cs ├── AllTypeQuery │ ├── Properties │ │ └── AssemblyInfo.cs │ └── AllTypeQuery.csproj ├── WSSchemaless │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── WSSchemaless.csproj ├── WSSubscription │ ├── Properties │ │ └── AssemblyInfo.cs │ └── WSSubscription.csproj ├── NativeSchemaless │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Program.cs │ └── NativeSchemaless.csproj ├── WSQueryWithReqID │ ├── Properties │ │ └── AssemblyInfo.cs │ └── WSQueryWithReqID.csproj ├── NativeSubscription │ ├── Properties │ │ └── AssemblyInfo.cs │ └── NativeSubscription.csproj ├── NativeQueryWithReqID │ ├── Properties │ │ └── AssemblyInfo.cs │ └── NativeQueryWithReqID.csproj ├── WSObjectDeserialize │ ├── Properties │ │ └── AssemblyInfo.cs │ └── WSObjectDeserialize.csproj └── NativeObjectDeserialize │ ├── Properties │ └── AssemblyInfo.cs │ └── NativeObjectDeserialize.csproj ├── test ├── Driver.Test │ ├── lib │ │ ├── TestExeOrder.cs │ │ ├── DatabaseCollection.cs │ │ ├── ResultSetUtils.cs │ │ └── TestExeOrderer.cs │ ├── Client │ │ ├── TMQ │ │ │ ├── Cloud.cs │ │ │ └── Native.cs │ │ ├── Query │ │ │ └── MockStmt.cs │ │ ├── Version │ │ │ └── TDengineVersionTests.cs │ │ └── Tools │ │ │ └── TaosAdapterTools.cs │ ├── Function.Test │ │ └── Reqid.cs │ └── Driver.Test.csproj ├── Benchmark │ ├── Benchmark.csproj │ ├── Connect.cs │ ├── CleanUp.cs │ ├── Aggregate.cs │ └── run_bench.sh └── Data.Tests │ ├── TDengineErrorTests.cs │ ├── Data.Tests.csproj │ ├── TDengineFactoryTests.cs │ └── TDengineParameterCollectionTests.cs ├── LICENSE └── .gitignore /src/resource/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taosdata/taos-connector-dotnet/HEAD/src/resource/logo.jpg -------------------------------------------------------------------------------- /.github/workflows/taos.cfg: -------------------------------------------------------------------------------- 1 | fqdn localhost 2 | firstEp localhost:6030 3 | asyncLog 0 4 | debugFlag 143 5 | supportVnodes 256 -------------------------------------------------------------------------------- /src/TMQ/MessageComponentType.cs: -------------------------------------------------------------------------------- 1 | namespace TDengine.TMQ 2 | { 3 | public enum MessageComponentType 4 | { 5 | Key = 1, 6 | Value = 2, 7 | } 8 | } -------------------------------------------------------------------------------- /src/TMQ/IHeader.cs: -------------------------------------------------------------------------------- 1 | namespace TDengine.TMQ 2 | { 3 | public interface IHeader 4 | { 5 | string Key { get; } 6 | byte[] GetValueBytes(); 7 | } 8 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSVersionReq.cs: -------------------------------------------------------------------------------- 1 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 2 | { 3 | public class WSVersionReq 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /src/TMQ/IDeserializer.cs: -------------------------------------------------------------------------------- 1 | namespace TDengine.TMQ 2 | { 3 | public interface IDeserializer 4 | { 5 | T Deserialize(ITMQRows data, bool isNull, SerializationContext context); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/WindowsFormsApp4.8/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQCommitReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQCommitReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQListTopicsReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQListTopicsReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQUnsubscribeReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQUnsubscribeReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /examples/WindowsFormsApp4.8/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSFetchReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSFetchReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("id")] public ulong ResultId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSQueryReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSQueryReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("sql")] public string Sql { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2ExecReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2ExecReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2CloseReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2CloseReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSFetchBlockReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSFetchBlockReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("id")] public ulong ResultId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSFreeResultReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSFreeResultReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("id")] public ulong ResultId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2UseResultReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2UseResultReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQFetchReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQFetchReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("message_id")] public ulong MessageId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQTopicVgroupId.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTopicVgroupId 6 | { 7 | [JsonProperty("topic")] public string Topic { get; set; } 8 | 9 | [JsonProperty("vgroup_id")] public int VGroupId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQFetchBlockReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQFetchBlockReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("message_id")] public ulong MessageId { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /test/Driver.Test/lib/TestExeOrder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Test.Case.Attributes 4 | { 5 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 6 | public class TestExeOrderAttribute : Attribute 7 | { 8 | public int ExeOrder { get; private set; } 9 | 10 | public TestExeOrderAttribute(int exeOrder) => ExeOrder = exeOrder; 11 | } 12 | } -------------------------------------------------------------------------------- /src/Data/Client/TDengineConnectionStringBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using TDengine.Driver; 3 | 4 | namespace TDengine.Data.Client 5 | { 6 | public class TDengineConnectionStringBuilder : ConnectionStringBuilder 7 | { 8 | public TDengineConnectionStringBuilder(string connectionString) : base(connectionString) 9 | { 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQGetTopicAssignmentReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQGetTopicAssignmentReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("topic")] public string Topic { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /test/Driver.Test/lib/DatabaseCollection.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using Test.Fixture; 3 | [CollectionDefinition("Database collection")] 4 | public class DatabaseCollection : ICollectionFixture 5 | { 6 | // This class has no code, and is never created. Its purpose is simply 7 | // to be the place to apply [CollectionDefinition] and all the 8 | // ICollectionFixture<> interfaces. 9 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQCommittedReq.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQCommittedReq 7 | { 8 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 9 | 10 | [JsonProperty("topic_vgroup_ids")] public List TopicVgroupIds { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /test/Benchmark/Benchmark.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Exe 9 | 10 | net5;net6;net7;net8;net9;net46;netcoreapp3.1 11 | NETSDK1138 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQPollReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQPollReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("blocking_time")] public long BlockingTime { get; set; } 10 | 11 | [JsonProperty("message_id")] public ulong MessageId { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQPositionReq.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQPositionReq 7 | { 8 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 9 | 10 | [JsonProperty("topic_vgroup_ids")] public List TopicVgroupIds { get; set; } 11 | } 12 | 13 | 14 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2InitReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2InitReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | [JsonProperty("single_stb_insert")] public bool SingleStbInsert { get; set; } 9 | 10 | [JsonProperty("single_table_bind_once")] 11 | public bool SingleTableBindOnce { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2PrepareReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2PrepareReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 10 | 11 | [JsonProperty("sql")] public string SQL { get; set; } 12 | 13 | [JsonProperty("get_fields")] public bool GetFields { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQOffsetSeekReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQOffsetSeekReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("topic")] public string Topic { get; set; } 10 | 11 | [JsonProperty("vgroup_id")] public int VGroupId { get; set; } 12 | 13 | [JsonProperty("offset")] public long Offset { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQCommitOffsetReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQCommitOffsetReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("topic")] public string Topic { get; set; } 10 | 11 | [JsonProperty("vgroup_id")] public int VGroupId { get; set; } 12 | 13 | [JsonProperty("offset")] public long Offset { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/Driver/Client/DbDriver.cs: -------------------------------------------------------------------------------- 1 | using TDengine.Driver.Client.Native; 2 | using TDengine.Driver.Client.Websocket; 3 | 4 | namespace TDengine.Driver.Client 5 | { 6 | public static class DbDriver 7 | { 8 | public static ITDengineClient Open(ConnectionStringBuilder builder) 9 | { 10 | if (builder.Protocol == TDengineConstant.ProtocolWebSocket) 11 | { 12 | return new WSClient(builder); 13 | } 14 | return new NativeClient(builder); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSSchemalessReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSSchemalessReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | 9 | [JsonProperty("protocol")] public int Protocol { get; set; } 10 | 11 | [JsonProperty("precision")] public string Precision { get; set; } 12 | 13 | [JsonProperty("ttl")] public int TTL { get; set; } 14 | 15 | [JsonProperty("data")] public string Data { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSConnResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSConnResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSSchemalessResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSSchemalessResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 12 | 13 | [JsonProperty("action")] public string Action { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQUnsubscribeResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQUnsubscribeResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | [JsonProperty("message")] public string Message { get; set; } 9 | 10 | [JsonProperty("action")] public string Action { get; set; } 11 | 12 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 13 | 14 | [JsonProperty("timing")] public long Timing { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQOffsetSeekResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQOffsetSeekResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQSubscribeResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQSubscribeResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSConnReq.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSConnReq 6 | { 7 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 8 | [JsonProperty("user")] public string User { get; set; } 9 | [JsonProperty("password")] public string Password { get; set; } 10 | [JsonProperty("db")] public string Db { get; set; } 11 | [JsonProperty("tz")] public string Timezone { get; set; } 12 | [JsonProperty("app")] public string App { get; set; } 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /examples/WindowsFormsApp4.8/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace WindowsFormsApp4._8 8 | { 9 | internal static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2BindResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2BindResp:IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2InitResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2InitResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/TMQ/Header.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.TMQ 4 | { 5 | public class Header : IHeader 6 | { 7 | private byte[] val; 8 | 9 | public string Key { get; private set; } 10 | 11 | public byte[] GetValueBytes() 12 | { 13 | return val; 14 | } 15 | 16 | public Header(string key, byte[] value) 17 | { 18 | if (key == null) 19 | { 20 | throw new ArgumentNullException("tmq message header key cannot be null."); 21 | } 22 | 23 | Key = key; 24 | val = value; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/TMQ/SerializationContext.cs: -------------------------------------------------------------------------------- 1 | namespace TDengine.TMQ 2 | { 3 | public class SerializationContext 4 | { 5 | public static SerializationContext Empty 6 | => default(SerializationContext); 7 | public SerializationContext(MessageComponentType component, string topic, Headers headers = null) 8 | { 9 | Component = component; 10 | Topic = topic; 11 | Headers = headers; 12 | } 13 | public string Topic { get; private set; } 14 | public MessageComponentType Component { get; private set; } 15 | 16 | public Headers Headers { get; private set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQCommitResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQCommitResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | [JsonProperty("message")] public string Message { get; set; } 9 | 10 | [JsonProperty("action")] public string Action { get; set; } 11 | 12 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 13 | 14 | [JsonProperty("timing")] public long Timing { get; set; } 15 | 16 | [JsonProperty("message_id")] public ulong MessageId { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSVersionResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSVersionResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("version")] public string Version { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQPositionResp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQPositionResp : IWSBaseResp 7 | { 8 | [JsonProperty("code")] public int Code { get; set; } 9 | 10 | [JsonProperty("message")] public string Message { get; set; } 11 | 12 | [JsonProperty("action")] public string Action { get; set; } 13 | 14 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 15 | 16 | [JsonProperty("timing")] public long Timing { get; set; } 17 | 18 | [JsonProperty("position")] public List Position { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQCommittedResp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQCommittedResp : IWSBaseResp 7 | { 8 | [JsonProperty("code")] public int Code { get; set; } 9 | 10 | [JsonProperty("message")] public string Message { get; set; } 11 | 12 | [JsonProperty("action")] public string Action { get; set; } 13 | 14 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 15 | 16 | [JsonProperty("timing")] public long Timing { get; set; } 17 | 18 | [JsonProperty("committed")] public List Committed { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQListTopicsResp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQListTopicsResp : IWSBaseResp 7 | { 8 | [JsonProperty("code")] public int Code { get; set; } 9 | 10 | [JsonProperty("message")] public string Message { get; set; } 11 | 12 | [JsonProperty("action")] public string Action { get; set; } 13 | 14 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 15 | 16 | [JsonProperty("timing")] public long Timing { get; set; } 17 | 18 | [JsonProperty("topics")] public List Topics { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/IWSResultResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public interface IWSMetaResp 6 | { 7 | [JsonProperty("fields_count")] int FieldsCount { get; set; } 8 | 9 | [JsonProperty("fields_names")] string[] FieldsNames { get; set; } 10 | 11 | [JsonProperty("fields_types")] byte[] FieldsTypes { get; set; } 12 | 13 | [JsonProperty("fields_lengths")] long[] FieldsLengths { get; set; } 14 | 15 | [JsonProperty("precision")] int Precision { get; set; } 16 | 17 | [JsonProperty("fields_precisions")] byte[] FieldsPrecisions { get; set; } 18 | 19 | [JsonProperty("fields_scales")] byte[] FieldsScales { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /test/Data.Tests/TDengineErrorTests.cs: -------------------------------------------------------------------------------- 1 | using TDengine.Data.Client; 2 | using TDengine.Driver; 3 | using Xunit; 4 | 5 | namespace Data.Tests 6 | { 7 | public class TDengineErrorTests 8 | { 9 | [Fact] 10 | public void TDengineError_Initialization() 11 | { 12 | // Arrange 13 | int expectedCode = 123; 14 | string expectedError = "Some error message"; 15 | 16 | // Act 17 | TDengineError error = new TDengineError(expectedCode, expectedError); 18 | 19 | // Assert 20 | Assert.Equal(expectedCode, error.Code); 21 | Assert.Equal(expectedError, error.Error); 22 | Assert.Equal($"code:[0x{expectedCode:x}],error:{expectedError}", error.Message); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/Data/Client/TDengineFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | 3 | namespace TDengine.Data.Client 4 | { 5 | public class TDengineFactory:DbProviderFactory 6 | { 7 | public override DbCommand CreateCommand() 8 | { 9 | return new TDengineCommand(); 10 | } 11 | 12 | public override DbConnection CreateConnection() 13 | { 14 | return new TDengineConnection(string.Empty); 15 | } 16 | 17 | public override DbConnectionStringBuilder CreateConnectionStringBuilder() 18 | { 19 | return new TDengineConnectionStringBuilder(string.Empty); 20 | } 21 | 22 | public override DbParameter CreateParameter() 23 | { 24 | return new TDengineParameter(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /test/Driver.Test/Client/TMQ/Cloud.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TDengine.Driver.Impl.WebSocketMethods; 4 | using Xunit; 5 | 6 | namespace Driver.Test.Client.TMQ 7 | { 8 | public partial class Consumer 9 | { 10 | [Fact] 11 | public void CloudConsumerTest() 12 | { 13 | var db = "cs_test"; 14 | var topic = "cs_tmq_test_decimal_topic"; 15 | if (string.IsNullOrEmpty(this._cloudConnectString) || this._cloudTMQCfg == null) 16 | { 17 | _output.WriteLine("Cloud connection string is not set. Skipping CloudConsumerTest."); 18 | return; 19 | } 20 | 21 | this.NewConsumerTest(this._cloudConnectString, db, topic, this._cloudTMQCfg); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/Driver/Client/AbstractStmtResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.Driver.Client 4 | { 5 | public abstract partial class AbstractStmt 6 | { 7 | public long Affected() 8 | { 9 | return _affectedRows; 10 | } 11 | 12 | public IRows Result() 13 | { 14 | if (!_executed) 15 | { 16 | throw new InvalidOperationException("Statement has not been executed yet."); 17 | } 18 | 19 | if (_isInsert) 20 | { 21 | return InsertResultInternal(_affectedRows); 22 | } 23 | 24 | return QueryResultInternal(); 25 | } 26 | 27 | protected abstract IRows QueryResultInternal(); 28 | protected abstract IRows InsertResultInternal(int affectedRows); 29 | } 30 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQCommitOffsetResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQCommitOffsetResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("topic")] public string Topic { get; set; } 18 | 19 | [JsonProperty("vgroup_id")] public int VGroupId { get; set; } 20 | 21 | [JsonProperty("offset")] public long Offset { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /test/Driver.Test/lib/ResultSetUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TDengine.Driver; 4 | using TDengine.Driver.Impl; 5 | using NativeMethods = TDengine.Driver.Impl.NativeMethods.NativeMethods; 6 | 7 | namespace Test.Utils.ResultSet 8 | { 9 | public class ResultSet 10 | { 11 | internal List ResultMeta { get; set; } 12 | internal List ResultData { get; set; } 13 | public ResultSet(IntPtr res) 14 | { 15 | 16 | ResultMeta = NativeMethods.FetchFields(res); 17 | ResultData = Tools.GetData(res); 18 | NativeMethods.FreeResult(res); 19 | } 20 | 21 | public ResultSet(List meta, List data) 22 | { 23 | ResultMeta = meta; 24 | ResultData = data; 25 | } 26 | 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2ExecResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using TDengine.Driver.Impl.WebSocketMethods.Protocol; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods 5 | { 6 | public class WSStmt2ExecResp:IWSBaseResp 7 | { 8 | [JsonProperty("code")] 9 | public int Code { get; set; } 10 | 11 | [JsonProperty("message")] 12 | public string Message { get; set; } 13 | 14 | [JsonProperty("action")] 15 | public string Action { get; set; } 16 | 17 | [JsonProperty("req_id")] 18 | public ulong ReqId { get; set; } 19 | 20 | [JsonProperty("timing")] 21 | public long Timing { get; set; } 22 | 23 | [JsonProperty("stmt_id")] 24 | public ulong StmtId { get; set; } 25 | 26 | [JsonProperty("affected")] 27 | public int Affected { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /src/TMQ/DictionaryDeserializer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TDengine.Driver; 3 | using TDengine.TMQ; 4 | 5 | namespace TDengineHelper 6 | { 7 | public class DictionaryDeserializer : IDeserializer> 8 | { 9 | public static IDeserializer> Dictionary = new DictionaryDeserializer(); 10 | public Dictionary Deserialize(ITMQRows result, bool isNull, SerializationContext context) 11 | { 12 | if (isNull) return null; 13 | 14 | var obj = new Dictionary(); 15 | for (int col = 0; col < result.FieldCount; col++) 16 | { 17 | var name = result.GetName(col); 18 | obj[name] = result.GetValue(col); 19 | } 20 | return obj; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Schemaless.cs: -------------------------------------------------------------------------------- 1 | using TDengine.Driver.Impl.WebSocketMethods.Protocol; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods 4 | { 5 | public partial class Connection 6 | { 7 | public WSSchemalessResp SchemalessInsert(string lines, TDengineSchemalessProtocol protocol, 8 | TDengineSchemalessPrecision precision, 9 | int ttl, long reqId) 10 | { 11 | var uReqId = (ulong)reqId; 12 | return SendJsonBackJson(WSAction.SchemalessWrite, new WSSchemalessReq 13 | { 14 | ReqId = uReqId, 15 | Protocol = (int)protocol, 16 | Precision = TDengineConstant.SchemalessPrecisionString(precision), 17 | TTL = ttl, 18 | Data = lines, 19 | },uReqId); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSFetchResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSFetchResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("id")] public ulong ResultId { get; set; } 18 | 19 | [JsonProperty("completed")] public bool Completed { get; set; } 20 | 21 | [JsonProperty("lengths")] public int[] Lengths { get; set; } 22 | 23 | [JsonProperty("rows")] public int Rows { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /src/TMQ/ITMQRows.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.TMQ 4 | { 5 | public interface ITMQRows 6 | { 7 | object GetValue(int ordinal); 8 | bool Read(); 9 | bool IsDBNull(int ordinal); 10 | 11 | int FieldCount { get; } 12 | string TableName { get; } 13 | string GetName(int ordinal); 14 | 15 | byte GetByte(int ordinal); 16 | short GetInt16(int ordinal); 17 | int GetInt32(int ordinal); 18 | long GetInt64(int ordinal); 19 | bool GetBoolean(int ordinal); 20 | 21 | DateTime GetDateTime(int ordinal); 22 | 23 | decimal GetDecimal(int ordinal); 24 | 25 | double GetDouble(int ordinal); 26 | 27 | float GetFloat(int ordinal); 28 | 29 | string GetString(int ordinal); 30 | 31 | DateTimeOffset GetDateTimeOffset(int ordinal); 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSBaseResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public interface IWSBaseResp 6 | { 7 | [JsonProperty("code")] int Code { get; set; } 8 | 9 | [JsonProperty("message")] string Message { get; set; } 10 | 11 | [JsonProperty("action")] string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] long Timing { get; set; } 16 | } 17 | 18 | public class WSBaseResp : IWSBaseResp 19 | { 20 | [JsonProperty("code")] public int Code { get; set; } 21 | 22 | [JsonProperty("message")] public string Message { get; set; } 23 | 24 | [JsonProperty("action")] public string Action { get; set; } 25 | 26 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 27 | 28 | [JsonProperty("timing")] public long Timing { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 taosdata.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQGetTopicAssignmentResp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQGetTopicAssignmentResp:IWSBaseResp 7 | { 8 | [JsonProperty("code")] public int Code { get; set; } 9 | 10 | [JsonProperty("message")] public string Message { get; set; } 11 | 12 | [JsonProperty("action")] public string Action { get; set; } 13 | 14 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 15 | 16 | [JsonProperty("timing")] public long Timing { get; set; } 17 | 18 | [JsonProperty("assignment")] public List Assignment { get; set; } 19 | } 20 | 21 | public class WSTMQAssignment 22 | { 23 | [JsonProperty("vgroup_id")] public int VGroupId { get; set; } 24 | 25 | [JsonProperty("offset")] public long Offset { get; set; } 26 | 27 | [JsonProperty("begin")] public long Begin { get; set; } 28 | 29 | [JsonProperty("end")] public long End { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | test/Driver.Test/bin/ 2 | test/Driver.Test/obj/ 3 | test/Driver.Test/doc/ 4 | test/Driver.Test/TestResults/ 5 | test/Benchmark/bin/ 6 | test/Benchmark/obj/ 7 | test/Benchmark/result/ 8 | test/Benchmark/Benchmark.csproj.user 9 | test/Benchmark/Properties/ 10 | testEnvironments.json 11 | coveragereport/ 12 | src/bin/ 13 | src/obj/ 14 | NugetPackTest/ 15 | examples/bin/ 16 | examples/obj/ 17 | examples/FrameWork45/Properties/ 18 | examples/FrameWork45/bin/ 19 | examples/FrameWork45/obj/ 20 | examples/NET6Examples/Properties/ 21 | examples/NET6Examples/bin/ 22 | examples/NET6Examples/obj/ 23 | examples/Properties/ 24 | examples/FrameWork45/FrameWork45.csproj.user 25 | .vs 26 | .idea 27 | .config/ 28 | # User-specific files 29 | *.rsuser 30 | *.suo 31 | *.user 32 | *.userosscache 33 | *.sln.docstates 34 | 35 | # User-specific files (MonoDevelop/Xamarin Studio) 36 | *.userprefs 37 | 38 | # Mono auto generated files 39 | mono_crash.* 40 | 41 | # Build results 42 | [Dd]ebug/ 43 | [Dd]ebugPublic/ 44 | [Rr]elease/ 45 | [Rr]eleases/ 46 | x64/ 47 | x86/ 48 | [Ww][Ii][Nn]32/ 49 | [Aa][Rr][Mm]/ 50 | [Aa][Rr][Mm]64/ 51 | bld/ 52 | [Bb]in/ 53 | [Oo]bj/ 54 | [Ll]og/ 55 | [Ll]ogs/ 56 | -------------------------------------------------------------------------------- /examples/WindowsFormsApp4.8/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("WindowsFormsApp4.8")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WindowsFormsApp4.8")] 13 | [assembly: AssemblyCopyright("Copyright © 2024")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("3002b815-ebd4-446d-b572-7212849eff61")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Driver/ITDengineClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.Driver 4 | { 5 | public interface ITDengineClient : IDisposable 6 | { 7 | IStmt StmtInit(); 8 | IStmt StmtInit(long reqId); 9 | IRows Query(string query); 10 | IRows Query(string query, long reqId); 11 | long Exec(string query); 12 | long Exec(string query, long reqId); 13 | 14 | void SchemalessInsert(string[] lines, TDengineSchemalessProtocol protocol, 15 | TDengineSchemalessPrecision precision, int ttl, long reqId); 16 | 17 | bool ConnectionAvailable(); 18 | } 19 | 20 | public interface IStmt : IDisposable 21 | { 22 | void Prepare(string query); 23 | bool IsInsert(); 24 | void SetTableName(string tableName); 25 | void SetTags(object[] tags); 26 | TaosFieldE[] GetTagFields(); 27 | TaosFieldE[] GetColFields(); 28 | void BindRow(object[] row); 29 | void BindColumn( TaosFieldE[] _,params Array[] arrays); 30 | void AddBatch(); 31 | void Exec(); 32 | long Affected(); 33 | IRows Result(); 34 | } 35 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQPollResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSTMQPollResp : IWSBaseResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("have_message")] public bool HaveMessage { get; set; } 18 | 19 | [JsonProperty("topic")] public string Topic { get; set; } 20 | 21 | [JsonProperty("database")] public string Database { get; set; } 22 | 23 | [JsonProperty("vgroup_id")] public int VgroupId { get; set; } 24 | 25 | [JsonProperty("message_type")] public int MessageType { get; set; } 26 | 27 | [JsonProperty("message_id")] public ulong MessageId { get; set; } 28 | 29 | [JsonProperty("offset")] public long Offset { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /src/TMQ/IConsumer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace TDengine.TMQ 5 | { 6 | public interface IConsumer 7 | { 8 | ConsumeResult Consume(int millisecondsTimeout); 9 | 10 | List Assignment { get; } 11 | 12 | List Subscription(); 13 | 14 | void Subscribe(IEnumerable topic); 15 | 16 | void Subscribe(string topic); 17 | 18 | /// 19 | /// Unsubscribe from current subscription 20 | /// 21 | void Unsubscribe(); 22 | 23 | //commit 24 | void Commit(ConsumeResult consumerResult); 25 | 26 | List Commit(); 27 | 28 | void Commit(IEnumerable offsets); 29 | 30 | void Seek(TopicPartitionOffset tpo); 31 | 32 | List Committed(TimeSpan timeout); 33 | 34 | List Committed(IEnumerable partitions, TimeSpan timeout); 35 | 36 | Offset Position(TopicPartition partition); 37 | 38 | void Close(); 39 | } 40 | } -------------------------------------------------------------------------------- /examples/WindowsFormsApp4.8/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WindowsFormsApp4._8.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/Benchmark/Connect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Driver; 3 | using NativeMethods = TDengine.Driver.Impl.NativeMethods.NativeMethods; 4 | 5 | namespace Benchmark 6 | { 7 | internal class Connect 8 | { 9 | string Host { get; set; } 10 | ushort Port { get; set; } 11 | string Username { get; set; } 12 | string Password { get; set; } 13 | string db = "benchmark"; 14 | 15 | public Connect(string host, string userName, string passwd, ushort port) 16 | { 17 | Host = host; 18 | Username = userName; 19 | Password = passwd; 20 | Port = port; 21 | } 22 | public void Run(int times) 23 | { 24 | Console.WriteLine("Connection ... "); 25 | int i = 0; 26 | while (i < times) 27 | { 28 | IntPtr conn = NativeMethods.Connect(Host, Username, Password, db, Port); 29 | if (conn != IntPtr.Zero) 30 | { 31 | NativeMethods.Close(conn); 32 | } 33 | else 34 | { 35 | throw new Exception("create TD connection failed"); 36 | } 37 | i++; 38 | } 39 | Console.WriteLine(" time:{0} done ...", i); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/Data.Tests/Data.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5;net6;net7;net8;net9;net46;netcoreapp3.1 5 | NETSDK1138 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | all 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2UseResultResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSStmt2UseResultResp:IWSBaseResp, IWSMetaResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 18 | 19 | [JsonProperty("id")] public ulong ResultId { get; set; } 20 | 21 | [JsonProperty("fields_count")] public int FieldsCount { get; set; } 22 | 23 | [JsonProperty("fields_names")] public string[] FieldsNames { get; set; } 24 | 25 | [JsonProperty("fields_types")] public byte[] FieldsTypes { get; set; } 26 | 27 | [JsonProperty("fields_lengths")] public long[] FieldsLengths { get; set; } 28 | 29 | [JsonProperty("precision")] public int Precision { get; set; } 30 | 31 | [JsonProperty("fields_precisions")] public byte[] FieldsPrecisions { get; set; } 32 | 33 | [JsonProperty("fields_scales")] public byte[] FieldsScales { get; set; } 34 | } 35 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQFetchResp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQFetchResp : IWSBaseResp 7 | { 8 | [JsonProperty("code")] public int Code { get; set; } 9 | 10 | [JsonProperty("message")] public string Message { get; set; } 11 | 12 | [JsonProperty("action")] public string Action { get; set; } 13 | 14 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 15 | 16 | [JsonProperty("timing")] public long Timing { get; set; } 17 | 18 | [JsonProperty("message_id")] public ulong MessageId { get; set; } 19 | 20 | [JsonProperty("completed")] public bool Completed { get; set; } 21 | 22 | [JsonProperty("table_name")] public string TableName { get; set; } 23 | 24 | [JsonProperty("rows")] public int Rows { get; set; } 25 | 26 | [JsonProperty("fields_count")] public int FieldsCount { get; set; } 27 | 28 | [JsonProperty("fields_names")] public List FieldsNames { get; set; } 29 | 30 | [JsonProperty("fields_types")] public List FieldsTypes { get; set; } 31 | 32 | [JsonProperty("fields_lengths")] public List FieldsLengths { get; set; } 33 | 34 | [JsonProperty("precision")] public int Precision { get; set; } 35 | } 36 | } -------------------------------------------------------------------------------- /src/TMQ/ReferenceDeserializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TDengine.Driver; 4 | 5 | namespace TDengine.TMQ 6 | { 7 | public class ReferenceDeserializer : IDeserializer where T : class 8 | { 9 | public T Deserialize(ITMQRows result, bool isNull, SerializationContext context) 10 | { 11 | if (isNull) return null; 12 | 13 | var obj = Activator.CreateInstance(); 14 | for (int col = 0; col < result.FieldCount; col++) 15 | { 16 | var name = result.GetName(col); 17 | var type = typeof(T); 18 | var property = type.GetProperty(name); 19 | if (property != null && property.CanWrite) 20 | { 21 | var value = result.GetValue(col); 22 | try 23 | { 24 | property.SetValue(obj, value); 25 | } 26 | catch (Exception e) 27 | { 28 | var exception = new Exception( 29 | $"Failed to set property {name} of type {property.PropertyType} with value {value} value type {value.GetType()}", 30 | e); 31 | throw exception; 32 | } 33 | } 34 | } 35 | 36 | return obj; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSQueryResp.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 4 | { 5 | public class WSQueryResp : IWSBaseResp, IWSMetaResp 6 | { 7 | [JsonProperty("code")] public int Code { get; set; } 8 | 9 | [JsonProperty("message")] public string Message { get; set; } 10 | 11 | [JsonProperty("action")] public string Action { get; set; } 12 | 13 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 14 | 15 | [JsonProperty("timing")] public long Timing { get; set; } 16 | 17 | [JsonProperty("id")] public ulong ResultId { get; set; } 18 | 19 | [JsonProperty("is_update")] public bool IsUpdate { get; set; } 20 | 21 | [JsonProperty("affected_rows")] public int AffectedRows { get; set; } 22 | 23 | [JsonProperty("fields_count")] public int FieldsCount { get; set; } 24 | 25 | [JsonProperty("fields_names")] public string[] FieldsNames { get; set; } 26 | 27 | [JsonProperty("fields_types")] public byte[] FieldsTypes { get; set; } 28 | 29 | [JsonProperty("fields_lengths")] public long[] FieldsLengths { get; set; } 30 | 31 | [JsonProperty("precision")] public int Precision { get; set; } 32 | 33 | [JsonProperty("fields_precisions")] public byte[] FieldsPrecisions { get; set; } 34 | 35 | [JsonProperty("fields_scales")] public byte[] FieldsScales { get; set; } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSStmt2PrepareResp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSStmt2PrepareResp:IWSBaseResp 7 | { 8 | [JsonProperty("code")] public int Code { get; set; } 9 | 10 | [JsonProperty("message")] public string Message { get; set; } 11 | 12 | [JsonProperty("action")] public string Action { get; set; } 13 | 14 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 15 | 16 | [JsonProperty("timing")] public long Timing { get; set; } 17 | 18 | [JsonProperty("stmt_id")] public ulong StmtId { get; set; } 19 | 20 | [JsonProperty("is_insert")] public bool IsInsert { get; set; } 21 | 22 | [JsonProperty("fields")] public List Fields { get; set; } 23 | 24 | [JsonProperty("fields_count")] public int FieldsCount { get; set; } 25 | } 26 | 27 | public class Stmt2AllField 28 | { 29 | [JsonProperty("name")] public string Name { get; set; } 30 | 31 | [JsonProperty("field_type")] public sbyte FieldType { get; set; } 32 | 33 | [JsonProperty("precision")] public byte Precision { get; set; } 34 | 35 | [JsonProperty("scale")] public byte Scale { get; set; } 36 | 37 | [JsonProperty("bytes")] public int Bytes { get; set; } 38 | 39 | [JsonProperty("bind_type")] public byte BindType { get; set; } 40 | } 41 | } -------------------------------------------------------------------------------- /src/TDengine.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5;net6;net7;net8;net9;netstandard2.0;netstandard2.1;net45;net451; 5 | TDengine.Connector 6 | image\logo.jpg 7 | docs\README.md 8 | 3.1.9 9 | taosdata 10 | https://tdengine.com/ 11 | MIT 12 | Taos;Data;Microsoft.NET.Sdk;IOT;bigdata;TDengine;taosdata 13 | 14 | The official TDengine C# connector. 15 | 16 | https://docs.tdengine.com/client-libraries/csharp/ 17 | https://github.com/taosdata/taos-connector-dotnet.git 18 | git 19 | "3.0" 20 | CS1591;NETSDK1138 21 | 22 | true 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/WSADO/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSADO")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSADO")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("15661804-01BB-4F4B-AD37-3B21234A5325")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/WSSeek/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSSeek")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSSeek")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("E945F882-95E1-4CE2-B689-6B859126ACD3")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/WSStmt/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSStmt")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSStmt")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("54F4CCBA-58EE-45D6-802A-4A6C0E55D144")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/WSQuery/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSQuery")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSQuery")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("18396378-750F-4053-8583-19DDE669BDDA")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /src/Driver/IRows.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.Driver 4 | { 5 | public interface IRows : IDisposable 6 | { 7 | bool HasRows { get; } 8 | int AffectRows { get; } 9 | int FieldCount { get; } 10 | long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length); 11 | char GetChar(int ordinal); 12 | long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length); 13 | string GetDataTypeName(int ordinal); 14 | object GetValue(int ordinal); 15 | Type GetFieldType(int ordinal); 16 | int GetFieldSize(int ordinal); 17 | string GetName(int ordinal); 18 | 19 | int GetFieldPrecision(int ordinal); 20 | 21 | int GetFieldScale(int ordinal); 22 | 23 | int GetOrdinal(string name); 24 | bool Read(); 25 | 26 | bool IsDBNull(int ordinal); 27 | 28 | byte GetByte(int ordinal); 29 | short GetInt16(int ordinal); 30 | int GetInt32(int ordinal); 31 | long GetInt64(int ordinal); 32 | bool GetBoolean(int ordinal); 33 | 34 | DateTime GetDateTime(int ordinal); 35 | 36 | decimal GetDecimal(int ordinal); 37 | 38 | double GetDouble(int ordinal); 39 | 40 | float GetFloat(int ordinal); 41 | 42 | string GetString(int ordinal); 43 | 44 | int GetValues(object[] values); 45 | 46 | DateTimeOffset GetDateTimeOffset(int ordinal); 47 | } 48 | } -------------------------------------------------------------------------------- /examples/NativeADO/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeADO")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeADO")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("A2877121-FFAD-4839-8BC2-982178A4E68C")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/NativeSeek/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeSeek")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeSeek")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("59F8A094-A796-4394-943B-FEAEAF4FB895")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/NativeStmt/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeStmt")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeStmt")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("549645EF-6041-41A5-A59C-79B79F104DCE")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/AllTypeStmt/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("AllTypeStmt")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("AllTypeStmt")] 12 | [assembly: AssemblyCopyright("Copyright © 2024")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("2FAFA322-4007-4ACC-95DB-5BAEAB3D0A5F")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/NativeQuery/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeQuery")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeQuery")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("EDAE50A9-7CB8-4683-8630-BC016C524410")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/AllTypeQuery/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("AllTypeQuery")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("AllTypeQuery")] 12 | [assembly: AssemblyCopyright("Copyright © 2024")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("5B2928A5-2688-4506-BFFB-3453C8E71861")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/WSSchemaless/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSSchemaless")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSSchemaless")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("DB996903-9121-4A35-B994-9AA8ED475E47")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/WSSubscription/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSSubscription")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSSubscription")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("AD0D5FE4-75A5-40C3-8E2D-9254679D135B")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/NativeSchemaless/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeSchemaless")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeSchemaless")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("66E42B31-B8C2-42A4-93E5-44640200C42C")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/WSQueryWithReqID/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSQueryWithReqID")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSQueryWithReqID")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("D321601E-1DC4-4628-8BE4-9DD05233D60B")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/NativeSubscription/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeSubscription")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeSubscription")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("A6650070-BF1A-4EFC-B344-E35D115AEA13")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/NativeQueryWithReqID/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeQueryWithReqID")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeQueryWithReqID")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("412BDD41-0BDA-4E70-9F5C-D53943927FF0")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/WSObjectDeserialize/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("WSObjectDeserialize")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("WSObjectDeserialize")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("BE6ADFD4-DE57-4F98-8656-F710ED6D7A04")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /examples/NativeObjectDeserialize/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("NativeObjectDeserialize")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("NativeObjectDeserialize")] 12 | [assembly: AssemblyCopyright("Copyright © 2023")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("2A03E53A-8999-4FAB-A32E-ECB9BEC0C82A")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /test/Driver.Test/Function.Test/Reqid.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | using TDengine.Driver; 4 | using Xunit; 5 | 6 | namespace Driver.Test.Function.Test 7 | { 8 | public class Reqid 9 | { 10 | [Fact] 11 | public void MurmurHash32_ReturnsExpectedHash() 12 | { 13 | // Arrange 14 | byte[] data = Encoding.UTF8.GetBytes("driver-go"); 15 | uint seed = 0; 16 | 17 | // Act 18 | uint hash = ReqId.MurmurHash32(data, seed); 19 | 20 | // Assert 21 | uint expectedHash = 3037880692; 22 | Assert.Equal(expectedHash, hash); 23 | } 24 | 25 | [Fact] 26 | public void GetReqId() 27 | { 28 | var reqId = ReqId.GetReqId(); 29 | var reqId2 = ReqId.GetReqId(); 30 | 31 | Assert.NotEqual(0, reqId); 32 | Assert.Equal((reqId+1) & 0xfffff,(reqId2) & 0xfffff); 33 | if (reqId2 != reqId+1) 34 | { 35 | Assert.Equal(((reqId>> 20) & 0x3ffffff)+1, (reqId2 >> 20) & 0x3ffffff); 36 | } 37 | 38 | var cont = 1000000; 39 | var reqIds = new Dictionary(); 40 | for (int i = 0; i < cont; i++) 41 | { 42 | var id = ReqId.GetReqId(); 43 | Assert.NotEqual(0, id); 44 | Assert.False(reqIds.ContainsKey(id), $"Duplicate ReqId found: {id}"); 45 | reqIds[id] = true; 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /test/Driver.Test/Driver.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5;net6;net7;net8;net9;net46;netcoreapp3.1 5 | 6 | 7 | CS1591;CS0168;NETSDK1138 8 | false 9 | true 10 | .\doc\Test.XML 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | all 23 | 24 | 25 | runtime; build; native; contentfiles; analyzers; buildtransitive 26 | all 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/NativeStmt/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Driver; 3 | using TDengine.Driver.Client; 4 | 5 | namespace NativeStmt 6 | { 7 | internal abstract class NativeStmt 8 | { 9 | public static void Main(string[] args) 10 | { 11 | var builder = new ConnectionStringBuilder("host=localhost;port=6030;username=root;password=taosdata"); 12 | using (var client = DbDriver.Open(builder)) 13 | { 14 | try 15 | { 16 | client.Exec($"create database power"); 17 | client.Exec( 18 | "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))"); 19 | using (var stmt = client.StmtInit()) 20 | { 21 | stmt.Prepare( 22 | "Insert into power.d1001 using power.meters tags(2,'California.SanFrancisco') values(?,?,?,?)"); 23 | var ts = DateTime.Now; 24 | stmt.BindRow(new object[] { ts, (float)10.30000, (int)219, (float)0.31000 }); 25 | stmt.AddBatch(); 26 | stmt.Exec(); 27 | var affected = stmt.Affected(); 28 | Console.WriteLine($"affected rows: {affected}"); 29 | } 30 | } 31 | catch (Exception e) 32 | { 33 | Console.WriteLine(e); 34 | throw; 35 | } 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/Driver/Impl/WebSocketMethods/Protocol/WSTMQSubscribeReq.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Newtonsoft.Json; 3 | 4 | namespace TDengine.Driver.Impl.WebSocketMethods.Protocol 5 | { 6 | public class WSTMQSubscribeReq 7 | { 8 | [JsonProperty("req_id")] public ulong ReqId { get; set; } 9 | 10 | [JsonProperty("user")] public string User { get; set; } 11 | 12 | [JsonProperty("password")] public string Password { get; set; } 13 | 14 | [JsonProperty("db")] public string Db { get; set; } 15 | 16 | [JsonProperty("group_id")] public string GroupId { get; set; } 17 | 18 | [JsonProperty("client_id")] public string ClientId { get; set; } 19 | 20 | [JsonProperty("offset_rest")] public string OffsetRest { get; set; } 21 | 22 | [JsonProperty("topics")] public List Topics { get; set; } 23 | 24 | [JsonProperty("auto_commit")] public string AutoCommit { get; set; } 25 | 26 | [JsonProperty("auto_commit_interval_ms")] 27 | public string AutoCommitIntervalMs { get; set; } 28 | 29 | [JsonProperty("snapshot_enable")] public string SnapshotEnable { get; set; } 30 | 31 | [JsonProperty("with_table_name")] public string WithTableName { get; set; } 32 | 33 | //session_timeout_ms 34 | [JsonProperty("session_timeout_ms")] public string SessionTimeoutMs { get; set; } 35 | 36 | //max_poll_interval_ms 37 | [JsonProperty("max_poll_interval_ms")] public string MaxPollIntervalMs { get; set; } 38 | 39 | // other config 40 | [JsonProperty("config")] public Dictionary Config { get; set; } 41 | } 42 | } -------------------------------------------------------------------------------- /examples/WSStmt/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Driver; 3 | using TDengine.Driver.Client; 4 | 5 | namespace WSStmt 6 | { 7 | internal abstract class WSStmt 8 | { 9 | public static void Main(string[] args) 10 | { 11 | var builder = 12 | new ConnectionStringBuilder( 13 | "protocol=WebSocket;host=localhost;port=6041;useSSL=false;username=root;password=taosdata"); 14 | using (var client = DbDriver.Open(builder)) 15 | { 16 | try 17 | { 18 | client.Exec($"create database power"); 19 | client.Exec( 20 | "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))"); 21 | using (var stmt = client.StmtInit()) 22 | { 23 | stmt.Prepare( 24 | "Insert into power.d1001 using power.meters tags(2,'California.SanFrancisco') values(?,?,?,?)"); 25 | var ts = DateTime.Now; 26 | stmt.BindRow(new object[] { ts, (float)10.30000, (int)219, (float)0.31000 }); 27 | stmt.AddBatch(); 28 | stmt.Exec(); 29 | var affected = stmt.Affected(); 30 | Console.WriteLine($"affected rows: {affected}"); 31 | } 32 | } 33 | catch (Exception e) 34 | { 35 | Console.WriteLine(e); 36 | throw; 37 | } 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /test/Benchmark/CleanUp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Driver; 3 | using NativeMethods = TDengine.Driver.Impl.NativeMethods.NativeMethods; 4 | 5 | namespace Benchmark 6 | { 7 | internal class CleanUp 8 | { 9 | string Host { get; set; } 10 | ushort Port { get; set; } 11 | string Username { get; set; } 12 | string Password { get; set; } 13 | string dropDb = $"drop database if exists benchmark"; 14 | 15 | public CleanUp(string host, string userName, string passwd, ushort port) 16 | { 17 | Host = host; 18 | Username = userName; 19 | Password = passwd; 20 | Port = port; 21 | } 22 | public void Run() 23 | { 24 | //Console.WriteLine("cleanup ..."); 25 | 26 | IntPtr conn = NativeMethods.Connect(Host, Username, Password, "", Port); 27 | IntPtr res; 28 | if (conn != IntPtr.Zero) 29 | { 30 | res = NativeMethods.Query(conn, dropDb); 31 | IfTaosQuerySucc(res, dropDb); 32 | NativeMethods.FreeResult(res); 33 | } 34 | else 35 | { 36 | throw new Exception("create TD connection failed"); 37 | } 38 | NativeMethods.Close(conn); 39 | } 40 | 41 | public bool IfTaosQuerySucc(IntPtr res, string sql) 42 | { 43 | if (NativeMethods.ErrorNo(res) == 0) 44 | { 45 | return true; 46 | } 47 | else 48 | { 49 | throw new Exception($"execute {sql} failed,reason {NativeMethods.Error(res)}, code{NativeMethods.ErrorNo(res)}"); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/NativeSchemaless/Program.cs: -------------------------------------------------------------------------------- 1 | using TDengine.Driver; 2 | using TDengine.Driver.Client; 3 | 4 | namespace NativeSchemaless 5 | { 6 | internal class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | var builder = 11 | new ConnectionStringBuilder("host=localhost;port=6030;username=root;password=taosdata"); 12 | using (var client = DbDriver.Open(builder)) 13 | { 14 | client.Exec("create database sml"); 15 | client.Exec("use sml"); 16 | var influxDBData = 17 | "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000"; 18 | client.SchemalessInsert(new string[] { influxDBData }, 19 | TDengineSchemalessProtocol.TSDB_SML_LINE_PROTOCOL, 20 | TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NANO_SECONDS, 0, ReqId.GetReqId()); 21 | var telnetData = "stb0_0 1626006833 4 host=host0 interface=eth0"; 22 | client.SchemalessInsert(new string[] { telnetData }, 23 | TDengineSchemalessProtocol.TSDB_SML_TELNET_PROTOCOL, 24 | TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_MILLI_SECONDS, 0, ReqId.GetReqId()); 25 | var jsonData = 26 | "{\"metric\": \"meter_current\",\"timestamp\": 1626846400,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"California.SanFrancisco\", \"id\": \"d1001\"}}"; 27 | client.SchemalessInsert(new string[] { jsonData }, TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL, 28 | TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_MILLI_SECONDS, 0, ReqId.GetReqId()); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/TMQ/ConsumerBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TDengine.Driver; 4 | 5 | namespace TDengine.TMQ 6 | { 7 | public class ConsumerBuilder 8 | { 9 | protected internal IEnumerable> Config { get; set; } 10 | 11 | protected internal IDeserializer ValueDeserializer { get; set; } 12 | 13 | 14 | 15 | public ConsumerBuilder SetValueDeserializer(IDeserializer deserializer) 16 | { 17 | if (this.ValueDeserializer != null) 18 | { 19 | throw new InvalidOperationException("Value deserializer may not be specified more than once."); 20 | } 21 | this.ValueDeserializer = deserializer; 22 | return this; 23 | } 24 | 25 | public IConsumer Build() 26 | { 27 | var connectType = TDengineConstant.ProtocolNative; 28 | foreach (var kv in Config) 29 | { 30 | if (kv.Key == "td.connect.type") 31 | { 32 | connectType = kv.Value; 33 | } 34 | } 35 | 36 | switch (connectType) 37 | { 38 | case TDengineConstant.ProtocolWebSocket: 39 | return new WebSocket.Consumer(this); 40 | case TDengineConstant.ProtocolNative: 41 | return new Native.Consumer(this); 42 | default: 43 | throw new ArgumentException($"Unsupported connect type: {connectType}"); 44 | } 45 | } 46 | 47 | public ConsumerBuilder(IEnumerable> config) 48 | { 49 | Config = config; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /examples/WSSchemaless/Program.cs: -------------------------------------------------------------------------------- 1 | using TDengine.Driver; 2 | using TDengine.Driver.Client; 3 | 4 | namespace WSSchemaless 5 | { 6 | internal class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | var builder = 11 | new ConnectionStringBuilder("protocol=WebSocket;host=localhost;port=6041;useSSL=false;username=root;password=taosdata"); 12 | using (var client = DbDriver.Open(builder)) 13 | { 14 | client.Exec("create database sml"); 15 | client.Exec("use sml"); 16 | var influxDBData = 17 | "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000"; 18 | client.SchemalessInsert(new string[] { influxDBData }, 19 | TDengineSchemalessProtocol.TSDB_SML_LINE_PROTOCOL, 20 | TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NANO_SECONDS, 0, ReqId.GetReqId()); 21 | var telnetData = "stb0_0 1626006833 4 host=host0 interface=eth0"; 22 | client.SchemalessInsert(new string[] { telnetData }, 23 | TDengineSchemalessProtocol.TSDB_SML_TELNET_PROTOCOL, 24 | TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_MILLI_SECONDS, 0, ReqId.GetReqId()); 25 | var jsonData = 26 | "{\"metric\": \"meter_current\",\"timestamp\": 1626846400,\"value\": 10.3, \"tags\": {\"groupid\": 2, \"location\": \"California.SanFrancisco\", \"id\": \"d1001\"}}"; 27 | client.SchemalessInsert(new string[] { jsonData }, TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL, 28 | TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_MILLI_SECONDS, 0, ReqId.GetReqId()); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /test/Driver.Test/Client/Query/MockStmt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Driver; 3 | using TDengine.Driver.Client; 4 | 5 | namespace Driver.Test.Client.Query 6 | { 7 | public class MockStmt:AbstractStmt 8 | { 9 | public delegate void PrepareAction(string query, out bool isInsert, out int count, out TaosFieldAll[] fields); 10 | private readonly PrepareAction _prepareAction; 11 | public delegate void BindBinaryAction(byte[] data, out int affectedRows); 12 | private readonly BindBinaryAction _bindBinaryAction; 13 | public MockStmt(PrepareAction prepare, BindBinaryAction bind):base(0) 14 | { 15 | _prepareAction = prepare; 16 | _bindBinaryAction = bind; 17 | } 18 | 19 | protected override void BindBinaryInternal(byte[] data, out int affectedRows) 20 | { 21 | _bindBinaryAction(data, out affectedRows); 22 | } 23 | 24 | protected override void PrepareInternal(string query, out bool isInsert, out int count, out TaosFieldAll[] fields) 25 | { 26 | _prepareAction(query, out isInsert, out count, out fields); 27 | } 28 | 29 | public override void Dispose() 30 | { 31 | } 32 | 33 | protected override bool IsConnectionAvailable(Exception exception) 34 | { 35 | return true; 36 | } 37 | 38 | protected override void ReconnectInternal() 39 | { 40 | } 41 | 42 | protected override bool AutoReconnectInternal() 43 | { 44 | return false; 45 | } 46 | 47 | protected override IRows QueryResultInternal() 48 | { 49 | return null; 50 | } 51 | 52 | protected override IRows InsertResultInternal(int affectedRows) 53 | { 54 | return null; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /test/Data.Tests/TDengineFactoryTests.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using TDengine.Data.Client; 3 | 4 | namespace Data.Tests 5 | { 6 | public class TDengineFactoryTests 7 | { 8 | [Fact] 9 | public void CreateCommand_ShouldReturnInstanceOfTDengineCommand() 10 | { 11 | // Arrange 12 | var factory = new TDengineFactory(); 13 | 14 | // Act 15 | var command = factory.CreateCommand(); 16 | 17 | // Assert 18 | Assert.IsType(command); 19 | } 20 | 21 | [Fact] 22 | public void CreateConnection_ShouldReturnInstanceOfTDengineConnection() 23 | { 24 | // Arrange 25 | var factory = new TDengineFactory(); 26 | 27 | // Act 28 | var connection = factory.CreateConnection(); 29 | 30 | // Assert 31 | Assert.IsType(connection); 32 | } 33 | 34 | [Fact] 35 | public void CreateConnectionStringBuilder_ShouldReturnInstanceOfTDengineConnectionStringBuilder() 36 | { 37 | // Arrange 38 | var factory = new TDengineFactory(); 39 | 40 | // Act 41 | var connectionStringBuilder = factory.CreateConnectionStringBuilder(); 42 | 43 | // Assert 44 | Assert.IsType(connectionStringBuilder); 45 | } 46 | 47 | [Fact] 48 | public void CreateParameter_ShouldReturnInstanceOfTDengineParameter() 49 | { 50 | // Arrange 51 | var factory = new TDengineFactory(); 52 | 53 | // Act 54 | var parameter = factory.CreateParameter(); 55 | 56 | // Assert 57 | Assert.IsType(parameter); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /test/Driver.Test/Client/Version/TDengineVersionTests.cs: -------------------------------------------------------------------------------- 1 | using TDengine.Driver; 2 | using Xunit; 3 | 4 | namespace Driver.Test.Client.Version 5 | { 6 | public class TDengineVersionTests 7 | { 8 | [Theory] 9 | [InlineData("3.3.6.3", 3, 3, 6, 3)] 10 | [InlineData("3.3.2.0", 3, 3, 2, 0)] 11 | [InlineData("3.3.6.3.alpha", 3, 3, 6, 3)] 12 | public void ParseVersion_ValidVersion_ReturnsVersion(string input, int major, int minor, int build, 13 | int revision) 14 | { 15 | var version = TDengineVersion.ParseVersion(input); 16 | Assert.Equal(new System.Version(major, minor, build, revision), version); 17 | } 18 | 19 | [Theory] 20 | [InlineData("")] 21 | [InlineData(null)] 22 | [InlineData("3.3")] 23 | [InlineData("3.3.6")] 24 | [InlineData("abc.def.ghi.jkl")] 25 | public void ParseVersion_InvalidVersion_ThrowsUnknownVersionException(string input) 26 | { 27 | Assert.Throws(() => TDengineVersion.ParseVersion(input)); 28 | } 29 | 30 | [Fact] 31 | public void CheckVersionCompatibility_VersionTooLow_ThrowsVersionMismatchException() 32 | { 33 | Assert.Throws(() => TDengineVersion.CheckVersionCompatibility("3.3.1.0")); 34 | Assert.Throws(() => TDengineVersion.CheckVersionCompatibility("3.3.2.0")); 35 | } 36 | 37 | [Fact] 38 | public void CheckVersionCompatibility_VersionEqualOrHigher_NoException() 39 | { 40 | TDengineVersion.CheckVersionCompatibility("3.3.6.0"); 41 | TDengineVersion.CheckVersionCompatibility("3.3.6.3"); 42 | TDengineVersion.CheckVersionCompatibility("3.3.10.0"); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /test/Data.Tests/TDengineParameterCollectionTests.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using TDengine.Data.Client; 3 | 4 | namespace Data.Tests 5 | { 6 | public class TDengineParameterCollectionTests 7 | { 8 | [Fact] 9 | public void Add_AddsParameterToCollection() 10 | { 11 | var collection = new TDengineParameterCollection(); 12 | var parameter = new TDengineParameter("@param1", 10); 13 | 14 | var index = collection.Add(parameter); 15 | 16 | Assert.Equal(0, index); 17 | Assert.Equal(1, collection.Count); 18 | Assert.Equal(parameter, collection[0]); 19 | } 20 | 21 | [Fact] 22 | public void Clear_RemovesAllParametersFromCollection() 23 | { 24 | var collection = new TDengineParameterCollection(); 25 | collection.Add(new TDengineParameter("@param1", 10)); 26 | collection.Add(new TDengineParameter("@2", "test")); 27 | 28 | collection.Clear(); 29 | 30 | Assert.Equal(0, collection.Count); 31 | } 32 | 33 | [Fact] 34 | public void Contains_ReturnsTrueIfParameterExistsInCollection() 35 | { 36 | var collection = new TDengineParameterCollection(); 37 | var parameter = new TDengineParameter("@param1", 10); 38 | collection.Add(parameter); 39 | 40 | var containsParameter = collection.Contains(parameter); 41 | 42 | Assert.True(containsParameter); 43 | } 44 | 45 | [Fact] 46 | public void Contains_ReturnsFalseIfParameterDoesNotExistInCollection() 47 | { 48 | var collection = new TDengineParameterCollection(); 49 | var parameter = new TDengineParameter("@param1", 10); 50 | 51 | var containsParameter = collection.Contains(parameter); 52 | 53 | Assert.False(containsParameter); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /examples/WindowsFormsApp4.8/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Windows.Forms; 5 | using TDengine.Driver; 6 | using TDengine.Driver.Client; 7 | 8 | namespace WindowsFormsApp4._8 9 | { 10 | public partial class Form1 : Form 11 | { 12 | public Form1() 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | private ITDengineClient client; 18 | 19 | private void Close(object sender, EventArgs e) 20 | { 21 | if (client != null) 22 | { 23 | client.Dispose(); 24 | } 25 | MessageBox.Show("closed"); 26 | button_show.Enabled = false; 27 | button_connect.Enabled = true; 28 | button_close.Enabled = false; 29 | } 30 | 31 | private void ShowDatabase(object sender, EventArgs e) 32 | { 33 | var query = "show databases"; 34 | var rowData = new List(); 35 | using (var rows = client.Query(query)) 36 | { 37 | while (rows.Read()) 38 | { 39 | for (int i = 0; i < rows.FieldCount; i++) 40 | { 41 | rowData.Add(Encoding.UTF8.GetString((byte[])rows.GetValue(i))); 42 | } 43 | } 44 | } 45 | 46 | MessageBox.Show(string.Join("\n", rowData)); 47 | } 48 | 49 | private void Connect(object sender, EventArgs e) 50 | { 51 | var builder = new ConnectionStringBuilder( 52 | "protocol=WebSocket;host=localhost;port=6041;useSSL=false;username=root;password=taosdata"); 53 | client = DbDriver.Open(builder); 54 | MessageBox.Show("connected"); 55 | button_show.Enabled = true; 56 | button_connect.Enabled = false; 57 | button_close.Enabled = true; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/Driver/Client/AbstractStmtAddBatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.Driver.Client 4 | { 5 | public abstract partial class AbstractStmt 6 | { 7 | public void AddBatch() 8 | { 9 | // check if the statement is prepared 10 | CheckPrepared(); 11 | // check if the table name is set if required 12 | if (_needTableName && !IsTableNameSet) 13 | { 14 | throw new InvalidOperationException("Table name must be set before adding a batch."); 15 | } 16 | 17 | // check if tags are set if required 18 | if (NeedTags && !IsTagsSet) 19 | { 20 | throw new InvalidOperationException("Tags must be set before adding a batch."); 21 | } 22 | 23 | // check if columns are set 24 | if (!IsColSet) 25 | { 26 | throw new InvalidOperationException("Columns must be set before adding a batch."); 27 | } 28 | 29 | // check row count 30 | 31 | var rowCount = _currentTableInfo.Cols[0].Count; 32 | for (var i = 0; i < _currentTableInfo.Cols.Length; i++) 33 | { 34 | if (_currentTableInfo.Cols[i].Count == 0) 35 | { 36 | throw new InvalidOperationException($"Column at index {i} has no rows to add."); 37 | } 38 | 39 | if (_currentTableInfo.Cols[i].Count != rowCount) 40 | { 41 | throw new InvalidOperationException( 42 | $"Column at index {i} has a different row count than the first column. Expected {rowCount}, but got {_currentTableInfo.Cols[i].Count}."); 43 | } 44 | } 45 | 46 | // cache to dictionary 47 | _tableInfos[_currentTableInfo.TableName] = _currentTableInfo; 48 | // reset the current table info 49 | 50 | _addBatched = true; 51 | CleanBatch(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /test/Driver.Test/lib/TestExeOrderer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Xunit.Abstractions; 4 | using Xunit.Sdk; 5 | using Test.Case.Attributes; 6 | 7 | namespace XUnit.Case.Orderers 8 | { 9 | public class TestExeOrderer : ITestCaseOrderer 10 | { 11 | public IEnumerable OrderTestCases( 12 | IEnumerable testCases) where TTestCase : ITestCase 13 | { 14 | var assemblyQualifiedName = typeof(TestExeOrderAttribute).AssemblyQualifiedName; 15 | if (assemblyQualifiedName != null) 16 | { 17 | string assemblyName = assemblyQualifiedName; 18 | var sortedMethods = new SortedDictionary>(); 19 | foreach (TTestCase testCase in testCases) 20 | { 21 | int exeOrder = testCase.TestMethod.Method 22 | .GetCustomAttributes(assemblyName) 23 | .FirstOrDefault() 24 | ?.GetNamedArgument(nameof(TestExeOrderAttribute.ExeOrder)) ?? 0; 25 | 26 | GetOrCreate(sortedMethods, exeOrder).Add(testCase); 27 | } 28 | 29 | foreach (TTestCase testCase in 30 | sortedMethods.Keys.SelectMany(exeOrder => 31 | sortedMethods[exeOrder].OrderBy(testCase => testCase.TestMethod.Method.Name))) 32 | { 33 | yield return testCase; 34 | } 35 | } 36 | } 37 | 38 | private static TValue GetOrCreate( 39 | IDictionary dictionary, TKey key) 40 | where TKey : struct 41 | where TValue : new() 42 | { 43 | if (dictionary.TryGetValue(key, out var result)) 44 | { 45 | return result; 46 | } 47 | 48 | result = new TValue(); 49 | dictionary[key] = result; 50 | return result; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/Driver/TDengineError.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.Driver 4 | { 5 | public class TDengineError : Exception 6 | { 7 | public int Code { get; } 8 | public string Error { get; } 9 | 10 | public byte[] ExtendedErrorBytes { get; } 11 | public string ExtendedErrorString { get; } 12 | 13 | public enum InternalErrorCode 14 | { 15 | WS_RECONNECT_FAILED = 0xf001, 16 | WS_UNEXPECTED_MESSAGE = 0xf002, 17 | WS_CONNECTION_CLOSED = 0xf003, 18 | WS_WRITE_TIMEOUT = 0xf004, 19 | WS_CONNEC_FAILED = 0xf005, 20 | WS_RECEIVE_CLOSE_FRAME = 0xf006, 21 | } 22 | 23 | public TDengineError(int code, string error) : base($"code:[0x{(code & 0xffff):x}],error:{error}") 24 | { 25 | Code = code & 0xffff; 26 | Error = error; 27 | } 28 | 29 | public TDengineError(int code, string error, byte[] extendedErrorBytes, string extendedErrorString) : base( 30 | $"code:[0x{(code & 0xffff):x}],error:{error},extendedBytes:{Format(extendedErrorBytes)},extendedString:{extendedErrorString}") 31 | { 32 | Code = code & 0xffff; 33 | Error = error; 34 | ExtendedErrorBytes = extendedErrorBytes; 35 | ExtendedErrorString = extendedErrorString; 36 | } 37 | 38 | public TDengineError(int code, string error, string extendedErrorString) : base( 39 | $"code:[0x{(code & 0xffff):x}],error:{error},extendedString:{extendedErrorString}") 40 | { 41 | Code = code & 0xffff; 42 | Error = error; 43 | ExtendedErrorString = extendedErrorString; 44 | } 45 | 46 | private static string Format(byte[] extendedError) 47 | { 48 | string hexString = ""; 49 | for (int i = 0; i < extendedError.Length; i++) 50 | { 51 | hexString += $"0x{extendedError[i]:X2},"; 52 | } 53 | 54 | return hexString; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/TMQ/WebSocket/TMQWSRows.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TDengine.Driver; 4 | using TDengine.Driver.Impl.WebSocketMethods; 5 | using TDengine.Driver.Impl.WebSocketMethods.Protocol; 6 | 7 | namespace TDengine.TMQ.WebSocket 8 | { 9 | public class TMQWSRows : AbstractRows 10 | { 11 | private readonly TMQConnection _connection; 12 | private readonly ulong _resultId; 13 | 14 | public TMQWSRows(WSTMQPollResp result, TMQConnection connection, TimeZoneInfo tz):base(24,38,tz) 15 | { 16 | _connection = connection; 17 | _resultId = result.MessageId; 18 | } 19 | 20 | protected override void FetchBlock() 21 | { 22 | if (Block == null) 23 | { 24 | var fetchRawResp = _connection.FetchRawBlock(_resultId); 25 | Block = fetchRawResp; 26 | BlockInfo = TmqBlockReader.Parse(Block); 27 | BlockIndex = 0; 28 | } 29 | else 30 | { 31 | BlockIndex += 1; 32 | } 33 | 34 | if (BlockIndex == BlockInfo.Length) 35 | { 36 | Completed = true; 37 | return; 38 | } 39 | 40 | BlockReader.SetTMQBlock(Block, BlockInfo[BlockIndex].precision, BlockInfo[BlockIndex].rawBlockOffset); 41 | BlockRows = BlockReader.GetRows(); 42 | CurrentRow = 0; 43 | 44 | FieldCount = BlockInfo[BlockIndex].schemas.Length; 45 | TableName = BlockInfo[BlockIndex].tableName; 46 | Metas = new List(); 47 | for (int i = 0; i < FieldCount; i++) 48 | { 49 | Metas.Add(new TDengineMeta 50 | { 51 | name = BlockInfo[BlockIndex].schemas[i].name, 52 | type = BlockInfo[BlockIndex].schemas[i].colType, 53 | size = BlockInfo[BlockIndex].schemas[i].bytes, 54 | }); 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/TMQ/Headers.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace TDengine.TMQ 5 | { 6 | public class Headers : IEnumerable 7 | { 8 | private readonly List headers = new List(); 9 | 10 | public IReadOnlyList BackingList => headers; 11 | 12 | public void Add(string key, byte[] val) 13 | { 14 | if (key == null) 15 | { 16 | throw new System.ArgumentNullException("tmq message header key cannot be null."); 17 | } 18 | 19 | headers.Add(new Header(key, val)); 20 | } 21 | 22 | internal class HeadersEnumerator : IEnumerator 23 | { 24 | private Headers headers; 25 | 26 | private int location = -1; 27 | 28 | public HeadersEnumerator(Headers headers) 29 | { 30 | this.headers = headers; 31 | } 32 | 33 | public object Current 34 | => ((IEnumerator)this).Current; 35 | 36 | IHeader IEnumerator.Current 37 | => headers.headers[location]; 38 | 39 | public void Dispose() {} 40 | 41 | public bool MoveNext() 42 | { 43 | location += 1; 44 | if (location >= headers.headers.Count) 45 | { 46 | return false; 47 | } 48 | 49 | return true; 50 | } 51 | 52 | public void Reset() 53 | { 54 | this.location = -1; 55 | } 56 | } 57 | 58 | public IEnumerator GetEnumerator() 59 | => new HeadersEnumerator(this); 60 | 61 | IEnumerator IEnumerable.GetEnumerator() 62 | => new HeadersEnumerator(this); 63 | 64 | public IHeader this[int index] 65 | => headers[index]; 66 | 67 | public int Count 68 | => headers.Count; 69 | } 70 | } -------------------------------------------------------------------------------- /src/Driver/TDengineVersion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.Driver 4 | { 5 | public class TDengineVersion 6 | { 7 | private static Version MinimumVersion { get; set; } = new Version(3, 3, 6, 0); 8 | 9 | public static Version ParseVersion(string version) 10 | { 11 | if (string.IsNullOrEmpty(version)) 12 | { 13 | throw new UnknownVersionException(version); 14 | } 15 | 16 | var parts = version.Split('.'); 17 | if (parts.Length < 4) 18 | { 19 | throw new UnknownVersionException(version); 20 | } 21 | 22 | version = string.Join(".", parts[0], parts[1], parts[2], parts[3]); 23 | if (!Version.TryParse(version, out var parsedVersion)) 24 | { 25 | throw new UnknownVersionException(version); 26 | } 27 | 28 | return parsedVersion; 29 | } 30 | 31 | public static void CheckVersionCompatibility(string ver) 32 | { 33 | var currentVersion = ParseVersion(ver); 34 | if (currentVersion < MinimumVersion) 35 | { 36 | throw new VersionMismatchException( 37 | currentVersion.ToString(), 38 | MinimumVersion.ToString()); 39 | } 40 | } 41 | } 42 | 43 | public class UnknownVersionException : Exception 44 | { 45 | public string Version { get; } 46 | 47 | public UnknownVersionException(string version) 48 | : base($"Unknown TDengine version: {version}") 49 | { 50 | Version = version; 51 | } 52 | } 53 | 54 | public class VersionMismatchException : Exception 55 | { 56 | public string CurrentVersion { get; } 57 | public string MinimumVersion { get; } 58 | 59 | public VersionMismatchException(string currentVersion, string minimumVersion) 60 | : base($"Version mismatch. The minimum required TDengine version is {minimumVersion}.") 61 | { 62 | CurrentVersion = currentVersion; 63 | MinimumVersion = minimumVersion; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/Driver/Client/AbstractStmtTableName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TDengine.Driver.Client 4 | { 5 | public abstract partial class AbstractStmt 6 | { 7 | public void SetTableName(string tableName) 8 | { 9 | CheckPrepared(); 10 | if (_needTableName) 11 | { 12 | if (IsTableNameSet) 13 | { 14 | throw new InvalidOperationException( 15 | "Table name has already been set for current batch"); 16 | } 17 | 18 | if (string.IsNullOrEmpty(tableName)) 19 | { 20 | throw new ArgumentException("Table name cannot be null or empty"); 21 | } 22 | 23 | if (_tableInfos.TryGetValue(tableName, out var info)) 24 | { 25 | _currentTableInfo = info; 26 | } 27 | else 28 | { 29 | _currentTableInfo.TableName = tableName; 30 | } 31 | 32 | IsTableNameSet = true; 33 | } 34 | else 35 | { 36 | throw new InvalidOperationException( 37 | "Table name is not required for this statement or not supported in this context."); 38 | } 39 | } 40 | 41 | public void SetTags(object[] tags) 42 | { 43 | CheckPrepared(); 44 | CheckTableNameSet(); 45 | if (tags == null || tags.Length == 0) 46 | { 47 | throw new ArgumentException("Tags cannot be null or empty"); 48 | } 49 | 50 | if (_tagFields == null || _tagFields.Length == 0 || !_isInsert) 51 | { 52 | throw new InvalidOperationException("This statement does not need tags."); 53 | } 54 | 55 | if (IsTagsSet) 56 | { 57 | return; 58 | } 59 | 60 | if (tags.Length != _tagFields.Length) 61 | { 62 | throw new ArgumentException( 63 | $"Expected {_tagFields.Length} tags, but got {tags.Length}"); 64 | } 65 | 66 | CheckRowValue(tags, _tagFields); 67 | if (_currentTableInfo.Tags == null) 68 | { 69 | _currentTableInfo.Tags = tags; 70 | } 71 | 72 | IsTagsSet = true; 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /.github/workflows/taosadapter.toml: -------------------------------------------------------------------------------- 1 | debug = true 2 | taosConfigDir = "" 3 | port = 6041 4 | logLevel = "info" 5 | httpCodeServerError = false 6 | SMLAutoCreateDB = false 7 | 8 | [cors] 9 | allowAllOrigins = true 10 | 11 | #[pool] 12 | #maxConnect = 0 13 | #maxIdle = 0 14 | #idleTimeout = 0 15 | 16 | [ssl] 17 | enable = false 18 | certFile = "" 19 | keyFile = "" 20 | 21 | [log] 22 | #path = "/var/log/taos" 23 | rotationCount = 30 24 | rotationTime = "24h" 25 | rotationSize = "1GB" 26 | enableRecordHttpSql = false 27 | sqlRotationCount = 2 28 | sqlRotationTime = "24h" 29 | sqlRotationSize = "1GB" 30 | 31 | [monitor] 32 | disable = false 33 | collectDuration = "3s" 34 | disableCollectClientIP = false 35 | incgroup = false 36 | pauseQueryMemoryThreshold = 70 37 | pauseAllMemoryThreshold = 80 38 | identity = "" 39 | writeToTD = false 40 | user = "root" 41 | password = "taosdata" 42 | writeInterval = "30s" 43 | 44 | [uploadKeeper] 45 | enable = false 46 | url = "http://127.0.0.1:6043/adapter_report" 47 | interval = "15s" 48 | timeout = "5s" 49 | retryTimes = 3 50 | retryInterval = "5s" 51 | 52 | [opentsdb] 53 | enable = true 54 | 55 | [influxdb] 56 | enable = true 57 | 58 | [statsd] 59 | enable = false 60 | port = 6044 61 | db = "statsd" 62 | user = "root" 63 | password = "taosdata" 64 | worker = 10 65 | gatherInterval = "5s" 66 | protocol = "udp4" 67 | maxTCPConnections = 250 68 | tcpKeepAlive = false 69 | allowPendingMessages = 50000 70 | deleteCounters = true 71 | deleteGauges = true 72 | deleteSets = true 73 | deleteTimings = true 74 | 75 | [collectd] 76 | enable = false 77 | port = 6045 78 | db = "collectd" 79 | user = "root" 80 | password = "taosdata" 81 | worker = 10 82 | 83 | 84 | [opentsdb_telnet] 85 | enable = false 86 | maxTCPConnections = 250 87 | tcpKeepAlive = false 88 | dbs = ["opentsdb_telnet", "collectd", "icinga2", "tcollector"] 89 | ports = [6046, 6047, 6048, 6049] 90 | user = "root" 91 | password = "taosdata" 92 | batchSize = 1 93 | flushInterval = "0s" 94 | 95 | [node_exporter] 96 | enable = false 97 | db = "node_exporter" 98 | user = "root" 99 | password = "taosdata" 100 | urls = ["http://localhost:9100"] 101 | responseTimeout = "5s" 102 | httpUsername = "" 103 | httpPassword = "" 104 | httpBearerTokenString = "" 105 | caCertFile = "" 106 | certFile = "" 107 | keyFile = "" 108 | insecureSkipVerify = true 109 | gatherDuration = "5s" 110 | 111 | [prometheus] 112 | enable = true 113 | 114 | [tmq] 115 | releaseIntervalMultiplierForAutocommit = 2 -------------------------------------------------------------------------------- /src/TMQ/ConsumeResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using TDengine.Driver; 4 | using NativeMethods = TDengine.Driver.Impl.NativeMethods.NativeMethods; 5 | 6 | namespace TDengine.TMQ 7 | { 8 | public class TmqMessage 9 | { 10 | public string TableName { get; set; } 11 | public TValue Value { get; set; } 12 | } 13 | 14 | /// 15 | /// Represent consume result. 16 | /// 17 | public class ConsumeResult : IDisposable 18 | { 19 | /// 20 | /// The topic associated with the message. 21 | /// 22 | public string Topic { get; set; } 23 | 24 | /// 25 | /// The partition associated with the message. 26 | /// 27 | public Partition Partition { get; set; } 28 | 29 | /// 30 | /// The partition offset associated with the message. 31 | /// 32 | public Offset Offset { get; set; } 33 | 34 | public ulong MessageId { get; } 35 | 36 | public TMQ_RES Type { get; set; } 37 | 38 | /// 39 | /// The TopicPartition associated with the message. 40 | /// 41 | public TopicPartition TopicPartition 42 | => new TopicPartition(Topic, Partition); 43 | 44 | /// 45 | /// The TopicPartitionOffset associated with the message. 46 | /// 47 | public TopicPartitionOffset TopicPartitionOffset 48 | { 49 | get => new TopicPartitionOffset(Topic, Partition, Offset); 50 | set 51 | { 52 | Topic = value.Topic; 53 | Partition = value.Partition; 54 | Offset = value.Offset; 55 | } 56 | } 57 | 58 | public List> Message { get; set; } 59 | 60 | public ConsumeResult(string topic, Partition partition, Offset offset, TMQ_RES type) 61 | { 62 | Topic = topic; 63 | Partition = partition; 64 | Offset = offset; 65 | Type = type; 66 | Message = new List>(); 67 | } 68 | 69 | public ConsumeResult(ulong messageId,string topic, Partition partition, Offset offset, TMQ_RES type):this(topic, partition, offset, type) 70 | { 71 | MessageId = messageId; 72 | } 73 | 74 | public void Dispose() 75 | { 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /test/Driver.Test/Client/TMQ/Native.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Xunit; 3 | 4 | namespace Driver.Test.Client.TMQ 5 | { 6 | public partial class Consumer 7 | { 8 | [Fact] 9 | public void NativeConsumerTest() 10 | { 11 | var db = "tmq_consumer_test"; 12 | var topic = "tmq_consumer_test_topic"; 13 | this.NewConsumerTest(this._nativeConnectString, db, topic, this._nativeTMQCfg); 14 | } 15 | 16 | [Fact] 17 | public void NativeConsumerSeekTest() 18 | { 19 | var db = "tmq_seek_test"; 20 | var topic = "tmq_seek_test_topic"; 21 | this.ConsumerSeekTest(this._nativeConnectString, db, topic, this._nativeTMQCfg); 22 | } 23 | 24 | [Fact] 25 | public void NativeConsumerCommitTest() 26 | { 27 | var db = "tmq_commit_test"; 28 | var topic = "tmq_commit_test_topic"; 29 | this.ConsumerCommitTest(this._nativeConnectString, db, topic, this._nativeTMQCfg); 30 | } 31 | 32 | [Fact] 33 | public void NativeAutoCommitTest() 34 | { 35 | var db = "tmq_auto_commit_test"; 36 | var topic = "tmq_auto_commit_test_topic"; 37 | this.ConsumerAutoCommitTest(this._nativeConnectString, db, topic, this._nativeTMQCfgAutoCommit); 38 | } 39 | 40 | [Fact] 41 | public void NativeConsumerMultiPollTest() 42 | { 43 | var db = "tmq_multi_poll_test"; 44 | var topic = "tmq_multi_poll_test_topic"; 45 | var cfg = new Dictionary(this._nativeTMQCfgAutoCommit) 46 | { 47 | ["auto.offset.reset"] = "latest" 48 | }; 49 | this.ConsumerMultiPollTest(this._nativeConnectString, db, topic, cfg); 50 | } 51 | [Fact] 52 | public void NativeConsumerTimezoneTest() 53 | { 54 | var db = "tmq_timezone_test"; 55 | var topic = "tmq_timezone_test_topic"; 56 | var tz = "Europe/Paris"; 57 | this.ConsumerTimezoneTest(this._nativeConnectString, db, topic, tz, this._nativeTMQCfg); 58 | } 59 | 60 | [Fact] 61 | public void NativeResultTest() 62 | { 63 | var db = "tmq_result_test"; 64 | var topic = "tmq_result_test_topic"; 65 | this.ResultTest(this._nativeConnectString, db, topic, this._nativeTMQCfg); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /test/Driver.Test/Client/Tools/TaosAdapterTools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Net.Http; 4 | using System.Threading.Tasks; 5 | 6 | namespace Driver.Test.Client.Tools 7 | { 8 | public class TaosAdapterTools 9 | { 10 | private static readonly HttpClient _httpClient = new HttpClient(); 11 | 12 | public static Process NewTaosAdapter(string port) 13 | { 14 | string exec; 15 | if (Environment.OSVersion.Platform == PlatformID.Win32NT) 16 | { 17 | exec = "C:\\TDengine\\taosadapter.exe"; 18 | } 19 | else 20 | { 21 | exec = "taosadapter"; 22 | } 23 | 24 | ProcessStartInfo startInfo = new ProcessStartInfo(exec, $"--port {port}"); 25 | Process process = new Process { StartInfo = startInfo }; 26 | return process; 27 | } 28 | 29 | public static async Task StartTaosAdapter(Process process, string port) 30 | { 31 | process.Start(); 32 | await WaitForStart(port); 33 | } 34 | 35 | public static void StopTaosAdapter(Process process) 36 | { 37 | if (process == null || process.Id == 0 || process.HasExited) return; 38 | process.Kill(); 39 | process.WaitForExit(5000); // 等待进程退出 40 | process.Close(); 41 | } 42 | 43 | private static async Task WaitForStart(string port) 44 | { 45 | string url = $"http://127.0.0.1:{port}/-/ping"; 46 | bool success = await WaitForPingSuccess(_httpClient, url); 47 | if (!success) 48 | { 49 | throw new Exception("Failed to start taosadapter"); 50 | } 51 | } 52 | 53 | static async Task WaitForPingSuccess(HttpClient client, string url) 54 | { 55 | bool success = false; 56 | int retryCount = 50; 57 | int retryDelayMs = 100; 58 | 59 | for (int i = 0; i < retryCount; i++) 60 | { 61 | try 62 | { 63 | HttpResponseMessage response = await client.GetAsync(url); 64 | if (response.IsSuccessStatusCode) 65 | { 66 | success = true; 67 | break; 68 | } 69 | } 70 | catch (Exception e) 71 | { 72 | // ignored 73 | } 74 | 75 | await Task.Delay(retryDelayMs); 76 | } 77 | 78 | return success; 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /src/TMQ/Native/TMQNativeRows.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.InteropServices; 4 | using TDengine.Driver; 5 | using TDengine.Driver.Impl.NativeMethods; 6 | 7 | namespace TDengine.TMQ.Native 8 | { 9 | public class TMQNativeRows : AbstractRows, ITMQRows 10 | { 11 | private readonly IntPtr _result; 12 | 13 | public TMQNativeRows(IntPtr result, TimeZoneInfo tz) : base(0,0,tz) 14 | { 15 | _result = result; 16 | } 17 | 18 | protected override void FetchBlock() 19 | { 20 | if (Block == null) 21 | { 22 | int structSize = Marshal.SizeOf(typeof(TMQRawData)); 23 | IntPtr raw = Marshal.AllocHGlobal(structSize); 24 | try 25 | { 26 | var code = NativeMethods.TmqGetRaw(_result, raw); 27 | if (code != 0) 28 | { 29 | throw new TDengineError(code, NativeMethods.Error(_result)); 30 | } 31 | 32 | TMQRawData rawData = (TMQRawData)Marshal.PtrToStructure(raw, typeof(TMQRawData)); 33 | Block = new byte[rawData.rawLen]; 34 | Marshal.Copy(rawData.raw, Block, 0, (int)rawData.rawLen); 35 | BlockInfo = TmqBlockReader.Parse(Block); 36 | BlockIndex = 0; 37 | } 38 | finally 39 | { 40 | Marshal.FreeHGlobal(raw); 41 | } 42 | } 43 | else 44 | { 45 | BlockIndex += 1; 46 | } 47 | 48 | if (BlockIndex == BlockInfo.Length) 49 | { 50 | Completed = true; 51 | return; 52 | } 53 | 54 | BlockReader.SetTMQBlock(Block, BlockInfo[BlockIndex].precision, BlockInfo[BlockIndex].rawBlockOffset); 55 | BlockRows = BlockReader.GetRows(); 56 | CurrentRow = 0; 57 | 58 | FieldCount = BlockInfo[BlockIndex].schemas.Length; 59 | TableName = BlockInfo[BlockIndex].tableName; 60 | Metas = new List(); 61 | for (int i = 0; i < FieldCount; i++) 62 | { 63 | Metas.Add(new TDengineMeta 64 | { 65 | name = BlockInfo[BlockIndex].schemas[i].name, 66 | type = BlockInfo[BlockIndex].schemas[i].colType, 67 | size = BlockInfo[BlockIndex].schemas[i].bytes, 68 | }); 69 | } 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /test/Benchmark/Aggregate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Driver.Impl.NativeMethods; 3 | 4 | namespace Benchmark 5 | { 6 | internal class Aggregate 7 | { 8 | string Host { get; set; } 9 | ushort Port { get; set; } 10 | string Username { get; set; } 11 | string Password { get; set; } 12 | readonly string db = "benchmark"; 13 | readonly string avgStb = "select avg(d64) from stb;"; 14 | readonly string avgJtb = "select avg(d64) from jtb;"; 15 | 16 | 17 | public Aggregate(string host, string userName, string passwd, ushort port) 18 | { 19 | Host = host; 20 | Username = userName; 21 | Password = passwd; 22 | Port = port; 23 | } 24 | 25 | public void Run(string types, int times) 26 | { 27 | //Console.WriteLine("Aggregate {0} ...", types); 28 | 29 | IntPtr conn = NativeMethods.Connect(Host, Username, Password, db, Port); 30 | IntPtr res; 31 | if (conn != IntPtr.Zero) 32 | { 33 | res = NativeMethods.Query(conn, $"use {db}"); 34 | IfTaosQuerySucc(res, $"use {db}"); 35 | NativeMethods.FreeResult(res); 36 | 37 | if (types == "normal") 38 | { 39 | AggregateLoop(conn, times, avgStb); 40 | } 41 | 42 | if (types == "json") 43 | { 44 | AggregateLoop(conn, times, avgJtb); 45 | } 46 | } 47 | else 48 | { 49 | throw new Exception("create TD connection failed"); 50 | } 51 | 52 | NativeMethods.Close(conn); 53 | } 54 | 55 | public void AggregateLoop(IntPtr conn, int times, string sql) 56 | { 57 | IntPtr res; 58 | int i = 0; 59 | while (i < times) 60 | { 61 | res = NativeMethods.Query(conn, sql); 62 | IfTaosQuerySucc(res, sql); 63 | NativeMethods.FetchFields(res); 64 | Tools.GetData(res); 65 | NativeMethods.FreeResult(res); 66 | i++; 67 | } 68 | //Console.WriteLine("last time:{0}", i); 69 | } 70 | 71 | public bool IfTaosQuerySucc(IntPtr res, string sql) 72 | { 73 | if (NativeMethods.ErrorNo(res) == 0) 74 | { 75 | return true; 76 | } 77 | else 78 | { 79 | throw new Exception( 80 | $"execute {sql} failed,reason {NativeMethods.Error(res)}, code{NativeMethods.ErrorNo(res)}"); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /test/Benchmark/run_bench.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | BENCHMARK_TIMES=$1 3 | BATCH_TABLES=$2 4 | BATCH_ROWS=$3 5 | 6 | REPORT_NAME="csharp_run_${BENCHMARK_TIMES}" 7 | RESULT_FOLDER="result" 8 | MAX_SQL_LENGTH=5000 9 | INSERT_TABLE_NUM=10000 10 | 11 | echo "===== start ..." 12 | if [ ! -d "result" ] 13 | then 14 | mkdir ${RESULT_FOLDER} 15 | fi 16 | echo "BENCHMARK_TIMES:${BENCHMARK_TIMES}" 17 | 18 | clear remaining result report 19 | rm ./${RESULT_FOLDER}/*.md 20 | 21 | echo "===== step 1 create tables ..." 22 | taosBenchmark -f ./data/only_create_table_with_normal_tag.json 23 | taosBenchmark -f ./data/only_create_table_with_json_tag.json 24 | 25 | echo "===== step 2 insert data..." 26 | hyperfine -r ${BENCHMARK_TIMES} -L types normal,json -L tables ${INSERT_TABLE_NUM} \ 27 | 'dotnet run -- -s insert -t {types} -b {tables}' \ 28 | --time-unit millisecond \ 29 | --show-output \ 30 | --export-markdown ${RESULT_FOLDER}/${REPORT_NAME}_insert.md \ 31 | --command-name insert_{types}_${INSERT_TABLE_NUM}_tables_${BENCHMARK_TIMES}_times 32 | 33 | echo "===== step 3 clean data and create tables ..." 34 | taosBenchmark -f ./data/only_create_table_with_normal_tag.json 35 | taosBenchmark -f ./data/only_create_table_with_json_tag.json 36 | 37 | echo "===== step 4 insert data with batch ..." 38 | hyperfine -r ${BENCHMARK_TIMES} -L rows ${BATCH_TABLES} -L tables ${BATCH_TABLES} \ 39 | -L sqlLength ${MAX_SQL_LENGTH} -L types normal,json \ 40 | 'dotnet run -- -s insert -t {types} -r {rows} -b {tables} -l {sqlLength}' \ 41 | --time-unit millisecond \ 42 | --show-output \ 43 | --export-markdown ${RESULT_FOLDER}/${REPORT_NAME}_bath.md \ 44 | --command-name batch_{types}_${BATCH_TABLES}_tables_${BENCHMARK_TIMES}_times 45 | 46 | echo "===== step 5 query..." 47 | hyperfine -r ${BENCHMARK_TIMES} -L types normal,json \ 48 | 'dotnet run -- -s query -t {types} ' \ 49 | --time-unit millisecond \ 50 | --show-output \ 51 | --export-markdown ${RESULT_FOLDER}/${REPORT_NAME}_query.md \ 52 | --command-name query_{types}_${BENCHMARK_TIMES}_times 53 | 54 | echo "===== step 6 avg ..." 55 | hyperfine -r ${BENCHMARK_TIMES} -L types normal,json \ 56 | 'dotnet run -- -s avg -t {types}' \ 57 | --time-unit millisecond \ 58 | --show-output \ 59 | --export-markdown ${RESULT_FOLDER}/${REPORT_NAME}_avg.md \ 60 | --command-name avg_{types}_${BENCHMARK_TIMES}_times 61 | 62 | 63 | echo "| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |">>./${RESULT_FOLDER}/${REPORT_NAME}.md 64 | echo "|:---|---:|---:|---:|---:|">>./${RESULT_FOLDER}/${REPORT_NAME}.md 65 | ls ./${RESULT_FOLDER}/*.md| 66 | while read filename; 67 | do 68 | sed -n '3,4p' ${filename}>>${RESULT_FOLDER}/${REPORT_NAME}.md 69 | #echo "">>${RESULT_FOLDER}/${REPORT_NAME}.md 70 | done 71 | 72 | echo "=== benchmark done ... " 73 | echo "=== result file:${RESULT_FOLDER}/${REPORT_NAME}.md " 74 | -------------------------------------------------------------------------------- /examples/NativeADO/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Data.Client; 3 | 4 | namespace NativeADO 5 | { 6 | internal class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | const string connectionString = "host=localhost;port=6030;username=root;password=taosdata"; 11 | using (var connection = new TDengineConnection(connectionString)) 12 | { 13 | try 14 | { 15 | connection.Open(); 16 | using (var command = new TDengineCommand(connection)) 17 | { 18 | command.CommandText = "create database power"; 19 | command.ExecuteNonQuery(); 20 | connection.ChangeDatabase("power"); 21 | command.CommandText = 22 | "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))"; 23 | command.ExecuteNonQuery(); 24 | command.CommandText = "INSERT INTO " + 25 | "power.d1001 USING power.meters TAGS(2,'California.SanFrancisco') " + 26 | "VALUES " + 27 | "(?,?,?,?)"; 28 | var parameters = command.Parameters; 29 | parameters.Add(new TDengineParameter("@0", DateTime.Now)); 30 | parameters.Add(new TDengineParameter("@1", (float)10.30000)); 31 | parameters.Add(new TDengineParameter("@2", (int)219)); 32 | parameters.Add(new TDengineParameter("@3", (float)0.31000)); 33 | command.ExecuteNonQuery(); 34 | command.Parameters.Clear(); 35 | command.CommandText = "SELECT * FROM meters"; 36 | using (var reader = command.ExecuteReader()) 37 | { 38 | while (reader.Read()) 39 | { 40 | Console.WriteLine( 41 | $"{((DateTime) reader.GetValue(0)):yyyy-MM-dd HH:mm:ss.fff}, {reader.GetValue(1)}, {reader.GetValue(2)}, {reader.GetValue(3)}, {reader.GetValue(4)}, {System.Text.Encoding.UTF8.GetString((byte[]) reader.GetValue(5))}"); 42 | } 43 | } 44 | } 45 | } 46 | catch (Exception e) 47 | { 48 | Console.WriteLine(e); 49 | throw; 50 | } 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /examples/WSADO/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TDengine.Data.Client; 3 | 4 | namespace WSADO 5 | { 6 | internal class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | const string connectionString = "protocol=WebSocket;host=localhost;port=6041;useSSL=false;username=root;password=taosdata"; 11 | using (var connection = new TDengineConnection(connectionString)) 12 | { 13 | try 14 | { 15 | connection.Open(); 16 | using (var command = new TDengineCommand(connection)) 17 | { 18 | command.CommandText = "create database power"; 19 | command.ExecuteNonQuery(); 20 | connection.ChangeDatabase("power"); 21 | command.CommandText = 22 | "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))"; 23 | command.ExecuteNonQuery(); 24 | command.CommandText = "INSERT INTO " + 25 | "power.d1001 USING power.meters TAGS(2,'California.SanFrancisco') " + 26 | "VALUES " + 27 | "(?,?,?,?)"; 28 | var parameters = command.Parameters; 29 | parameters.Add(new TDengineParameter("@0", DateTime.Now)); 30 | parameters.Add(new TDengineParameter("@1", (float)10.30000)); 31 | parameters.Add(new TDengineParameter("@2", (int)219)); 32 | parameters.Add(new TDengineParameter("@3", (float)0.31000)); 33 | command.ExecuteNonQuery(); 34 | command.Parameters.Clear(); 35 | command.CommandText = "SELECT * FROM meters"; 36 | using (var reader = command.ExecuteReader()) 37 | { 38 | while (reader.Read()) 39 | { 40 | Console.WriteLine( 41 | $"{((DateTime) reader.GetValue(0)):yyyy-MM-dd HH:mm:ss.fff}, {reader.GetValue(1)}, {reader.GetValue(2)}, {reader.GetValue(3)}, {reader.GetValue(4)}, {System.Text.Encoding.UTF8.GetString((byte[]) reader.GetValue(5))}"); 42 | } 43 | } 44 | } 45 | } 46 | catch (Exception e) 47 | { 48 | Console.WriteLine(e); 49 | throw; 50 | } 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /examples/WindowsFormsApp4.8/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WindowsFormsApp4._8.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsApp4._8.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 重写当前线程的 CurrentUICulture 属性,对 56 | /// 使用此强类型资源类的所有资源查找执行重写。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /examples/WSQuery/WSQuery.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {18396378-750F-4053-8583-19DDE669BDDA} 8 | Exe 9 | Properties 10 | WSQuery 11 | WSQuery 12 | v4.8 13 | 512 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | x64 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/WSADO/WSADO.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {15661804-01BB-4F4B-AD37-3B21234A5325} 9 | Exe 10 | Properties 11 | WSADO 12 | WSADO 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/WSSeek/WSSeek.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {E945F882-95E1-4CE2-B689-6B859126ACD3} 9 | Exe 10 | Properties 11 | WSSeek 12 | WSSeek 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/WSStmt/WSStmt.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {54F4CCBA-58EE-45D6-802A-4A6C0E55D144} 9 | Exe 10 | Properties 11 | WSStmt 12 | WSStmt 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/NativeQuery/NativeQuery.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {EDAE50A9-7CB8-4683-8630-BC016C524410} 8 | Exe 9 | Properties 10 | NativeSql 11 | NativeQuery 12 | v4.8 13 | 512 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | x64 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/NativeADO/NativeADO.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {A2877121-FFAD-4839-8BC2-982178A4E68C} 9 | Exe 10 | Properties 11 | NativeADO 12 | NativeADO 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/NativeSeek/NativeSeek.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {59F8A094-A796-4394-943B-FEAEAF4FB895} 9 | Exe 10 | Properties 11 | NativeSeek 12 | NativeSeek 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/WSSchemaless/WSSchemaless.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {DB996903-9121-4A35-B994-9AA8ED475E47} 9 | Exe 10 | Properties 11 | WSSchemaless 12 | WSSchemaless 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/NativeSubscription/NativeSubscription.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {A6650070-BF1A-4EFC-B344-E35D115AEA13} 8 | Exe 9 | Properties 10 | NativeSubscription 11 | NativeSubscription 12 | v4.8 13 | 512 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | x64 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /examples/WSSubscription/WSSubscription.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {AD0D5FE4-75A5-40C3-8E2D-9254679D135B} 9 | Exe 10 | Properties 11 | WSSubscription 12 | WSSubscription 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/WSQueryWithReqID/WSQueryWithReqID.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {D321601E-1DC4-4628-8BE4-9DD05233D60B} 9 | Exe 10 | Properties 11 | WSQueryWithReqID 12 | WSQueryWithReqID 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/WSObjectDeserialize/WSObjectDeserialize.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {BE6ADFD4-DE57-4F98-8656-F710ED6D7A04} 9 | Exe 10 | Properties 11 | WSObjectDeserialize 12 | WSObjectDeserialize 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/NativeObjectDeserialize/NativeObjectDeserialize.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {2A03E53A-8999-4FAB-A32E-ECB9BEC0C82A} 9 | Exe 10 | Properties 11 | NativeObjectDeserialize 12 | NativeObjectDeserialize 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/NativeQueryWithReqID/NativeQueryWithReqID.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {412BDD41-0BDA-4E70-9F5C-D53943927FF0} 8 | Exe 9 | Properties 10 | NativeQueryWithReqID 11 | NativeQueryWithReqID 12 | v4.8 13 | 512 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/NativeStmt/NativeStmt.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {549645EF-6041-41A5-A59C-79B79F104DCE} 8 | Exe 9 | Properties 10 | NativeStmt 11 | NativeStmt 12 | v4.8 13 | 512 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/Driver/Client/Native/NativeRows.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using TDengine.Driver.Impl.NativeMethods; 4 | 5 | namespace TDengine.Driver.Client.Native 6 | { 7 | public class NativeRows : AbstractRows, IRows 8 | { 9 | private IntPtr _result; 10 | private IntPtr _block = IntPtr.Zero; 11 | private readonly bool _disableFreeResult; 12 | 13 | public NativeRows(int affectedRows) : base(affectedRows) 14 | { 15 | } 16 | 17 | public NativeRows(IntPtr result, TimeZoneInfo tz, bool disableFreeResult) 18 | : base(NativeMethods.FieldCount(result), NativeMethods.FetchFields(result), tz, 19 | NativeMethods.ResultPrecision(result)) 20 | { 21 | _disableFreeResult = disableFreeResult; 22 | _result = result; 23 | } 24 | 25 | public override void Dispose() 26 | { 27 | if (_disableFreeResult) 28 | { 29 | return; 30 | } 31 | 32 | if (_result != IntPtr.Zero) 33 | { 34 | NativeMethods.FreeResult(_result); 35 | _result = IntPtr.Zero; 36 | } 37 | } 38 | 39 | protected override bool HasBlockData() => _block != IntPtr.Zero; 40 | 41 | protected override void FetchBlock() 42 | { 43 | IntPtr numOfRowsPrt = Marshal.AllocHGlobal(sizeof(Int32)); 44 | IntPtr pDataPtr = Marshal.AllocHGlobal(IntPtr.Size); 45 | try 46 | { 47 | int code = NativeMethods.FetchRawBlock(_result, numOfRowsPrt, pDataPtr); 48 | if (code != 0) 49 | { 50 | throw new TDengineError(code, NativeMethods.Error(_result)); 51 | } 52 | 53 | int numOfRows = Marshal.ReadInt32(numOfRowsPrt); 54 | if (numOfRows == 0) 55 | { 56 | Completed = true; 57 | } 58 | else if (numOfRows < 0) 59 | { 60 | throw new TDengineError(NativeMethods.ErrorNo(_result), NativeMethods.Error(_result)); 61 | } 62 | else 63 | { 64 | BlockSize = numOfRows; 65 | CurrentRow = 0; 66 | var dataPtr = Marshal.ReadIntPtr(pDataPtr); 67 | _block = dataPtr; 68 | BlockReader.SetBlockPtr(dataPtr, BlockSize); 69 | } 70 | } 71 | catch 72 | { 73 | _block = IntPtr.Zero; 74 | Completed = true; 75 | throw; 76 | } 77 | finally 78 | { 79 | Marshal.FreeHGlobal(numOfRowsPrt); 80 | Marshal.FreeHGlobal(pDataPtr); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /src/Driver/ReqId.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Security.Cryptography; 4 | using System.Threading; 5 | 6 | namespace TDengine.Driver 7 | { 8 | public static class ReqId 9 | { 10 | private static readonly long UuidHashId; 11 | private static long _serialNo; 12 | private static readonly long Pid; 13 | static ReqId() 14 | { 15 | using (var md5 = MD5.Create()) 16 | { 17 | var tUuidBytes = Guid.NewGuid().ToByteArray(); 18 | var hashBytes = md5.ComputeHash(tUuidBytes); 19 | UuidHashId = ((long)BitConverter.ToUInt32(hashBytes, 0) & 0x07ff) << 52; 20 | } 21 | 22 | Pid = ((long)(Process.GetCurrentProcess().Id & 0x0f)) << 48; 23 | } 24 | 25 | public static long GetReqId() 26 | { 27 | long timeSpan = ((DateTime.UtcNow.Ticks -TDengineConstant.TimeZero.Ticks) / 10000)>> 8; 28 | long val = Interlocked.Increment(ref _serialNo); 29 | return UuidHashId | Pid | ((timeSpan & 0x3ffffff) << 20) | (val & 0xfffff); 30 | } 31 | 32 | private const uint C1 = 0xcc9e2d51; 33 | private const uint C2 = 0x1b873593; 34 | 35 | public static uint MurmurHash32(byte[] data, uint seed) 36 | { 37 | uint h1 = seed; 38 | 39 | int nBlocks = data.Length / 4; 40 | int p = 0; 41 | uint k1; 42 | for (int i = 0; i < nBlocks; i++) 43 | { 44 | k1 = BitConverter.ToUInt32(data, p); 45 | 46 | k1 *= C1; 47 | k1 = (k1 << 15) | (k1 >> 17); 48 | k1 *= C2; 49 | 50 | h1 ^= k1; 51 | h1 = (h1 << 13) | (h1 >> 19); 52 | h1 = h1 * 5 + 0xe6546b64; 53 | 54 | p += 4; 55 | } 56 | 57 | byte[] tail = new byte[data.Length - nBlocks * 4]; 58 | Buffer.BlockCopy(data, nBlocks * 4, tail, 0, tail.Length); 59 | 60 | k1 = 0; 61 | switch (tail.Length & 3) 62 | { 63 | case 3: 64 | k1 ^= (uint)tail[2] << 16; 65 | goto case 2; 66 | case 2: 67 | k1 ^= (uint)tail[1] << 8; 68 | goto case 1; 69 | case 1: 70 | k1 ^= (uint)tail[0]; 71 | k1 *= C1; 72 | k1 = (k1 << 15) | (k1 >> 17); 73 | k1 *= C2; 74 | h1 ^= k1; 75 | break; 76 | } 77 | 78 | h1 ^= (uint)data.Length; 79 | 80 | h1 ^= h1 >> 16; 81 | h1 *= 0x85ebca6b; 82 | h1 ^= h1 >> 13; 83 | h1 *= 0xc2b2ae35; 84 | h1 ^= h1 >> 16; 85 | 86 | return h1; 87 | } 88 | 89 | } 90 | } -------------------------------------------------------------------------------- /examples/AllTypeStmt/AllTypeStmt.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {2FAFA322-4007-4ACC-95DB-5BAEAB3D0A5F} 9 | Exe 10 | Properties 11 | AllTypeStmt 12 | AllTypeStmt 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | 28 | 29 | x64 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | false 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /examples/NativeQuery/Query.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using TDengine.Driver; 4 | using TDengine.Driver.Client; 5 | 6 | namespace NativeQuery 7 | { 8 | internal class Query 9 | { 10 | public static void Main(string[] args) 11 | { 12 | var builder = new ConnectionStringBuilder("host=localhost;port=6030;username=root;password=taosdata"); 13 | using (var client = DbDriver.Open(builder)) 14 | { 15 | try 16 | { 17 | client.Exec($"create database power"); 18 | client.Exec($"use power"); 19 | client.Exec( 20 | "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))"); 21 | string insertQuery = 22 | "INSERT INTO " + 23 | "power.d1001 USING power.meters TAGS(2,'California.SanFrancisco') " + 24 | "VALUES " + 25 | "('2023-10-03 14:38:05.000', 10.30000, 219, 0.31000) " + 26 | "('2023-10-03 14:38:15.000', 12.60000, 218, 0.33000) " + 27 | "('2023-10-03 14:38:16.800', 12.30000, 221, 0.31000) " + 28 | "power.d1002 USING power.meters TAGS(3, 'California.SanFrancisco') " + 29 | "VALUES " + 30 | "('2023-10-03 14:38:16.650', 10.30000, 218, 0.25000) " + 31 | "power.d1003 USING power.meters TAGS(2,'California.LosAngeles') " + 32 | "VALUES " + 33 | "('2023-10-03 14:38:05.500', 11.80000, 221, 0.28000) " + 34 | "('2023-10-03 14:38:16.600', 13.40000, 223, 0.29000) " + 35 | "power.d1004 USING power.meters TAGS(3,'California.LosAngeles') " + 36 | "VALUES " + 37 | "('2023-10-03 14:38:05.000', 10.80000, 223, 0.29000) " + 38 | "('2023-10-03 14:38:06.500', 11.50000, 221, 0.35000)"; 39 | client.Exec(insertQuery); 40 | string query = "SELECT * FROM meters"; 41 | using (var rows = client.Query(query)) 42 | { 43 | while (rows.Read()) 44 | { 45 | Console.WriteLine( 46 | $"{((DateTime)rows.GetValue(0)):yyyy-MM-dd HH:mm:ss.fff}, {rows.GetValue(1)}, {rows.GetValue(2)}, {rows.GetValue(3)}, {rows.GetValue(4)}, {Encoding.UTF8.GetString((byte[])rows.GetValue(5))}"); 47 | } 48 | } 49 | } 50 | catch (Exception e) 51 | { 52 | Console.WriteLine(e.ToString()); 53 | throw; 54 | } 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /examples/NativeSchemaless/NativeSchemaless.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {66E42B31-B8C2-42A4-93E5-44640200C42C} 8 | Exe 9 | Properties 10 | NativeSchemaless 11 | NativeSchemaless 12 | v4.8 13 | 512 14 | true 15 | 16 | 17 | x64 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | x64 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/AllTypeQuery/AllTypeQuery.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | Debug 7 | AnyCPU 8 | {5B2928A5-2688-4506-BFFB-3453C8E71861} 9 | Exe 10 | Properties 11 | AllTypeQuery 12 | AllTypeQuery 13 | v4.8 14 | 512 15 | true 16 | 17 | 18 | x64 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | 28 | 29 | x64 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | false 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 56 | 57 | 58 | 59 | 60 | 61 | --------------------------------------------------------------------------------