Using inreg with peewee (SQLite)

8 views
Skip to first unread message

Space

unread,
Feb 11, 2021, 11:23:01 AM2/11/21
to peewee-orm

Right now I have a database filled with warning records for my discord server, the only problem is when someone is trying to search for a record, it has the match the EXACT case. Is there a way to make insensitive? I've looked at the docs and found an inreg operation but I kept on getting syntax errors.

My current setup:

```

databaseData = [database.MRP_Blacklist_Data.DiscUsername, database.MRP_Blacklist_Data.DiscID, database.MRP_Blacklist_Data.Gamertag, database.MRP_Blacklist_Data.BannedFrom, database.MRP_Blacklist_Data.KnownAlts, database.MRP_Blacklist_Data.ReasonforBan, database.MRP_Blacklist_Data.DateofIncident, database.MRP_Blacklist_Data.TypeofBan, database.MRP_Blacklist_Data.DatetheBanEnds] 
 for data in databaseData:
 query = (database.MRP_Blacklist_Data.select().where(data.iregexp(data == req))).get() 
for p in query: 
#do stuff
```

Although I keep getting syntax errors and im not sure how I would include the inregexp. 

Charles Leifer

unread,
Feb 11, 2021, 11:31:20 AM2/11/21
to peewe...@googlegroups.com
You have several problems. The first is sqlite does not implement regexp so you need to bring your own implementation, which is trivial. But to set that aside for now, the real issue is your where clause makes no sense.

What you want is this:

.where(MRP_Blacklist_Data.data.contains(req))

Which translates into a case-insensitive LIKE:

.where(MRP_Blacklist_Data.data ** ('%' + req + '%'))

--
You received this message because you are subscribed to the Google Groups "peewee-orm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to peewee-orm+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/peewee-orm/87db0ef9-af58-43b5-8811-b952ff9ec147n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages