0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Ignore trailing spaces in sqlite3 statements, #585

This commit is contained in:
Roland Bock 2024-07-26 14:13:11 +02:00
parent 09a98736d7
commit 46cffc8398
2 changed files with 9 additions and 3 deletions

View File

@ -74,9 +74,14 @@ namespace sqlpp
detail::prepared_statement_handle_t result{nullptr, handle->config->debug}; 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 char* uncompiledTail = nullptr;
const auto rc = sqlite3_prepare_v2(handle->native_handle(), statement.c_str(), const auto rc = sqlite3_prepare_v2(handle->native_handle(), statement.c_str(),
static_cast<int>(statement.size()), &result.sqlite_statement, &uncompiledTail); static_cast<int>(length), &result.sqlite_statement, &uncompiledTail);
if (rc != SQLITE_OK) if (rc != SQLITE_OK)
{ {
@ -85,7 +90,7 @@ namespace sqlpp
" ,statement was >>" + (rc == SQLITE_TOOBIG ? statement.substr(0, 128) + "..." : statement) + "<<\n"}; " ,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"}; throw sqlpp::exception{"Sqlite3 connector: Cannot execute multi-statements: >>" + statement + "<<\n"};
} }

View File

@ -53,7 +53,8 @@ int Sample(int, char*[])
alpha INTEGER PRIMARY KEY, alpha INTEGER PRIMARY KEY,
beta varchar(255) DEFAULT NULL, beta varchar(255) DEFAULT NULL,
gamma bool DEFAULT NULL gamma bool DEFAULT NULL
))"); )
)");
db.execute(R"(CREATE TABLE tab_foo ( db.execute(R"(CREATE TABLE tab_foo (
omega bigint(20) DEFAULT NULL omega bigint(20) DEFAULT NULL
))"); ))");