From 4d5982317947ba16a010ff5203472faafb2b0428 Mon Sep 17 00:00:00 2001 From: xleili Date: Tue, 13 Sep 2022 15:55:27 +0800 Subject: [PATCH] docs(cloud):C# supplement cloud docs --- docs/en/07-data-in/01-insert-data.md | 11 ++- docs/en/09-data-out/01-query-data.md | 13 ++- docs/examples/csharp/.gitignore | 2 + .../csharp/cloud-example/cloud-example.sln | 6 ++ .../csharp/cloud-example/inout/Program.cs | 81 +++++++++++++++++++ .../csharp/cloud-example/inout/inout.csproj | 13 +++ docs/examples/node/insert.js | 4 +- docs/examples/node/query.js | 2 +- 8 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 docs/examples/csharp/cloud-example/inout/Program.cs create mode 100644 docs/examples/csharp/cloud-example/inout/inout.csproj diff --git a/docs/en/07-data-in/01-insert-data.md b/docs/en/07-data-in/01-insert-data.md index f9c64601c0..b8396632fc 100644 --- a/docs/en/07-data-in/01-insert-data.md +++ b/docs/en/07-data-in/01-insert-data.md @@ -86,8 +86,17 @@ In this example, we use `exec` method to execute SQL. `exec` is designed for som ``` + + + +```C# +{{#include docs/examples/csharp/cloud-example/inout/Program.cs:insert}} +``` + + + -:::note +:::note `Use` statement is not applicable for cloud service since REST API is stateless. ::: \ No newline at end of file diff --git a/docs/en/09-data-out/01-query-data.md b/docs/en/09-data-out/01-query-data.md index 24ea7ffcdd..2ac5614b76 100644 --- a/docs/en/09-data-out/01-query-data.md +++ b/docs/en/09-data-out/01-query-data.md @@ -226,4 +226,15 @@ Get all rows and print each row: ``` - \ No newline at end of file + + + +In this example, we use query method to execute SQL and get a result object. + +```C# +{{#include docs/examples/csharp/cloud-example/inout/Program.cs:query}} +``` + + + + diff --git a/docs/examples/csharp/.gitignore b/docs/examples/csharp/.gitignore index 627e2d891b..f816d2b931 100644 --- a/docs/examples/csharp/.gitignore +++ b/docs/examples/csharp/.gitignore @@ -4,4 +4,6 @@ cloud-example/usage/bin cloud-example/usage/obj cloud-example/stmt/bin cloud-example/stmt/obj +cloud-example/inout/bin +cloud-example/inout/obj .vs \ No newline at end of file diff --git a/docs/examples/csharp/cloud-example/cloud-example.sln b/docs/examples/csharp/cloud-example/cloud-example.sln index a870f4e602..39ee563bbb 100644 --- a/docs/examples/csharp/cloud-example/cloud-example.sln +++ b/docs/examples/csharp/cloud-example/cloud-example.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "usage", "usage\usage.csproj EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stmt", "stmt\stmt.csproj", "{B6907CB6-41CB-4644-AEE1-551456EADE12}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "inout", "inout\inout.csproj", "{058C3864-CF33-459D-B1A7-F7E1C6AED452}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,5 +32,9 @@ Global {B6907CB6-41CB-4644-AEE1-551456EADE12}.Debug|Any CPU.Build.0 = Debug|Any CPU {B6907CB6-41CB-4644-AEE1-551456EADE12}.Release|Any CPU.ActiveCfg = Release|Any CPU {B6907CB6-41CB-4644-AEE1-551456EADE12}.Release|Any CPU.Build.0 = Release|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Debug|Any CPU.Build.0 = Debug|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Release|Any CPU.ActiveCfg = Release|Any CPU + {058C3864-CF33-459D-B1A7-F7E1C6AED452}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/docs/examples/csharp/cloud-example/inout/Program.cs b/docs/examples/csharp/cloud-example/inout/Program.cs new file mode 100644 index 0000000000..d82d3440d9 --- /dev/null +++ b/docs/examples/csharp/cloud-example/inout/Program.cs @@ -0,0 +1,81 @@ +using System; +using TDengineDriver; +using TDengineWS.Impl; +using System.Collections.Generic; + +namespace Cloud.Examples +{ + public class InOutExample + { + static void Main(string[] args) + { + string dsn = Environment.GetEnvironmentVariable("TDENGINE_CLOUD_DSN"); + IntPtr conn = LibTaosWS.WSConnectWithDSN(dsn); + if (conn != IntPtr.Zero) + { + + try + { + // ANCHOR: insert + string createTable = "CREATE STABLE if not exists test.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"; + string insertData = "INSERT INTO test.d1001 USING test.meters TAGS('California.SanFrancisco', 1) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000)" + + "test.d1002 USING test.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)" + + "test.d1003 USING test.meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)" + + "test.d1004 USING test.meters TAGS('California.LosAngeles', 4) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) "; + + // create database under database named 'test' + IntPtr res = LibTaosWS.WSQuery(conn, createTable); + ValidQueryExecution(res); + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + + // insert data into the table created in previous step. + res = LibTaosWS.WSQuery(conn, insertData); + ValidQueryExecution(res); + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + // ANCHOR: query + void ValidQueryExecution(IntPtr res) + { + int code = LibTaosWS.WSErrorNo(res); + if (code != 0) + { + throw new Exception($"execute SQL failed: reason: {LibTaosWS.WSErrorStr(res)}, code:{code}"); + } + } + // ANCHOR_END: insert + string selectTable = "select * from test.meters"; + IntPtr res = LibTaosWS.WSQueryTimeout(conn, selectTable, 5000); + ValidQueryExecution(res); + + // get meta info of the retrieved data as List + List metas = LibTaosWS.WSGetFields(res); + + // get data of the retrieved data as List. + List dataSet = LibTaosWS.WSGetData(res); + + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + // ANCHOR_END: query + } + finally + { + // close connect + LibTaosWS.WSClose(conn); + } + } + else + { + throw new Exception($"get connection failed,reason:{LibTaosWS.WSErrorStr(conn)},code:{LibTaosWS.WSErrorNo(conn)}"); + } + sum(1, 2); + void sum(int i, int j) + { + Console.WriteLine("{0} + {1} = {2}", i, j, i + j); + } + + + } + + } +} \ No newline at end of file diff --git a/docs/examples/csharp/cloud-example/inout/inout.csproj b/docs/examples/csharp/cloud-example/inout/inout.csproj new file mode 100644 index 0000000000..757d36dc10 --- /dev/null +++ b/docs/examples/csharp/cloud-example/inout/inout.csproj @@ -0,0 +1,13 @@ + + + + Exe + net5.0 + enable + + + + + + + diff --git a/docs/examples/node/insert.js b/docs/examples/node/insert.js index e7e59eb26b..77b360752d 100644 --- a/docs/examples/node/insert.js +++ b/docs/examples/node/insert.js @@ -1,4 +1,4 @@ -const { options, connect } = require("td2.0-rest-connector"); +const { options, connect } = require("@tdengine/client"); function checkError(result) { if (result.getErrCode() !== undefined) { @@ -19,7 +19,7 @@ async function test() { checkError(result); result = await cursor.query("CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"); checkError(result); - result = await cursor.query("INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000) power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)"); + result = await cursor.query("INSERT INTO power.d1001 USING power.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000) power.d1002 USING power.meters TAGS('California.SanFrancisco', 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)"); checkError(result); console.log("AffectedRows:", result.getAffectRows()) } catch (err) { diff --git a/docs/examples/node/query.js b/docs/examples/node/query.js index c6218515c0..8ba50ff4bd 100644 --- a/docs/examples/node/query.js +++ b/docs/examples/node/query.js @@ -1,4 +1,4 @@ -const { options, connect } = require("td2.0-rest-connector"); +const { options, connect } = require("@tdengine/client"); function checkError(result) { if (result.getErrCode() !== undefined) { -- GitLab