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

How to create query with IN? #18

Closed
makorne opened this issue Jun 30, 2021 · 1 comment
Closed

How to create query with IN? #18

makorne opened this issue Jun 30, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@makorne
Copy link

makorne commented Jun 30, 2021

Something like this test but with ["bar", "baz", "foo?bar"] ( with ? inside string)

#[test]
    fn it_builds_sql_with_in_clause() {
        fn t(arg: &[&str], expected: &str) {
            let mut sql = SqlBuilder::new("SELECT ?fields FROM test WHERE a IN ?");
            sql.bind_arg(arg);
            sql.bind_fields::<Row>();
            assert_eq!(sql.finish().unwrap(), expected);
        }

        const ARGS: &[&str] = &["bar", "baz", "foo?bar"];
        t(&ARGS[..0], r"SELECT `a`,`b` FROM test WHERE a IN []");
        t(&ARGS[..1], r"SELECT `a`,`b` FROM test WHERE a IN ['bar']");
        t(
            &ARGS[..2],
            r"SELECT `a`,`b` FROM test WHERE a IN ['bar','baz']",
        );
        t(
            ARGS,
            r"SELECT `a`,`b` FROM test WHERE a IN ['bar','baz','foo?bar']",
        );
    }
unbound query argument: ?
thread 'sql::test::it_builds_sql_with_in_clause' panicked at 'unbound query argument: ?', clickhouse.rs/src/sql/mod.rs:69:21
stack backtrace:
   0: std::panicking::begin_panic
             at /home/f/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:519:12
   1: clickhouse::sql::SqlBuilder::finish
             at ./src/sql/mod.rs:69:21
   2: clickhouse::sql::test::it_builds_sql_with_in_clause::t
             at ./src/sql/mod.rs:116:24
   3: clickhouse::sql::test::it_builds_sql_with_in_clause
             at ./src/sql/mod.rs:126:9
   4: clickhouse::sql::test::it_builds_sql_with_in_clause::{{closure}}
@loyd loyd added the bug Something isn't working label Jul 23, 2021
@azhe403
Copy link

azhe403 commented Aug 23, 2021

any solution about unbound query argument ?
escaping ? with \\ or \ seem not working for this issue

gambar

@loyd loyd closed this as completed in a4226cc Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants