From 31fb4b12d360bb40ad7ed3dd7fc173e807931fe9 Mon Sep 17 00:00:00 2001 From: program-- Date: Mon, 10 Jul 2023 10:52:32 -0700 Subject: [PATCH] rev: rename SQLite.hpp; move sqlite_error def changes per https://github.com/NOAA-OWP/ngen/pull/522#discussion_r1258593990, and https://github.com/NOAA-OWP/ngen/pull/522#discussion_r1258584308. --- include/geopackage/GeoPackage.hpp | 2 +- .../{SQLite.hpp => NGen_SQLite.hpp} | 38 ------------------- src/geopackage/sqlite/database.cpp | 26 ++++++++++++- src/geopackage/sqlite/iterator.cpp | 19 +++++++++- test/geopackage/SQLite_Test.cpp | 2 +- 5 files changed, 45 insertions(+), 42 deletions(-) rename include/geopackage/{SQLite.hpp => NGen_SQLite.hpp} (84%) diff --git a/include/geopackage/GeoPackage.hpp b/include/geopackage/GeoPackage.hpp index e0b4d6e650..71203f4bcb 100644 --- a/include/geopackage/GeoPackage.hpp +++ b/include/geopackage/GeoPackage.hpp @@ -2,7 +2,7 @@ #define NGEN_GEOPACKAGE_H #include "FeatureCollection.hpp" -#include "SQLite.hpp" +#include "NGen_SQLite.hpp" namespace geopackage { diff --git a/include/geopackage/SQLite.hpp b/include/geopackage/NGen_SQLite.hpp similarity index 84% rename from include/geopackage/SQLite.hpp rename to include/geopackage/NGen_SQLite.hpp index 1dceea19f6..4c9b07b50d 100644 --- a/include/geopackage/SQLite.hpp +++ b/include/geopackage/NGen_SQLite.hpp @@ -10,20 +10,6 @@ namespace geopackage { -/** - * Runtime error for iterations that haven't started - */ -const auto sqlite_get_notstarted_error = std::runtime_error( - "sqlite iteration is has not started, get() is not callable (call sqlite_iter::next() before)" -); - -/** - * Runtime error for iterations that are finished - */ -const auto sqlite_get_done_error = std::runtime_error( - "sqlite iteration is done, get() is not callable" -); - /** * Deleter used to provide smart pointer support for sqlite3 structs. */ @@ -43,30 +29,6 @@ using sqlite_t = std::unique_ptr; */ using stmt_t = std::shared_ptr; -/** - * Get a runtime error based on a function and code. - * - * @param f String denoting the function where the error originated - * @param code sqlite3 result code - * @param extra additional messages to add to the end of the error - * @return std::runtime_error - */ -inline std::runtime_error sqlite_error(const std::string& f, int code, const std::string& extra = "") -{ - std::string errmsg = f + " returned code " - + std::to_string(code) - + " (msg: " - + std::string(sqlite3_errstr(code)) - + ")"; - - if (!extra.empty()) { - errmsg += " "; - errmsg += extra; - } - - return std::runtime_error(errmsg); -} - /** * SQLite3 row iterator * diff --git a/src/geopackage/sqlite/database.cpp b/src/geopackage/sqlite/database.cpp index 02e3736f76..7145f35642 100644 --- a/src/geopackage/sqlite/database.cpp +++ b/src/geopackage/sqlite/database.cpp @@ -1,7 +1,31 @@ -#include "SQLite.hpp" +#include "NGen_SQLite.hpp" using namespace geopackage; +/** + * Get a runtime error based on a function and code. + * + * @param f String denoting the function where the error originated + * @param code sqlite3 result code + * @param extra additional messages to add to the end of the error + * @return std::runtime_error + */ +std::runtime_error sqlite_error(const std::string& f, int code, const std::string& extra = "") +{ + std::string errmsg = f + " returned code " + + std::to_string(code) + + " (msg: " + + std::string(sqlite3_errstr(code)) + + ")"; + + if (!extra.empty()) { + errmsg += " "; + errmsg += extra; + } + + return std::runtime_error(errmsg); +} + sqlite::sqlite(const std::string& path) { sqlite3* conn; diff --git a/src/geopackage/sqlite/iterator.cpp b/src/geopackage/sqlite/iterator.cpp index 6982d4e488..9b0a7ec9e7 100644 --- a/src/geopackage/sqlite/iterator.cpp +++ b/src/geopackage/sqlite/iterator.cpp @@ -1,9 +1,26 @@ #include -#include "SQLite.hpp" +#include "NGen_SQLite.hpp" using namespace geopackage; +// Defined in database.cpp +extern std::runtime_error sqlite_error(const std::string& f, int code, const std::string& extra = ""); + +/** + * Runtime error for iterations that haven't started + */ +const auto sqlite_get_notstarted_error = std::runtime_error( + "sqlite iteration is has not started, get() is not callable (call sqlite_iter::next() before)" +); + +/** + * Runtime error for iterations that are finished + */ +const auto sqlite_get_done_error = std::runtime_error( + "sqlite iteration is done, get() is not callable" +); + sqlite_iter::sqlite_iter(stmt_t stmt) : stmt(stmt) { diff --git a/test/geopackage/SQLite_Test.cpp b/test/geopackage/SQLite_Test.cpp index b09171c4b3..6bba79c2cb 100644 --- a/test/geopackage/SQLite_Test.cpp +++ b/test/geopackage/SQLite_Test.cpp @@ -1,6 +1,6 @@ #include -#include "SQLite.hpp" +#include "NGen_SQLite.hpp" #include "FileChecker.h" using namespace geopackage;