Skip to content
Advertisement

How Can My sqllite3 interaction be fixed?

I’m trying to get an admin account to edit a ‘rank’ (basically access level) for one of the profiles in my data-base. The error is:

JavaScript

The code that seems to be the problem is:

JavaScript

Originally, it was all on one line and it didn’t work, and now I’ve tried it on multiple lines and it still doesn’t work. So I checked here to see if anyone could help.

EDIT1: Thanks for the suggestions. None of them have fixed the code, but I’ve narrowed the problem code to: where Uzaname = %s""" % (NewRank, Findaname))

Advertisement

Answer

Unless you use ATTACH, SQLite (a file-level database) does not recognize other databases. Usually server-level databases (Oracle, Postgres, SQL Server, etc.) use the database.schema.table reference. However, in SQLite the very database file you connect to is the main database in scope. But ATTACH allows you to connect to other SQLite databases and then recognizes database.table referencing.

Additionally, for best practices:

  • In sqlite3 and any other Python DB-APIs, use parameterization for literal values and do not format values to SQL statement.
  • In general Python, stop using the de-emphasized (not deprecated yet) string modulo operator, %. Use str.format or more recent F-string for string formatting. But neither is needed here.

Altogether, if you connect to the 0rk_D4T4B453 database, simply query without database reference:

JavaScript

If you do connect to a different database, call ATTACH. Here also, you can alias other database with better naming instead of number leading identifier.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement