2222#include " arrow/flight/sql/odbc/flight_sql/utils.h"
2323#include " arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
2424#include " arrow/flight/types.h"
25+ #include " arrow/util/string.h"
2526
2627namespace driver {
2728namespace flight_sql {
@@ -31,6 +32,15 @@ using arrow::flight::FlightClientOptions;
3132using arrow::flight::FlightInfo;
3233using arrow::flight::sql::FlightSqlClient;
3334
35+ static void AddTableType (std::string& table_type, std::vector<std::string>& table_types) {
36+ std::string trimmed_type = arrow::internal::TrimString (table_type);
37+
38+ // Only put the string if the trimmed result is non-empty
39+ if (trimmed_type.length () > 0 ) {
40+ table_types.emplace_back (trimmed_type);
41+ }
42+ }
43+
3444void ParseTableTypes (const std::string& table_type,
3545 std::vector<std::string>& table_types) {
3646 bool encountered = false ; // for checking if there is a single quote
@@ -39,36 +49,23 @@ void ParseTableTypes(const std::string& table_type,
3949 for (char temp : table_type) { // while still in the string
4050 switch (temp) { // switch depending on the character
4151 case ' \' ' : // if the character is a single quote
42- if (encountered) {
43- encountered = false ; // if we already found a single quote, reset encountered
44- } else {
45- encountered =
46- true ; // if we haven't found a single quote, set encountered to true
47- }
52+ // track when we've encountered a single opening quote
53+ // and are still looking for the closing quote
54+ encountered = !encountered;
4855 break ;
49- case ' ,' : // if it is a comma
50- if (!encountered) { // if we have not found a single quote
51- table_types. push_back (curr_parse); // put our current string into our vector
52- curr_parse = " " ; // reset the current string
56+ case ' ,' : // if it is a comma
57+ if (!encountered) { // if we have not found a single quote
58+ AddTableType (curr_parse, table_types ); // put current string into vector
59+ curr_parse = " " ; // reset the current string
5360 break ;
5461 }
55- default : // if it is a normal character
56- if (encountered && isspace (temp)) {
57- curr_parse.push_back (temp); // if we have found a single quote put the
58- // whitespace, we don't care
59- } else if (temp == ' \' ' || temp == ' ' ) {
60- break ; // if the current character is a single quote, trash it and go to
61- // the next character.
62- } else {
63- curr_parse.push_back (temp); // if all of the above failed, put the
64- // character into the current string
65- }
66- break ; // go to the next character
62+ [[fallthrough]];
63+ default : // if it is a normal character
64+ curr_parse.push_back (temp); // put the character into the current string
65+ break ; // go to the next character
6766 }
6867 }
69- table_types.emplace_back (
70- curr_parse); // if we have found a single quote put the whitespace,
71- // we don't care
68+ AddTableType (curr_parse, table_types);
7269}
7370
7471std::shared_ptr<ResultSet> GetTablesForSQLAllCatalogs (
0 commit comments