One, Memory database:
In SQLite, a database is usually stored in a disk file. In some cases, however, we can make the database always reside in memory. One of the most common ways is when calling Sqlite3_open (), the database filename parameter passes ": Memory:" such as:
Copy Code code as follows:
rc = Sqlite3_open (": Memory:", &db);
After you call the above function, no disk files are generated, and instead, a new database is created successfully in pure memory. Because there is no persistence, the database disappears immediately after the current database connection is closed. It should be noted that although multiple database connections can create memory databases through the above methods, they are different databases and have no relationship to each other. In fact, we can also attach the memory database, like other normal databases, to the current connection through the attach command, such as:
ATTACH DATABASE ': Memory: ' as aux1;
Ii. Provisional database:
When you invoke the Sqlite3_open () function or execute 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;
and memory databases are very similar, and the temporary databases created by two database connections are separate, and the staging database automatically disappears after the connection is closed, and the underlying files are automatically deleted.
Although disk files are created to store data information in the staging database, the staging database usually resides in memory as well as the memory database, except that when the amount of data in the staging database is too large, SQLite to ensure that more memory is available for other operations, some of the data in the staging database is written to a disk file, while the memory database always stores the data in memory.