未验证 提交 4f1817d5 编写于 作者: X xiaolei li 提交者: GitHub

docs:refine C# reference without api reference (#11701)

* docs:refine C# reference without api reference

* docs:refine c# user reference with new template

* docs:fix c# doc with comment and add api reference

* docs:csharp connector reference doc fixed with comment

* docs:csharp connector reference doc fixed with comment

* docs:csharp connector reference doc fixed with comments

* docs:csharp connector reference doc fixed with comments

* docs:csharp connector reference doc fixed with comments

* docs:csharp connector reference doc fixed with comments
上级 7fd9db99
......@@ -4,79 +4,168 @@ sidebar_label: C#
title: C# Connector
---
## 简介
## 总体介绍
- C# 连接器支持的系统有:Linux 64/Windows x64/Windows x86
TDengine.Connector 是 TDengine 提供的 C# 本地客户端驱动连接器。该连接器通过 TDengine 客户端驱动建立本地连接,进而可以访问 TDengine 数据库。目前已支持 TDengine 的绝大部分特性。例如:同步查询、异步查询、管理连接、订阅消费,schemaless 等。
- C# 连接器支持从 [Nuget 下载引用](https://www.nuget.org/packages/TDengine.Connector/)
本文介绍如何在 Windows 或 Linux 环境中安装 TDengine.Connector,并通过 TDengine.Connector 连接 TDengine 数据库、进行数据查询、数据写入等基本操作。
- 在 Windows 系统上,C# 应用程序可以使用 TDengine 的原生 C 接口来执行所有数据库操作,后续版本将提供 ORM(Dapper)框架驱动
TDengine.Connector 目前暂未封装 RESTful 接口,用户可以参考 [RESTful APIs](https://docs.taosdata.com//reference/restful-api/) 文档自行编写
## 安装准备
## 支持的平台
- 应用驱动安装请参考[安装连接器驱动步骤](/reference/connector/#安装客户端驱动)。
- 接口文件 TDengineDrivercs.cs 和参考程序示例 TDengineTest.cs 均位于 Windows 客户端 install_directory/examples/C# 目录下。
- 安装 [.NET SDK](https://dotnet.microsoft.com/download)
C# 连接器支持的系统有:Linux 64 / Windows x64/ Windows x86
## 示例程序
## 版本支持
示例程序源码位于
| TDengine.Connector | TDengine 版本 | 说明 |
|--------------------|:-------------------------------------:|--------------------------------|
| 1.0.2 | v2.5.0.x,v2.4.0.x,v2.3.4+ | 支持连接管理、同步查询、错误信息等功能。 |
| 1.0.3 | v2.5.0.x,v2.4.0.x,v2.3.4+ | 新增参数绑定、schemaless, json tag 等功能。 |
| 1.0.4 | v2.5.0.x,v2.4.0.x,v2.3.4+ | 新增异步查询,订阅等功能,修复绑定参数 bug。 |
| 1.0.5 | v2.5.0.x,v2.4.0.x,v2.3.4+ | 修复 Windows 同步查询中文报错 bug。 |
| 1.0.6 | v2.5.0.x,v2.4.0.x,v2.3.4+ | 修复schemaless bug。|
- {client_install_directory}/examples/C#
- [C# example source code on GitHub](https://github.com/taosdata/TDengine/tree/develop/examples/C%23)
## 支持的特性
:::note
### 本地连接
TDengineTest.cs C# 示例源程序,包含了数据库连接参数,以及如何执行数据插入、查询等操作。
“本地连接”指连接器通过本地客户端驱动程序 taosc 直接与服务端程序 taosd 建立连接。
“本地连接”支持的特新如下:
:::
1. 连接管理
2. 同步查询
3. 异步查询
4. 参数绑定
5. 错误信息
6. 订阅功能
7. Schemaless
## 安装验证
## 安装步骤
需要先安装 .NET SDK
### 安装前的准备
```cmd
cd {client_install_directory}/examples/C#/C#Checker
//运行测试
dotnet run -- -h <FQDN>. // 此步骤会先build,然后再运行。
* 安装 [.NET SDK](https://dotnet.microsoft.com/download)
* 安装 [TDengine 客户端](/reference/connector/#安装客户端驱动)
* 安装 (可选) [Nuget 客户端](https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools)
### 使用 dotnet CLI 安装
使用 C# Connector 连接数据库前,需要具备以下条件:
1. Linux 或 Windows 操作系统
2. .Net 5.0 及以上运行时环境
3. TDengine-client
**注意**:使用 C# 连接器包时需要安装对应的客户端驱动。
- 在 Linux 系统中成功安装 TDengine 客户端之后,TDengine.Connector 依赖的本地客户端驱动 libtaos.so 文件会被自动拷贝至 /usr/lib/libtaos.so,该目录包含在 Linux 自动扫描路径上,无需单独指定。
- 在 Windows 系统中成功安装 TDengine 客户端之后,TDengine.Connector 依赖的本地客户端驱动 taos.dll 文件会自动拷贝到系统默认搜索路径 C:/Windows/System32 下,同样无需单独指定。
**注意**:在 Windows 环境下开发时,需要安装 TDengine 对应的 [Windows 客户端](https://www.taosdata.com/cn/all-downloads/#TDengine-Windows-Client),Linux 服务器安装完 TDengine 之后默认已安装 client,也可以单独安装 [Linux 客户端](/get-started/) 连接远程 TDengine Server。
#### 使用 dotnet CLI 获取 C# 驱动
可以在当前 .NET 项目的路径下,通过 dotnet 命令引用 Nuget 中发布的 TDengine.Connector 到当前项目。
``` bash
dotnet add package TDengine.Connector
```
## C# 连接器的使用
#### 使用源码获取 C# 驱动
可以下载 TDengine 的源码,直接引用最新版本的 TDengine.Connector库
```bash
git clone https://github.com/taosdata/TDengine.git
cd TDengine/src/connector/C#/src/
cp -r C#/src/TDengineDriver/ myProject
cd myProject
dotnet add TDengineDriver/TDengineDriver.csproj
```
## 建立连接
### 建立本地连接
``` C#
using TDengineDriver;
namespace TDengineExample
{
internal class EstablishConnection
{
static void Main(String[] args)
{
string host = "localhost";
short port = 6030;
string username = "root";
string password = "taosdata";
string dbname = "";
var conn = TDengine.Connect(host, username, password, dbname, port);
if (conn == IntPtr.Zero)
{
Console.WriteLine("Connect to TDengine failed");
}
else
{
Console.WriteLine("Connect to TDengine success");
}
TDengine.Close(conn);
TDengine.Cleanup();
}
}
}
```
在 Windows 系统上,C# 应用程序可以使用 TDengine 的 C# 连接器接口来执行所有数据库的操作。使用的具体步骤如下所示:
## 使用示例
- 创建一个 C# project(需要 .NET SDK).
|示例程序 | 示例程序描述 |
|--------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| [C#checker](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/C%23checker) | 使用 TDengine.Connector 可以通过 help 命令中提供的参数,测试C# Driver的同步写入和查询 |
| [TDengineTest](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/TDengineTest) | 使用 TDengine.Connector 实现的简单写入和查询的示例 |
| [insertCn](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/insertCn) | 使用 TDengine.Connector 实现的写入和查询中文字符的示例 |
| [jsonTag](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/jsonTag) | 使用 TDengine.Connector 实现的写入和查询 json tag 类型数据的示例 |
| [stmt](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/stmt) | 使用 TDengine.Connector 实现的参数绑定的示例 |
| [schemaless](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/schemaless) | 使用 TDengine.Connector 实现的使用 schemaless 写入的示例 |
| [benchmark](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/taosdemo) | 使用 TDengine.Connector 实现的简易 Benchmark |
| [async query](https://github.com/taosdata/TDengine/blob/develop/src/connector/C%23/examples/QueryAsyncSample.cs) | 使用 TDengine.Connector 实现的异步查询的示例 |
| [subscribe](https://github.com/taosdata/TDengine/blob/develop/src/connector/C%23/examples/SubscribeSample.cs) | 使用 TDengine.Connector 实现的订阅数据的示例 |
```cmd
mkdir test
cd test
dotnet new console
```
## 重要更新记录
- 通过 Nuget 引用 TDengineDriver 包
| TDengine.Connector | 说明 |
|--------------------|--------------------------------|
| 1.0.2 | 新增连接管理、同步查询、错误信息等功能。 |
| 1.0.3 | 新增参数绑定、schemaless、 json tag等功能。 |
| 1.0.4 | 新增异步查询,订阅等功能。修复绑定参数 bug。 |
| 1.0.5 | 修复 Windows 同步查询中文报错 bug。 |
| 1.0.6 | 修复 schemaless 在 1.0.4 和 1.0.5 中失效 bug。 |
```cmd
dotnet add package TDengine.Connector
```
## 其他说明
- 在项目中需要用到 TDengineConnector 的地方引用 TDengineDriver namespace。
### 第三方驱动
```cs
using TDengineDriver;
```
- 用户可以参考[TDengineTest.cs](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/TDengineTest)来定义数据库连接参数,以及如何执行数据插入、查询等操作。
Maikebing.Data.Taos 是一个 TDengine 的 ADO.NET 连接器,支持 Linux,Windows 平台。该连接器由社区贡献者`麦壳饼@@maikebing` 提供,具体请参考:
:::note
* 接口下载:<https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos>
* 用法说明:<https://www.taosdata.com/blog/2020/11/02/1901.html>
- TDengine V2.0.3.0 之后同时支持 32 位和 64 位 Windows 系统,所以 C# 项目在生成 .exe 文件时,“解决方案”/“项目”的“平台”请选择对应的 x86 或 x64。
- 此接口目前已经在 Visual Studio 2015/2017 中验证过,其它 Visual Studio 版本尚待验证。
- 此连接器需要用到 taos.dll 文件,所以在未安装客户端时需要在执行应用程序前,拷贝 Windows{client_install_directory}/driver 目录中的 taos.dll 文件到项目最后生成 .exe 可执行文件所在的文件夹。之后运行 exe 文件,即可访问 TDengine 数据库并做插入、查询等操作。
## 常见问题
:::
* "Unable to establish connection","Unable to resolve FQDN"
## 第三方驱动
一般是因为 FQDN 配置不正确。可以参考[如何彻底搞懂 TDengine 的 FQDN](https://www.taosdata.com/blog/2021/07/29/2741.html)解决。
Maikebing.Data.Taos 是一个 TDengine 的 ADO.NET 提供器,支持 Linux,Windows。该开发包由热心贡献者`麦壳饼@@maikebing`提供,具体请参考:
* Unhandled exception. System.DllNotFoundException: Unable to load DLL 'taos' or one of its dependencies: 找不到指定的模块。
- 接口下载:https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos
- 用法说明:https://www.taosdata.com/blog/2020/11/02/1901.html
一般是因为程序没有找到依赖的客户端驱动。解决方法为:Windows 下可以将 `C:\TDengine\driver\taos.dll` 拷贝到 `C:\Windows\System32\ ` 目录下,Linux 下建立如下软链接 `ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so` 即可。
## API 参考
[API 参考](https://docs.taosdata.com/api/connector-csharp/html/860d2ac1-dd52-39c9-e460-0829c4e5a40b.htm)
......@@ -8,4 +8,5 @@ src/test/doc/
NugetPackTest/
examples/bin/
examples/obj/
src/TDengineDriver/doc/
.vs
......@@ -17,8 +17,14 @@ using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
/// <summary>
/// TDengine C# Driver.
/// </summary>
namespace TDengineDriver
{
/// <summary>
/// The enum indicate the data types and their code that TDengine supports.
/// </summary>
public enum TDengineDataType
{
TSDB_DATA_TYPE_NULL = 0, // 1 bytes
......@@ -31,7 +37,7 @@ namespace TDengineDriver
TSDB_DATA_TYPE_DOUBLE = 7, // 8 bytes
TSDB_DATA_TYPE_BINARY = 8, // string
TSDB_DATA_TYPE_TIMESTAMP = 9,// 8 bytes
TSDB_DATA_TYPE_NCHAR = 10, // unicode string
TSDB_DATA_TYPE_NCHAR = 10, // Unicode string
TSDB_DATA_TYPE_UTINYINT = 11,// 1 byte
TSDB_DATA_TYPE_USMALLINT = 12,// 2 bytes
TSDB_DATA_TYPE_UINT = 13, // 4 bytes
......@@ -39,6 +45,10 @@ namespace TDengineDriver
TSDB_DATA_TYPE_JSONTAG = 15 //4096 bytes
}
/// <summary>
/// Options that can be set before get TDegnine connection. Can set like locale,char-set,timezone,taos.cfg Dir
/// and connection active time.
/// </summary>
public enum TDengineInitOption
{
TSDB_OPTION_LOCALE = 0,
......@@ -47,14 +57,30 @@ namespace TDengineDriver
TSDB_OPTION_CONFIGDIR = 3,
TSDB_OPTION_SHELL_ACTIVITY_TIMER = 4
}
/// <summary>
/// This enum is used to indicate different TDengine's different schemaless protocol.
/// </summary>
public enum TDengineSchemalessProtocol
{
TSDB_SML_UNKNOWN_PROTOCOL = 0,
/// <summary>
/// Same as InfluxDB's line protocol.
/// </summary>
TSDB_SML_LINE_PROTOCOL = 1,
/// <summary>
/// Same as OpenTSDB's telnet protocol.
/// </summary>
TSDB_SML_TELNET_PROTOCOL = 2,
/// <summary>
/// Same as OpenTSDB's json protocol,can insert json format data.
/// </summary>
TSDB_SML_JSON_PROTOCOL = 3
}
/// <summary>
/// Precision string of the timestamps in the text data while using schemaless insert.
/// </summary>
public enum TDengineSchemalessPrecision
{
TSDB_SML_TIMESTAMP_NOT_CONFIGURED = 0,
......@@ -71,13 +97,32 @@ namespace TDengineDriver
NAME_LENGTH = 65,
TYPE_OFFSET = 65,
BYTES_OFFSET = 66,
}
/// <summary>
/// TDengine's meta info.
/// </summary>
public class TDengineMeta
{
/// <summary>
/// Retrieve result's column name.
/// </summary>
public string name;
/// <summary>
/// Column's length.(Unit bytes)
/// </summary>
public short size;
/// <summary>
/// Column type code from retrieved result. Correspond with <see cref="TDengineDataType"/>
/// </summary>
public byte type;
/// <summary>
/// Get the type name from retrieved result.
/// </summary>
/// <returns></returns>
public string TypeName()
{
switch ((TDengineDataType)type)
......@@ -113,122 +158,229 @@ namespace TDengineDriver
case TDengineDataType.TSDB_DATA_TYPE_JSONTAG:
return "JSON";
default:
return "undefine";
return "undefined";
}
}
}
/// <summary>
/// <c>TAOS_BIND</c> struct, used to hold a parameter(one value) while using "stmt insert".
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct TAOS_BIND
{
// column type
/// <summary>
/// Indicate the <see cref="TDengineDataType"/> of data you want to bind.
/// </summary>
public int buffer_type;
// one column value
/// <summary>
/// A reference point to the value you want to bind.
/// </summary>
public IntPtr buffer;
// unused
/// <summary>
/// Unused,but need to allocate space.
/// </summary>
public Int32 buffer_length;
// actual value length in buffer
/// <summary>
/// Actual value length in <see cref="buffer"/>.
/// </summary>
public IntPtr length;
// indicates the column value is null or not
/// <summary>
/// A reference to an variable to indicate if the column value is null or not
/// </summary>
public IntPtr is_null;
// unused
/// <summary>
/// Unused,but need to allocate space.
/// </summary>
public int is_unsigned;
// unused
/// <summary>
/// Unused,but need to allocate space.
/// </summary>
public IntPtr error;
/// <summary>
/// Unused,but need to allocate space.
/// </summary>
public Int64 u;
/// <summary>
/// Unused,but need to allocate space.
/// </summary>
public uint allocated;
}
/// <summary>
/// <c>TAOS_MULTI_BIND</c>struct,used to hold a multiple values while using "stmt bind".
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct TAOS_MULTI_BIND
{
// column type
/// <summary>
/// Indicate the <see cref="TDengineDataType"/> of data you want to bind.
/// </summary>
public int buffer_type;
// array, one or more lines column value
/// <summary>
/// The reference point to the array which stores multiple lines column values you want to bind.
/// </summary>
public IntPtr buffer;
//length of element in TAOS_MULTI_BIND.buffer (for binary and nchar it is the longest element's length)
/// <summary>
/// Actual value length in <see cref="buffer"/>.
/// </summary>
public ulong buffer_length;
//array, actual data length for each value
/// <summary>
/// A reference point to the array which stores actual data length for each value.
/// </summary>
public IntPtr length;
//array, indicates each column value is null or not
/// <summary>
/// A reference point to the array which stores identifies to indicate each value is null or not.
/// </summary>
public IntPtr is_null;
// line number, or the values number in buffer
/// <summary>
/// Line number or the count of values in buffer.
/// </summary>
public int num;
}
/// <summary>
/// User defined callback function for interface "QueryAsync()"
/// ,actually is a delegate in .Net.
/// This function aim to handle the taoRes which points to
/// the caller method's sql resultset.
/// User defined callback function for interface <c><see cref="TDengine.QueryAsync(IntPtr, string, QueryAsyncCallback, IntPtr)"/></c>,actually is a delegate in .Net.
/// This function aim to handle the <c>taoRes</c> which points to the caller method's SQL result set.
/// </summary>
/// <param name="param"> This parameter will sent by caller method (QueryAsync()).</param>
/// <param name="taoRes"> This is the retrieved by caller method's sql.</param>
/// <param name="code"> 0 for indicate operation success and negative for operation fail.</param>
/// <param name="param">This parameter will sent by caller method (<see cref="TDengine.QueryAsync(IntPtr, string, QueryAsyncCallback, IntPtr)"/>)</param>
/// <param name="taoRes">This is the retrieved by caller method's SQL.</param>
/// <param name="code">0 for indicate operation success and negative for operation fail.</param>
public delegate void QueryAsyncCallback(IntPtr param, IntPtr taoRes, int code);
/// <summary>
/// User defined callback function for interface "FetchRowAsync()"
/// ,actually is a delegate in .Net.
/// This callback allow applications to get each row of the
/// batch records by calling FetchRowAsync() forward iteration.
/// After reading all the records in a block, the application needs to continue calling
/// FetchRowAsync() in this callback function to obtain the next batch of records for
/// processing until the number of records
/// User defined callback function for interface <c><see cref="TDengine.FetchRowAsync(IntPtr, FetchRowAsyncCallback, IntPtr)"/></c>,actually is a delegate in .Net.
/// This callback allow applications to get each row of the batch records by calling <c><see cref="TDengine.FetchRowAsync(IntPtr, FetchRowAsyncCallback, IntPtr)"/></c>
/// forward iteration.After reading all the records in a block, the application needs to continue calling
/// <c><see cref="TDengine.FetchRowAsync(IntPtr, FetchRowAsyncCallback, IntPtr)"/></c> in this callback function to obtain the next batch of records for
/// processing until the number of records is zero.
/// </summary>
/// <param name="param">The parameter passed by <see cref="FetchRowAsync"/></param>
/// <param name="taoRes">Query status</param>
/// <param name="param">The parameter passed by <c><see cref="TDengine.FetchRowAsync(IntPtr, FetchRowAsyncCallback, IntPtr)"/></c></param>
/// <param name="taoRes">Query Result.</param>
/// <param name="numOfRows"> The number of rows of data obtained (not a function of
/// the entire query result set). When the number is zero (the result is returned)
/// or the number of records is negative (the query fails).</param>
public delegate void FetchRowAsyncCallback(IntPtr param, IntPtr taoRes, int numOfRows);
/// <summary>
/// In asynchronous mode, the prototype of the callback function.
/// In asynchronous subscribe mode, the prototype of the callback function.
/// </summary>
/// <param name="subscribe">Subscription object return by <see cref = "Subscribe"> </param>
/// <param name="tasRes"> Query retrieve result set. (Note there may be no record in the result set.)</param>
/// <param name="param"> Additional parameters supplied by the client when taos_subscribe is called.</param>
/// <param name="code"> Error code.</param>
/// <param name="subscribe">Subscription object return by <c><see cref="TDengine.Subscribe(IntPtr, bool, string, string, SubscribeCallback, IntPtr, int)"/></c></param>
/// <param name="tasRes">Query retrieve result set. (Note there may be no record in the result set.)</param>
/// <param name="param">Additional parameters supplied by the client when <c><see cref="TDengine.Subscribe(IntPtr, bool, string, string, SubscribeCallback, IntPtr, int)"/> is called.</c></param>
/// <param name="code">Error code.</param>
public delegate void SubscribeCallback(IntPtr subscribe, IntPtr tasRes, IntPtr param, int code);
/// <summary>
/// Defined this Driver's mainly APIs
/// </summary>
public class TDengine
{
/// <summary>
/// The success code return by major of this <c><see cref="TDengineDriver"/></c>'s operators.
/// </summary>
public const int TSDB_CODE_SUCCESS = 0;
/// <summary>
/// Initialize the running environment.
/// If the application does not actively call the API, the API will be automatically called when the application call
/// <c><see cref="Connect"/></c>, so the application generally does not need to call the API manually.
/// </summary>
[DllImport("taos", EntryPoint = "taos_init", CallingConvention = CallingConvention.Cdecl)]
static extern public void Init();
/// <summary>
/// Clean up the running environment and call this API before the application exits.
/// </summary>
[DllImport("taos", EntryPoint = "taos_cleanup", CallingConvention = CallingConvention.Cdecl)]
static extern public void Cleanup();
/// <summary>
/// Set client options, currently only time zone setting (_TSDB_OPTIONTIMEZONE)and encoding setting (_TSDB_OPTIONLOCALE) are supported.
/// The time zone and encoding default to the current operating system settings.
/// </summary>
/// <param name="option"></param>
/// <param name="value">When the return value is 0, it means success, and when it is -1, it means failure.</param>
[DllImport("taos", EntryPoint = "taos_options", CallingConvention = CallingConvention.Cdecl)]
static extern public void Options(int option, string value);
/// <summary>
/// Create a database connection and initialize the connection context. The parameters that need to be provided by user.
/// </summary>
/// <param name="ip"> FQDN used by TDengine to manage the master node.</param>
/// <param name="user">User name.</param>
/// <param name="password">Password</param>
/// <param name="db">Database name. If user does not provide it, it can be connected normally,
/// means user can create a new database through this connection.
/// If user provides a database name, means the user has created the database and the database is used by default</param>
/// <param name="port">Port number</param>
/// <returns>A null return value indicates a failure.
/// The application needs to save the returned parameters for subsequent API calls.
/// Note: The same process can connect to multiple taosd processes based on ip/port</returns>
[DllImport("taos", EntryPoint = "taos_connect", CallingConvention = CallingConvention.Cdecl)]
static extern public IntPtr Connect(string ip, string user, string password, string db, short port);
/// <summary>
/// Private function.Get the reason why the last API call failed, and the return value is a string.
/// Also see<seealso cref="Error"/>.
/// </summary>
/// <param name="res">Reference return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c></param>
/// <returns>Error reason.</returns>
[DllImport("taos", EntryPoint = "taos_errstr", CallingConvention = CallingConvention.Cdecl)]
static extern private IntPtr taos_errstr(IntPtr res);
/// <summary>
/// Public function,calling <c><see cref="taos_errstr"/></c> inside.Get the reason why the last API call failed, and the return value is a string.
/// Also see <c><seealso cref="taos_errstr"/></c>.
/// </summary>
/// <param name="res">Reference return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c>.</param>
/// <returns>Error reason.</returns>
static public string Error(IntPtr res)
{
IntPtr errPtr = taos_errstr(res);
return Marshal.PtrToStringAnsi(errPtr);
}
/// <summary>
/// Get the reason why the last API call failed, and the return value is the error code.
/// </summary>
/// <param name="res">Reference return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c>.</param>
/// <returns>Error code.</returns>
[DllImport("taos", EntryPoint = "taos_errno", CallingConvention = CallingConvention.Cdecl)]
static extern public int ErrorNo(IntPtr res);
/// <summary>
/// Private function.
/// This API is used to execute SQL statements, which can be DQL, DML or DDL statements.
/// </summary>
/// <param name="conn">The database connection returned by calling <c><see cref="Connect(string, string, string, string, short)"/></c>.</param>
/// <param name="byteArr">The SQL statement needed to execute.</param>
/// <returns>A reference point to the result.</returns>
[DllImport("taos", EntryPoint = "taos_query", CallingConvention = CallingConvention.Cdecl)]
// static extern public IntPtr Query(IntPtr conn, string sqlstr);
static extern private IntPtr Query(IntPtr conn, IntPtr byteArr);
/// <summary>
/// Public function.
/// This API is used to execute SQL statements, which can be DQL, DML or DDL statements.
/// Change the SQL command to UTF-8 to avoid error under Windows.
/// </summary>
/// <param name="conn">The database connection returned by calling <c><see cref="Connect(string, string, string, string, short)"/></c></param>
/// <param name="command">The SQL statement needed to execute.</param>
/// <returns>A reference point to the result.</returns>
static public IntPtr Query(IntPtr conn, string command)
{
IntPtr res = IntPtr.Zero;
......@@ -239,17 +391,41 @@ namespace TDengineDriver
return res;
}
/// <summary>
/// Get the number of rows affected by the executed SQL statement.
/// </summary>
/// <param name="res">Result return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c>.</param>
/// <returns>Number of row have been affected.</returns>
[DllImport("taos", EntryPoint = "taos_affected_rows", CallingConvention = CallingConvention.Cdecl)]
static extern public int AffectRows(IntPtr res);
/// <summary>
/// Get the number of columns in the query result set.
/// </summary>
/// <param name="res">Result return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c>.</param>
/// <returns>Number of columns in the query result set</returns>
[DllImport("taos", EntryPoint = "taos_field_count", CallingConvention = CallingConvention.Cdecl)]
static extern public int FieldCount(IntPtr res);
/// <summary>
/// Get the attributes (data type, name, number of bytes) of each column of data in the query result set,
/// which can be used in conjunction with taos_num_files to parse the data of a tuple (one row) returned
/// by <c><see cref="FetchRows(IntPtr)"/></c>.
/// </summary>
/// <param name="res">Result return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c>.</param>
/// <returns>A reference point to the attributes (data type, name, number of bytes) of each column of data in the query result set.</returns>
[DllImport("taos", EntryPoint = "taos_fetch_fields", CallingConvention = CallingConvention.Cdecl)]
static extern private IntPtr taos_fetch_fields(IntPtr res);
/// <summary>
/// Get the attributes (data type, name, number of bytes) of each column of data in the query result set,
/// which can be used in conjunction with taos_num_files to parse the data of a tuple (one row) returned
/// by <c><see cref="FetchRows(IntPtr)"/></c>
/// </summary>
/// <param name="res">Result return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c>.</param>
/// <returns>A list of <see cref="TDengineMeta"/></returns>
static public List<TDengineMeta> FetchFields(IntPtr res)
{
// const int fieldSize = 68;
List<TDengineMeta> metaList = new List<TDengineMeta>();
if (res == IntPtr.Zero)
......@@ -273,21 +449,55 @@ namespace TDengineDriver
return metaList;
}
/// <summary>
/// Get the data in the query result set by rows.
/// </summary>
/// <param name="res">Result return by APIs like <c><see cref="Query(IntPtr, IntPtr)"/></c>.</param>
/// <returns>Reference point to the query result set.</returns>
[DllImport("taos", EntryPoint = "taos_fetch_row", CallingConvention = CallingConvention.Cdecl)]
static extern public IntPtr FetchRows(IntPtr res);
/// <summary>
/// Release the query result set and related resources.
/// After the query is completed, be sure to call the API to release resources,
/// otherwise it may lead to application memory leakage. However,
/// it should also be noted that after releasing resources,
/// if you call functions such as <c><see cref="Consume(IntPtr)"/></c> to obtain query results,
/// it will lead the application to Crash.
/// </summary>
/// <param name="res">Reference point to the query result set.</param>
[DllImport("taos", EntryPoint = "taos_free_result", CallingConvention = CallingConvention.Cdecl)]
static extern public void FreeResult(IntPtr res);
/// <summary>
/// Close the connection.
/// </summary>
/// <param name="taos">Pointer returned by <c><see cref="Connect(string, string, string, string, short)"/></c> function.</param>
[DllImport("taos", EntryPoint = "taos_close", CallingConvention = CallingConvention.Cdecl)]
static extern public void Close(IntPtr taos);
//get precision of restultset
/// <summary>
/// The precision of the timestamp field in the returned result set.
/// </summary>
/// <param name="taos">Pointer returned by <c><see cref="Connect(string, string, string, string, short)"/></c> function.</param>
/// <returns> 0 for milliseconds, 1 for microseconds, and 2 for nanoseconds.</returns>
[DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)]
static extern public int ResultPrecision(IntPtr taos);
//schemaless API
/// <summary>
/// In addition to writing data using SQL or using the parameter binding API, writing can also be done using Schemaless,
/// which eliminates the need to create a super table/data sub-table data structure in advance and writes data directly,
/// while the TDengine system automatically creates and maintains the required table structure based on the written data
/// content.
/// </summary>
/// <param name="taos">Database connection, the database connection established by <c><see cref="Connect(string, string, string, string, short)"/></c> function.</param>
/// <param name="lines">A pattern-free text string that meets the parsing format requirements.</param>
/// <param name="numLines">The number of lines of the text data, cannot be 0.</param>
/// <param name="protocol">The protocol type <c><seealso cref="TDengineSchemalessProtocol"/></c> of the lines, used to identify the format of the text data.</param>
/// <param name="precision">Precision <c><seealso cref="TDengineSchemalessPrecision"/></c> string of the timestamps in the text data.</param>
/// <returns></returns>
[DllImport("taos", SetLastError = true, EntryPoint = "taos_schemaless_insert", CallingConvention = CallingConvention.Cdecl)]
static extern public IntPtr SchemalessInsert(IntPtr taos, string[] lines, int numLines, int protocol, int precision);
......@@ -307,7 +517,6 @@ namespace TDengineDriver
/// </summary>
/// <param name="stmt">could be the value returned by 'StmtInit', that may be a valid object or NULL.</param>
/// <param name="sql">sql string,used to bind parameters with</param>
/// <param name="length">no used</param>
/// <returns>0 for success, non-zero for failure.</returns>
[DllImport("taos", EntryPoint = "taos_stmt_prepare", CallingConvention = CallingConvention.Cdecl)]
static extern public int StmtPrepare(IntPtr stmt, string sql);
......@@ -421,13 +630,13 @@ namespace TDengineDriver
[DllImport("taos", EntryPoint = "taos_stmt_close", CallingConvention = CallingConvention.Cdecl)]
static extern public int StmtClose(IntPtr stmt);
[DllImport("taos", EntryPoint = "taos_load_table_info", CallingConvention = CallingConvention.Cdecl)]
/// <summary>
/// user application must call this API to load all tables meta,
/// <summary>
/// user application must call this API to load all tables meta.
/// </summary>
/// <param name="taos">taos connection</param>
/// <param name="tableList">tablelist</param>
/// <returns></returns>
[DllImport("taos", EntryPoint = "taos_load_table_info", CallingConvention = CallingConvention.Cdecl)]
static extern private int LoadTableInfoDll(IntPtr taos, string tableList);
/// <summary>
......@@ -484,7 +693,7 @@ namespace TDengineDriver
/// <summary>
/// Get the result set of asynchronous queries in batch,
/// which can only be used with QueryAsync().<c>FetchRowAsyncCallback<c>
/// which can only be used with QueryAsync().<c>FetchRowAsyncCallback</c>
/// </summary>
/// <param name="taoRes"> The result set returned when backcall QueryAsyncCallback </param>
/// <param name="fq"> Callback function.<see cref="FetchRowAsyncCallback"/></param>
......@@ -497,7 +706,7 @@ namespace TDengineDriver
/// <summary>
/// This function is used for start subscription service.
/// </summary>
/// <param name="taos"> taos connection return by <see cref = "Connect"></param>
/// <param name="taos"> taos connection return by <see cref = "Connect"></see></param>
/// <param name="restart">If the subscription is already exists, to decide whether to
/// start over or continue with previous subscription.</param>
/// <param name="topic"> The name of the subscription.(This is the unique identification of the subscription).</param>
......@@ -514,6 +723,26 @@ namespace TDengineDriver
/// <returns>Return null for failure, return subscribe object for success.</returns>
[DllImport("taos", EntryPoint = "taos_subscribe", CallingConvention = CallingConvention.Cdecl)]
static extern private IntPtr Subscribe(IntPtr taos, int restart, string topic, string sql, SubscribeCallback fq, IntPtr param, int interval);
/// <summary>
/// This function is used for start subscription service.
/// </summary>
/// <param name="taos"> taos connection return by <see cref = "Connect"></see></param>
/// <param name="restart">If the subscription is already exists, to decide whether to
/// start over or continue with previous subscription.</param>
/// <param name="topic"> The name of the subscription.(This is the unique identification of the subscription).</param>
/// <param name="sql">The subscribe statement(select only).Only query original data and in positive time sequence.</param>
/// <param name="fq">The callback function <c><see cref="TDengineDriver.SubscribeCallback"/></c>when the query result is received.</param>
/// <param name="param"> Additional parameter when calling callback function. System API will pass it to
/// callback function without any operations.It is only used when calling asynchronously,
/// and this parameter should be passed to NULL when calling synchronously</param>
/// <param name="interval">Polling period in milliseconds. During asynchronous call, the callback function will be
/// called periodically according to this parameter; In order to avoid affecting system
/// performance, it is not recommended to set this parameter too small; When calling synchronously,
/// if the interval between two calls to taos_consume is less than this period, the API will block
/// until the interval exceeds this period.</param>
/// <returns>Return null for failure, return subscribe object for success.</returns>
/// <exception cref="Exception"></exception>
static public IntPtr Subscribe(IntPtr taos, bool restart, string topic, string sql, SubscribeCallback fq, IntPtr param, int interval)
{
if (taos == IntPtr.Zero)
......@@ -536,10 +765,21 @@ namespace TDengineDriver
/// record, otherwise it will return an empty result set with no records.
/// If the return value is NULL, it indicates a system error.
/// </summary>
/// <param name="subscribe"> Subscription object return by <see cref = "Subscribe">. </param>
/// <returns></returns>
/// <param name="subscribe"> Subscription object return by <c><see cref="Subscribe(IntPtr, bool, string, string, SubscribeCallback, IntPtr, int)"/></c> </param>
/// <returns>A result set. The data retrieve by consumer.</returns>
[DllImport("taos", EntryPoint = "taos_consume", CallingConvention = CallingConvention.Cdecl)]
static extern private IntPtr TaosConsume(IntPtr subscribe);
/// <summary>
/// Only synchronous mode, this function is used to get the result of subscription.
/// If the interval between two calls to taos_consume is less than the polling
/// cycle of the subscription, the API will block until the interval exceeds this
/// cycle. If a new record arrives in the database, the API will return the latest
/// record, otherwise it will return an empty result set with no records.
/// If the return value is NULL, it indicates a system error.
/// </summary>
/// <param name="subscribe"> Subscription object return by <c><see cref="Subscribe(IntPtr, bool, string, string, SubscribeCallback, IntPtr, int)"/></c> </param>
/// <returns></returns>
static public IntPtr Consume(IntPtr subscribe)
{
IntPtr res = IntPtr.Zero;
......@@ -558,7 +798,7 @@ namespace TDengineDriver
/// <summary>
/// Unsubscribe.
/// </summary>
/// <param name="subscribe"> Subscription object return by <see cref = "Subscribe">.</param>
/// <param name="subscribe"> Subscription object return by "Subscribe" </param>
/// <param name="keep"> If it is not 0, the API will keep the progress of subscription,
/// and the and the subsequent call to taos_subscribe can continue
/// based on this progress; otherwise, the progress information will
......@@ -566,6 +806,17 @@ namespace TDengineDriver
/// </param>
[DllImport("taos", EntryPoint = "taos_unsubscribe", CallingConvention = CallingConvention.Cdecl)]
static extern private void Unsubscribe(IntPtr subscribe, int keep);
/// <summary>
/// Unsubscribe.
/// </summary>
/// <param name="subscribe"> Subscription object return by "Subscribe" </param>
/// <param name="keep"> If it is not true, the API will keep the progress of subscription,
/// and the and the subsequent call to taos_subscribe can continue
/// based on this progress; otherwise, the progress information will
/// be deleted and the data can only be read again.
/// </param>
/// <exception cref="Exception"></exception>
static public void Unsubscribe(IntPtr subscribe, bool keep)
{
if (subscribe == IntPtr.Zero)
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5;netstandard2.1;</TargetFrameworks>
<PropertyGroup>
<TargetFrameworks>net5;netstandard2.1;</TargetFrameworks>
<PackageId>TDengine.Connector</PackageId>
<PackageIcon>logo.jpg</PackageIcon>
<Version>1.0.6</Version>
<Authors>taosdata</Authors>
<Company>www.taosdata.com</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>Taos;Data;Microsoft.NET.Sdk;IOT;bigdata;TDengine;taosdata</PackageTags>
<Description>
This is the C# connector's classlib that lets you connect to TDengine.
......@@ -15,11 +15,14 @@
more information please visit: https://www.taosdata.com
</Description>
<RepositoryUrl>https://github.com/taosdata/TDengine/tree/develop/src/connector/C%2523/src/TDengineDriver</RepositoryUrl>
<NoWarn>CS1591</NoWarn>
<NoWarn>CS1591;CS0168;CS1587</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>.\doc\TDengineDriver.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="resource\logo.jpg" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
......@@ -12,6 +12,11 @@ namespace TDengineDriver
/// </summary>
public class TaosBind
{
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_BOOL"/></c>.
/// </summary>
/// <param name="val">A not null boolean value.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindBool(bool val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -32,6 +37,12 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_TINYINT"/></c>.
/// </summary>
/// <param name="val">A not null sbyte. </param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindTinyInt(sbyte val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -53,7 +64,12 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_SMALLINT"/></c>.
/// </summary>
/// <param name="val">A not null short value.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindSmallInt(short val)
{
......@@ -74,6 +90,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_INT"/></c>.
/// </summary>
/// <param name="val">A not null int value.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindInt(int val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -93,6 +114,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_BIGINT"/></c>.
/// </summary>
/// <param name="val">A not null long value.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindBigInt(long val)
{
......@@ -113,6 +139,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_UTINYINT"/></c>.
/// </summary>
/// <param name="val">An unsigned byte and can be null.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindUTinyInt(byte val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -133,6 +164,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_USMALLINT"/></c>.
/// </summary>
/// <param name="val">A not null Uint16.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindUSmallInt(UInt16 val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -155,6 +191,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_UINT"/></c>.
/// </summary>
/// <param name="val">A not null uint.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindUInt(uint val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -177,6 +218,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_UBIGINT"/></c>.
/// </summary>
/// <param name="val">A not null ulong.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindUBigInt(ulong val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -199,6 +245,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_FLOAT"/></c>.
/// </summary>
/// <param name="val">A not null float.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindFloat(float val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -221,6 +272,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_DOUBLE"/></c>.
/// </summary>
/// <param name="val">A not null double.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindDouble(Double val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -243,6 +299,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_BINARY"/></c>.
/// </summary>
/// <param name="val">A not null string.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindBinary(String val)
{
......@@ -263,6 +324,12 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_NCHAR"/></c>.
/// </summary>
/// <param name="val">A not null string.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindNchar(String val)
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -284,6 +351,10 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_NULL"/></c>.
/// </summary>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindNil()
{
TAOS_BIND bind = new TAOS_BIND();
......@@ -297,6 +368,11 @@ namespace TDengineDriver
return bind;
}
/// <summary>
/// Used to bind TDengine's <c><see cref="TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP"/></c>.
/// </summary>
/// <param name="ts">A not null long.</param>
/// <returns><c><see cref="TAOS_BIND"/></c></returns>
public static TAOS_BIND BindTimestamp(long ts)
{
......@@ -318,6 +394,10 @@ namespace TDengineDriver
}
/// <summary>
/// Used to free allocated unmanaged memory.
/// </summary>
/// <param name="binds">An array of <see cref="TAOS_BIND"/></param>
public static void FreeTaosBind(TAOS_BIND[] binds)
{
foreach (TAOS_BIND bind in binds)
......
......@@ -4,8 +4,16 @@ using System.Runtime.InteropServices;
namespace TDengineDriver
{
/// <summary>
/// Using to bind different columns types in multiple rows.
/// </summary>
public class TaosMultiBind
{
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_BOOL"/></c> values.
/// </summary>
/// <param name="arr">A nullable boolean array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindBool(bool?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -42,6 +50,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_TINYINT"/></c> values.
/// </summary>
/// <param name="arr">A nullable sbyte array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindTinyInt(sbyte?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -81,6 +95,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_SMALLINT"/></c> values.
/// </summary>
/// <param name="arr">A nullable short array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindSmallInt(short?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -118,6 +138,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_INT"/></c> values.
/// </summary>
/// <param name="arr">A nullable int array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindInt(int?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -153,6 +179,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_BIGINT"/></c> values.
/// </summary>
/// <param name="arr">A nullable long array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindBigint(long?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -189,6 +221,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_FLOAT"/></c> values.
/// </summary>
/// <param name="arr">A nullable float array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindFloat(float?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -228,6 +266,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_DOUBLE"/></c> values.
/// </summary>
/// <param name="arr">A nullable double array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindDouble(double?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -267,6 +311,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_UTINYINT"/></c> values.
/// </summary>
/// <param name="arr">A nullable byte array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindUTinyInt(byte?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -305,6 +355,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_USMALLINT"/></c> values.
/// </summary>
/// <param name="arr">A nullable ushort array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindUSmallInt(ushort?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -347,6 +403,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_UINT"/></c> values.
/// </summary>
/// <param name="arr">A nullable uint array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindUInt(uint?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -389,6 +451,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_UBIGINT"/></c> values.
/// </summary>
/// <param name="arr">A nullable ulong array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindUBigInt(ulong?[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -431,6 +499,12 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_BINARY"/></c> values.
/// </summary>
/// <param name="arr">A nullable string array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindBinary(string[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -483,6 +557,11 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_NCHAR"/></c> values.
/// </summary>
/// <param name="arr">A nullable string array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindNchar(string[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -534,6 +613,11 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Using to bind a array of <c><see cref="TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP"/></c> values.
/// </summary>
/// <param name="arr">A nullable long array.</param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static TAOS_MULTI_BIND MultiBindTimestamp(long[] arr)
{
TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND();
......@@ -569,6 +653,11 @@ namespace TDengineDriver
return multiBind;
}
/// <summary>
/// Used to free allocated unmanaged memory.
/// </summary>
/// <param name="mBinds">The <c><see cref="TAOS_MULTI_BIND"/></c> array have been instantiated. </param>
/// <returns><see cref="TAOS_MULTI_BIND"/></returns>
public static void FreeTaosBind(TAOS_MULTI_BIND[] mBinds)
{
foreach (TAOS_MULTI_BIND bind in mBinds)
......@@ -579,16 +668,25 @@ namespace TDengineDriver
}
}
private static char[] AlignCharArr(int offSet)
/// <summary>
/// Used to initial a char array with given length.
/// </summary>
/// <param name="length">The length you want to initial.</param>
/// <returns>A char array.</returns>
private static char[] AlignCharArr(int length)
{
char[] alignChar = new char[offSet];
for (int i = 0; i < offSet; i++)
char[] alignChar = new char[length];
for (int i = 0; i < length; i++)
{
alignChar[i] = char.MinValue;
}
return alignChar;
}
/// <summary>
/// Calculate the max length of the element in the string array.
/// </summary>
/// <param name="strArr">A string array.</param>
/// <returns>Max length.</returns>
private static int MaxElementLength(String[] strArr)
{
int max = 0;
......@@ -602,7 +700,11 @@ namespace TDengineDriver
}
return max;
}
/// <summary>
/// Change the string to Byte Array.
/// </summary>
/// <param name="str">string</param>
/// <returns>Byte array.</returns>
private static Byte[] GetStringEncodeByte(string str)
{
Byte[] strToBytes = null;
......
......@@ -14,7 +14,7 @@ namespace Cases
public class FetchFieldCases
{
DatabaseFixture database;
DatabaseFixture database;
public FetchFieldCases(DatabaseFixture fixture)
......@@ -26,7 +26,7 @@ namespace Cases
/// <describe>test taos_fetch_fields(), check the meta data</describe>
/// <filename>FetchFields.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "FetchFieldsCases.TestFetchFieldJsonTag()"),TestExeOrder(1),Trait("Category", "FetchFieldJsonTag")]
[Fact(DisplayName = "FetchFieldsCases.TestFetchFieldJsonTag()"), TestExeOrder(1), Trait("Category", "FetchFieldJsonTag")]
public void TestFetchFieldJsonTag()
{
IntPtr conn = database.conn;
......
......@@ -16,7 +16,7 @@ namespace Cases
/// <describe>TD-12103 C# connector fetch_row with binary data retrieving error</describe>
/// <filename>FetchLength.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "FetchLengthCase.TestRetrieveBinary()"),TestExeOrder(1)]
[Fact(DisplayName = "FetchLengthCase.TestRetrieveBinary()"), TestExeOrder(1)]
public void TestRetrieveBinary()
{
IntPtr conn = UtilsTools.TDConnection();
......@@ -47,7 +47,7 @@ namespace Cases
ResultSet actualResult = new ResultSet(resPtr);
List<string> actualData = actualResult.GetResultData();
List<TDengineMeta> actualMeta = actualResult.GetResultMeta();
// Make expected data and retrieved data in same order
expectData.Sort();
actualData.Sort();
......@@ -66,5 +66,5 @@ namespace Cases
}
}
}
}
......@@ -30,7 +30,7 @@ namespace Cases
/// <describe>Test query without condition</describe>
/// <filename>QueryAsync.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "QueryAsyncCases.QueryWithoutCondition()"),TestExeOrder(1),Trait("Category", "QueryAWithoutCondition")]
[Fact(DisplayName = "QueryAsyncCases.QueryWithoutCondition()"), TestExeOrder(1), Trait("Category", "QueryAWithoutCondition")]
public void QueryWithoutCondition()
{
IntPtr conn = database.conn;
......@@ -115,7 +115,7 @@ namespace Cases
/// <describe>Test query with condition</describe>
/// <filename>QueryAsync.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "QueryAsyncCases.QueryWithCondition()"),TestExeOrder(2),Trait("Category", "QueryAWithCondition")]
[Fact(DisplayName = "QueryAsyncCases.QueryWithCondition()"), TestExeOrder(2), Trait("Category", "QueryAWithCondition")]
public void QueryWithCondition()
{
IntPtr conn = database.conn;
......@@ -202,7 +202,7 @@ namespace Cases
/// <describe>Test query with condition</describe>
/// <filename>QueryAsync.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "QueryAsyncCases.QueryWithJsonCondition()"),TestExeOrder(3),Trait("Category", "QueryAWithJsonCondition")]
[Fact(DisplayName = "QueryAsyncCases.QueryWithJsonCondition()"), TestExeOrder(3), Trait("Category", "QueryAWithJsonCondition")]
public void QueryWithJsonCondition()
{
IntPtr conn = database.conn;
......
......@@ -25,7 +25,7 @@ namespace Cases
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "NormalTableStmtCases.TestBindSingleLineCN()"),TestExeOrder(2),Trait("Category", "bindParamCN")]
[Fact(DisplayName = "NormalTableStmtCases.TestBindSingleLineCN()"), TestExeOrder(2), Trait("Category", "bindParamCN")]
public void TestBindSingleLineCN()
{
string tableName = "ntb_stmt_cases_test_bind_single_line_cn";
......@@ -91,7 +91,7 @@ namespace Cases
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "NormalTableStmtCases.TestBindColumnCN()"),TestExeOrder(4),Trait("Category", "bindSingleColumnCN")]
[Fact(DisplayName = "NormalTableStmtCases.TestBindColumnCN()"), TestExeOrder(4), Trait("Category", "bindSingleColumnCN")]
public void TestBindColumnCN()
{
string tableName = "ntb_stmt_cases_test_bind_column_cn";
......@@ -173,7 +173,7 @@ namespace Cases
/// <describe>Test stmt insert single line of chinese character into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "NormalTableStmtCases.TestBindMultiLineCN()"),TestExeOrder(6),Trait("Category", "bindParamBatchCN")]
[Fact(DisplayName = "NormalTableStmtCases.TestBindMultiLineCN()"), TestExeOrder(6), Trait("Category", "bindParamBatchCN")]
public void TestBindMultiLineCN()
{
string tableName = "ntb_stmt_cases_test_bind_multi_lines_cn";
......@@ -242,7 +242,7 @@ namespace Cases
/// <describe>Test stmt insert single line data into normal table</describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "NormalTableStmtCases.TestBindSingleLine"),TestExeOrder(3),Trait("Category", "BindSingleColumn")]
[Fact(DisplayName = "NormalTableStmtCases.TestBindSingleLine"), TestExeOrder(3), Trait("Category", "BindSingleColumn")]
public void TestBindSingleLine()
{
string tableName = "ntb_stmt_cases_test_bind_single_line";
......@@ -311,7 +311,7 @@ namespace Cases
/// <describe>Test stmt insert multiple rows of data into normal table</describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "NormalTableStmtCases.TestBindMultiLine()"),TestExeOrder(5),Trait("Category", "bindParamBatch")]
[Fact(DisplayName = "NormalTableStmtCases.TestBindMultiLine()"), TestExeOrder(5), Trait("Category", "bindParamBatch")]
public void TestBindMultiLine()
{
string tableName = "ntb_stmt_case_test_bind_multi_lines";
......@@ -380,7 +380,7 @@ namespace Cases
/// <describe>Test stmt insert multiple rows of data into normal table by column after column </describe>
/// <filename>StmtNormalTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "NormalTableStmtCases.TestBindColumn()"),TestExeOrder(1),Trait("Category", "bindParam")]
[Fact(DisplayName = "NormalTableStmtCases.TestBindColumn()"), TestExeOrder(1), Trait("Category", "bindParam")]
public void TestBindColumn()
{
string tableName = "ntb_stmt_cases_test_bind_column";
......
......@@ -28,7 +28,7 @@ namespace Cases
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "StableStmtCases.TestBindSingleLineCN()"),TestExeOrder(2),Trait("Category", "BindParamCN")]
[Fact(DisplayName = "StableStmtCases.TestBindSingleLineCN()"), TestExeOrder(2), Trait("Category", "BindParamCN")]
public void TestBindSingleLineCN()
{
string tableName = "stb_stmt_cases_test_bind_single_line_cn";
......@@ -112,7 +112,7 @@ namespace Cases
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "StableStmtCases.TestBindColumnCN()"),TestExeOrder(4),Trait("Category", "BindParamColumnCN")]
[Fact(DisplayName = "StableStmtCases.TestBindColumnCN()"), TestExeOrder(4), Trait("Category", "BindParamColumnCN")]
public void TestBindColumnCN()
{
string tableName = "stb_stmt_cases_test_bindcolumn_cn";
......@@ -212,7 +212,7 @@ namespace Cases
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "StableStmtCases.TestBindMultiLineCN()"),TestExeOrder(6),Trait("Category", "BindParamBatchCN")]
[Fact(DisplayName = "StableStmtCases.TestBindMultiLineCN()"), TestExeOrder(6), Trait("Category", "BindParamBatchCN")]
public void TestBindMultiLineCN()
{
string tableName = "stb_stmt_cases_test_bind_multi_line_cn";
......@@ -295,7 +295,7 @@ namespace Cases
/// <describe>Test stmt insert single line into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "StableStmtCases.TestBindMultiLine()"),TestExeOrder(5),Trait("Category", "BindParamBatch")]
[Fact(DisplayName = "StableStmtCases.TestBindMultiLine()"), TestExeOrder(5), Trait("Category", "BindParamBatch")]
public void TestBindMultiLine()
{
string tableName = "stb_stmt_cases_test_bind_multi_line";
......@@ -383,7 +383,7 @@ namespace Cases
/// <describe>Test stmt insert single line of chinese character into stable by column after column </describe>
/// <filename>StmtSTable.cs</filename>
/// <result>pass or failed </result>
[Fact(DisplayName = "StableStmtCases.TestBindColumn()"),TestExeOrder(3),Trait("Category", "BindParamColumn")]
[Fact(DisplayName = "StableStmtCases.TestBindColumn()"), TestExeOrder(3), Trait("Category", "BindParamColumn")]
public void TestBindColumn()
{
string tableName = "stb_stmt_cases_test_bindcolumn";
......
......@@ -48,24 +48,24 @@ namespace Test.Fixture
public void Dispose()
{
IntPtr res;
if (conn != IntPtr.Zero)
IntPtr res;
if (conn != IntPtr.Zero)
{
if ((res = TDengine.Query(conn, $"drop database if exists {db}")) != IntPtr.Zero)
{
if ((res = TDengine.Query(conn, $"drop database if exists {db}")) != IntPtr.Zero)
{
TDengine.Close(conn);
Console.WriteLine("close connection success");
}
else
{
throw new Exception(TDengine.Error(res));
}
TDengine.Close(conn);
Console.WriteLine("close connection success");
}
else
{
throw new Exception("connection if already null");
throw new Exception(TDengine.Error(res));
}
}
else
{
throw new Exception("connection if already null");
}
}
......
using System;
namespace Test.Case.Attributes
namespace Test.Case.Attributes
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class TestExeOrderAttribute : Attribute
......
......@@ -31,7 +31,7 @@ namespace XUnit.Case.Orderers
yield return testCase;
}
}
private static TValue GetOrCreate<TKey, TValue>(
IDictionary<TKey, TValue> dictionary, TKey key)
where TKey : struct
......
......@@ -163,7 +163,7 @@ namespace Test.UtilsTools
}
else
{
throw new Exception("connection if already null");
throw new Exception("connection if already null");
}
}
public static List<TDengineMeta> GetResField(IntPtr res)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册