Simon Slavin: "Please don't use numbers as names."

The manual states:
- "?NNN": where N is an *integer*.
- "?": Programmers are encouraged to use one of the symbolic formats below
or the ?NNN format above instead."


The use case:

I am creating a library that takes SQL from the application and runs it via
the SQLite FFI.

I want to be able to write this function:

if has_bound_all_placeholders_in_query_string() {
    // run query
} else {
    throw Error("You must bind all query parameters.")

    // This branch cannot be created with the current SQLite FFI APIs.
    // It is useful because the SQLite default is to bind NULL to unbound
placeholders, which may not be what the user wanted. If they wanted this
they would of just used the constant NULL instead of a placeholder.
    // In dynamic languages where both the query string and the data could
be dynamically generated, being able to enforce binding all placeholders is
useful for correctness.
}


A new function could be added:

For query string "SELECT ?, ?10"

`sqlite3_bind_parameter_valid_indexes() -> [1, 10]`

How can I propose adding this?

On Mon, Jul 22, 2019 at 6:52 AM Hick Gunter <h...@scigames.at> wrote:

> No. As the creator of a statement, you are expected to know either the
> position or the name of any SQL parameters contained therein.
> Determining which indexes are legal does not help in determining what has
> been bound, not even if anything has been bound. Please note that
> sqlite3_reset() does not clear the bindings.
>
> What is the underlying use case?
>
> -----Ursprüngliche Nachricht-----
> Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org]
> Im Auftrag von test user
> Gesendet: Sonntag, 21. Juli 2019 21:04
> An: sqlite-users@mailinglists.sqlite.org
> Betreff: [EXTERNAL] [sqlite] Determining valid statement placeholders.
>
> Is there a `sqlite3` C FFI API that allows me to determine which index
> values are valid to bind to?
>
> The `sqlite3_bind_parameter_*` APIs (count, name, index) do not actually
> provide the valid indexes.
>
> For example: "?, ?10" would have two valid indexes: (1, 10).
>
> But how can I know that indexes 2-9 are invalid from the API?
>
> I have tried binding null to 2-9, but get SQLITE_OK.
>
> I want to be able to check clients have provided all data needed for a
> query instead having SQLite bind null by default for placeholders with no
> data binding.
>
> Thanks.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
> ___________________________________________
>  Gunter Hick | Software Engineer | Scientific Games International GmbH |
> Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O)
> +43 1 80100 - 0
>
> May be privileged. May be confidential. Please delete if not the addressee.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to