Skip to content

Commit

Permalink
rev: rename SQLite.hpp; move sqlite_error def
Browse files Browse the repository at this point in the history
changes per #522 (comment),
and #522 (comment).
  • Loading branch information
program-- authored and mattw-nws committed Jul 18, 2023
1 parent 58eece1 commit 45b6a91
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion include/geopackage/GeoPackage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define NGEN_GEOPACKAGE_H

#include "FeatureCollection.hpp"
#include "SQLite.hpp"
#include "NGen_SQLite.hpp"

namespace geopackage {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -43,30 +29,6 @@ using sqlite_t = std::unique_ptr<sqlite3, sqlite_deleter>;
*/
using stmt_t = std::shared_ptr<sqlite3_stmt>;

/**
* 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
*
Expand Down
26 changes: 25 additions & 1 deletion src/geopackage/sqlite/database.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
19 changes: 18 additions & 1 deletion src/geopackage/sqlite/iterator.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
#include <algorithm>

#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)
{
Expand Down
2 changes: 1 addition & 1 deletion test/geopackage/SQLite_Test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <gtest/gtest.h>

#include "SQLite.hpp"
#include "NGen_SQLite.hpp"
#include "FileChecker.h"

using namespace geopackage;
Expand Down

0 comments on commit 45b6a91

Please sign in to comment.