Skip to content

Commit 3d18b41

Browse files
committed
Address remaining feedback
1 parent 8c383a3 commit 3d18b41

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

cpp/src/arrow/flight/sql/odbc/odbc_api.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#if defined _WIN32
3535
// For displaying DSN Window
3636
# include "arrow/flight/sql/odbc/odbc_impl/system_dsn.h"
37-
#endif
37+
#endif // defined(_WIN32)
3838

3939
namespace arrow::flight::sql::odbc {
4040
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) {
@@ -780,9 +780,11 @@ SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND window_handle,
780780
std::string connection_string =
781781
ODBC::SqlWcharToString(in_connection_string, in_connection_string_len);
782782
Connection::ConnPropertyMap properties;
783-
std::string dsn = ODBCConnection::GetDsnIfExists(connection_string);
784-
if (!dsn.empty()) {
785-
LoadPropertiesFromDSN(dsn, properties);
783+
std::string dsn_value = "";
784+
std::optional<std::string> dsn = ODBCConnection::GetDsnIfExists(connection_string);
785+
if (dsn.has_value()) {
786+
dsn_value = dsn.value();
787+
LoadPropertiesFromDSN(dsn_value, properties);
786788
}
787789
ODBCConnection::GetPropertiesFromConnString(connection_string, properties);
788790

@@ -798,11 +800,11 @@ SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND window_handle,
798800
if (!DisplayConnectionWindow(window_handle, config, properties)) {
799801
return static_cast<SQLRETURN>(SQL_NO_DATA);
800802
}
801-
connection->Connect(dsn, properties, missing_properties);
803+
connection->Connect(dsn_value, properties, missing_properties);
802804
} else if (driver_completion == SQL_DRIVER_COMPLETE ||
803805
driver_completion == SQL_DRIVER_COMPLETE_REQUIRED) {
804806
try {
805-
connection->Connect(dsn, properties, missing_properties);
807+
connection->Connect(dsn_value, properties, missing_properties);
806808
} catch (const DriverException&) {
807809
// If first connection fails due to missing attributes, load
808810
// the DSN window and try to connect again
@@ -813,14 +815,14 @@ SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND window_handle,
813815
if (!DisplayConnectionWindow(window_handle, config, properties)) {
814816
return static_cast<SQLRETURN>(SQL_NO_DATA);
815817
}
816-
connection->Connect(dsn, properties, missing_properties);
818+
connection->Connect(dsn_value, properties, missing_properties);
817819
} else {
818820
throw;
819821
}
820822
}
821823
} else {
822824
// Default case: attempt connection without showing DSN window
823-
connection->Connect(dsn, properties, missing_properties);
825+
connection->Connect(dsn_value, properties, missing_properties);
824826
}
825827
#else
826828
// Attempt connection without loading DSN window on macOS/Linux

cpp/src/arrow/flight/sql/odbc/odbc_impl/attribute_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
2828
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
2929

30+
// GH-48083 TODO: replace `namespace ODBC` with `namespace arrow::flight::sql::odbc`
3031
namespace ODBC {
3132

3233
using arrow::flight::sql::odbc::Diagnostics;

cpp/src/arrow/flight/sql/odbc/odbc_impl/encoding_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ inline size_t ConvertToSqlWChar(std::string_view str, SQLWCHAR* buffer,
8585
/// \param[in] msg_len Number of characters in wchar_msg
8686
/// \return wchar_msg in std::string format
8787
inline std::string SqlWcharToString(SQLWCHAR* wchar_msg, SQLINTEGER msg_len = SQL_NTS) {
88-
if (!wchar_msg || wchar_msg[0] == 0 || msg_len == 0) {
88+
if (msg_len == 0 || !wchar_msg || wchar_msg[0] == 0) {
8989
return std::string();
9090
}
9191

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ void ODBCConnection::DropDescriptor(ODBCDescriptor* desc) {
684684

685685
// Public Static
686686
// ===================================================================================
687-
std::string ODBCConnection::GetDsnIfExists(const std::string& conn_str) {
687+
std::optional<std::string> ODBCConnection::GetDsnIfExists(const std::string& conn_str) {
688688
const int groups[] = {1, 2}; // CONNECTION_STR_REGEX has two groups. key: 1, value: 2
689689
boost::xpressive::sregex_token_iterator regex_iter(conn_str.begin(), conn_str.end(),
690690
CONNECTION_STR_REGEX, groups),
@@ -703,7 +703,7 @@ std::string ODBCConnection::GetDsnIfExists(const std::string& conn_str) {
703703
if (boost::iequals(key, "DSN")) {
704704
return value;
705705
} else if (boost::iequals(key, "Driver")) {
706-
return std::string("");
706+
return std::nullopt;
707707
} else {
708708
throw DriverException(
709709
"Connection string is faulty. The first key should be DSN or Driver.", "HY000");

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_connection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sql.h>
2424
#include <map>
2525
#include <memory>
26+
#include <optional>
2627
#include <vector>
2728

2829
namespace ODBC {
@@ -75,9 +76,8 @@ class ODBCConnection : public ODBCHandle<ODBCConnection> {
7576

7677
inline bool IsOdbc2Connection() const { return is_2x_connection_; }
7778

78-
/// @return the DSN or an empty string if the DSN is not found or is found after the
79-
/// driver
80-
static std::string GetDsnIfExists(const std::string& conn_str);
79+
/// \return an optional DSN
80+
static std::optional<std::string> GetDsnIfExists(const std::string& conn_str);
8181

8282
/// Read properties from connection string, but does not read values from DSN
8383
static void GetPropertiesFromConnString(

cpp/src/arrow/flight/sql/odbc/odbc_impl/system_dsn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
2020

2121
#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
22-
#include "arrow/result.h"
22+
#include "arrow/status.h"
2323

2424
namespace arrow::flight::sql::odbc {
2525

0 commit comments

Comments
 (0)