Skip to content

Commit

Permalink
memvfs: make it work with 'projinfo --list-crs'
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 3, 2024
1 parent 18f895c commit 98b1582
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ static void PROJ_SQLITE_intersects_bbox(sqlite3_context *pContext,
// ---------------------------------------------------------------------------

class SQLiteHandle {
std::string path_{};
sqlite3 *sqlite_handle_ = nullptr;
bool close_handle_ = true;

Expand Down Expand Up @@ -278,6 +279,8 @@ class SQLiteHandle {
public:
~SQLiteHandle();

const std::string &path() const { return path_; }

sqlite3 *handle() { return sqlite_handle_; }

#ifdef REOPEN_SQLITE_DB_AFTER_FORK
Expand All @@ -287,7 +290,7 @@ class SQLiteHandle {
#endif

static std::shared_ptr<SQLiteHandle> open(PJ_CONTEXT *ctx,
const std::string &path);
const std::string &pathIn);

// might not be shared between thread depending how the handle was opened!
static std::shared_ptr<SQLiteHandle>
Expand Down Expand Up @@ -388,6 +391,7 @@ std::shared_ptr<SQLiteHandle> SQLiteHandle::open(PJ_CONTEXT *ctx,
handle->vfs_ = std::move(vfs);
#endif
handle->initialize();
handle->path_ = path;
handle->checkDatabaseLayout(path, path, std::string());
return handle;
}
Expand Down Expand Up @@ -1256,7 +1260,7 @@ void DatabaseContext::Private::open(const std::string &databasePath,

sqlite_handle_ = SQLiteHandleCache::get().getHandle(path, ctx);

databasePath_ = std::move(path);
databasePath_ = sqlite_handle_->path();
}

// ---------------------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions src/memvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ static int memOpen(sqlite3_vfs *pVfs, const char *zName, sqlite3_file *pFile,
int flags, int *pOutFlags) {
MemFile *p = (MemFile *)pFile;
memset(p, 0, sizeof(*p));
if ((flags & SQLITE_OPEN_MAIN_DB) == 0)
return SQLITE_CANTOPEN;
if ((flags & SQLITE_OPEN_MAIN_DB) == 0) {
return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags,
pOutFlags);
}
p->aData = (unsigned char *)sqlite3_uri_int64(zName, "ptr", 0);
if (p->aData == 0)
return SQLITE_CANTOPEN;
Expand Down Expand Up @@ -424,6 +426,8 @@ int pj_sqlite3_memvfs_init(sqlite3_vfs *vfs, const char *vfs_name) {
if (!defaultVFS)
return SQLITE_ERROR;
vfs->szOsFile = sizeof(MemFile);
if (vfs->szOsFile < defaultVFS->szOsFile)
vfs->szOsFile = defaultVFS->szOsFile;
return sqlite3_vfs_register(vfs, 0);
}

Expand Down

0 comments on commit 98b1582

Please sign in to comment.