Add support for more SQLite database open options. (#565)

* Add support for in-memory SQLite databases.

* Add support for opening SQLite databases via file URI.
This commit is contained in:
Nicholas Hastings 2016-12-04 11:23:08 -05:00 committed by GitHub
parent 19db7aef46
commit 70d81430f8
2 changed files with 70 additions and 58 deletions

View File

@ -12,7 +12,9 @@ elif binary.compiler.vendor == 'msvc':
binary.compiler.defines += [
'SQLITE_OMIT_LOAD_EXTENSION',
'SQLITE_THREADSAFE'
'SQLITE_THREADSAFE',
'SQLITE_USE_URI',
'SQLITE_ALLOW_URI_AUTHORITY',
]
if builder.target_platform == 'linux':
binary.compiler.postlink += ['-ldl', '-lpthread']

View File

@ -33,6 +33,7 @@
#include "extension.h"
#include "SqDriver.h"
#include "SqDatabase.h"
#include <am-string.h>
SqDriver g_SqDriver;
@ -179,6 +180,15 @@ IDatabase *SqDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
{
ke::AutoLock lock(&m_OpenLock);
/* Full path to the database file */
char fullpath[PLATFORM_MAX_PATH];
if (strcmp(info->database, ":memory:") == 0 || strncmp(info->database, "file:", 5) == 0)
{
ke::SafeStrcpy(fullpath, sizeof(fullpath), info->database);
}
else
{
/* Format our path */
char path[PLATFORM_MAX_PATH];
size_t len = libsys->PathFormat(path, sizeof(path), "sqlite/%s", info->database);
@ -196,7 +206,6 @@ IDatabase *SqDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
}
/* Test the full path */
char fullpath[PLATFORM_MAX_PATH];
g_pSM->BuildPath(Path_SM, fullpath, sizeof(fullpath), "data/%s", path);
if (!libsys->IsPathDirectory(fullpath))
{
@ -243,6 +252,7 @@ IDatabase *SqDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
/* Build the FINAL path. */
g_pSM->BuildPath(Path_SM, fullpath, sizeof(fullpath), "data/sqlite/%s.sq3", info->database);
}
/* If we're requesting a persistent connection, see if something is already open */
if (persistent)