This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch dev-1.1.2 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/dev-1.1.2 by this push: new 03d5f017b0 [bugfix](odbc) return error if convert unicode failed (#11728) 03d5f017b0 is described below commit 03d5f017b0dbce60e223d7804ec8e50e42a0cd63 Author: TengJianPing <18241664+jackte...@users.noreply.github.com> AuthorDate: Fri Aug 12 17:28:48 2022 +0800 [bugfix](odbc) return error if convert unicode failed (#11728) * [bugfix](odbc) return error if convert unicode failed --- be/src/exec/odbc_connector.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/be/src/exec/odbc_connector.cpp b/be/src/exec/odbc_connector.cpp index 2fd296dfee..1de8337e5d 100644 --- a/be/src/exec/odbc_connector.cpp +++ b/be/src/exec/odbc_connector.cpp @@ -48,9 +48,14 @@ static constexpr uint32_t BIG_COLUMN_SIZE_BUFFER = 65535; // Default max buffer size use in insert to: 50MB, normally a batch is smaller than the size static constexpr uint32_t INSERT_BUFFER_SIZE = 1024l * 1024 * 50; -static std::u16string utf8_to_wstring(const std::string& str) { +static doris::Status utf8_to_wstring(const std::string& str, std::u16string& out) { std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8_ucs2_cvt; - return utf8_ucs2_cvt.from_bytes(str); + try { + out = utf8_ucs2_cvt.from_bytes(str); + } catch (std::range_error& e) { + return doris::Status::InternalError("UNICODE out of supported range"); + } + return doris::Status::OK(); } namespace doris { @@ -128,7 +133,8 @@ Status ODBCConnector::query() { "alloc statement"); // Translate utf8 string to utf16 to use unicode encoding - auto wquery = utf8_to_wstring(_sql_str); + std::u16string wquery; + RETURN_IF_ERROR(utf8_to_wstring(_sql_str, wquery)); ODBC_DISPOSE(_stmt, SQL_HANDLE_STMT, SQLExecDirectW(_stmt, (SQLWCHAR*)(wquery.c_str()), SQL_NTS), "exec direct"); @@ -309,9 +315,10 @@ Status ODBCConnector::append(const std::string& table_name, RowBatch* batch, } } // Translate utf8 string to utf16 to use unicode encodeing - insert_stmt = utf8_to_wstring( + RETURN_IF_ERROR(utf8_to_wstring( std::string(_insert_stmt_buffer.data(), - _insert_stmt_buffer.data() + _insert_stmt_buffer.size())); + _insert_stmt_buffer.data() + _insert_stmt_buffer.size()), + insert_stmt)); } { @@ -494,9 +501,10 @@ Status ODBCConnector::append(const std::string& table_name, vectorized::Block* b } } // Translate utf8 string to utf16 to use unicode encodeing - insert_stmt = utf8_to_wstring( + RETURN_IF_ERROR(utf8_to_wstring( std::string(_insert_stmt_buffer.data(), - _insert_stmt_buffer.data() + _insert_stmt_buffer.size())); + _insert_stmt_buffer.data() + _insert_stmt_buffer.size()), + insert_stmt)); } { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org