22
22
#include " arrow/flight/sql/odbc/flight_sql/utils.h"
23
23
#include " arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
24
24
#include " arrow/flight/types.h"
25
+ #include " arrow/util/string.h"
25
26
26
27
namespace driver {
27
28
namespace flight_sql {
@@ -31,6 +32,15 @@ using arrow::flight::FlightClientOptions;
31
32
using arrow::flight::FlightInfo;
32
33
using arrow::flight::sql::FlightSqlClient;
33
34
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
+
34
44
void ParseTableTypes (const std::string& table_type,
35
45
std::vector<std::string>& table_types) {
36
46
bool encountered = false ; // for checking if there is a single quote
@@ -39,36 +49,23 @@ void ParseTableTypes(const std::string& table_type,
39
49
for (char temp : table_type) { // while still in the string
40
50
switch (temp) { // switch depending on the character
41
51
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;
48
55
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
53
60
break ;
54
61
}
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
67
66
}
68
67
}
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);
72
69
}
73
70
74
71
std::shared_ptr<ResultSet> GetTablesForSQLAllCatalogs (
0 commit comments