summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/psycopg_any.py
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2022-12-12 09:08:46 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-12 10:35:38 +0100
commit2f38f7b8f9bd65905dc6bec4f3e2a30b5da8e338 (patch)
tree83d8afed86eaea00bc908ffabe0370eb74d7e0f0 /django/db/backends/postgresql/psycopg_any.py
parent2ebfbd894e21e1656c1e1f32d98b8df7a32d3649 (diff)
downloaddjango-2f38f7b8f9bd65905dc6bec4f3e2a30b5da8e338.tar.gz
Refs #33308 -- Added psycopg_any.sql.quote() hook.
Diffstat (limited to 'django/db/backends/postgresql/psycopg_any.py')
-rw-r--r--django/db/backends/postgresql/psycopg_any.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/psycopg_any.py b/django/db/backends/postgresql/psycopg_any.py
index 6dcd68f5eb..8e0d170867 100644
--- a/django/db/backends/postgresql/psycopg_any.py
+++ b/django/db/backends/postgresql/psycopg_any.py
@@ -1,6 +1,17 @@
-from psycopg2 import errors, extensions # NOQA
+from psycopg2 import errors, extensions, sql # NOQA
from psycopg2.extras import DateRange, DateTimeRange, DateTimeTZRange, Inet # NOQA
from psycopg2.extras import Json as Jsonb # NOQA
from psycopg2.extras import NumericRange, Range # NOQA
RANGE_TYPES = (DateRange, DateTimeRange, DateTimeTZRange, NumericRange)
+
+
+def _quote(value, connection=None):
+ adapted = extensions.adapt(value)
+ if hasattr(adapted, "encoding"):
+ adapted.encoding = "utf8"
+ # getquoted() returns a quoted bytestring of the adapted value.
+ return adapted.getquoted().decode()
+
+
+sql.quote = _quote