From 231bfbacc7fba68aab2585212b9a66f2510e640b Mon Sep 17 00:00:00 2001 From: program-- Date: Tue, 11 Jul 2023 08:34:54 -0700 Subject: [PATCH] rev: remove `stmt` from sqlite; shared -> unique changes per https://github.com/NOAA-OWP/ngen/pull/522#discussion_r1258715285 and https://github.com/NOAA-OWP/ngen/pull/522#discussion_r1258717997. --- include/geopackage/NGen_SQLite.hpp | 8 +------- src/geopackage/read.cpp | 3 ++- src/geopackage/sqlite/database.cpp | 9 +++------ src/geopackage/sqlite/iterator.cpp | 10 +++------- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/include/geopackage/NGen_SQLite.hpp b/include/geopackage/NGen_SQLite.hpp index eecc999748..9aaf55d3a7 100644 --- a/include/geopackage/NGen_SQLite.hpp +++ b/include/geopackage/NGen_SQLite.hpp @@ -22,7 +22,7 @@ struct sqlite_deleter /** * Smart pointer (shared) type for sqlite3 prepared statements */ -using stmt_t = std::shared_ptr; +using stmt_t = std::unique_ptr; /** * SQLite3 row iterator @@ -77,11 +77,6 @@ class sqlite_iter */ sqlite_iter& restart(); - /** - * Call the row iterator destructor - */ - void close(); - /** * Get the current row index for the iterator * @@ -158,7 +153,6 @@ class sqlite using sqlite_t = std::unique_ptr; sqlite_t conn = nullptr; - stmt_t stmt = nullptr; public: sqlite() = delete; diff --git a/src/geopackage/read.cpp b/src/geopackage/read.cpp index e53797d947..218d817761 100644 --- a/src/geopackage/read.cpp +++ b/src/geopackage/read.cpp @@ -19,7 +19,8 @@ std::shared_ptr geopackage::read( std::string errmsg = "[" + std::string(sqlite3_errmsg(db.connection())) + "] " + "table " + layer + " does not exist.\n\tTables: "; - auto errquery = db.query("SELECT name FROM sqlite_master WHERE type='table'").next(); + auto errquery = db.query("SELECT name FROM sqlite_master WHERE type='table'"); + errquery.next(); while(!errquery.done()) { errmsg += errquery.get(0); errmsg += ", "; diff --git a/src/geopackage/sqlite/database.cpp b/src/geopackage/sqlite/database.cpp index 20bc07e5ee..b768aa1882 100644 --- a/src/geopackage/sqlite/database.cpp +++ b/src/geopackage/sqlite/database.cpp @@ -60,8 +60,7 @@ sqlite_iter sqlite::query(const std::string& statement) throw sqlite_error("sqlite3_prepare_v2", code, "(query: " + statement + ")"); } - this->stmt = stmt_t(stmt, sqlite_deleter{}); - return sqlite_iter(this->stmt); + return sqlite_iter(std::move(stmt_t(stmt))); } sqlite_iter sqlite::query(const std::string& statement, const std::vector& binds) @@ -83,8 +82,7 @@ sqlite_iter sqlite::query(const std::string& statement, const std::vectorstmt = stmt_t(stmt, sqlite_deleter{}); - return sqlite_iter(this->stmt); + return sqlite_iter(std::move(stmt_t(stmt))); } template @@ -106,6 +104,5 @@ inline sqlite_iter sqlite::query(const std::string& statement, T const&... param } } - this->stmt = stmt_t(stmt, sqlite_deleter{}); - return sqlite_iter(this->stmt); + return sqlite_iter(std::move(stmt_t(stmt))); } diff --git a/src/geopackage/sqlite/iterator.cpp b/src/geopackage/sqlite/iterator.cpp index befffbab27..4cd322533f 100644 --- a/src/geopackage/sqlite/iterator.cpp +++ b/src/geopackage/sqlite/iterator.cpp @@ -1,4 +1,5 @@ #include +#include #include "NGen_SQLite.hpp" @@ -22,7 +23,7 @@ const auto sqlite_get_done_error = std::runtime_error( ); sqlite_iter::sqlite_iter(stmt_t stmt) - : stmt(stmt) + : stmt(std::move(stmt)) { // sqlite3_column_type requires the last result code to be // SQLITE_ROW, so we need to iterate on the first row. @@ -39,7 +40,7 @@ sqlite_iter::sqlite_iter(stmt_t stmt) } this->restart(); -}; +} sqlite3_stmt* sqlite_iter::ptr() const noexcept { @@ -92,11 +93,6 @@ sqlite_iter& sqlite_iter::restart() return *this; } -void sqlite_iter::close() -{ - this->~sqlite_iter(); -} - int sqlite_iter::current_row() const noexcept { return this->iteration_step;