[fix](multi-catalog) values in sqlserver should be enclosed by single quotes (#19971)

Fix errors when inserting string/date/datetime values into SQLServer:

ERROR 1105 (HY000): errCode = 2, detailMessage = (172.21.0.101)[INTERNAL_ERROR]UdfRuntimeException: JDBC executor sql has error:
CAUSED BY: SQLServerException: Invalid column name '2021-10-30'.
When using double quotes enclose string values, it will be parsed as column name, so we should enclose string values with single quotes.
This commit is contained in:
Ashin Gau
2023-05-26 20:04:45 +08:00
committed by GitHub
parent ce45d6119d
commit 9458a24cd7

View File

@ -231,6 +231,9 @@ Status TableConnector::convert_column_data(const vectorized::ColumnPtr& column_p
}
} else if (table_type == TOdbcTableType::POSTGRESQL) {
fmt::format_to(_insert_stmt_buffer, "'{}'::date", str);
} else if (table_type == TOdbcTableType::SQLSERVER) {
// Values in sqlserver should be enclosed by single quotes
fmt::format_to(_insert_stmt_buffer, "'{}'", str);
} else {
fmt::format_to(_insert_stmt_buffer, "\"{}\"", str);
}