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

sqlite: support binding named query parameters #70

Open
nwf-msr opened this issue Feb 26, 2023 · 2 comments
Open

sqlite: support binding named query parameters #70

nwf-msr opened this issue Feb 26, 2023 · 2 comments

Comments

@nwf-msr
Copy link

nwf-msr commented Feb 26, 2023

sqlite3 supports named query parameters in addition to positional ones (see https://sqlite.org/lang_expr.html). These are particularly nice for big, complex queries likely to evolve with software maintenance and it'd be great to be able support them in luadbi. Perhaps extending statement handles' :execute method to behave differently when given a single argument of type table.

As it stands, I've had to fall back to LuaSQLite3 to better support these complex queries.

@sparked435
Copy link
Collaborator

I think this is a great feature, and it's worth adding support in LuaDBI.

Perhaps extending statement handles' :execute method to behave differently when given a single argument of type table.

I like this idea. The problem is, I don't (currently) see anything similar in the PostgreSQL or MySQL API's. They will need a way to cleanly and consistently fail if the programmer tries to use this SQLite-specific feature on one of those databases. It is probably not a big deal to have them simply call error() in the event of a single table being provided as bind arguments; but now I'm worried about what kinds of edge cases this presents.

I'd love to hear other thoughts/opinions.

@nwf-msr
Copy link
Author

nwf-msr commented Nov 6, 2023

Wow, I had no idea that that was so SQLite specific or that the SQLite one-at-a-time parameter binding was at all unusual. Great work, everyone.

In any case, I think I'd be OK with the drivers for backend SQLs that don't have named parameters being extended to accept array-like tables and quietly discarding any non-numeric keys, since those can't have meaning in their query languages. FWIW, it looks like Oracle might also support similar things, but MS SQL seems to not (https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlbindparameter-function?view=sql-server-ver16).

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

No branches or pull requests

2 participants