From c13a9db7992885f524ba1d3fd057d8a3244b1382 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 3 Oct 2024 02:35:52 +0200 Subject: [PATCH] memvfs: make it work with 'projinfo --list-crs' --- src/iso19111/factory.cpp | 8 ++++++-- src/memvfs.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 44890457ad..17fa5ddcd7 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -244,6 +244,7 @@ static void PROJ_SQLITE_intersects_bbox(sqlite3_context *pContext, // --------------------------------------------------------------------------- class SQLiteHandle { + std::string path_{}; sqlite3 *sqlite_handle_ = nullptr; bool close_handle_ = true; @@ -276,6 +277,8 @@ class SQLiteHandle { public: ~SQLiteHandle(); + const std::string &path() const { return path_; } + sqlite3 *handle() { return sqlite_handle_; } #ifdef REOPEN_SQLITE_DB_AFTER_FORK @@ -285,7 +288,7 @@ class SQLiteHandle { #endif static std::shared_ptr 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 @@ -386,6 +389,7 @@ std::shared_ptr SQLiteHandle::open(PJ_CONTEXT *ctx, handle->vfs_ = std::move(vfs); #endif handle->initialize(); + handle->path_ = path; handle->checkDatabaseLayout(path, path, std::string()); return handle; } @@ -1254,7 +1258,7 @@ void DatabaseContext::Private::open(const std::string &databasePath, sqlite_handle_ = SQLiteHandleCache::get().getHandle(path, ctx); - databasePath_ = std::move(path); + databasePath_ = sqlite_handle_->path(); } // --------------------------------------------------------------------------- diff --git a/src/memvfs.c b/src/memvfs.c index eea86d30f0..60ba0544d2 100644 --- a/src/memvfs.c +++ b/src/memvfs.c @@ -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; @@ -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); }