diff --git a/include/sqlpp11/sqlite3/connection.h b/include/sqlpp11/sqlite3/connection.h index 63aac63c..1909782a 100644 --- a/include/sqlpp11/sqlite3/connection.h +++ b/include/sqlpp11/sqlite3/connection.h @@ -74,9 +74,14 @@ namespace sqlpp detail::prepared_statement_handle_t result{nullptr, handle->config->debug}; + // ignore trailing spaces + const auto end = + std::find_if(statement.rbegin(), statement.rend(), [](char ch) { return !std::isspace(ch); }).base(); + const auto length = end - statement.begin(); + const char* uncompiledTail = nullptr; const auto rc = sqlite3_prepare_v2(handle->native_handle(), statement.c_str(), - static_cast(statement.size()), &result.sqlite_statement, &uncompiledTail); + static_cast(length), &result.sqlite_statement, &uncompiledTail); if (rc != SQLITE_OK) { @@ -85,7 +90,7 @@ namespace sqlpp " ,statement was >>" + (rc == SQLITE_TOOBIG ? statement.substr(0, 128) + "..." : statement) + "<<\n"}; } - if (uncompiledTail != statement.c_str() + statement.size()) + if (uncompiledTail != statement.c_str() + length) { throw sqlpp::exception{"Sqlite3 connector: Cannot execute multi-statements: >>" + statement + "<<\n"}; } diff --git a/tests/sqlite3/usage/Sample.cpp b/tests/sqlite3/usage/Sample.cpp index 61fb9169..c0b4e6f1 100644 --- a/tests/sqlite3/usage/Sample.cpp +++ b/tests/sqlite3/usage/Sample.cpp @@ -53,7 +53,8 @@ int Sample(int, char*[]) alpha INTEGER PRIMARY KEY, beta varchar(255) DEFAULT NULL, gamma bool DEFAULT NULL - ))"); + ) + )"); db.execute(R"(CREATE TABLE tab_foo ( omega bigint(20) DEFAULT NULL ))");