Scalextrix
Scalextrix

Reputation: 531

Can sqlite3 in-memory database be locked for writing by all other processes in python

I want a temporary database that can sit in memory, and only the application that created it can write to it. The data isnt secret so its not an encryption question per-se, I just want to ensure only the python program that creates the database can write to it, so that the data in the tables cant be altered by any other program or user.

If I do

conn = sqlite3.connect(':memory:')

does that mean anyone else can call that same in memory database by using the conn variable? Is there some other way to write to the in memory database?

Upvotes: 1

Views: 210

Answers (1)

phihag
phihag

Reputation: 287835

This is the default behavior;

import sqlite3
conn = sqlite3.connect(':memory:')

gives you a new in-memory database in your process. If another process runs the same code, they get their own in-memory database. If you execute sqlite3.connect(':memory:') another time, you can even get a second in-memory database in your process!

By default, another process running with the same credentials can go ahead and read and write your memory. There is little legitimate reason in doing that though; it's the domain of malware, not something a program can do by accident.

To be safe from these malicious processes, you can run your program under its own user account.

Upvotes: 2

Related Questions