-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Description
If you want developers to not make SQL injection vulnerabilities, you should make their job easier.
Look at sqlite3 API design:
c.execute('SELECT * FROM stocks WHERE symbol=?', t).
Compare this to BigQuery:
query = """
SELECT word, word_count
FROM `bigquery-public-data.samples.shakespeare`
WHERE corpus = @corpus
AND word_count >= @min_word_count
ORDER BY word_count DESC;
"""
query_params = [
bigquery.ScalarQueryParameter('corpus', 'STRING', 'romeoandjuliet'),
bigquery.ScalarQueryParameter('min_word_count', 'INT64', 250)
]
job_config = bigquery.QueryJobConfig()
job_config.query_parameters = query_params
query_job = client.query(
query,
# Location must match that of the dataset(s) referenced in the query.
location='US',
job_config=job_config) # API request - starts the query
Why I need to put query params into job config?
Why I need to mutate the job config?
Query params should be a query function parameter. Or at least part of QueryJobConfig constructor, so I can do:
query_job = client.query(
query,
# Location must match that of the dataset(s) referenced in the query.
location='US',
job_config=QueryJobConfig(query_pameters=query_params)) # API request - starts the query
Metadata
Metadata
Assignees
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.