Skip to content

MSSQL documentation: Binding a variable to a query #905

@joshbenaron

Description

@joshbenaron

Hey,

I'm trying to bind a variable to a query like so:

#[derive(sqlx::FromRow)]
struct Test {
    BOOKING_TYPE_ID: String,
    BOOKING_TYPE: String,
    DESCRIPTION: String,
}

let row = sqlx::query_as::<_, Test>("SELECT * FROM BOOKING_TYPE WHERE DESCRIPTION = ?)
        .bind("hio")
        .fetch_one(&state.sql_pool).await.unwrap();

This produces invalid SQL. I've also tried {0} and @p1 instead of ?. I'm just not sure what the syntax is.
I've noticed there is different syntax for MySql and Postgres but I see no documentation on MSSQL. So:

  1. How do I bind to a query with MSSQL?
  2. Also, what Rust data type relates to MSSQL's uniqueidentifier (GUID)?
  3. I would be happy to contribute to the MSSQL documentation maybe with an example (I noticed there's only an example for MySql and Postgres)

Metadata

Metadata

Assignees

No one assigned

    Labels

    db:mssqlquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions