Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ODBC] Rework Connect to the ODBC driver and add functionality to set all DuckDB configurations in the Connection String #10692

Merged
merged 69 commits into from
Feb 23, 2024

Conversation

maiadegraaf
Copy link
Contributor

@maiadegraaf maiadegraaf commented Feb 15, 2024

Previously, when connecting to the ODBC driver using either SQLDriverConnect or with a populated ODBC.ini, only the DSN and database fields would be read, with the rest being ignored. There were also no tests for reading from the ODBC.ini file

As of this PR, this has been reworked. The entire connection string is now parsed and errors are correctly returned in the case of an unrecognized attribute or any other issues that are encountered.

Now all DuckDB configurations can be set.

Special mention:

Finally, I've added extensive testing for both reading from the connection string as well as reading from the ODBC.ini file.

Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Looks good. Some comments from my side

@github-actions github-actions bot marked this pull request as draft February 16, 2024 13:50
@maiadegraaf maiadegraaf changed the title [ODBC] Rework Connect to the ODBC driver [ODBC] Rework Connect to the ODBC driver and add functionality to set all DuckDB configurations in the Connection String Feb 16, 2024
Copy link
Contributor

@taniabogatsch taniabogatsch left a comment

Choose a reason for hiding this comment

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

Looks great! I added a few nits.

tools/odbc/test/tests/cte.cpp Outdated Show resolved Hide resolved
tools/odbc/test/tests/declare_fetch_block.cpp Outdated Show resolved Hide resolved
tools/odbc/include/connect.hpp Outdated Show resolved Hide resolved
tools/odbc/connect/connect.cpp Outdated Show resolved Hide resolved
tools/odbc/connect/connect.cpp Outdated Show resolved Hide resolved
tools/odbc/connect/connect.cpp Outdated Show resolved Hide resolved
tools/odbc/connect/connect.cpp Show resolved Hide resolved
tools/odbc/connect/connect.cpp Outdated Show resolved Hide resolved
tools/odbc/odbc_utils.cpp Outdated Show resolved Hide resolved
@maiadegraaf maiadegraaf marked this pull request as ready for review February 16, 2024 15:09
@github-actions github-actions bot marked this pull request as draft February 19, 2024 11:31
@maiadegraaf maiadegraaf marked this pull request as ready for review February 22, 2024 12:13
@maiadegraaf maiadegraaf marked this pull request as draft February 22, 2024 12:14
@maiadegraaf maiadegraaf marked this pull request as ready for review February 22, 2024 17:39
Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes! LGTM - some minor nits but nothing blocking, feel free to pick up if you want at some point in the future

SQLINTEGER *id = new SQLINTEGER[TABLE_SIZE[size[i]]];
SQLLEN *id_ind = new SQLLEN[TABLE_SIZE[size[i]]];
auto *id = new SQLINTEGER[TABLE_SIZE[i]];
auto *id_ind = new SQLLEN[TABLE_SIZE[i]];
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: using unique_ptr here would clean up the code a bit and prevent memory from leaking in case of a failure

#include <utility>

#if WIN32
#include <windows.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: we have duckdb/common/windows.hpp that can be used for this

return SQL_SUCCESS;
}

while ((row_pos = input_str.find(ROW_DEL)) != std::string::npos) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think this code could be simplified somewhat by using StringUtil::Split

SQLRETURN Connect::FindKeyValPair(const std::string &row) {
string key;

size_t val_pos = row.find(KEY_VAL_DEL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here - StringUtil::Split could simplify the code here

@Mytherin Mytherin merged commit 3e97e99 into duckdb:main Feb 23, 2024
22 of 23 checks passed
@maiadegraaf maiadegraaf deleted the ODBC_Connect branch February 23, 2024 09:07
github-actions bot pushed a commit to duckdb/duckdb-r that referenced this pull request Mar 15, 2024
Merge pull request duckdb/duckdb#10796 from yiyuanliu/lyy/arrow-map
Merge pull request duckdb/duckdb#10692 from maiadegraaf/ODBC_Connect
Merge pull request duckdb/duckdb#10814 from szarnyasg/update-readme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Documentation Use for issues or PRs that require changes in the documentation Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants