mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
sqlite: open read-only when appropriate
This commit is contained in:
@@ -151,20 +151,32 @@ private:
|
||||
CUniquePtr<sqlite3_close_v2, SQLITE_OK> Connection;
|
||||
|
||||
public:
|
||||
Database(llvm::StringRef Path) {
|
||||
enum class OpenMode {
|
||||
ReadWrite,
|
||||
ReadOnly
|
||||
};
|
||||
|
||||
Database(llvm::StringRef Path, OpenMode Mode) {
|
||||
sqlite3 *Ptr = nullptr;
|
||||
int Result;
|
||||
|
||||
if (Path == ":memory:")
|
||||
if (Path == ":memory:") {
|
||||
Result = sqlite3_open_v2("",
|
||||
&Ptr,
|
||||
SQLITE_OPEN_MEMORY | SQLITE_OPEN_PRIVATECACHE,
|
||||
NULL);
|
||||
else
|
||||
} else if (Mode == OpenMode::ReadOnly) {
|
||||
std::string URI = ("file:" + Path.str() + "?immutable=1");
|
||||
Result = sqlite3_open_v2(URI.c_str(),
|
||||
&Ptr,
|
||||
SQLITE_OPEN_READONLY | SQLITE_OPEN_URI,
|
||||
NULL);
|
||||
} else {
|
||||
Result = sqlite3_open_v2(Path.str().c_str(),
|
||||
&Ptr,
|
||||
SQLITE_OPEN_READWRITE,
|
||||
NULL);
|
||||
}
|
||||
revng_assert(Result == SQLITE_OK);
|
||||
|
||||
Connection.reset(Ptr);
|
||||
|
||||
@@ -84,7 +84,8 @@ private:
|
||||
sqlite::Database Database;
|
||||
|
||||
public:
|
||||
PrototypeDatabase(llvm::StringRef Path) : Database(Path) {}
|
||||
PrototypeDatabase(llvm::StringRef Path) :
|
||||
Database(Path, sqlite::Database::OpenMode::ReadOnly) {}
|
||||
|
||||
/// Find a platform by its exact name.
|
||||
/// Returns -1 if no platform with that name exists.
|
||||
|
||||
@@ -17,5 +17,5 @@ commands:
|
||||
- type: source
|
||||
filter: db-invariants
|
||||
command: |-
|
||||
sqlite3 "$SOURCES_ROOT/share/revng/prototypes.sqlite" < "$INPUT"
|
||||
sqlite3 -cmd ".open \"file:$SOURCES_ROOT/share/revng/prototypes.sqlite?immutable=1\"" < "$INPUT"
|
||||
| FileCheck "$INPUT"
|
||||
|
||||
Reference in New Issue
Block a user