Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Use of the LIKE operator聽#85

Closed
Closed

Description

@david-alm

Hello 馃憢

After trawling through the code, trying to figure out how to perform a prefix search, I've realized that this this dictionary maps orm operators to sqlalchemy methods. Note that iexact, contains and icontains reference some variant of like.
Meanwhile, this code escapes the search string when using like - but only for the operators contains and icontains.

So to my knowledge:

Activity

  1. david-alm commented on Dec 15, 2020

    @david-alm
    Author

    Here's a quick repro of the issue:

    import databases
    import orm
    import sqlalchemy
    
    database = databases.Database("sqlite:///db.sqlite")
    metadata = sqlalchemy.MetaData()
    
    
    class Note(orm.Model):
        __tablename__ = "notes"
        __database__ = database
        __metadata__ = metadata
    
        id = orm.Integer(primary_key=True)
        text = orm.String(max_length=100)
        completed = orm.Boolean(default=False)
    
    # Create the database
    engine = sqlalchemy.create_engine(str(database.url))
    metadata.create_all(engine)
    
    # Create three somewhat similar notes
    await Note.objects.create(text="Find the first bug", completed=True)
    await Note.objects.create(text="Find the second bug", completed=False)
    await Note.objects.create(text="find_the_second_bug", completed=False)
    
    # Search for `find%`
    await Note.objects.filter(text__iexact="find%").all() 
    # This returns all 3 notes, even though none of them is "lowercase exact" `find%`
    
    # In the same vein, this occurs with `_` as well
    await Note.objects.filter(text__iexact="find_the_second_bug").all() 
    # This returns the last 2 notes.
    
  2. locked and limited conversation to collaborators on Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions