Skip to content

Commit

Permalink
[SQLite] Add Case Sensitivity to LIKEs for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Mar 14, 2024
1 parent 75b169a commit 3afe0f0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CSRFProtect
from flask_babel import Babel
from sqlalchemy.engine import Engine
from .ext_config import get_locale
from .markdown_ext import Markdown
from sqlite3 import Connection as SQLite3Connection


basedir = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -38,7 +41,15 @@ def create_app(config_name="dev"):
app.config.from_object(config)
else:
app.config.from_object(config[config_name])


# SQLite does not perform CASE SENSITIVE LIKEs by default.
if app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite:"):
@db.event.listens_for(Engine, "connect")
def _set_sqlite_case_insensitive_pragma(dbapi_con, connection_record):
""" This ensures that SQLite is not case-insensitive when using LIKEs"""
if isinstance(dbapi_con, SQLite3Connection):
dbapi_con.execute("PRAGMA case_sensitive_like=ON;")

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

config[config_name].init_app(app)
Expand Down

0 comments on commit 3afe0f0

Please sign in to comment.