From da31f56451a19cb130c03c56dea355099b794555 Mon Sep 17 00:00:00 2001 From: Denis Glazachev Date: Fri, 6 Mar 2020 22:18:39 +0400 Subject: [PATCH 1/3] Treat unknown types as Strings in ODBCDriver2 format --- driver/api/odbc.cpp | 7 ++++++- driver/format/ODBCDriver2.cpp | 7 ++++++- driver/format/RowBinaryWithNamesAndTypes.cpp | 2 +- driver/result_set.cpp | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/driver/api/odbc.cpp b/driver/api/odbc.cpp index 6b0639339..41569a068 100755 --- a/driver/api/odbc.cpp +++ b/driver/api/odbc.cpp @@ -1013,9 +1013,14 @@ SQLRETURN SQL_API EXPORTED_FUNCTION_MAYBE_W(SQLColumns)( if (parser.parse(&ast)) { tmp_column_info.assignTypeInfo(ast); + + if (convertUnparametrizedTypeNameToTypeId(tmp_column_info.type_without_parameters) == DataSourceTypeId::Unknown) { + // Interpret all unknown types as String. + tmp_column_info.type_without_parameters = "String"; + } } else { - // Interpret all unknown types as String. + // Interpret all unparsable types as String. tmp_column_info.type_without_parameters = "String"; } diff --git a/driver/format/ODBCDriver2.cpp b/driver/format/ODBCDriver2.cpp index ae9441e6d..673eaa649 100644 --- a/driver/format/ODBCDriver2.cpp +++ b/driver/format/ODBCDriver2.cpp @@ -36,9 +36,14 @@ ODBCDriver2ResultSet::ODBCDriver2ResultSet(AmortizedIStreamReader & stream, std: if (parser.parse(&ast)) { columns_info[i].assignTypeInfo(ast); + + if (convertUnparametrizedTypeNameToTypeId(columns_info[i].type_without_parameters) == DataSourceTypeId::Unknown) { + // Interpret all unknown types as String. + columns_info[i].type_without_parameters = "String"; + } } else { - // Interpret all unknown types as String. + // Interpret all unparsable types as String. columns_info[i].type_without_parameters = "String"; } diff --git a/driver/format/RowBinaryWithNamesAndTypes.cpp b/driver/format/RowBinaryWithNamesAndTypes.cpp index 0b672bc43..3e8ffaa11 100644 --- a/driver/format/RowBinaryWithNamesAndTypes.cpp +++ b/driver/format/RowBinaryWithNamesAndTypes.cpp @@ -24,7 +24,7 @@ RowBinaryWithNamesAndTypesResultSet::RowBinaryWithNamesAndTypesResultSet(Amortiz columns_info[i].assignTypeInfo(ast); } else { - // Interpret all unknown types as String. + // Interpret all unparsable types as String. columns_info[i].type_without_parameters = "String"; } diff --git a/driver/result_set.cpp b/driver/result_set.cpp index 64a7263d9..fdfd4d4f9 100644 --- a/driver/result_set.cpp +++ b/driver/result_set.cpp @@ -62,7 +62,7 @@ void ColumnInfo::assignTypeInfo(const TypeAst & ast) { assignTypeInfo(ast.elements.front()); } else { - // Interpret all unsupported types as String. + // Interpret all unrecognized ASTs as of String type. type_without_parameters = "String"; } } From 8bd003f215b83a0365edef859b230b8b3cfb1a8d Mon Sep 17 00:00:00 2001 From: Denis Glazachev Date: Fri, 6 Mar 2020 22:32:07 +0400 Subject: [PATCH 2/3] More strict type parsing for synthetic query in SQLColums --- driver/api/odbc.cpp | 15 +++------------ driver/result_set.cpp | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/driver/api/odbc.cpp b/driver/api/odbc.cpp index 41569a068..0c549e5cf 100755 --- a/driver/api/odbc.cpp +++ b/driver/api/odbc.cpp @@ -1011,19 +1011,10 @@ SQLRETURN SQL_API EXPORTED_FUNCTION_MAYBE_W(SQLColumns)( TypeParser parser{type_name}; TypeAst ast; - if (parser.parse(&ast)) { - tmp_column_info.assignTypeInfo(ast); - - if (convertUnparametrizedTypeNameToTypeId(tmp_column_info.type_without_parameters) == DataSourceTypeId::Unknown) { - // Interpret all unknown types as String. - tmp_column_info.type_without_parameters = "String"; - } - } - else { - // Interpret all unparsable types as String. - tmp_column_info.type_without_parameters = "String"; - } + if (!parser.parse(&ast)) + throw std::runtime_error("Unsupported type: " + type_name); + tmp_column_info.assignTypeInfo(ast); tmp_column_info.updateTypeInfo(); }, row.fields.at(5).data); diff --git a/driver/result_set.cpp b/driver/result_set.cpp index fdfd4d4f9..995c995e5 100644 --- a/driver/result_set.cpp +++ b/driver/result_set.cpp @@ -62,7 +62,7 @@ void ColumnInfo::assignTypeInfo(const TypeAst & ast) { assignTypeInfo(ast.elements.front()); } else { - // Interpret all unrecognized ASTs as of String type. + // Interpret all types with unrecognized ASTs as String. type_without_parameters = "String"; } } From e5aaaeaac44fd707fc0106b92e52f75f4e882dfd Mon Sep 17 00:00:00 2001 From: Denis Glazachev Date: Fri, 6 Mar 2020 22:45:04 +0400 Subject: [PATCH 3/3] Revert to more permissive type parsing in SQColumns --- driver/api/odbc.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/driver/api/odbc.cpp b/driver/api/odbc.cpp index 0c549e5cf..41569a068 100755 --- a/driver/api/odbc.cpp +++ b/driver/api/odbc.cpp @@ -1011,10 +1011,19 @@ SQLRETURN SQL_API EXPORTED_FUNCTION_MAYBE_W(SQLColumns)( TypeParser parser{type_name}; TypeAst ast; - if (!parser.parse(&ast)) - throw std::runtime_error("Unsupported type: " + type_name); + if (parser.parse(&ast)) { + tmp_column_info.assignTypeInfo(ast); + + if (convertUnparametrizedTypeNameToTypeId(tmp_column_info.type_without_parameters) == DataSourceTypeId::Unknown) { + // Interpret all unknown types as String. + tmp_column_info.type_without_parameters = "String"; + } + } + else { + // Interpret all unparsable types as String. + tmp_column_info.type_without_parameters = "String"; + } - tmp_column_info.assignTypeInfo(ast); tmp_column_info.updateTypeInfo(); }, row.fields.at(5).data);