ds_common_placeholder_py_lib.sql

File: sql.py Region: ds-common-placeholder-py-lib

Description

Placeholders in SQL text become SQL literals, never raw text (contract §8.3). The lexer knows DuckDB’s quoting: '…', E'…', "…", $tag$…$tag$, -- and nested /* */ comments.

Functions

refuse_secrets_in_sql(sql, path) → list[ds_common_placeholder_py_lib.grammar.Segment]

Check the SQL text at path before anything is read.

sql_errors(sql) → list[ds_common_placeholder_py_lib.errors.PlaceholderError]

Every error of the SQL text that its text alone shows, for

literal(value, placeholder) → str

Render a JSON value as a SQL literal.

position_errors(sql, segments) → list[ds_common_placeholder_py_lib.errors.PlaceholderError]

Find placeholders inside quotes or comments, or glued to other tokens.

Module Contents

ds_common_placeholder_py_lib.sql.refuse_secrets_in_sql(sql: str, path: str) → list[ds_common_placeholder_py_lib.grammar.Segment][source]

Check the SQL text at path before anything is read.

Returns:

parse(sql).

Raises:

PlaceholderError – syntax, sql_position, or sql_secret for a get_secret or secret call at any depth, with path.

ds_common_placeholder_py_lib.sql.sql_errors(sql: str) → list[ds_common_placeholder_py_lib.errors.PlaceholderError][source]

Every error of the SQL text that its text alone shows, for validate(): sql_position for each misplaced placeholder, sql_secret for each one with a get_secret or secret call at any depth.

Raises:

PlaceholderError – syntax, if sql does not parse.

ds_common_placeholder_py_lib.sql.literal(value: Any, placeholder: ds_common_placeholder_py_lib.grammar.Placeholder) → str[source]

Render a JSON value as a SQL literal.

Raises:

PlaceholderError – type for anything but a string, number, or boolean.

ds_common_placeholder_py_lib.sql.position_errors(sql: str, segments: list[ds_common_placeholder_py_lib.grammar.Segment]) → list[ds_common_placeholder_py_lib.errors.PlaceholderError][source]

Find placeholders inside quotes or comments, or glued to other tokens.

Parameters:
  • sql – The statement.

  • segments – parse(sql).

Returns:

One sql_position error per misplaced placeholder.