Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8db31201
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8db31201
编写于
8月 26, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1236 native c# examples for 2.0
上级
00aaa44c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
70 addition
and
66 deletion
+70
-66
src/inc/taos.h
src/inc/taos.h
+1
-1
tests/examples/C#/TDengineDriver.cs
tests/examples/C#/TDengineDriver.cs
+28
-28
tests/examples/C#/TDengineTest.cs
tests/examples/C#/TDengineTest.cs
+41
-37
未找到文件。
src/inc/taos.h
浏览文件 @
8db31201
...
...
@@ -93,7 +93,7 @@ DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision
DLL_EXPORT
void
taos_free_result
(
TAOS_RES
*
res
);
DLL_EXPORT
int
taos_field_count
(
TAOS_RES
*
tres
);
DLL_EXPORT
int
taos_num_fields
(
TAOS_RES
*
res
);
DLL_EXPORT
int
taos_affected_rows
(
TAOS_RES
*
tao
s
);
DLL_EXPORT
int
taos_affected_rows
(
TAOS_RES
*
re
s
);
DLL_EXPORT
TAOS_FIELD
*
taos_fetch_fields
(
TAOS_RES
*
res
);
DLL_EXPORT
int
taos_select_db
(
TAOS
*
taos
,
const
char
*
db
);
DLL_EXPORT
int
taos_print_row
(
char
*
str
,
TAOS_ROW
row
,
TAOS_FIELD
*
fields
,
int
num_fields
);
...
...
tests/examples/C#/TDengineDriver.cs
浏览文件 @
8db31201
...
...
@@ -20,16 +20,17 @@ using System.Runtime.InteropServices;
namespace
TDengineDriver
{
enum
TDengineDataType
{
TSDB_DATA_TYPE_BOOL
=
1
,
TSDB_DATA_TYPE_TINYINT
=
2
,
TSDB_DATA_TYPE_SMALLINT
=
3
,
TSDB_DATA_TYPE_INT
=
4
,
TSDB_DATA_TYPE_BIGINT
=
5
,
TSDB_DATA_TYPE_FLOAT
=
6
,
TSDB_DATA_TYPE_DOUBLE
=
7
,
TSDB_DATA_TYPE_BINARY
=
8
,
TSDB_DATA_TYPE_TIMESTAMP
=
9
,
TSDB_DATA_TYPE_NCHAR
=
10
TSDB_DATA_TYPE_NULL
=
0
,
// 1 bytes
TSDB_DATA_TYPE_BOOL
=
1
,
// 1 bytes
TSDB_DATA_TYPE_TINYINT
=
2
,
// 1 bytes
TSDB_DATA_TYPE_SMALLINT
=
3
,
// 2 bytes
TSDB_DATA_TYPE_INT
=
4
,
// 4 bytes
TSDB_DATA_TYPE_BIGINT
=
5
,
// 8 bytes
TSDB_DATA_TYPE_FLOAT
=
6
,
// 4 bytes
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
}
enum
TDengineInitOption
...
...
@@ -83,50 +84,49 @@ namespace TDengineDriver
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_init"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
void
Init
();
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_cleanup"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
void
Cleanup
();
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_options"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
void
Options
(
int
option
,
string
value
);
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_connect"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
long
Connect
(
string
ip
,
string
user
,
string
password
,
string
db
,
in
t
port
);
static
extern
public
long
Connect
(
string
ip
,
string
user
,
string
password
,
string
db
,
shor
t
port
);
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_errstr"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
private
IntPtr
taos_errstr
(
long
tao
s
);
static
public
string
Error
(
long
conn
)
static
extern
private
IntPtr
taos_errstr
(
long
re
s
);
static
public
string
Error
(
long
res
)
{
IntPtr
errPtr
=
taos_errstr
(
conn
);
IntPtr
errPtr
=
taos_errstr
(
res
);
return
Marshal
.
PtrToStringAnsi
(
errPtr
);
}
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_errno"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
int
ErrorNo
(
long
tao
s
);
static
extern
public
int
ErrorNo
(
long
re
s
);
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_query"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
int
Query
(
long
taos
,
string
sqlstr
);
static
extern
public
long
Query
(
long
conn
,
string
sqlstr
);
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_affected_rows"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
int
AffectRows
(
long
taos
);
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_use_result"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
long
UseResult
(
long
taos
);
static
extern
public
int
AffectRows
(
long
res
);
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_field_count"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
public
int
FieldCount
(
long
tao
s
);
static
extern
public
int
FieldCount
(
long
re
s
);
[
DllImport
(
"taos.dll"
,
EntryPoint
=
"taos_fetch_fields"
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
private
IntPtr
taos_fetch_fields
(
long
res
);
static
public
List
<
TDengineMeta
>
FetchFields
(
long
tao
s
)
static
public
List
<
TDengineMeta
>
FetchFields
(
long
re
s
)
{
const
int
fieldSize
=
68
;
List
<
TDengineMeta
>
metas
=
new
List
<
TDengineMeta
>();
long
result
=
TDengine
.
UseResult
(
taos
);
if
(
result
==
0
)
if
(
res
==
0
)
{
return
metas
;
}
int
fieldCount
=
FieldCount
(
tao
s
);
IntPtr
fieldsPtr
=
taos_fetch_fields
(
res
ult
);
int
fieldCount
=
FieldCount
(
re
s
);
IntPtr
fieldsPtr
=
taos_fetch_fields
(
res
);
for
(
int
i
=
0
;
i
<
fieldCount
;
++
i
)
{
...
...
@@ -134,8 +134,8 @@ namespace TDengineDriver
TDengineMeta
meta
=
new
TDengineMeta
();
meta
.
name
=
Marshal
.
PtrToStringAnsi
(
fieldsPtr
+
offset
);
meta
.
size
=
Marshal
.
ReadInt16
(
fieldsPtr
+
offset
+
64
);
meta
.
type
=
Marshal
.
ReadByte
(
fieldsPtr
+
offset
+
66
);
meta
.
type
=
Marshal
.
ReadByte
(
fieldsPtr
+
offset
+
65
);
meta
.
size
=
Marshal
.
ReadInt16
(
fieldsPtr
+
offset
+
66
);
metas
.
Add
(
meta
);
}
...
...
tests/examples/C#/TDengineTest.cs
浏览文件 @
8db31201
...
...
@@ -28,7 +28,7 @@ namespace TDengineDriver
private
string
configDir
;
private
string
user
;
private
string
password
;
private
int
port
=
0
;
private
short
port
=
0
;
//sql parameters
private
string
dbName
;
...
...
@@ -211,58 +211,62 @@ namespace TDengineDriver
StringBuilder
sql
=
new
StringBuilder
();
sql
.
Append
(
"create database if not exists "
).
Append
(
this
.
dbName
);
int
code
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
code
==
TDengine
.
TSDB_CODE_SUCCESS
)
long
res
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
res
!=
0
)
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" success"
);
}
else
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
conn
));
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
res
));
ExitProgram
();
}
TDengine
.
FreeResult
(
res
);
sql
.
Clear
();
sql
.
Append
(
"use "
).
Append
(
this
.
dbName
);
code
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
code
==
TDengine
.
TSDB_CODE_SUCCESS
)
res
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
res
!=
0
)
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" success"
);
}
else
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
this
.
conn
));
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
res
));
ExitProgram
();
}
TDengine
.
FreeResult
(
res
);
sql
.
Clear
();
sql
.
Append
(
"create table if not exists "
).
Append
(
this
.
stableName
).
Append
(
"(ts timestamp, v1
int
) tags(t1 int)"
);
code
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
code
==
TDengine
.
TSDB_CODE_SUCCESS
)
sql
.
Append
(
"create table if not exists "
).
Append
(
this
.
stableName
).
Append
(
"(ts timestamp, v1
bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10)
) tags(t1 int)"
);
res
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
res
!=
0
)
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" success"
);
}
else
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
this
.
conn
));
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
res
));
ExitProgram
();
}
TDengine
.
FreeResult
(
res
);
for
(
int
i
=
0
;
i
<
this
.
tableCount
;
i
++)
{
sql
.
Clear
();
sql
=
sql
.
Append
(
"create table if not exists "
).
Append
(
this
.
tablePrefix
).
Append
(
i
)
.
Append
(
" using "
).
Append
(
this
.
stableName
).
Append
(
" tags("
).
Append
(
i
).
Append
(
")"
);
code
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
code
==
TDengine
.
TSDB_CODE_SUCCESS
)
res
=
TDengine
.
Query
(
this
.
conn
,
sql
.
ToString
());
if
(
res
!=
0
)
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" success"
);
}
else
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
this
.
conn
));
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
res
));
ExitProgram
();
}
TDengine
.
FreeResult
(
res
);
}
Console
.
WriteLine
(
"create db and table success"
);
...
...
@@ -287,16 +291,22 @@ namespace TDengineDriver
for
(
int
batch
=
0
;
batch
<
this
.
batchRows
;
++
batch
)
{
long
rows
=
loop
*
this
.
batchRows
+
batch
;
sql
.
Append
(
"("
).
Append
(
this
.
beginTimestamp
+
rows
).
Append
(
","
).
Append
(
rows
).
Append
(
")"
);
sql
.
Append
(
"("
)
.
Append
(
this
.
beginTimestamp
+
rows
)
.
Append
(
", 1, 2, 3,"
)
.
Append
(
rows
)
.
Append
(
", 5, 6, 7, 'abc', 'def')"
);
}
int
code
=
TDengine
.
Query
(
conn
,
sql
.
ToString
());
if
(
code
!=
TDengine
.
TSDB_CODE_SUCCESS
)
long
res
=
TDengine
.
Query
(
conn
,
sql
.
ToString
());
if
(
res
==
0
)
{
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
conn
));
Console
.
WriteLine
(
sql
.
ToString
()
+
" failure, reason: "
+
TDengine
.
Error
(
res
));
}
int
affectRows
=
TDengine
.
AffectRows
(
conn
);
int
affectRows
=
TDengine
.
AffectRows
(
res
);
this
.
rowsInserted
+=
affectRows
;
TDengine
.
FreeResult
(
res
);
}
}
...
...
@@ -322,32 +332,25 @@ namespace TDengineDriver
String
sql
=
"select * from "
+
this
.
dbName
+
"."
+
tablePrefix
+
i
;
Console
.
WriteLine
(
sql
);
int
code
=
TDengine
.
Query
(
conn
,
sql
);
if
(
code
!=
TDengine
.
TSDB_CODE_SUCCESS
)
long
res
=
TDengine
.
Query
(
conn
,
sql
);
if
(
res
==
0
)
{
Console
.
WriteLine
(
sql
+
" failure, reason: "
+
TDengine
.
Error
(
conn
));
Console
.
WriteLine
(
sql
+
" failure, reason: "
+
TDengine
.
Error
(
res
));
ExitProgram
();
}
int
fieldCount
=
TDengine
.
FieldCount
(
conn
);
//
Console.WriteLine("field count: " + fieldCount);
int
fieldCount
=
TDengine
.
FieldCount
(
res
);
Console
.
WriteLine
(
"field count: "
+
fieldCount
);
List
<
TDengineMeta
>
metas
=
TDengine
.
FetchFields
(
conn
);
List
<
TDengineMeta
>
metas
=
TDengine
.
FetchFields
(
res
);
for
(
int
j
=
0
;
j
<
metas
.
Count
;
j
++)
{
TDengineMeta
meta
=
(
TDengineMeta
)
metas
[
j
];
//Console.WriteLine("index:" + j + ", type:" + meta.type + ", typename:" + meta.TypeName() + ", name:" + meta.name + ", size:" + meta.size);
}
long
result
=
TDengine
.
UseResult
(
conn
);
if
(
result
==
0
)
{
Console
.
WriteLine
(
sql
+
" result set is null"
);
return
;
Console
.
WriteLine
(
"index:"
+
j
+
", type:"
+
meta
.
type
+
", typename:"
+
meta
.
TypeName
()
+
", name:"
+
meta
.
name
+
", size:"
+
meta
.
size
);
}
IntPtr
rowdata
;
while
((
rowdata
=
TDengine
.
FetchRows
(
res
ult
))
!=
IntPtr
.
Zero
)
while
((
rowdata
=
TDengine
.
FetchRows
(
res
))
!=
IntPtr
.
Zero
)
{
queryRows
++;
for
(
int
fields
=
0
;
fields
<
fieldCount
;
++
fields
)
...
...
@@ -411,12 +414,12 @@ namespace TDengineDriver
//Console.WriteLine("---");
}
if
(
TDengine
.
ErrorNo
(
conn
)
!=
0
)
if
(
TDengine
.
ErrorNo
(
res
)
!=
0
)
{
Console
.
Write
(
"Query is not complete
, Error {0:G}"
,
TDengine
.
ErrorNo
(
conn
),
TDengine
.
Error
(
conn
));
Console
.
Write
(
"Query is not complete
, Error {0:G}"
,
TDengine
.
ErrorNo
(
res
),
TDengine
.
Error
(
res
));
}
TDengine
.
FreeResult
(
res
ult
);
TDengine
.
FreeResult
(
res
);
}
System
.
DateTime
end
=
new
System
.
DateTime
();
...
...
@@ -436,6 +439,7 @@ namespace TDengineDriver
static
void
ExitProgram
()
{
TDengine
.
Cleanup
();
System
.
Environment
.
Exit
(
0
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录