Tdslite.h - SELECT with Parameters

Exemple tdslite - whitc parameters

I don't know if this is the place to ask this question. It's about the tdslite library, make a SELECT with parameters.
I am tested on examples 05-query-wicht-parameters.
In this table, I have several lines where I have "test", but I'm only interested in the line where "b" is the largest.
I need to make a query to a database and I only want the record where a="test" and of all these, the one where the value of b is the largest of all.
The example query returns all the lines where a="test" and b=1

Don't make the inquiry!!!

  // Execute SELECT query on every tenth loop.
    if (0 == (loop_counter % 10)) {
        auto query{TDSL_PMEMSTR("SELECT * FROM #example_table WHERE a = @p0 AND b = @p1")};

        SERIAL_PRINTF("Executing query: ");
        SERIAL_PRINTLNF_PROGMEM(query.raw_data());
        // We're using the row
        tdsl::sql_parameter_varchar a{"test"};
        tdsl::sql_parameter_int b{1};
        tdsl::sql_parameter_binding params []{a, b};
        driver.execute_rpc(query, params, tdsl::rpc_mode::executesql, row_callback);
        // SERIAL_PRINTLNF("Result: %d", ra);
    }

An sql query could be

SELECT *
FROM your_table_name
WHERE a = 'test'
ORDER BY b DESC
LIMIT 1;

Thanks.

"SELECT * FROM example_table WHERE a = @p0 ORDER BY b DESC LIMIT 1 "

It doesn't give any error, but it doesn't work for me!!!

Try the command manually to see if it works

Then try with a canned request with nothing variable to see if things work in your code

"SELECT TOP 1 * FROM example_table WHERE a = @p0 ORDER by b DESC"

Thank you so much.
That's how it works.

Ok - each database has its own specificities. Have fun

Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.