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

Provide interfaces and support for Parameterised Queries #34

Open
byapparov opened this issue Apr 18, 2021 · 3 comments
Open

Provide interfaces and support for Parameterised Queries #34

byapparov opened this issue Apr 18, 2021 · 3 comments

Comments

@byapparov
Copy link

I would like to have functionality in Rmarkdown files that is similar to BigQuery Magics via yihui/knitr#1867

here a some interfaces that I think are missing in DBI package for it to be work:

  1. Extract variables from sql
    Function that can extract parameter names from sql based on different notations, as opposed to current DBI::sqlParseVariables implementation will support different options:
database notation
postgres $param_name
bigquery @param_name
other ?param_name
  1. Each package that supports DBI interfaces should provide information about notation used by the corresponding database
    Interface in the DBI package that will allow to access notation for parameters used in the engine

  2. Each package should implement a flag that indicates if database supports parameterised queries
    Interface in the DBI package that will define if interpolation should be done or not, e.g. whether DB engine supports parameterised queries

@krlmlr
Copy link
Member

krlmlr commented Sep 6, 2021

Thanks, good points. What is the difference between items 2 and 3? Item 1 might be available already but needs better documentation.

@byapparov
Copy link
Author

byapparov commented Sep 16, 2021

2 is more details, I guess you could implement 2 in a way that allows you to check if database supports parameters in queries:

Function returns a vector of possible characters that identify parameter. if that vector has zero length it means that parameters are not supported

@krlmlr krlmlr transferred this issue from r-dbi/DBI Nov 1, 2021
@pnacht
Copy link

pnacht commented Nov 1, 2021

As someone who is a beginner in the subtleties of query safety, is glue::glue_sql() sufficiently safe? It doesn't use the actual SQL parameterization methods which keep the query and the data separate, but it might be simple enough.

Hell, I've written a package myself which does precisely this (the package is for access to a specific database, so the connection pool is internalized so we don't need to keep copying it all over the place):

myPackage::getQuery("
  SELECT *
  FROM foo
  WHERE a = { a }
    AND b IN ({ b* })")

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

No branches or pull requests

3 participants