Skip to content

Asking how to send variable along with a SQL query. #10

Answered by mustafakemalgilor
SupulP asked this question in Q&A
Discussion options

You must be logged in to vote

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_param…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mustafakemalgilor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #7 on April 28, 2023 08:49.