diff options
Diffstat (limited to 'common.py')
-rw-r--r-- | common.py | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -164,6 +164,16 @@ def format_time(ts : float, precision : int = 3) -> str: h, m = divmod(m, 60) return f'{h:02d}:{m:02d}:{s:0{w}.{precision}f}' +def escape_identifier(identifier : str) -> str: + """Escape the given identifier, cf. + swig/python/gdal-utils/osgeo_utils/samples/validate_gpkg.py:_esc_id().""" + + if identifier is None or '\x00' in identifier: + raise RuntimeError(f'Invalid identifier "{identifier}"') + + # SQL:1999 delimited identifier + return '"' + identifier.replace('"', '""') + '"' + ###### # The function definitions below are taken from cpython's source code |