MCPcopy Create free account
hub / github.com/apache/arrow / SQLDriverConnect

Function SQLDriverConnect

cpp/src/arrow/flight/sql/odbc/odbc_api.cc:831–916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

829}
830
831SQLRETURN SQLDriverConnect(SQLHDBC conn, SQLHWND window_handle,
832 SQLWCHAR* in_connection_string,
833 SQLSMALLINT in_connection_string_len,
834 SQLWCHAR* out_connection_string,
835 SQLSMALLINT out_connection_string_buffer_len,
836 SQLSMALLINT* out_connection_string_len,
837 SQLUSMALLINT driver_completion) {
838 ARROW_LOG(DEBUG) << "SQLDriverConnectW called with conn: " << conn
839 << ", window_handle: " << static_cast<const void*>(window_handle)
840 << ", in_connection_string: "
841 << static_cast<const void*>(in_connection_string)
842 << ", in_connection_string_len: " << in_connection_string_len
843 << ", out_connection_string: "
844 << static_cast<const void*>(out_connection_string)
845 << ", out_connection_string_buffer_len: "
846 << out_connection_string_buffer_len << ", out_connection_string_len: "
847 << static_cast<const void*>(out_connection_string_len)
848 << ", driver_completion: " << driver_completion;
849
850 // GH-46449 TODO: Implement FILEDSN and SAVEFILE keywords according to the spec
851
852 // GH-46560 TODO: Copy connection string properly in SQLDriverConnect according to the
853 // spec
854
855 using ODBC::ODBCConnection;
856
857 return ODBCConnection::ExecuteWithDiagnostics(conn, SQL_ERROR, [=]() {
858 ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(conn);
859 std::string connection_string =
860 ODBC::SqlWcharToString(in_connection_string, in_connection_string_len);
861 Connection::ConnPropertyMap properties;
862 std::string dsn_value = "";
863 std::optional<std::string> dsn = ODBCConnection::GetDsnIfExists(connection_string);
864 if (dsn.has_value()) {
865 dsn_value = dsn.value();
866 LoadPropertiesFromDSN(dsn_value, properties);
867 }
868 ODBCConnection::GetPropertiesFromConnString(connection_string, properties);
869
870 std::vector<std::string_view> missing_properties;
871
872 // GH-46448 TODO: Implement SQL_DRIVER_COMPLETE_REQUIRED in SQLDriverConnect according
873 // to the spec
874#if defined _WIN32
875 // Load the DSN window according to driver_completion
876 if (driver_completion == SQL_DRIVER_PROMPT) {
877 // Load DSN window before first attempt to connect
878 config::Configuration config;
879 if (!DisplayConnectionWindow(window_handle, config, properties)) {
880 return static_cast<SQLRETURN>(SQL_NO_DATA);
881 }
882 connection->Connect(dsn_value, properties, missing_properties);
883 } else if (driver_completion == SQL_DRIVER_COMPLETE ||
884 driver_completion == SQL_DRIVER_COMPLETE_REQUIRED) {
885 try {
886 connection->Connect(dsn_value, properties, missing_properties);
887 } catch (const DriverException&) {
888 // If first connection fails due to missing attributes, load

Callers 4

ConnectWithStringMethod · 0.50
TYPED_TESTFunction · 0.50
TYPED_TESTFunction · 0.50
TEST_FFunction · 0.50

Calls 8

SqlWcharToStringFunction · 0.85
LoadPropertiesFromDSNFunction · 0.85
DisplayConnectionWindowFunction · 0.85
GetStringAttributeFunction · 0.85
valueMethod · 0.45
ConnectMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by 4

ConnectWithStringMethod · 0.40
TYPED_TESTFunction · 0.40
TYPED_TESTFunction · 0.40
TEST_FFunction · 0.40