Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro fails on bytes data #57

Closed
tsvisabo opened this issue Jan 15, 2020 · 6 comments
Closed

Macro fails on bytes data #57

tsvisabo opened this issue Jan 15, 2020 · 6 comments
Labels

Comments

@tsvisabo
Copy link

For table called my_table with id -> Integer, value-> Integer and data->BYTEA (Postgress)

the following macro seems to fail when trying to insert a record (without BYTEA it seemed to work)

Fails with: "error: "unknown type param ID: 17""

        let id : i32 = 2;
        let value : i32 = 100;
        let v: Vec<u8> = vec![0, 2, 4, 6];

        let row = sqlx::query(            r#"
        INSERT INTO transactions ( id , value, data)
        VALUES ( $1, $2 , $3)
        RETURNING id, value, signature_or_message
                "#,)
            .bind(id).bind(value).bind(v)
            .fetch_one(&mut tx)
            .await.unwrap();


        tx.commit().await.unwrap();

This works fine:


        let id : i32 = 2;
        let value : i32 = 100;
        let v: Vec<u8> = vec![0, 2, 4, 6];
        let rec = sqlx::query!(
            r#"
 INSERT INTO transactions ( id , value, signature_or_message)
 VALUES ( $1, $2 , $3)
 RETURNING id, value, signature_or_message
         "#,
            0,
            0,
            v
        )
        .fetch_one(&mut tx)
        .await
        .unwrap();

        tx.commit().await.unwrap();

@mehcode mehcode added the bug label Jan 15, 2020
@eraffaelli
Copy link

I'm not sure if it's exactly the same problem but it seems to fail with other type like UUID (user_id: uuid::Uuid) and the hash (from the example, passed as hash: String) too.
I'm trying to modulate my project (based on the example more or less) so some data are passed to function and may be different from the example) .

error: "unknown type param ID: 1043"
  --> src/utils/database.rs:9:15
   |
9  |       let rec = sqlx::query!(
   |  _______________^
10 | |         r#"
11 | | INSERT INTO users ( username, email, password )
12 | | VALUES ( $1, $2, $3 )
...  |
17 | |         hash
18 | |     )
   | |_____^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: "unknown type param ID: 2950"
  --> src/utils/database.rs:43:15
   |
43 |       let rec = sqlx::query!(
   |  _______________^
44 | |         r#"
45 | |     SELECT *
46 | |     FROM users
...  |
49 | |         user_id
50 | |     )
   | |_____^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 2 previous errors

error: could not compile `tide_api`.

Using PostgreSQL.

I can't print the value because the query check seems to happen before it, would it be possible to log/debug the prepared request with sqlx?

@mehcode
Copy link
Member

mehcode commented Jan 16, 2020

We plan to add debug logging to SQLx that will print the query if you turn it on.


Your primary issue though is you need to turn on the uuid feature flag.

See https://github.com/launchbadge/sqlx/blob/master/README.md#cargo-feature-flags for more flags as well.

@mehcode
Copy link
Member

mehcode commented Jan 16, 2020

As to the OP, the query macro does not support bytes yet because of a small oversight. We'll correct and make a patch release shortly.

@mehcode
Copy link
Member

mehcode commented Jan 17, 2020

Fixed and released as v0.2.2

@mehcode mehcode closed this as completed Jan 17, 2020
@eraffaelli
Copy link

I'll read the README more often, thanks for updating this that often.

@nkconnor
Copy link
Contributor

confirmed works in 0.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants