From 33dc7daa54355594939f87fed5569b2f81cf25a2 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 May 2022 22:45:38 +0000 Subject: [PATCH] Clickhouse: send NULL as NULL and not string --- lib/ClickHouse_Server.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ClickHouse_Server.cpp b/lib/ClickHouse_Server.cpp index 8c51f556b..2bf92ec48 100644 --- a/lib/ClickHouse_Server.cpp +++ b/lib/ClickHouse_Server.cpp @@ -71,7 +71,6 @@ using namespace clickhouse; __thread MySQL_Session * clickhouse_thread___mysql_sess; -//static void ClickHouse_to_MySQL(SQLite3_result *result, char *error, int affected_rows, MySQL_Protocol *myprot) { inline void ClickHouse_to_MySQL(const Block& block) { MySQL_Session *sess = clickhouse_thread___mysql_sess; MySQL_Protocol *myprot=NULL; @@ -110,6 +109,7 @@ inline void ClickHouse_to_MySQL(const Block& block) { for (int r=0; rType()->GetCode(); + bool is_null = false; string s; switch (cc) { case clickhouse::Type::Code::Int8: @@ -178,7 +178,7 @@ inline void ClickHouse_to_MySQL(const Block& block) { { auto s_t = block[i]->As(); if (s_t->IsNull(r)) { - s = "NULL"; + is_null = true; } else { clickhouse::Type::Code cnc = block[i]->Type()->GetCode(); switch (cnc) { @@ -247,8 +247,12 @@ inline void ClickHouse_to_MySQL(const Block& block) { default: break; } - l[i]=s.length(); - p[i]=strdup((char *)s.c_str()); + if (is_null == false) { + l[i]=s.length(); + p[i]=strdup((char *)s.c_str()); + } else { + p[i]=NULL; + } } myprot->generate_pkt_row(true,NULL,NULL,sid,columns,l,p); sid++; for (int i=0; i