Skip to content

Conversation

@alinaliBQ
Copy link

Implements SQLDriverConnect

@alinaliBQ alinaliBQ force-pushed the sql-driver-connect branch 10 times, most recently from cfe56a4 to 730a621 Compare May 14, 2025 19:24
Comment on lines 209 to 271
Copy link
Author

Choose a reason for hiding this comment

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

SQLDriverConnect implementation

Copy link
Author

Choose a reason for hiding this comment

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

SQLDisconnect implementation

Copy link

Choose a reason for hiding this comment

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

Can you check if disconnect() does proper clean-up of the connection? It should closes and drop statements on the connection and end any transactions.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, disconnect() doesn't close statements directly, but the destructor of all ODBCStatement objects from to the connection will be called after the m_statements.clear(); line. m_statements should contain all statements/transactions.

The implementation:

void ODBCConnection::disconnect() {
  if (m_isConnected) {
    // Ensure that all statements (and corresponding SPI statements) get cleaned
    // up before terminating the SPI connection in case they need to be de-allocated in
    // the reverse of the allocation order.
    m_statements.clear();
    m_spiConnection->Close();
    m_isConnected = false;
  }
}

Copy link

Choose a reason for hiding this comment

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

This should prompt the dialog based on the driverCompletion variable. Maybe leave integrating the actual dialog to a separate PR but setup the infrastructure and leave TODOs here.

Copy link
Author

Choose a reason for hiding this comment

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

Good call, added TODOs

@alinaliBQ alinaliBQ force-pushed the sql-driver-connect branch 6 times, most recently from ccea21f to a2c2cb5 Compare May 21, 2025 23:05
Comment on lines 119 to 123
Copy link
Author

Choose a reason for hiding this comment

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

Fixed an issue where ExecuteWithDiagnostics attempts to get diagnostics from conn after conn is freed, and results in a seg fault error.

@alinaliBQ alinaliBQ force-pushed the sql-driver-connect branch from a2c2cb5 to 5dbdcbe Compare May 22, 2025 01:00
@alinaliBQ alinaliBQ force-pushed the sql-driver-connect branch 3 times, most recently from 00d2e3a to 4fd1fe8 Compare May 22, 2025 17:52
Copy link

Choose a reason for hiding this comment

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

Catch as const DriverException& if possible

Copy link
Author

Choose a reason for hiding this comment

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

added const, since this is the only usage of DriverException in the file, I will leave the prefix driver::odbcabstraction as is

Copy link

Choose a reason for hiding this comment

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

Micro-optimization. Add a move-version of config.Set() (eg Set(const std::string& key, std::string&& value)) and call it Emplace(). Then use config.Emplace(key, std::move(value)) to avoid copying.

Copy link
Author

Choose a reason for hiding this comment

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

Added Emplace and switched to use it

Copy link

Choose a reason for hiding this comment

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

Can you check if disconnect() does proper clean-up of the connection? It should closes and drop statements on the connection and end any transactions.

Copy link

Choose a reason for hiding this comment

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

This might need to be conditional based on driver manager. Also, this can be a string_view (and GetStringAttribute should probably be reworked to take in string_views?)

Copy link
Author

Choose a reason for hiding this comment

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

I can use string_view here but will just keep using 3.80 as it works

Copy link
Author

Choose a reason for hiding this comment

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

Updated code to make GetStringAttribute take string_views

@alinaliBQ alinaliBQ force-pushed the sql-driver-connect branch from eb16ca1 to 9672af8 Compare May 22, 2025 21:14
@alinaliBQ alinaliBQ marked this pull request as ready for review May 22, 2025 21:15
Copy link
Author

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

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

@jduo I have addressed all comments

Copy link
Author

Choose a reason for hiding this comment

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

added const, since this is the only usage of DriverException in the file, I will leave the prefix driver::odbcabstraction as is

Copy link
Author

Choose a reason for hiding this comment

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

Added Emplace and switched to use it

Copy link
Author

Choose a reason for hiding this comment

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

Yes, disconnect() doesn't close statements directly, but the destructor of all ODBCStatement objects from to the connection will be called after the m_statements.clear(); line. m_statements should contain all statements/transactions.

The implementation:

void ODBCConnection::disconnect() {
  if (m_isConnected) {
    // Ensure that all statements (and corresponding SPI statements) get cleaned
    // up before terminating the SPI connection in case they need to be de-allocated in
    // the reverse of the allocation order.
    m_statements.clear();
    m_spiConnection->Close();
    m_isConnected = false;
  }
}

Copy link
Author

Choose a reason for hiding this comment

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

Updated code to make GetStringAttribute take string_views

Copy link

Choose a reason for hiding this comment

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

Shouldn't this be properties[copy]?

Copy link
Author

Choose a reason for hiding this comment

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

copy holds a copy of the value, we still need to construct a std::string copy for key

Copy link

Choose a reason for hiding this comment

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

Use properties.emplace(std::move(copy), value))

Copy link
Author

Choose a reason for hiding this comment

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

I misunderstood usage of emplace before, I have fixed this now. In SQLConnect, uid and pwd specified in DSN will take precedence

@alinaliBQ alinaliBQ force-pushed the sql-driver-connect branch 2 times, most recently from a7d8803 to ef337f6 Compare May 22, 2025 22:01
Copy link

Choose a reason for hiding this comment

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

Shouldn't we be using the execute with diagnostics wrapper here?

Copy link
Author

Choose a reason for hiding this comment

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

There was a bug that I ran into and had to remove the wrapper. The issue is that ExecuteWithDiagnostics calls GetDiagnostics().HasError() at the end of lambda function execution, and it will assume that conn is still a valid pointer. But GetDiagnostics() will fail because conn has been destructed. I didn't find any exceptions to be thrown inside releaseConnection call so it should be ok

Copy link

Choose a reason for hiding this comment

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

Minor nit picking, but might be clearer to be passing in connection pointer instead of conn, even thought is pointing to same data.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, I have moved the connection pointer creation code to be inside the ExecuteWithDiagnostics call so conn can still be passed

@alinaliBQ alinaliBQ requested a review from jduo May 23, 2025 19:12
Implement stubs for SQLGetInfo, SQLGetDiagField and SQLGetDiagRec

Separate RegisterDsn and UnregisterDsn from windows build

Update code to save driver value from connection string

Add ReadMes for ODBC and tests

Fix test issues with string_view

Address code reviews

Update entry_points.cc to fix build issue

Remove Dremio references

Use emplace properly

Address comment from Rob and add SQLDisconnect test case
@alinaliBQ alinaliBQ force-pushed the sql-driver-connect branch from c98f368 to ce4a14e Compare May 23, 2025 22:29
@alinaliBQ alinaliBQ merged commit 573581b into apache-odbc May 23, 2025
@alinaliBQ
Copy link
Author

All comments have been addressed.
If there are new additional comments, I will address them in a separate PR

@alinaliBQ alinaliBQ deleted the sql-driver-connect branch June 17, 2025 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants