Skip to content

Commit

Permalink
rev: remove stmt from sqlite; shared -> unique
Browse files Browse the repository at this point in the history
  • Loading branch information
program-- authored and mattw-nws committed Jul 18, 2023
1 parent 1f8b75d commit 231bfba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
8 changes: 1 addition & 7 deletions include/geopackage/NGen_SQLite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct sqlite_deleter
/**
* Smart pointer (shared) type for sqlite3 prepared statements
*/
using stmt_t = std::shared_ptr<sqlite3_stmt>;
using stmt_t = std::unique_ptr<sqlite3_stmt, sqlite_deleter>;

/**
* SQLite3 row iterator
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -158,7 +153,6 @@ class sqlite
using sqlite_t = std::unique_ptr<sqlite3, sqlite_deleter>;

sqlite_t conn = nullptr;
stmt_t stmt = nullptr;

public:
sqlite() = delete;
Expand Down
3 changes: 2 additions & 1 deletion src/geopackage/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ std::shared_ptr<geojson::FeatureCollection> 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<std::string>(0);
errmsg += ", ";
Expand Down
9 changes: 3 additions & 6 deletions src/geopackage/sqlite/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& binds)
Expand All @@ -83,8 +82,7 @@ sqlite_iter sqlite::query(const std::string& statement, const std::vector<std::s
}
}

this->stmt = stmt_t(stmt, sqlite_deleter{});
return sqlite_iter(this->stmt);
return sqlite_iter(std::move(stmt_t(stmt)));
}

template<typename... T>
Expand All @@ -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)));
}
10 changes: 3 additions & 7 deletions src/geopackage/sqlite/iterator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <algorithm>
#include <memory>

#include "NGen_SQLite.hpp"

Expand All @@ -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.
Expand All @@ -39,7 +40,7 @@ sqlite_iter::sqlite_iter(stmt_t stmt)
}

this->restart();
};
}

sqlite3_stmt* sqlite_iter::ptr() const noexcept
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 231bfba

Please sign in to comment.