Skip to content
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
40 changes: 40 additions & 0 deletions be/src/util/mysql_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <float.h>
#include <stdint.h>

#include <cstring>
#include <string>

namespace doris {

typedef unsigned char uchar;
Expand Down Expand Up @@ -61,4 +64,41 @@ typedef unsigned char uchar;
/* -[digits].[frac] */
#define MAX_DECIMAL_STR_LENGTH 29

inline void direct_write_to_mysql_result_string(std::string& mysql_rows, const char* str,
size_t size) {
// MySQL protocol length encoding:
// <= 250: 1 byte for length
// < 65536: 1 byte (252) + 2 bytes for length
// < 16777216: 1 byte (253) + 3 bytes for length
// >= 16777216: 1 byte (254) + 8 bytes for length

char buf[16];
if (size < 251ULL) {
int1store(buf, size);
mysql_rows.append(buf, 1);
} else if (size < 65536ULL) {
buf[0] = static_cast<char>(252);
uint16_t temp16 = static_cast<uint16_t>(size);
memcpy(buf + 1, &temp16, sizeof(temp16));
mysql_rows.append(buf, 3);
} else if (size < 16777216ULL) {
buf[0] = static_cast<char>(253);
int3store(buf + 1, size);
mysql_rows.append(buf, 4);
} else {
buf[0] = static_cast<char>(254);
uint64_t temp64 = static_cast<uint64_t>(size);
memcpy(buf + 1, &temp64, sizeof(temp64));
mysql_rows.append(buf, 9);
}

// Append string content
mysql_rows.append(str, size);
}

inline void direct_write_to_mysql_result_null(std::string& mysql_rows) {
// MySQL protocol for NULL value is a single byte with value 251
mysql_rows.push_back(static_cast<char>(251));
}

} // namespace doris
Loading
Loading