first, the memory database:
In SQLite, a database is usually stored in a disk file. In some cases, however, we can have the database always reside in memory. One of the most common ways is when calling Sqlite3_open (), the database file name parameter passes ": Memory:", such as:
rc = Sqlite3_open (": Memory:", &db);
After calling the above function, no disk files are generated, and instead, a new database is created in pure memory. Because there is no persistence, the database disappears immediately after the current database connection is closed. It is important to note that although multiple database connections can create memory databases through the methods above, they are different databases and have no relationship to each other. In fact, we can also attach the memory database to the current connection, like any other normal database, through the attach command, such as:
ATTACH DATABASE ': Memory:' As Aux1;
Second, the temporary database:
When calling the Sqlite3_open () function or executing the attach command, if the database file parameter passes an empty string, a new temporary file is created as the underlying file for the staging database, such as:
rc = Sqlite3_open ("", &db);
Or
ATTACH DATABASE ' as aux2;
Very similar to the in-memory database, the temporary database created by two database connections is independent, and the temporary database disappears automatically after the connection is closed, and the underlying file is automatically deleted.
Although disk files are created to store data information in the staging database, the temporary database is in fact the same as the memory database, and the only difference is that when the amount of data in the staging database is too large, SQLite is guaranteed to have more memory available for other operations. As a result, some of the data in the staging database is written to the disk file, while the in-memory database always stores the data in memory.
In-memory database