rusoto_rds_data::ExecuteSqlRequest // passing value through parameter

I'm referring to https://rusoto.github.io/rusoto/rusoto_rds_data/index.html

Consider the following piece of code:

        let x = Self::exec_stmt(
            "SELECT \"hello world\"".to_string(),
            Some(vec![SqlParameter {
                name: Some("EntryName".to_string()),
                value: Some(rusoto_rds_data::Field {
                    blob_value: None,
                    boolean_value: None,
                    double_value: None,
                    is_null: None,
                    long_value: None,
                    string_value: Some("hello world".to_string()),
                }),
            }]),
        )
        .sync();
        println!("000 got: {:?}", x);

        let x = Self::exec_stmt(
            "SELECT @EntryName".to_string(),
            Some(vec![SqlParameter {
                name: Some("EntryName".to_string()),
                value: Some(rusoto_rds_data::Field {
                    blob_value: None,
                    boolean_value: None,
                    double_value: None,
                    is_null: None,
                    long_value: None,
                    string_value: Some("hello world".to_string()),
                }),
            }]),
        )
        .sync();
        println!("111 got: {:?}", x);

        let x = Self::exec_stmt(
            "SELECT @EntryName".to_string(),
            Some(vec![SqlParameter {
                name: Some("@EntryName".to_string()),
                value: Some(rusoto_rds_data::Field {
                    blob_value: None,
                    boolean_value: None,
                    double_value: None,
                    is_null: None,
                    long_value: None,
                    string_value: Some("hello world".to_string()),
                }),
            }]),
        )
        .sync();
        println!("222 got: {:?}", x);

I get output of:

000 got: Ok(ExecuteStatementResponse { column_metadata: None, generated_fields: None, number_of_records_updated: Some(
0), records: Some([[Field { blob_value: None, boolean_value: None, double_value: None, is_null: None, long_value: None
, string_value: Some("hello world") }]]) })
111 got: Ok(ExecuteStatementResponse { column_metadata: None, generated_fields: None, number_of_records_updated: Some(
0), records: Some([[Field { blob_value: None, boolean_value: None, double_value: None, is_null: Some(true), long_value
: None, string_value: None }]]) })
222 got: Err(Service(BadRequest("Named parameter syntax is invalid, input: @EntryName")))
get_db_wiki_entry_by_short_title "trig_circle_def" database error: Service(BadRequest("Named parameter syntax is inval
id, input: @EntryName"))

The problem here is that I don't know how to pass a parameter to SQL.

In the first example, it works when I hard code the "hello world" into the sql query.

In the second example, I am trying to pass it via "@EntryName" -- but I get NULL in return value.

In the last example, I'm trying to give the parameter the name "@EntryName" -- but am being told that that isinvalid.

What am I doing wrong?

I'm not sure where the exec_stmt function comes from, but the crate you linked to doesn't seem to (publicly) contain anything with that name.

Furthermore, I must say I'm no expert with RDS Data services, but most examples I've seen use a colon (:) as the leading character of a parameter name, not an at-sign.

1 Like
  1. @EntryName -> :EntryName fixed it

  2. This is my first time using SQL parameters, and didn't realize the convention was ":".

Thanks!

Alas, it's not "THE" convention. At least if I'm not wrong, there are several different ways different SQL engines denote parameters, and I do remember seeing @ as one of them. Others include : (as here), the question mark ?name, I may even have come accross #name or %name at some point, although I'm not remotely sure. Again, I haven't really used RDS before, it's just that the examples I've seen after a quick Google DuckDuckGo search used the colon, so I thought why not try that. Talk about luck, heh.

1 Like

The official MySQL docs uses @ , i.e. see https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-parameters.html

string sql = "SELECT Name, HeadOfState FROM Country WHERE Continent = @Continent";

It even states:

The parameter is preceded by an '@' symbol to indicate it is to be treated as a parameter.

Then, for my Aurora Serverless setup, I chose "MySQL compatible" rather than "Postgres compatible"

So in my prior-distribution for "where is the bug", I did not even consider the possibility of @ being wrong.

Anyway, good thing you're more diligent and searched for AWS Aurora Serverless RDS Data API examples. :slight_smile:

1 Like

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