Python3 | SQL request failed

2020-04-01 sqlite python-3.8

So. Simple request SELECT * FROM access WHERE {arg}=TRUE, where arg = "friends_grinder".

File "/root/python/NaVK/source/main/FriendsGrinderEngine.py", line 51, in __routine
    users = ADB.get_authorized_users('friends_grinder')
  File "/root/python/NaVK/source/database/AccessDB.py", line 30, in get_authorized_users
    users = self.__conn.cursor().execute(f'SELECT * FROM access WHERE {arg}=TRUE').fetchall()
sqlite3.OperationalError: no such column: TRUE

I don't get this error on windows. But I get it on Ubuntu.
friends_grinder column is BOOLEAN.

Answers

From the documentation:

Beginning with SQLite 3.23.0 (2018-04-02), SQLite recognizes the identifiers "TRUE" and "FALSE" as boolean literals, if and only if those identifiers are not already used for some other meaning. If there already exists columns or tables or other objects named TRUE or FALSE, then for the sake of backwards compatibility, the TRUE and FALSE identifiers refer to those other objects, not to the boolean values.

The boolean identifiers TRUE and FALSE are usually just aliases for the integer values 1 and 0, respectively. However, if TRUE or FALSE occur on the right-hand side of an IS operator, then they form new unary postfix operators "IS TRUE" and "IS FALSE" which test the boolean value of the operand on the left.

If you're getting no such column: TRUE as an error, that means the version of sqlite being used on that system is too old to recognize the identifier. Upgrade, or use 1 instead.

Related