Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Alexander Samoylenko
    @lxmnk
    Hello! I would like to run SELECT * FROM notes WHERE id IN (?1) (?1 is a Vec<i32>). Could you provide me example, how to pass vector to parameters? I've searched docs and issues, but found examples only for inserting/updating rows.
    Thom Chiovoloni
    @thomcc
    In general SQLite doesn't work like that, but there are workarounds, see rusqlite/rusqlite#430 for a discussion of using the array feature
    but note that using that requires loading the module first
    Alexander Samoylenko
    @lxmnk

    In general SQLite doesn't work like that, but there are workarounds, see rusqlite/rusqlite#430 for a discussion of using the array feature

    Thank you! Just now I've discovered, that I also can generate a SQL string with right placeholders number (?1, ?2). Could you explain, why using array feature is a better choice?

    Thom Chiovoloni
    @thomcc
    I'd probably generate the string
    Alexander Samoylenko
    @lxmnk
    Thank you again)
    Thom Chiovoloni
    @thomcc
    Alexander Samoylenko
    @lxmnk

    I wrote https://github.com/mozilla/application-services/blob/main/components/support/sql/src/repeat.rs for this purpose once upon a time

    I'll check it out, thanks!

    Thom Chiovoloni
    @thomcc
    @lxmnk oh, note that there's a maximum number of parameters that you can pass to SQLite at once. The maximum number is likely either 999 (for versions older than 3.32, e.g. released before 2020-05-22) or 32766 for ones after that. so, you may need to chunk
    you can query it with https://docs.rs/rusqlite/0.24.2/rusqlite/limits/enum.Limit.html#variant.SQLITE_LIMIT_VARIABLE_NUMBER (which requires the limits feature to be on)
    Cédric Bellegarde
    @gnumdk_gitlab
    Hello
    Looking at previous comments, I'm not sure about my question
    I have a built SQL request with random parameters: one string, one vec<i32> and one vec<string>. Will I be able to generate params with array feature?
    Cédric Bellegarde
    @gnumdk_gitlab
    Another question, Is there an equivalent of https://www.kite.com/python/docs/sqlite3.Connection.create_function in ruqlite ?
    Thom Chiovoloni
    @thomcc
    yes: https://docs.rs/rusqlite/0.24.2/rusqlite/struct.Connection.html#method.create_scalar_function (also create_aggregate_function or create_window_function for different kinds of functions — i don't think these have equivalents in the python binding though)
    you need to turn on the functions feature
    Cédric Bellegarde
    @gnumdk_gitlab
    Ok, thanks
    Cédric Bellegarde
    @gnumdk_gitlab
    Looking at the documentation, I understand that this function are only available on query result.
    Thom Chiovoloni
    @thomcc
    hm?
    thats not really true
    what context do you want to use it in?
    Cédric Bellegarde
    @gnumdk_gitlab
    Python allows to do something like this: SELECT * FROM table WHERE myfunction(column)='value'
    Thom Chiovoloni
    @thomcc
    yes that definitely is allowed here
    Cédric Bellegarde
    @gnumdk_gitlab
    ok
    Thom Chiovoloni
    @thomcc
    what part of the documentation makes you think that wouldnt be
    perhaps the docs should be improved
    Cédric Bellegarde
    @gnumdk_gitlab
    English is not my language, so maybe a confusion around the word scalar, will try to implement, if there is really something confusing, will report the an issue
    Thom Chiovoloni
    @thomcc
    oh
    scalar just means the function takes 1 argument
    err
    one rows worth
    aggregate functions are like SUM(...)
    which take many rows as arguments
    Cédric Bellegarde
    @gnumdk_gitlab
    Thanks, so it's me :D
    Thom Chiovoloni
    @thomcc
    and window functions are... weirder: https://sqlite.org/windowfunctions.html
    scalar functions are normal sqlite functions. i dont think the python bindings expose any way to define non-scalar functions, so it doesnt bother distinguishing
    Justin Wood
    @ankhers
    I am trying to use rusqlite::named_params! macro, but I am getting an error with compiling saying "the trait ToSql is not implemented for (&str, &dyn ToSql)", am I supposed to enable a feature for this?
    Thom Chiovoloni
    @thomcc
    can you file a bug?
    that sounds wrong but helping in a github issue seems easier
    Justin Wood
    @ankhers
    Sure thing.
    Thom Chiovoloni
    @thomcc
    thanks. if you’re using master, it might be possible... we changed some stuff and havent cut a release yet, but maybe i missed named_params somehow
    Thom Chiovoloni
    @thomcc
    @ankhers FYI in the next release (and on the master branch) we support using named_params! with normal execute/query functions
    (well be deprecating the _named versions, but they'll still be there for a while probably as to not break all the code out there using the "old" way)
    hutchisr
    @hutchisr
    Is there a way to generate a variable set of named parameters at runtime? I have a situation where I need to generate a query and query parameters based on user input and then run it across multiple databases and I can't figure out how to generate/store the parameters in a form methods like query_named will accept
    Justin Wood
    @ankhers
    The second parameter to query_named is a list of tuples. A literal would be [(":foo", foo), (":bar", bar)]. You might need to write foo as &dyn ToSql.
    Sorry, it should be &foo, not just foo.
    Take a look at the documentation, it includes an example https://docs.rs/rusqlite/0.24.2/rusqlite/struct.Connection.html#method.execute_named
    hutchisr
    @hutchisr
    I think my problem is I'm unclear how to construct an owned type I can store that can be passed as a &[(&str, &dyn ToSql)]. My first thought was Vec<(&'static str, Box<dyn ToSql>)> but that doesn't seem to work
    Thom Chiovoloni
    @thomcc
    should work if you do &the_vec