Skip to content

Conversation

@alinaliBQ
Copy link
Contributor

@alinaliBQ alinaliBQ commented Oct 27, 2025

Rationale for this change

Add ODBC driver connection support for the driver, so the driver can connect to servers.

What changes are included in this PR?

Implementation of unicode APIs:

  • SQLDriverConnect
  • SQLDisconnect
  • SQLConnect
  • DSN Window
  • Test refactoring

Are these changes tested?

Tested locally on Windows.
Note that this PR depends on #47763 to get tests passing.

Are there any user-facing changes?

N/A

@github-actions
Copy link

⚠️ GitHub issue #46574 has been automatically assigned in GitHub to PR creator.

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Oct 27, 2025
@alinaliBQ alinaliBQ force-pushed the gh-46574-driver-connectivity branch 2 times, most recently from f28ed1f to 8ad5b6a Compare October 28, 2025 22:29
@alinaliBQ
Copy link
Contributor Author

@lidavidm @kou Changes in this PR are ready for review, please let me know if you have any comments. Thank you! This PR is in draft because it depends on #47763 to get 2 of its tests passing.

alinaliBQ referenced this pull request in Bit-Quill/arrow Oct 29, 2025
* use suggestion from James for one-liner change to return `Status::OK` directly

* fix for iterating endpoints, it is based on JDBC's fix for the same bug

* save value of `FlightClientOptions`

* Use `TestFlightServer`

Add `arrow_flight_sql_shared` to enable usages for `TestFlightServer`

* Fix build errors from missing `gmock`

* Add checks for array data

Update flight_sql_stream_chunk_buffer_test.cc

Add `FlightStreamChunkBufferTest` unit test

Draft test with `FlightSQLODBCMockEndpointTestBase`

* Reference apacheGH-47117 and Clean up code

* Add driver and DSN to built-in properties to not pass driver/dsn as attributes to server

* Allow `=` in values inside connection strings, fixes connectivity problems

* Address comments from Rob
alinaliBQ and others added 4 commits October 29, 2025 11:12
* SQLDriverConnect requires SQLGetInfo to be implemented for tests to pass, because driver manager requires SQLGetInfo

Co-Authored-By: alinalibq <[email protected]>
Co-authored-by: justing-bq <[email protected]>
@alinaliBQ alinaliBQ force-pushed the gh-46574-driver-connectivity branch from b5159a7 to fc95da6 Compare October 29, 2025 18:35
@alinaliBQ alinaliBQ marked this pull request as ready for review October 29, 2025 18:36
@alinaliBQ alinaliBQ requested a review from lidavidm as a code owner October 29, 2025 18:36
@alinaliBQ
Copy link
Contributor Author

alinaliBQ commented Oct 29, 2025

Rebased onto master to get changes from #47763

Edit: getting segfault error, looking into it.

@alinaliBQ alinaliBQ marked this pull request as draft October 29, 2025 20:42
Iirc, there is segfault error associated with `SQLGetStmtAttrW`

Attempt to fix segfault error by adding impl for `SQLSetConnectAttr`

Part-fix remove `using` that isn't needed
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
#include "arrow/result.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if you wanted arrow::Status, just include status.h

namespace arrow::flight::sql::odbc {

/// \brief Case insensitive comparator that takes string_view
struct CaseInsensitiveComparatorStrView {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this defined here? It seems to only be used inside the implementation


// PropertyMap is case-insensitive for keys.
typedef std::map<std::string_view, std::string, CaseInsensitiveComparator> PropertyMap;
typedef std::map<std::string, std::string, CaseInsensitiveComparator> PropertyMap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the right definitions, you should be able to avoid wrapping every lookup in std::string. Can we avoid that? (See the note about 'transparent' comparator in https://en.cppreference.com/w/cpp/container/map/find)

#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

namespace ODBC {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(maybe for a separate issue but) can we fix this namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea we can do it for a separate issue. Are we thinking of replacing ODBC with namespace arrow::flight::sql::odbc?

// Return the number of bytes required for the conversion.
template <typename CHAR_TYPE>
inline size_t ConvertToSqlWChar(const std::string& str, SQLWCHAR* buffer,
inline size_t ConvertToSqlWChar(const std::string_view& str, SQLWCHAR* buffer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string_view can (and should) be passed by value.

/// \return wchar_msg in std::string format
inline std::string SqlWcharToString(SQLWCHAR* wchar_msg, SQLINTEGER msg_len = SQL_NTS) {
if (msg_len == 0 || !wchar_msg || wchar_msg[0] == 0) {
if (!wchar_msg || wchar_msg[0] == 0 || msg_len == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you check length before dereferencing the pointer?

static std::string GetPropertiesFromConnString(
/// @return the DSN or an empty string if the DSN is not found or is found after the
/// driver
static std::string GetDsnIfExists(const std::string& conn_str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would std::optional<std::string> be better?

Comment on lines +78 to +79
/// @return the DSN or an empty string if the DSN is not found or is found after the
/// driver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use \return not @return.

#if defined _WIN32
// For displaying DSN Window
# include "arrow/flight/sql/odbc/odbc_impl/system_dsn.h"
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif // defined(_WIN32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants