Skip to content

Fixes #63 #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2752,14 +2752,14 @@ $as_echo "no" >&6; }

if test "" == ""
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler flag -std=c++11 works" >&5
$as_echo_n "checking if compiler flag -std=c++11 works... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler flag -std=c++14 works" >&5
$as_echo_n "checking if compiler flag -std=c++14 works... " >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking " >&5
$as_echo_n "checking ... " >&6; }
fi
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -std=c++11"
CXXFLAGS="$CXXFLAGS -std=c++14"



Expand Down
11 changes: 9 additions & 2 deletions hdr/sqlite_modern_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,19 @@ namespace sqlite {
class database_binder {

public:
database_binder(database_binder&& other) = default;
// database_binder is not copyable
database_binder() = delete;
database_binder(const database_binder& other) = delete;
database_binder& operator=(const database_binder&) = delete;

database_binder(database_binder&& other) :
_db(std::move(other._db)),
_sql(std::move(other._sql)),
_stmt(std::move(other._stmt)),
_inx(other._inx), execution_started(other.execution_started) {
_db = nullptr;
_stmt = nullptr;
}

void reset() {
sqlite3_reset(_stmt.get());
Expand Down Expand Up @@ -253,7 +260,7 @@ namespace sqlite {
~database_binder() noexcept(false) {
/* Will be executed if no >>op is found, but not if an exception
is in mid flight */
if(!execution_started && !std::uncaught_exception()) {
if(!execution_started && !std::uncaught_exception() && _stmt) {
execute();
}
}
Expand Down
39 changes: 39 additions & 0 deletions tests/mov_ctor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Fixing https://github.com/aminroosta/sqlite_modern_cpp/issues/63
#include <iostream>
#include <cstdlib>
#include <unistd.h>
#include <sqlite_modern_cpp.h>
#include <memory>
using namespace sqlite;
using namespace std;

struct dbFront {
std::unique_ptr<database_binder> storedProcedure;
database db;
dbFront(): db(":memory:") {
db << "CREATE TABLE tbl (id integer, name string);";
// the temporary moved object should not run _execute() function on destruction.
storedProcedure = std::make_unique<database_binder>(
db << "INSERT INTO tbl VALUES (?, ?);"
);
}
};


int main() {

try {
dbFront dbf;
}
catch(sqlite_exception e) {
cout << "Unexpected error " << e.what() << endl;
exit(EXIT_FAILURE);
}
catch(...) {
cout << "Unknown error\n";
exit(EXIT_FAILURE);
}

cout << "OK\n";
exit(EXIT_SUCCESS);
}