Asking how to send variable along with a SQL query. #10
-
When I'm trying to put a variables into write SQL query after convert them to strings, I got a compile error in the below attached arduino file. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hello @SupulP, Can you provide the error message as well? |
Beta Was this translation helpful? Give feedback.
-
I believe you're trying to bind variables to a query, see the following example for how to do so: |
Beta Was this translation helpful? Give feedback.
-
I got this earlier. And I have insert it to my code.Can you check my code whether I'm right or not? |
Beta Was this translation helpful? Give feedback.
-
Please guide me how to send my query as I declared as "x" in my code to the SQL server. I have attached full code and ss of particular part of problem. Please give me some solution as soon as possible. Thanks https://drive.google.com/drive/folders/1FnakqYvI_1lq9m5ue19BHRH8f_PnfxN-?usp=sharing |
Beta Was this translation helpful? Give feedback.
-
Code - |
Beta Was this translation helpful? Give feedback.
-
Hello @SupulP You can bind the parameters in your code to your SQL query like below: // mock_table
command_ctx.execute_query(
tdsl::string_view{"CREATE TABLE #food_voting_system(a int, b varchar(50), c int, d int, e "
"int, f int, g varchar(50))"});
int timestamp = {0}, excellent_count = {0}, good_count = {0}, fair_count = {0},
poor_count = {0};
tdsl::detail::sql_parameter_int p0{timestamp};
tdsl::detail::sql_parameter_varchar p1{"Morning"};
tdsl::detail::sql_parameter_int p2{excellent_count};
tdsl::detail::sql_parameter_int p3{good_count};
tdsl::detail::sql_parameter_int p4{fair_count};
tdsl::detail::sql_parameter_int p5{poor_count};
tdsl::detail::sql_parameter_varchar p6{"Excellent"};
tdsl::detail::sql_parameter_binding params [] = {p0, p1, p2, p3, p4, p5, p6};
// Fill some data
command_ctx.execute_rpc(
tdsl::string_view{
"INSERT INTO #food_voting_system VALUES(@p0, @p1, @p2, @p3, @p4, @p5, @p6)"},
params, tdsl::detail::e_rpc_mode::executesql); |
Beta Was this translation helpful? Give feedback.
Hello @SupulP
You can bind the parameters in your code to your SQL query like below: