Repository navigation
Ablility to use :memory: and URI filename in db_open - #547
Closed
AmyrAhmady wants to merge 2 commits into
Closed
AmyrAhmady wants to merge 2 commits into
AmyrAhmady wants to merge 2 commits into
Conversation
db_open_raw and DB_OpenRaw
AmyrAhmady
force-pushed
the
amir/inmemory-db
branch
from
December 28, 2022 11:17
14a75fb to
4e37d62
Compare
Southclaws
reviewed
Dec 28, 2022
Collaborator
|
I was working on a version of this as well: SCRIPT_API(db_open, int(const std::string& name))
{
int flags = 0x02 /* SQLITE_OPEN_READWRITE */ | 0x04 /* SQLITE_OPEN_CREATE */;
size_t start;
size_t end;
// Get the flags.
auto params = GetParams();
if ((params[0] / sizeof(cell)) >= 2)
{
// Optional parameter.
flags = params[2];
}
// Get the protocol.
String protocol = name.substr(0, 5);
if (protocol == "file:")
{
// We always use an aboslute path, even when a relative path is given.
protocol = "file:///";
// URI mode.
if (name[5] == '/' && name[6] == '/')
{
// Skip the next `/`.
start = name.find('/', 7) + 1;
if (start == 0)
{
return 0;
}
}
else
{
start = 5;
}
}
else
{
protocol = "";
start = 0;
}
// Get the parameters.
String parameters;
end = name.find('?', start);
if (end == std::string::npos)
{
parameters = "";
end = name.length();
}
else
{
// There are parameters.
parameters = name.substr(end);
}
// Get the path.
String path = name.substr(start, end - start);
// Get the database.
IDatabaseConnection* database_connection;
if ((flags & 0x80 /* SQLITE_OPEN_MEMORY */) != 0 || path == ":memory:" || path == "" || parameters.find("mode=memory") != std::string::npos)
{
// All the ways of opening an in-memory database that I know of.
database_connection = PawnManager::Get()->databases->open(name);
}
else
{
// TODO: Pass in the flags.
ghc::filesystem::path dbFilePath = ghc::filesystem::absolute("scriptfiles/" + path);
database_connection = PawnManager::Get()->databases->open(protocol + dbFilePath.string() + parameters);
}
return database_connection ? database_connection->getID() : 0;
} |
Member
Author
|
The reason I didn't go that way to support all possible in-memory database methods, is to support opening databases in a more standard way, support everything and not just absolute DB path on disk |
Merged
Member
Author
|
Closing this in favor of #553 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ablility to use :memory: and URI filename in db_open.
for example:
db_open("file::memory:?cache=shared")to have a shared-cached in-memory database