stratified_packager.toolbelt.sql

Plugin-agnostic SQL string building for the SQLite/GeoPackage dialect.

Pure standard library: this module imports neither qgis nor osgeo (GDAL/OGR), so its helpers stay usable from background threads, scripts/ and osgeo-free tests. It owns the SQL text concerns — identifier quoting and reserved-table-name guarding — while gpkg owns the OGR and sqlite3 work that consumes the quoting.

Functions

quote_identifier(name, /)

Quote an SQL identifier (table or column name) with double quotes.

safe_table_name(name, /)

Prefix _ to dodge GeoPackage/SQLite reserved table-name prefixes.

stratified_packager.toolbelt.sql.quote_identifier(name, /)[source]

Quote an SQL identifier (table or column name) with double quotes.

Parameters:

name (str) – The raw identifier.

Return type:

str

Returns:

The double-quoted identifier with embedded quotes doubled.

stratified_packager.toolbelt.sql.safe_table_name(name, /)[source]

Prefix _ to dodge GeoPackage/SQLite reserved table-name prefixes.

OGR refuses to create a GeoPackage layer whose name begins with gpkg, and SQLite reserves the sqlite_ prefix for its own tables. A name that begins with either (case-insensitively, since both dialects fold table-name case) gets a leading _; every other name is returned unchanged. Idempotent: _gpkg… no longer matches.

Parameters:

name (str) – A candidate (already-sanitized) table name.

Return type:

str

Returns:

The name, with a leading _ when it would otherwise be reserved.

stratified_packager.toolbelt.sql._RESERVED_TABLE_PREFIXES: Final = ('gpkg', 'sqlite_')

Reserved table-name prefixes: OGR rejects gpkg; SQLite reserves sqlite_.