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

refactor(c/driver/postgresql): Remove utils duplication #628

Merged
merged 10 commits into from
May 2, 2023

Conversation

WillAyd
Copy link
Contributor

@WillAyd WillAyd commented Apr 28, 2023

  • Use the new SetError with variadic arguments
  • Replaced StringBuilder with some std::string concatenation where applicable
  • Replaced any CHECK_ macro with the variant from either nanoarrow or existing util
  • Renamed util.h -> postgres_util.h to disambiguate; right now this seems just scoped to utils for network byte swapping


namespace adbcpq {
AdbcStatusCode PostgresConnection::Commit(struct AdbcError* error) {
if (autocommit_) {
SetError(error, "Cannot commit when autocommit is enabled");
SetError(error, "%s", "[libpq] Cannot commit when autocommit is enabled");
Copy link
Contributor Author

@WillAyd WillAyd Apr 28, 2023

Choose a reason for hiding this comment

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

Instead of hard-coding libpq or SQLite another option would be to wrap this in a macro, use __FILE__ and traverse up to the parent directory to get either postgresql or sqlite, etc...

@@ -42,7 +42,8 @@ AdbcStatusCode PostgresDatabase::Init(struct AdbcError* error) {

AdbcStatusCode PostgresDatabase::Release(struct AdbcError* error) {
if (open_connections_ != 0) {
SetError(error, "Database released with ", open_connections_, " open connections");
SetError(error, "%s%d%s", "[libpq] Database released with ", open_connections_,
Copy link
Member

Choose a reason for hiding this comment

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

Is open_connections_ an int? I forget the details, but I think -Wpedantic on gcc will fire if it is not and 32-bit windows may segfault. I usually do static_cast<int>() for %d or static_cast<long>() for %ld to make sure since most of our C++ uses int32_t and int64_t.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch this is a mistake

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its an int32 so replaced with the appropriate inttypes macro

Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

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

Thanks.

Having to manually put the driver name everywhere is a bit unfortunate but oh well.

@lidavidm
Copy link
Member

Kicked the R jobs since they failed

@lidavidm
Copy link
Member

lidavidm commented May 1, 2023

I think the R build does need updating from the error

@paleolimbot
Copy link
Member

Yes, the postgres driver's bootstrap.R will need to be updated to (1) copy the additional utils.h file and (2) apply the rename of util.h to postgres_util.h (I think!).

@@ -206,15 +211,17 @@ struct BindStream {
param_lengths[i] = 0;
break;
default:
SetError(error, "Field #", i + 1, " ('", bind_schema->children[i]->name,
SetError(error, "%s%" PRIu64 "%s%s%s%s", "[libpq] Field #",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The R builds using mingw32 didn't like the %z specifier statement.cc:214:31: warning: unknown conversion type character 'z' in format [-Wformat=]

@WillAyd
Copy link
Contributor Author

WillAyd commented May 1, 2023

Out of my element with the R stuff but think I got it. Windows build still failing - assuming unrelated to this PR

Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

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

Thank you!

@lidavidm lidavidm added this to the ADBC Libraries 0.4.0 milestone May 2, 2023
@lidavidm lidavidm merged commit 9b68784 into apache:main May 2, 2023
@WillAyd WillAyd deleted the consolidate-utils branch June 28, 2024 14:56
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.

3 participants