mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-06-21 16:11:57 -04:00
Merge "Postgresql default to no backslash escaping" into main
This commit is contained in:
+1
-1
@@ -4,4 +4,4 @@
|
||||
|
||||
Added :paramref:`.selectinload.chunksize` parameter to :func`.selectinload`
|
||||
allowing users to configure the number of primary keys sent per IN clause
|
||||
when loading reltaionships. Pull request courtesy bekapono.
|
||||
when loading relationships. Pull request courtesy bekapono.
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
.. change::
|
||||
:tags: postgresql, usecase
|
||||
:tickets: 13268
|
||||
|
||||
Changed the default backslash escape value in the PostgreSQL dialect to
|
||||
``False`` to align it with the default value of
|
||||
``standard_conforming_strings=on``. This change should not affect most users
|
||||
since the value is set at driver initialization on first connect.
|
||||
@@ -3522,7 +3522,7 @@ class PGDialect(default.DefaultDialect):
|
||||
|
||||
reflection_options = ("postgresql_ignore_search_path",)
|
||||
|
||||
_backslash_escapes = True
|
||||
_backslash_escapes = False
|
||||
_supports_create_index_concurrently = True
|
||||
_supports_drop_index_concurrently = True
|
||||
_supports_jsonb_subscripting = True
|
||||
|
||||
@@ -3265,7 +3265,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
|
||||
dialect = postgresql.dialect()
|
||||
self.assert_compile(
|
||||
sql.column("foo").ilike("bar", escape="\\"),
|
||||
"foo ILIKE %(foo_1)s::VARCHAR ESCAPE '\\\\'",
|
||||
"foo ILIKE %(foo_1)s::VARCHAR ESCAPE '\\'",
|
||||
)
|
||||
|
||||
self.assert_compile(
|
||||
@@ -3276,7 +3276,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
|
||||
|
||||
self.assert_compile(
|
||||
sql.column("foo").notilike("bar", escape="\\"),
|
||||
"foo NOT ILIKE %(foo_1)s::VARCHAR ESCAPE '\\\\'",
|
||||
"foo NOT ILIKE %(foo_1)s::VARCHAR ESCAPE '\\'",
|
||||
)
|
||||
|
||||
self.assert_compile(
|
||||
|
||||
@@ -986,17 +986,18 @@ class MiscBackendTest(
|
||||
def test_backslash_escapes_detection(self, explicit_setting, expected):
|
||||
engine = engines.testing_engine()
|
||||
|
||||
if explicit_setting is not None:
|
||||
# check the default value before connect
|
||||
eq_(engine.dialect._backslash_escapes, False)
|
||||
|
||||
@event.listens_for(engine, "connect", insert=True)
|
||||
@event.listens_for(engine, "first_connect", insert=True)
|
||||
def connect(dbapi_connection, connection_record):
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute(
|
||||
"SET SESSION standard_conforming_strings = %s"
|
||||
% ("off" if not explicit_setting else "on")
|
||||
)
|
||||
dbapi_connection.commit()
|
||||
@event.listens_for(engine, "connect", insert=True)
|
||||
@event.listens_for(engine, "first_connect", insert=True)
|
||||
def connect(dbapi_connection, connection_record):
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute(
|
||||
"SET SESSION standard_conforming_strings = %s"
|
||||
% ("off" if not explicit_setting else "on")
|
||||
)
|
||||
dbapi_connection.commit()
|
||||
|
||||
with engine.connect():
|
||||
eq_(engine.dialect._backslash_escapes, expected)
|
||||
|
||||
@@ -3219,14 +3219,14 @@ class LikeTest(fixtures.TestBase, testing.AssertsCompiledSQL):
|
||||
def test_like_7(self):
|
||||
self.assert_compile(
|
||||
self.table1.c.myid.ilike("somstr", escape="\\"),
|
||||
"mytable.myid ILIKE %(myid_1)s::VARCHAR ESCAPE '\\\\'",
|
||||
"mytable.myid ILIKE %(myid_1)s::VARCHAR ESCAPE '\\'",
|
||||
dialect=postgresql.dialect(),
|
||||
)
|
||||
|
||||
def test_like_8(self):
|
||||
self.assert_compile(
|
||||
~self.table1.c.myid.ilike("somstr", escape="\\"),
|
||||
"mytable.myid NOT ILIKE %(myid_1)s::VARCHAR ESCAPE '\\\\'",
|
||||
"mytable.myid NOT ILIKE %(myid_1)s::VARCHAR ESCAPE '\\'",
|
||||
dialect=postgresql.dialect(),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user