pyaccesskit.schema.queries¶
pyaccesskit.schema.queries ¶
Saved query specifications and Access SQL helpers.
Access rewrites SQL when it saves a query (keywords upper-cased, one clause per line, a trailing ;,
DELETE becoming DELETE *...). :func:sql_equivalent compares SQL modulo those cosmetic changes, which
is what change detection needs.
MAX_SQL_LENGTH
module-attribute
¶
MAX_SQL_LENGTH = 64000
Approximate Access limit on the length of a SQL statement.
DAO_QUERY_KINDS
module-attribute
¶
DAO_QUERY_KINDS: dict[int, QueryKind] = {
0: QueryKind.SELECT,
16: QueryKind.CROSSTAB,
32: QueryKind.DELETE,
48: QueryKind.UPDATE,
64: QueryKind.APPEND,
80: QueryKind.MAKE_TABLE,
96: QueryKind.DDL,
112: QueryKind.PASS_THROUGH,
128: QueryKind.UNION,
144: QueryKind.PASS_THROUGH_BULK,
160: QueryKind.COMPOUND,
224: QueryKind.PROCEDURE,
240: QueryKind.ACTION,
}
DAO QueryDefTypeEnum values (verified against the ACEDAO type library) → :class:QueryKind.
PassThroughOptions ¶
Bases: SpecModel
Settings of an ODBC pass-through query.
Attributes:
| Name | Type | Description |
|---|---|---|
connect |
str
|
ODBC connection string; must start with |
returns_records |
bool
|
Whether the statement returns rows. |
timeout |
int
|
ODBC timeout in seconds (0 = no timeout). |
QuerySpec ¶
Bases: SpecModel
A saved query (Access QueryDef).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Query name (tables and queries share one namespace). |
sql |
str
|
The SQL text (Access SQL, or the server's dialect for pass-through queries). |
description |
str | None
|
Query Description property. |
pass_through |
PassThroughOptions | None
|
Set for ODBC pass-through queries. |
normalize_sql ¶
normalize_sql(sql: str) -> str
A canonical single-line form of sql for comparisons.
Whitespace is collapsed and dropped around punctuation, words and bracketed identifiers are
upper-cased (Access identifiers are case-insensitive), string and date literals are preserved, trailing
semicolons are removed, and Access's DELETE * FROM rewrite is undone.
sql_equivalent ¶
sql_equivalent(left: str, right: str) -> bool
Whether two SQL texts differ only cosmetically (see :func:normalize_sql).
detect_query_kind ¶
detect_query_kind(
sql: str, *, pass_through: bool = False
) -> QueryKind
Infer the kind of query from its SQL text (used before Access has classified a saved query).