未验证 提交 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 ...@@ -165,7 +165,7 @@ namespace TDengineDriver
public void ReadArgument(String[] argv) public void ReadArgument(String[] argv)
{ {
PrintHelp(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"); user = this.GetArgumentAsString(argv, "-u", "root");
password = this.GetArgumentAsString(argv, "-p", "taosdata"); password = this.GetArgumentAsString(argv, "-p", "taosdata");
dbName = this.GetArgumentAsString(argv, "-d", "db"); dbName = this.GetArgumentAsString(argv, "-d", "db");
...@@ -212,42 +212,54 @@ namespace TDengineDriver ...@@ -212,42 +212,54 @@ namespace TDengineDriver
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.Append("create database if not exists ").Append(this.dbName); sql.Append("create database if not exists ").Append(this.dbName);
IntPtr res = TDengine.Query(this.conn, sql.ToString()); 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 else
{ {
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res)); Console.WriteLine(sql.ToString() + " success");
ExitProgram();
} }
TDengine.FreeResult(res); TDengine.FreeResult(res);
sql.Clear(); sql.Clear();
sql.Append("use ").Append(this.dbName); sql.Append("use ").Append(this.dbName);
res = TDengine.Query(this.conn, sql.ToString()); 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 else
{ {
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res)); Console.WriteLine(sql.ToString() + " success");
ExitProgram();
} }
TDengine.FreeResult(res); TDengine.FreeResult(res);
sql.Clear(); 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)"); 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()); 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 else
{ {
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res)); Console.WriteLine(sql.ToString() + " success");
ExitProgram();
} }
TDengine.FreeResult(res); TDengine.FreeResult(res);
...@@ -257,14 +269,18 @@ namespace TDengineDriver ...@@ -257,14 +269,18 @@ namespace TDengineDriver
sql = sql.Append("create table if not exists ").Append(this.tablePrefix).Append(i) sql = sql.Append("create table if not exists ").Append(this.tablePrefix).Append(i)
.Append(" using ").Append(this.stableName).Append(" tags(").Append(i).Append(")"); .Append(" using ").Append(this.stableName).Append(" tags(").Append(i).Append(")");
res = TDengine.Query(this.conn, sql.ToString()); 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 else
{ {
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res)); Console.WriteLine(sql.ToString() + " success");
ExitProgram();
} }
TDengine.FreeResult(res); TDengine.FreeResult(res);
} }
...@@ -298,9 +314,13 @@ namespace TDengineDriver ...@@ -298,9 +314,13 @@ namespace TDengineDriver
.Append(", 5, 6, 7, 'abc', 'def')"); .Append(", 5, 6, 7, 'abc', 'def')");
} }
IntPtr res = TDengine.Query(this.conn, sql.ToString()); 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); int affectRows = TDengine.AffectRows(res);
...@@ -326,16 +346,20 @@ namespace TDengineDriver ...@@ -326,16 +346,20 @@ namespace TDengineDriver
System.DateTime start = new System.DateTime(); System.DateTime start = new System.DateTime();
long queryRows = 0; long queryRows = 0;
for (int i = 0; i < 1/*this.tableCount*/; ++i) for (int i = 0; i < 1/*this.tableCount*/; ++i)
{ {
String sql = "select * from " + this.dbName + "." + tablePrefix + i; String sql = "select * from " + this.dbName + "." + tablePrefix + i;
Console.WriteLine(sql); Console.WriteLine(sql);
IntPtr res = TDengine.Query(conn, 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(); ExitProgram();
} }
...@@ -423,8 +447,10 @@ namespace TDengineDriver ...@@ -423,8 +447,10 @@ namespace TDengineDriver
if (TDengine.ErrorNo(res) != 0) 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); TDengine.FreeResult(res);
} }
......
...@@ -370,16 +370,19 @@ namespace TDengineDriver ...@@ -370,16 +370,19 @@ namespace TDengineDriver
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.Append("DROP DATABASE IF EXISTS ").Append(this.dbName); sql.Append("DROP DATABASE IF EXISTS ").Append(this.dbName);
IntPtr res = TDengine.Query(this.conn, sql.ToString()); 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 else
{ {
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res)); VerbosePrint(sql.ToString() + " success\n");
CleanAndExitProgram(1);
} }
} }
public void CreateDb() public void CreateDb()
...@@ -387,14 +390,18 @@ namespace TDengineDriver ...@@ -387,14 +390,18 @@ namespace TDengineDriver
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.Append("CREATE DATABASE IF NOT EXISTS ").Append(this.dbName).Append(" replica ").Append(this.replica); sql.Append("CREATE DATABASE IF NOT EXISTS ").Append(this.dbName).Append(" replica ").Append(this.replica);
IntPtr res = TDengine.Query(this.conn, sql.ToString()); 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 else
{ {
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res)); VerbosePrint(sql.ToString() + " success\n");
CleanAndExitProgram(1);
} }
TDengine.FreeResult(res); TDengine.FreeResult(res);
} }
...@@ -408,14 +415,18 @@ namespace TDengineDriver ...@@ -408,14 +415,18 @@ namespace TDengineDriver
Append(this.dbName).Append(".").Append(this.stablePrefix). 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)"); 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()); 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 else
{ {
Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(res)); VerbosePrint(sql.ToString() + " success\n");
CleanAndExitProgram(1);
} }
TDengine.FreeResult(res); TDengine.FreeResult(res);
} }
...@@ -495,9 +506,13 @@ namespace TDengineDriver ...@@ -495,9 +506,13 @@ namespace TDengineDriver
IntPtr res = TDengine.Query(conn, sql); IntPtr res = TDengine.Query(conn, sql);
DebugPrintFormat("res: {0}\n", res); 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); CleanAndExitProgram(1);
} }
...@@ -761,9 +776,13 @@ namespace TDengineDriver ...@@ -761,9 +776,13 @@ namespace TDengineDriver
} }
IntPtr res = TDengine.Query(this.conn, sql.ToString()); 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; inserted += this.batchRows;
...@@ -840,14 +859,18 @@ namespace TDengineDriver ...@@ -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))"); 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()); 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 else
{ {
VerbosePrint(sql.ToString() + " failure, reason: " + TDengine.Error(res) + "\n"); VerbosePrint(sql.ToString() + " success\n");
CleanAndExitProgram(1);
} }
TDengine.FreeResult(res); TDengine.FreeResult(res);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册