summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/sqlite/pysqlite.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-11-15 16:58:46 +0100
committerMike Bayer <mike_mp@zzzcomputing.com>2020-11-19 13:49:32 -0500
commitec264a5a2c810394ee4ebd7a78f83fc0ea785c1f (patch)
tree8b4caff6a39429167584bcb4f9f5c39c1fbecc41 /lib/sqlalchemy/dialects/sqlite/pysqlite.py
parentcef2871ef99af3cc6a40d98a2651c6dad7542d75 (diff)
downloadsqlalchemy-ec264a5a2c810394ee4ebd7a78f83fc0ea785c1f.tar.gz
Use ``re.search`` instead of ``re.match`` in sqlite
Use python ``re.search()`` instead of ``re.match()`` as the operation used by the :meth:`Column.regexp_match` method when using sqlite. This matches the behavior of regular expressions on other databases as well as that of well-known SQLite plugins. Fixes: #5699 Change-Id: I14b2c7faf51fef172842aeb2dba2500f14544f24
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite/pysqlite.py')
-rw-r--r--lib/sqlalchemy/dialects/sqlite/pysqlite.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
index 377411520..dac04e0ca 100644
--- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py
+++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
@@ -128,7 +128,7 @@ Regular Expression Support
.. versionadded:: 1.4
Support for the :meth:`_sql.ColumnOperators.regexp_match` operator is provided
-using Python's re.match_ function. SQLite itself does not include a working
+using Python's re.search_ function. SQLite itself does not include a working
regular expression operator; instead, it includes a non-implemented placeholder
operator ``REGEXP`` that calls a user-defined function that must be provided.
@@ -137,7 +137,7 @@ as follows::
def regexp(a, b):
- return bool(re.match(a, b))
+ return re.search(a, b) is not None
sqlite_connection.create_function(
"regexp", 2, regexp,
@@ -154,9 +154,9 @@ details.
.. _create_function: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function
-.. _re.match: https://docs.python.org/3/library/re.html#re.match
+.. _re.search: https://docs.python.org/3/library/re.html#re.search
-.. _Python regular expressions: https://docs.python.org/3/library/re.html#re.match
+.. _Python regular expressions: https://docs.python.org/3/library/re.html#re.search
@@ -508,7 +508,7 @@ class SQLiteDialect_pysqlite(SQLiteDialect):
def regexp(a, b):
if b is None:
return None
- return bool(re.match(a, b))
+ return re.search(a, b) is not None
def set_regexp(connection):
if hasattr(connection, "connection"):