diff --git a/Jenkinsfile2 b/Jenkinsfile2 index 9ae4dde5223592ecf119de32b1404a451d6d07e9..7a7cdbe3627e6a93dd0bce08a617c17cd1dc2f7b 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -162,6 +162,5 @@ pipeline { LOGDIR = '/var/data/jenkins/workspace/log' } stages { - } } diff --git a/docs/en/07-data-in/01-insert-data.md b/docs/en/07-data-in/01-insert-data.md index f9c64601c0722e81d42b8eac345810a6596ceddc..b8396632fc049567ed42f6cb374600cd3937d957 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 24ea7ffcdd7cd08266bb0cac8425be51cb00abd3..2ac5614b76065ea8aa808176180068200f764980 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/en/09-data-out/_sub_cs.mdx b/docs/en/09-data-out/_sub_cs.mdx index 694970e7eb8415d991389b68727012592113af4c..a09e91422b12d3bfea1794d73aec28335dea9056 100644 --- a/docs/en/09-data-out/_sub_cs.mdx +++ b/docs/en/09-data-out/_sub_cs.mdx @@ -1,3 +1,3 @@ ```csharp -// {{#include docs/examples/csharp/SubscribeDemo.cs}} +{{#include docs/examples/csharp/native-example/SubscribeDemo.cs}} ``` \ No newline at end of file diff --git a/docs/examples/csharp/.gitignore b/docs/examples/csharp/.gitignore index 627e2d891bb373f27bf77455c8cc12f7bd9eac37..f816d2b931533364cf156098a4095202d04307b6 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 a870f4e60217f62f534a5a6c9f22f763cc0dc247..43f3fb77b99e965e1bfabbd6f1761585fd3ecbe9 100644 --- a/docs/examples/csharp/cloud-example/cloud-example.sln +++ b/docs/examples/csharp/cloud-example/cloud-example.sln @@ -1,34 +1,40 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30114.105 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "connect", "connect\connect.csproj", "{4006CF0C-17BE-4508-9682-A85298F8C92D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "usage", "usage\usage.csproj", "{243C420F-FC47-4F21-B81E-83CDE91F2D47}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stmt", "stmt\stmt.csproj", "{B6907CB6-41CB-4644-AEE1-551456EADE12}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.Build.0 = Release|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.Build.0 = Debug|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.ActiveCfg = Release|Any CPU - {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.Build.0 = Release|Any CPU - {B6907CB6-41CB-4644-AEE1-551456EADE12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {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 - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "connect", "connect\connect.csproj", "{4006CF0C-17BE-4508-9682-A85298F8C92D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "usage", "usage\usage.csproj", "{243C420F-FC47-4F21-B81E-83CDE91F2D47}" +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 + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4006CF0C-17BE-4508-9682-A85298F8C92D}.Release|Any CPU.Build.0 = Release|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {243C420F-FC47-4F21-B81E-83CDE91F2D47}.Release|Any CPU.Build.0 = Release|Any CPU + {B6907CB6-41CB-4644-AEE1-551456EADE12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 0000000000000000000000000000000000000000..6f3b53de716ee46fb067f2532d3008e6e67ee4a5 --- /dev/null +++ b/docs/examples/csharp/cloud-example/inout/Program.cs @@ -0,0 +1,84 @@ +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); + ValidUpdateExecution(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); + ValidUpdateExecution(res); + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + + void ValidUpdateExecution(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 + + // ANCHOR: query + string selectTable = "select * from test.meters"; + res = LibTaosWS.WSQueryTimeout(conn, selectTable, 5000); + ValidQueryExecution(res); + + // get meta info of the retrieved data as List + List metas = LibTaosWS.WSGetFields(res); + Console.WriteLine(metas.Count); + // get data of the retrieved data as List. + List dataSet = LibTaosWS.WSGetData(res); + Console.WriteLine(dataSet.Count); + // Free the query result every time when used up it. + LibTaosWS.WSFreeResult(res); + 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: query + } + finally + { + // close connect + LibTaosWS.WSClose(conn); + } + } + else + { + throw new Exception($"get connection failed,reason:{LibTaosWS.WSErrorStr(conn)},code:{LibTaosWS.WSErrorNo(conn)}"); + } + } + + } +} \ 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 0000000000000000000000000000000000000000..34951dc761903e5a4b7a4bec5dfe55a965ab88be --- /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 e7e59eb26b1b05597d6827e93f0b13301cd50efe..a6acf80a31d1cd59ac2b982d04fcb452a8767e45 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/rest"); 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/package.json b/docs/examples/node/package.json index d00d71d99fdff89af68f31a50416681733a08274..5f149dc60d740c9de47e25a585c3bfd0f1354c70 100644 --- a/docs/examples/node/package.json +++ b/docs/examples/node/package.json @@ -5,6 +5,6 @@ "license": "MIT", "dependencies": { "@tdengine/client": "^3.0.1", - "@tdengine/rest": "^3.0.0" + "@tdengine/rest": "^3.0.1" } } diff --git a/docs/examples/node/query.js b/docs/examples/node/query.js index c6218515c0f34e555a8530ca2e0f04c304763a0a..bff05e4b91f011174611a3ebf041e601efb99d34 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/rest"); function checkError(result) { if (result.getErrCode() !== undefined) { diff --git a/docs/examples/node/reference_example.js b/docs/examples/node/reference_example.js index 46d5ef2b2b7ff84be6ebf081271663d7e9bec673..c0dceb2530da4fb2d3ca203f6f4c5ae122d48cb1 100644 --- a/docs/examples/node/reference_example.js +++ b/docs/examples/node/reference_example.js @@ -1,4 +1,4 @@ -const { options, connect } = require("td2.0-rest-connector"); +const { options, connect } = require("@tdengine/rest"); options.url = process.env.TDENGINE_CLOUD_URL; options.query = { token: process.env.TDENGINE_CLOUD_TOKEN };