diff --git a/examples/C#/C#checker/C#checker.cs b/examples/C#/C#checker/C#checker.cs index 7d0b6a50b673278ac6982a97de7eb31ce76761b6..f49fda88cdd8d298f2253bb8f47ccce58c3b0118 100644 --- a/examples/C#/C#checker/C#checker.cs +++ b/examples/C#/C#checker/C#checker.cs @@ -389,7 +389,7 @@ namespace TDengineDriver static void ExitProgram() { - System.Environment.Exit(0); + System.Environment.Exit(1); } public void cleanup() diff --git a/examples/C#/C#checker/C#checker.csproj b/examples/C#/C#checker/C#checker.csproj index afeeaf3f01301210c0e945c8e02b40790ebec743..68bc2b5ad50cd37d0a11cc806a0d3742082c36a9 100644 --- a/examples/C#/C#checker/C#checker.csproj +++ b/examples/C#/C#checker/C#checker.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 C_checker diff --git a/examples/C#/TDengineTest/TDengineTest.csproj b/examples/C#/TDengineTest/TDengineTest.csproj index 211c927d3d36df5941291319e3c85707610c6a8f..af51b4eeecb33754e7005dd30c08cc56ee495fce 100644 --- a/examples/C#/TDengineTest/TDengineTest.csproj +++ b/examples/C#/TDengineTest/TDengineTest.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 diff --git a/examples/C#/insertCn/insertCn.csproj b/examples/C#/insertCn/insertCn.csproj index 69ddfdfbbff10fd9c26c92dcb8c8c2928b5c8511..afd8df62e4f23807dcacaca52aaefc7cc0133a4a 100644 --- a/examples/C#/insertCn/insertCn.csproj +++ b/examples/C#/insertCn/insertCn.csproj @@ -6,7 +6,7 @@ Exe - net5.0 + net6.0 diff --git a/examples/C#/insertCn/lib/ResultSetUtils.cs b/examples/C#/insertCn/lib/ResultSetUtils.cs new file mode 100644 index 0000000000000000000000000000000000000000..7d299411ee68067fca9b8cc5fc8c38e53510fa5d --- /dev/null +++ b/examples/C#/insertCn/lib/ResultSetUtils.cs @@ -0,0 +1,43 @@ +using System; +using TDengineDriver; +using System.Runtime.InteropServices; +using System.Text; +using System.Collections.Generic; +namespace Test.UtilsTools.ResultSet +{ + public class ResultSet + { + private List resultMeta; + private List resultData; + // private bool isValidResult = false; + public ResultSet(IntPtr res) + { + + resultMeta = UtilsTools.GetResField(res); + resultData = UtilsTools.GetResData(res); + } + + public ResultSet(List metas, List datas) + { + resultMeta = metas; + resultData = datas; + } + + public List GetResultData() + { + return resultData; + } + + public List GetResultMeta() + { + return resultMeta; + } + + public int GetFieldsNum() + { + return resultMeta.Count; + } + } + + +} diff --git a/examples/C#/insertCn/lib/Utils.cs b/examples/C#/insertCn/lib/Utils.cs new file mode 100644 index 0000000000000000000000000000000000000000..6107ecab57869fbdd001988d54ba36930bb1fd0d --- /dev/null +++ b/examples/C#/insertCn/lib/Utils.cs @@ -0,0 +1,418 @@ +using System; +using TDengineDriver; +using System.Runtime.InteropServices; +using System.Text; +using System.Collections.Generic; +namespace Test.UtilsTools +{ + public class UtilsTools + { + + static string ip = "127.0.0.1"; + static string user = "root"; + static string password = "taosdata"; + static string db = ""; + static short port = 0; + //get a tdengine connection + public static IntPtr TDConnection() + { + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, GetConfigPath()); + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); + TDengine.Init(); + IntPtr conn = TDengine.Connect(ip, user, password, db, port); + return conn; + } + //get taos.cfg file based on different os + public static string GetConfigPath() + { + string configDir = "" ; + if(OperatingSystem.IsOSPlatform("Windows")) + { + configDir = "C:/TDengine/cfg"; + } + else if(OperatingSystem.IsOSPlatform("Linux")) + { + configDir = "/etc/taos"; + } + else if(OperatingSystem.IsOSPlatform("macOS")) + { + configDir = "/etc/taos"; + } + return configDir; + } + + public static IntPtr ExecuteQuery(IntPtr conn, String sql) + { + IntPtr res = TDengine.Query(conn, sql); + if (!IsValidResult(res)) + { + Console.Write(sql.ToString() + " failure, "); + ExitProgram(); + } + else + { + Console.WriteLine(sql.ToString() + " success"); + } + return res; + } + + public static IntPtr ExecuteErrorQuery(IntPtr conn, String sql) + { + IntPtr res = TDengine.Query(conn, sql); + if (!IsValidResult(res)) + { + Console.Write(sql.ToString() + " failure, "); + ExitProgram(); + } + else + { + Console.WriteLine(sql.ToString() + " success"); + + } + return res; + } + + public static void ExecuteUpdate(IntPtr conn, String sql) + { + IntPtr res = TDengine.Query(conn, sql); + if (!IsValidResult(res)) + { + Console.Write(sql.ToString() + " failure, "); + ExitProgram(); + } + else + { + Console.WriteLine(sql.ToString() + " success"); + + } + TDengine.FreeResult(res); + } + + + public static bool IsValidResult(IntPtr res) + { + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + return false; + } + Console.WriteLine(""); + return false; + } + return true; + } + public static void CloseConnection(IntPtr conn) + { + if (conn != IntPtr.Zero) + { + if (TDengine.Close(conn) == 0) + { + Console.WriteLine("close connection sucess"); + } + else + { + Console.WriteLine("close Connection failed"); + } + } + TDengine.Cleanup(); + } + public static List GetResField(IntPtr res) + { + List metas = TDengine.FetchFields(res); + return metas; + } + public static void AssertEqual(string expectVal, string actualVal) + { + if (expectVal == actualVal) + { + Console.WriteLine("{0}=={1} pass", expectVal, actualVal); + } + else + { + Console.WriteLine("{0}=={1} failed", expectVal, actualVal); + ExitProgram(); + } + } + public static void ExitProgram() + { + TDengine.Cleanup(); + System.Environment.Exit(1); + } + public static List GetResData(IntPtr res) + { + List dataRaw = new List(); + if (!IsValidResult(res)) + { + ExitProgram(); + } + List metas = GetResField(res); + dataRaw = QueryRes(res, metas); + return dataRaw; + } + + public static TDengineMeta ConstructTDengineMeta(string name, string type) + { + + TDengineMeta _meta = new TDengineMeta(); + _meta.name = name; + char[] separators = new char[] { '(', ')' }; + string[] subs = type.Split(separators, StringSplitOptions.RemoveEmptyEntries); + + switch (subs[0].ToUpper()) + { + case "BOOL": + _meta.type = 1; + _meta.size = 1; + break; + case "TINYINT": + _meta.type = 2; + _meta.size = 1; + break; + case "SMALLINT": + _meta.type = 3; + _meta.size = 2; + break; + case "INT": + _meta.type = 4; + _meta.size = 4; + break; + case "BIGINT": + _meta.type = 5; + _meta.size = 8; + break; + case "TINYINT UNSIGNED": + _meta.type = 11; + _meta.size = 1; + break; + case "SMALLINT UNSIGNED": + _meta.type = 12; + _meta.size = 2; + break; + case "INT UNSIGNED": + _meta.type = 13; + _meta.size = 4; + break; + case "BIGINT UNSIGNED": + _meta.type = 14; + _meta.size = 8; + break; + case "FLOAT": + _meta.type = 6; + _meta.size = 4; + break; + case "DOUBLE": + _meta.type = 7; + _meta.size = 8; + break; + case "BINARY": + _meta.type = 8; + _meta.size = short.Parse(subs[1]); + break; + case "TIMESTAMP": + _meta.type = 9; + _meta.size = 8; + break; + case "NCHAR": + _meta.type = 10; + _meta.size = short.Parse(subs[1]); + break; + case "JSON": + _meta.type = 15; + _meta.size = 4096; + break; + default: + _meta.type = byte.MaxValue; + _meta.size = 0; + break; + } + return _meta; + } + + private static List QueryRes(IntPtr res, List metas) + { + IntPtr rowdata; + long queryRows = 0; + List dataRaw = new List(); + int fieldCount = metas.Count; + while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero) + { + queryRows++; + IntPtr colLengthPtr = TDengine.FetchLengths(res); + int[] colLengthArr = new int[fieldCount]; + Marshal.Copy(colLengthPtr, colLengthArr, 0, fieldCount); + + for (int fields = 0; fields < fieldCount; ++fields) + { + TDengineMeta meta = metas[fields]; + int offset = IntPtr.Size * fields; + IntPtr data = Marshal.ReadIntPtr(rowdata, offset); + + if (data == IntPtr.Zero) + { + dataRaw.Add("NULL"); + continue; + } + + switch ((TDengineDataType)meta.type) + { + case TDengineDataType.TSDB_DATA_TYPE_BOOL: + bool v1 = Marshal.ReadByte(data) == 0 ? false : true; + dataRaw.Add(v1); + break; + case TDengineDataType.TSDB_DATA_TYPE_TINYINT: + sbyte v2 = (sbyte)Marshal.ReadByte(data); + dataRaw.Add(v2); + break; + case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: + short v3 = Marshal.ReadInt16(data); + dataRaw.Add(v3); + break; + case TDengineDataType.TSDB_DATA_TYPE_INT: + int v4 = Marshal.ReadInt32(data); + dataRaw.Add(v4); + break; + case TDengineDataType.TSDB_DATA_TYPE_BIGINT: + long v5 = Marshal.ReadInt64(data); + dataRaw.Add(v5); + break; + case TDengineDataType.TSDB_DATA_TYPE_FLOAT: + float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); + dataRaw.Add(v6); + break; + case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: + double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); + dataRaw.Add(v7); + break; + case TDengineDataType.TSDB_DATA_TYPE_BINARY: + // string v8 = Marshal.PtrToStringAnsi(data, colLengthArr[fields]); + string v8 = Marshal.PtrToStringUTF8(data, colLengthArr[fields]); + dataRaw.Add(v8); + break; + case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: + long v9 = Marshal.ReadInt64(data); + dataRaw.Add(v9); + break; + case TDengineDataType.TSDB_DATA_TYPE_NCHAR: + // string v10 = Marshal.PtrToStringAnsi(data, colLengthArr[fields]); + string v10 = Marshal.PtrToStringUTF8(data, colLengthArr[fields]); + dataRaw.Add(v10); + break; + case TDengineDataType.TSDB_DATA_TYPE_UTINYINT: + byte v12 = Marshal.ReadByte(data); + dataRaw.Add(v12); + break; + case TDengineDataType.TSDB_DATA_TYPE_USMALLINT: + ushort v13 = (ushort)Marshal.ReadInt16(data); + dataRaw.Add(v13); + break; + case TDengineDataType.TSDB_DATA_TYPE_UINT: + uint v14 = (uint)Marshal.ReadInt32(data); + dataRaw.Add(v14); + break; + case TDengineDataType.TSDB_DATA_TYPE_UBIGINT: + ulong v15 = (ulong)Marshal.ReadInt64(data); + dataRaw.Add(v15); + break; + default: + dataRaw.Add("unknown value"); + break; + } + } + + } + if (TDengine.ErrorNo(res) != 0) + { + Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res)); + } + TDengine.FreeResult(res); + Console.WriteLine(""); + return dataRaw; + } + + // Generate insert sql for the with the coldata and tag data + public static string ConstructInsertSql(string table,string stable,List colData,List tagData,int numOfRows) + { + int numofFileds = colData.Count / numOfRows; + StringBuilder insertSql; + + if (stable == "") + { + insertSql = new StringBuilder($"insert into {table} values("); + } + else + { + insertSql = new StringBuilder($"insert into {table} using {stable} tags("); + + for (int j = 0; j < tagData.Count; j++) + { + if (tagData[j] is String) + { + insertSql.Append('\''); + insertSql.Append(tagData[j]); + insertSql.Append('\''); + } + else + { + insertSql.Append(tagData[j]); + } + if (j + 1 != tagData.Count) + { + insertSql.Append(','); + } + } + + insertSql.Append(")values("); + } + for (int i = 0; i < colData.Count; i++) + { + + if (colData[i] is String) + { + insertSql.Append('\''); + insertSql.Append(colData[i]); + insertSql.Append('\''); + } + else + { + insertSql.Append(colData[i]); + } + + if ((i + 1) % numofFileds == 0 && (i + 1) != colData.Count) + { + insertSql.Append(")("); + } + else if ((i + 1) == colData.Count) + { + insertSql.Append(')'); + } + else + { + insertSql.Append(','); + } + } + insertSql.Append(';'); + //Console.WriteLine(insertSql.ToString()); + + return insertSql.ToString(); + } + + public static List CombineColAndTagData(List colData,List tagData, int numOfRows) + { + var list = new List(); + for (int i = 0; i < colData.Count; i++) + { + list.Add(colData[i]); + if ((i + 1) % (colData.Count / numOfRows) == 0) + { + for (int j = 0; j < tagData.Count; j++) + { + list.Add(tagData[j]); + } + } + } + return list; + } + } +} diff --git a/examples/C#/jsonTag/JsonTag.cs b/examples/C#/jsonTag/JsonTag.cs index 453e54eabdc9a4ec61cdc2a061af69ed64753416..5c94df8b5a36bf20589250567e0352cfe7ef9b25 100644 --- a/examples/C#/jsonTag/JsonTag.cs +++ b/examples/C#/jsonTag/JsonTag.cs @@ -11,7 +11,7 @@ namespace Cases IntPtr conn = IntPtr.Zero; Console.WriteLine("===================JsonTagTest===================="); conn = conn = UtilsTools.TDConnection("127.0.0.1", "root", "taosdata", "", 0); - UtilsTools.ExecuteUpdate(conn, "create database if not exists csharp_sample keep 3650"); + UtilsTools.ExecuteUpdate(conn, "create database if not exists csharp keep 3650"); UtilsTools.ExecuteUpdate(conn, "use csharp"); JsonTagSample jsonTagSample = new JsonTagSample(); jsonTagSample.Test(conn); diff --git a/examples/C#/jsonTag/Util.cs b/examples/C#/jsonTag/Util.cs index 5138938df60532616e75b45d8a95597c322dfd1a..7446378fc75a4cfe49840f778961e92c37d7699d 100644 --- a/examples/C#/jsonTag/Util.cs +++ b/examples/C#/jsonTag/Util.cs @@ -217,10 +217,10 @@ namespace Utils } } } - public static void ExitProgram() + public static void ExitProgram(int i = 1) { TDengine.Cleanup(); - System.Environment.Exit(0); + System.Environment.Exit(i); } } } \ No newline at end of file diff --git a/examples/C#/jsonTag/jsonTag.csproj b/examples/C#/jsonTag/jsonTag.csproj index ed3af6e806f0321828742597d226011bfb4d5185..2962d33a697e3b6fa6dd3f3390bfc8c2545ffaeb 100644 --- a/examples/C#/jsonTag/jsonTag.csproj +++ b/examples/C#/jsonTag/jsonTag.csproj @@ -2,11 +2,11 @@ Exe - net5.0 + net6.0 - - + + diff --git a/examples/C#/schemaless/schemaless.csproj b/examples/C#/schemaless/schemaless.csproj index d132e34589525826d5b0ff0f0055156fad2d5a38..50e84ec1f91d6045c7fc6b967aa4c7b9bd27f6ad 100644 --- a/examples/C#/schemaless/schemaless.csproj +++ b/examples/C#/schemaless/schemaless.csproj @@ -2,11 +2,11 @@ Exe - net5.0 + net6.0 - - + + diff --git a/examples/C#/schemaless/schemalessSample.cs b/examples/C#/schemaless/schemalessSample.cs index f27ac352a6fc8a3fbbaf84966ae3b82e6036e91a..8d0b7f60d0dad60d382887e9c0661f72ca522c18 100644 --- a/examples/C#/schemaless/schemalessSample.cs +++ b/examples/C#/schemaless/schemalessSample.cs @@ -289,7 +289,7 @@ namespace TDengineDriver static void ExitProgram() { - System.Environment.Exit(0); + System.Environment.Exit(1); } public void cleanup() diff --git a/examples/C#/stmt/StmtDemo.cs b/examples/C#/stmt/StmtDemo.cs index fdd647fdb5f9c4bb528a2e99acc6975adf4c30a3..56a5aa20f3456524d9cca4f056d5510de23d4689 100644 --- a/examples/C#/stmt/StmtDemo.cs +++ b/examples/C#/stmt/StmtDemo.cs @@ -543,7 +543,7 @@ namespace TDengineDriver public static void ExitProgram() { TDengine.Cleanup(); - System.Environment.Exit(0); + System.Environment.Exit(1); } } } diff --git a/examples/C#/stmt/stmt.csproj b/examples/C#/stmt/stmt.csproj index f0370cbf5684418edb026b56e306d7d7295a6638..629f476422fab58863bb57266054bf64ea772cd4 100644 --- a/examples/C#/stmt/stmt.csproj +++ b/examples/C#/stmt/stmt.csproj @@ -6,7 +6,7 @@ Exe - net5.0 + net6.0 diff --git a/examples/C#/taosdemo/taosdemo.csproj b/examples/C#/taosdemo/taosdemo.csproj index 8d4b786ba3a99b600783a5b4ee55d99f03e47655..f6beeda56be3f8b09d108cc001729f8bf928b2a2 100644 --- a/examples/C#/taosdemo/taosdemo.csproj +++ b/examples/C#/taosdemo/taosdemo.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 false diff --git a/tests/develop-test/3-connectors/c#/test.sh b/tests/develop-test/3-connectors/c#/test.sh index 8cfb3fe4fcff6ab820b53698e508189e557676ca..06d31887880feab20351995da0fc8f1342763e76 100755 --- a/tests/develop-test/3-connectors/c#/test.sh +++ b/tests/develop-test/3-connectors/c#/test.sh @@ -15,25 +15,45 @@ rm -rf /var/lib/taos/* rm -rf /var/log/taos/* nohup taosd -c /etc/taos/ > /dev/null 2>&1 & sleep 10 + +# define fun to check if execute correct. +check(){ +if [ $1 -eq 0 ] +then + echo "===================$2 succeed===================" +else + echo "===================$2 failed===================" + exit 1 +fi +} + 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 +echo "WKC:${WKC}" # run example with neuget package cd ${WKC}/tests/examples/C# + dotnet run --project C#checker/C#checker.csproj +check $? C#checker.csproj + dotnet run --project TDengineTest/TDengineTest.csproj +check $? TDengineTest.csproj + dotnet run --project schemaless/schemaless.csproj +check $? schemaless.csproj + dotnet run --project jsonTag/jsonTag.csproj +check $? jsonTag.csproj + dotnet run --project stmt/stmt.csproj +check $? stmt.csproj + +dotnet run --project insertCn/insertCn.csproj +check $? insertCn.csproj cd ${WKC}/tests/examples/C#/taosdemo dotnet build -c Release tree | true -./bin/Release/net5.0/taosdemo -c /etc/taos -y +./bin/Release/net6.0/taosdemo -c /etc/taos -y +check $? taosdemo diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index e8e7b286681b03688440f931f7089a5c8765cf44..059d77f18d9c0a0e7c06ff89cdbbdbd6b0cd03d4 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -236,6 +236,7 @@ 30,,script,./test.sh -f general/import/commit.sim 30,,script,./test.sh -f general/compute/diff2.sim 30,,develop-test,bash 3-connectors/R/test.sh +30,,develop-test,bash 3-connectors/c#/test.sh 29,,system-test,python3 ./test.py -f 0-others/create_col_tag.py 29,,script,./test.sh -f unique/arbitrator/dn3_mn1_full_createTableFail.sim 29,,script,./test.sh -f general/wal/maxtables.sim