未验证 提交 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
<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.
先完成此消息的编辑!
想要评论请 注册