1, 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:
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:
Copy Code code as follows:
ATTACH DATABASE ': Memory: ' as aux1;
2. 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
Copy Code ATABASE ' as aux2;
and the memory database is very similar to the two database connections to create a temporary database is also separate, after the connection is closed, the temporary database will automatically disappear, and its underlying files will also be 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. As a result, some of the data in the staging database is written to a disk file, and the memory database always keeps the data in memory.