aboutsummaryrefslogtreecommitdiffstats
path: root/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'common.py')
-rw-r--r--common.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/common.py b/common.py
index 0bece11..eab9dd5 100644
--- a/common.py
+++ b/common.py
@@ -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