Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cd98f236
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cd98f236
编写于
4月 02, 2022
作者:
X
xiaolei li
提交者:
GitHub
4月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-14470]<hotfix>:csharp supplement schemaless and add example to ci (#11217)
上级
806068f3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
128 addition
and
9 deletion
+128
-9
src/connector/C#/examples/Main.cs
src/connector/C#/examples/Main.cs
+3
-1
src/connector/C#/examples/SchemalessSample.cs
src/connector/C#/examples/SchemalessSample.cs
+90
-0
src/connector/C#/examples/lib/Utils.cs
src/connector/C#/examples/lib/Utils.cs
+8
-6
src/connector/C#/src/TDengineDriver/TDengineDriver.cs
src/connector/C#/src/TDengineDriver/TDengineDriver.cs
+21
-1
src/connector/C#/src/TDengineDriver/TDengineDriver.csproj
src/connector/C#/src/TDengineDriver/TDengineDriver.csproj
+1
-1
tests/develop-test/3-connectors/c#/test.sh
tests/develop-test/3-connectors/c#/test.sh
+5
-0
未找到文件。
src/connector/C#/examples/Main.cs
浏览文件 @
cd98f236
...
...
@@ -19,8 +19,10 @@ namespace AsyncQueryExample
SubscribeSample
subscribeSample
=
new
SubscribeSample
();
subscribeSample
.
RunSubscribeWithCallback
(
conn
,
"subscribe_with_callback"
);
subscribeSample
.
RunSubscribeWithoutCallback
(
conn
,
"subscribe_without_callback"
);
UtilsTools
.
CloseConnection
(
conn
);
SchemalessSample
schemalessSample
=
new
SchemalessSample
();
schemalessSample
.
RunSchemaless
();
}
}
}
src/connector/C#/examples/SchemalessSample.cs
0 → 100644
浏览文件 @
cd98f236
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using
System
;
using
System.Text
;
using
System.Collections.Generic
;
using
System.Runtime.InteropServices
;
using
System.Collections
;
using
Sample.UtilsTools
;
using
TDengineDriver
;
namespace
Example
{
class
SchemalessSample
{
private
IntPtr
conn
=
IntPtr
.
Zero
;
private
string
dbName
=
"csharp_schemaless_example"
;
public
void
RunSchemaless
()
{
string
[]
lines
=
{
"stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000"
,
"stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833641000000"
};
string
[]
jsonStr
=
{
"{"
+
"\"metric\": \"stb0_0\","
+
"\"timestamp\": 1626006833,"
+
"\"value\": 10,"
+
"\"tags\": {"
+
" \"t1\": true,"
+
"\"t2\": false,"
+
"\"t3\": 10,"
+
"\"t4\": \"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>\""
+
"}"
+
"}"
};
StringBuilder
querySql
=
new
StringBuilder
();
Console
.
WriteLine
(
querySql
.
ToString
());
this
.
conn
=
UtilsTools
.
TDConnection
(
this
.
dbName
);
schemalessInsert
(
lines
,
2
,
(
int
)
TDengineSchemalessProtocol
.
TSDB_SML_LINE_PROTOCOL
,
(
int
)
TDengineSchemalessPrecision
.
TSDB_SML_TIMESTAMP_NANO_SECONDS
);
querySql
.
Append
(
"select * from "
).
Append
(
this
.
dbName
).
Append
(
"."
).
Append
(
"stg"
);
UtilsTools
.
DisplayRes
(
UtilsTools
.
ExecuteQuery
(
this
.
conn
,
querySql
.
ToString
()));
schemalessInsert
(
jsonStr
,
1
,
(
int
)
TDengineSchemalessProtocol
.
TSDB_SML_JSON_PROTOCOL
,
(
int
)
TDengineSchemalessPrecision
.
TSDB_SML_TIMESTAMP_SECONDS
);
querySql
.
Clear
();
querySql
.
Append
(
"select * from "
).
Append
(
this
.
dbName
).
Append
(
"."
).
Append
(
"stb0_0"
);
UtilsTools
.
DisplayRes
(
UtilsTools
.
ExecuteQuery
(
this
.
conn
,
querySql
.
ToString
()));
querySql
.
Clear
();
querySql
.
Append
(
"drop database if exists "
).
Append
(
this
.
dbName
);
UtilsTools
.
ExecuteUpdate
(
this
.
conn
,
querySql
.
ToString
());
UtilsTools
.
CloseConnection
(
this
.
conn
);
}
public
void
schemalessInsert
(
string
[]
sqlstr
,
int
lineCnt
,
int
protocol
,
int
precision
)
{
IntPtr
res
=
TDengine
.
SchemalessInsert
(
this
.
conn
,
sqlstr
,
lineCnt
,
protocol
,
precision
);
if
(
TDengine
.
ErrorNo
(
res
)
!=
0
)
{
Console
.
WriteLine
(
"schemaless_insert failed:{0}"
,
TDengine
.
Error
(
res
));
Console
.
WriteLine
(
"line string:{0}"
,
sqlstr
);
Console
.
WriteLine
(
""
);
System
.
Environment
.
Exit
(
0
);
}
else
{
Console
.
WriteLine
(
"else"
);
Console
.
WriteLine
(
"schemaless insert success:{0}"
,
TDengine
.
ErrorNo
(
res
));
}
}
}
}
src/connector/C#/examples/lib/Utils.cs
浏览文件 @
cd98f236
...
...
@@ -15,16 +15,18 @@ namespace Sample.UtilsTools
static
short
port
=
0
;
static
string
globalDbName
=
"csharp_example_db"
;
//get a TDengine connection
public
static
IntPtr
TDConnection
()
public
static
IntPtr
TDConnection
(
string
dbName
=
"csharp_example_db"
)
{
TDengine
.
Options
((
int
)
TDengineInitOption
.
TSDB_OPTION_CONFIGDIR
,
GetConfigPath
());
TDengine
.
Options
((
int
)
TDengineInitOption
.
TSDB_OPTION_SHELL_ACTIVITY_TIMER
,
"60"
);
TDengine
.
Init
();
IntPtr
conn
=
TDengine
.
Connect
(
ip
,
user
,
password
,
db
,
port
);
UtilsTools
.
ExecuteUpdate
(
conn
,
$"drop database if exists
{
globalDbName
}
"
);
UtilsTools
.
ExecuteUpdate
(
conn
,
$"create database if not exists
{
globalDbName
}
keep 3650"
);
UtilsTools
.
ExecuteUpdate
(
conn
,
$"use
{
globalDbName
}
"
);
UtilsTools
.
ExecuteUpdate
(
conn
,
$"drop database if exists
{
dbName
}
"
);
UtilsTools
.
ExecuteUpdate
(
conn
,
$"create database if not exists
{
dbName
}
keep 3650"
);
UtilsTools
.
ExecuteUpdate
(
conn
,
$"use
{
dbName
}
"
);
return
conn
;
}
//get taos.cfg file based on different os
...
...
@@ -199,7 +201,7 @@ namespace Sample.UtilsTools
int
fieldCount
=
meta
.
Count
;
while
((
taosRow
=
TDengine
.
FetchRows
(
res
))
!=
IntPtr
.
Zero
)
{
dataRaw
.
AddRange
(
FetchRow
(
taosRow
,
res
));
dataRaw
.
AddRange
(
FetchRow
(
taosRow
,
res
));
}
if
(
TDengine
.
ErrorNo
(
res
)
!=
0
)
{
...
...
@@ -293,7 +295,7 @@ namespace Sample.UtilsTools
case
TDengineDataType
.
TSDB_DATA_TYPE_JSONTAG
:
string
v16
=
Marshal
.
PtrToStringUTF8
(
data
,
colLengthArr
[
i
]);
dataRaw
.
Add
(
v16
);
break
;
break
;
default
:
dataRaw
.
Add
(
"nonsupport data type"
);
break
;
...
...
src/connector/C#/src/TDengineDriver/TDengineDriver.cs
浏览文件 @
cd98f236
...
...
@@ -47,6 +47,24 @@ namespace TDengineDriver
TSDB_OPTION_CONFIGDIR
=
3
,
TSDB_OPTION_SHELL_ACTIVITY_TIMER
=
4
}
public
enum
TDengineSchemalessProtocol
{
TSDB_SML_UNKNOWN_PROTOCOL
=
0
,
TSDB_SML_LINE_PROTOCOL
=
1
,
TSDB_SML_TELNET_PROTOCOL
=
2
,
TSDB_SML_JSON_PROTOCOL
=
3
}
public
enum
TDengineSchemalessPrecision
{
TSDB_SML_TIMESTAMP_NOT_CONFIGURED
=
0
,
TSDB_SML_TIMESTAMP_HOURS
=
1
,
TSDB_SML_TIMESTAMP_MINUTES
=
2
,
TSDB_SML_TIMESTAMP_SECONDS
=
3
,
TSDB_SML_TIMESTAMP_MILLI_SECONDS
=
4
,
TSDB_SML_TIMESTAMP_MICRO_SECONDS
=
5
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
=
6
}
enum
TaosField
{
STRUCT_SIZE
=
68
,
...
...
@@ -268,7 +286,9 @@ namespace TDengineDriver
[
DllImport
(
"taos"
,
EntryPoint
=
"taos_result_precision"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
static
extern
public
int
ResultPrecision
(
IntPtr
taos
);
//schemaless API
[
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
);
//stmt APIs:
/// <summary>
...
...
src/connector/C#/src/TDengineDriver/TDengineDriver.csproj
浏览文件 @
cd98f236
...
...
@@ -4,7 +4,7 @@
<TargetFrameworks>net5;netstandard2.1;</TargetFrameworks>
<PackageId>TDengine.Connector</PackageId>
<PackageIcon>logo.jpg</PackageIcon>
<Version>1.0.
5
</Version>
<Version>1.0.
6
</Version>
<Authors>taosdata</Authors>
<Company>www.taosdata.com</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
...
...
tests/develop-test/3-connectors/c#/test.sh
浏览文件 @
cd98f236
...
...
@@ -19,8 +19,13 @@ cd ../../
WKC
=
`
pwd
`
cd
${
WKC
}
/src/connector/C#
dotnet
test
# run example under Driver
cd
${
WKC
}
/src/connector/C#/examples
dotnet run
#dotnet run --project src/test/Cases/Cases.csproj
# run example with neuget package
cd
${
WKC
}
/tests/examples/C#
dotnet run
--project
C#checker/C#checker.csproj
dotnet run
--project
TDengineTest/TDengineTest.csproj
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录