From 0ea84fbb37583f32d90ed0d8464b6fc605dda7ff Mon Sep 17 00:00:00 2001 From: an-tao Date: Wed, 4 Jun 2025 14:05:55 +0800 Subject: [PATCH] Fix error when executing SQL through string_view without null terminator --- orm_lib/inc/drogon/orm/SqlBinder.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/orm_lib/inc/drogon/orm/SqlBinder.h b/orm_lib/inc/drogon/orm/SqlBinder.h index 3335e6ffbd..83cb737532 100644 --- a/orm_lib/inc/drogon/orm/SqlBinder.h +++ b/orm_lib/inc/drogon/orm/SqlBinder.h @@ -312,6 +312,13 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable client_(client), type_(type) { + if (sql[sqlLength] != '\0') + { + // if the sql is not null terminated, we need to copy it to a string + sqlPtr_ = std::make_shared(sql, sqlLength); + sqlViewPtr_ = sqlPtr_->data(); + sqlViewLength_ = sqlPtr_->length(); + } } SqlBinder(SqlBinder &&that) noexcept