未验证 提交 808019af 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Hotfix/sangshuduo/td 3877 c sharp query result (#5866)

* [TD-3877]<fix>: C# query result determination mechanism changed.

* [TD-3877]<fix>: C# query result determination mechanism changed.

change taosdemo and C#checker.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 3281a563
......@@ -165,7 +165,7 @@ namespace TDengineDriver
public void ReadArgument(String[] argv)
{
PrintHelp(argv);
host = this.GetArgumentAsString(argv, "-h", "192.168.100.128");
host = this.GetArgumentAsString(argv, "-h", "127.0.0.1");
user = this.GetArgumentAsString(argv, "-u", "root");
password = this.GetArgumentAsString(argv, "-p", "taosdata");
dbName = this.GetArgumentAsString(argv, "-d", "db");
......@@ -212,42 +212,54 @@ namespace TDengineDriver
StringBuilder sql = new StringBuilder();
sql.Append("create database if not exists ").Append(this.dbName);
IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.WriteLine(sql.ToString() + " success");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
ExitProgram();
}
else
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
ExitProgram();
Console.WriteLine(sql.ToString() + " success");
}
TDengine.FreeResult(res);
sql.Clear();
sql.Append("use ").Append(this.dbName);
res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.WriteLine(sql.ToString() + " success");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
ExitProgram();
}
else
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
ExitProgram();
Console.WriteLine(sql.ToString() + " success");
}
TDengine.FreeResult(res);
sql.Clear();
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 != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.WriteLine(sql.ToString() + " success");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
ExitProgram();
}
else
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
ExitProgram();
Console.WriteLine(sql.ToString() + " success");
}
TDengine.FreeResult(res);
......@@ -257,14 +269,18 @@ namespace TDengineDriver
sql = sql.Append("create table if not exists ").Append(this.tablePrefix).Append(i)
.Append(" using ").Append(this.stableName).Append(" tags(").Append(i).Append(")");
res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.WriteLine(sql.ToString() + " success");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
ExitProgram();
}
else
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
ExitProgram();
Console.WriteLine(sql.ToString() + " success");
}
TDengine.FreeResult(res);
}
......@@ -298,9 +314,13 @@ namespace TDengineDriver
.Append(", 5, 6, 7, 'abc', 'def')");
}
IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res == IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
}
int affectRows = TDengine.AffectRows(res);
......@@ -326,16 +346,20 @@ namespace TDengineDriver
System.DateTime start = new System.DateTime();
long queryRows = 0;
for (int i = 0; i < 1/*this.tableCount*/; ++i)
{
String sql = "select * from " + this.dbName + "." + tablePrefix + i;
Console.WriteLine(sql);
IntPtr res = TDengine.Query(conn, sql);
if (res == IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.WriteLine(sql + " failure, reason: " + TDengine.Error(res));
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
ExitProgram();
}
......@@ -423,8 +447,10 @@ namespace TDengineDriver
if (TDengine.ErrorNo(res) != 0)
{
Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res));
Console.Write("Query is not complete, Error {0:G}",
TDengine.ErrorNo(res), TDengine.Error(res));
}
Console.WriteLine("");
TDengine.FreeResult(res);
}
......
......@@ -370,16 +370,19 @@ namespace TDengineDriver
StringBuilder sql = new StringBuilder();
sql.Append("DROP DATABASE IF EXISTS ").Append(this.dbName);
IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
VerbosePrint(sql.ToString() + " success\n");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
CleanAndExitProgram(1);
}
else
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
CleanAndExitProgram(1);
VerbosePrint(sql.ToString() + " success\n");
}
}
public void CreateDb()
......@@ -387,14 +390,18 @@ namespace TDengineDriver
StringBuilder sql = new StringBuilder();
sql.Append("CREATE DATABASE IF NOT EXISTS ").Append(this.dbName).Append(" replica ").Append(this.replica);
IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
VerbosePrint(sql.ToString() + " success\n");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
CleanAndExitProgram(1);
}
else
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
CleanAndExitProgram(1);
VerbosePrint(sql.ToString() + " success\n");
}
TDengine.FreeResult(res);
}
......@@ -408,14 +415,18 @@ namespace TDengineDriver
Append(this.dbName).Append(".").Append(this.stablePrefix).
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)");
IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
VerbosePrint(sql.ToString() + " success\n");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
CleanAndExitProgram(1);
}
else
{
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res));
CleanAndExitProgram(1);
VerbosePrint(sql.ToString() + " success\n");
}
TDengine.FreeResult(res);
}
......@@ -495,9 +506,13 @@ namespace TDengineDriver
IntPtr res = TDengine.Query(conn, sql);
DebugPrintFormat("res: {0}\n", res);
if (res == IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
Console.WriteLine(sql + " failure, reason: " + TDengine.Error(res));
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
CleanAndExitProgram(1);
}
......@@ -761,9 +776,13 @@ namespace TDengineDriver
}
IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res == IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
VerbosePrint(sql.ToString() + " failure, reason: " + TDengine.Error(res) + "\n");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
}
inserted += this.batchRows;
......@@ -840,14 +859,18 @@ namespace TDengineDriver
sql = sql.Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10))");
}
IntPtr res = TDengine.Query(this.conn, sql.ToString());
if (res != IntPtr.Zero)
if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0))
{
VerbosePrint(sql.ToString() + " success\n");
Console.Write(sql.ToString() + " failure, ");
if (res != IntPtr.Zero) {
Console.Write("reason: " + TDengine.Error(res));
}
Console.WriteLine("");
CleanAndExitProgram(1);
}
else
{
VerbosePrint(sql.ToString() + " failure, reason: " + TDengine.Error(res) + "\n");
CleanAndExitProgram(1);
VerbosePrint(sql.ToString() + " success\n");
}
TDengine.FreeResult(res);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册