Skip to content

add DuckDB::PreparedStatement#bind_uint32(refs #704).#933

Merged
suketa merged 2 commits intomainfrom
bind_uint32
Apr 5, 2025
Merged

add DuckDB::PreparedStatement#bind_uint32(refs #704).#933
suketa merged 2 commits intomainfrom
bind_uint32

Conversation

@suketa
Copy link
Owner

@suketa suketa commented Apr 5, 2025

refs #704

Summary by CodeRabbit

  • New Features

    • Expanded prepared statement functionality to support binding 32-bit unsigned integer values with built-in range validation.
  • Tests

    • Added tests to verify proper binding behavior and ensure that invalid values, such as negatives, trigger appropriate errors.

@coderabbitai
Copy link

coderabbitai bot commented Apr 5, 2025

Walkthrough

This change extends the DuckDB prepared statement functionality by adding support for binding 32‐bit unsigned integers. It introduces a new public method bind_uint32 in the Ruby layer and its corresponding private C implementation _bind_uint32. The documentation (CHANGELOG.md) was updated accordingly, and new tests were added to verify both successful binding and error handling when an invalid (negative) value is provided.

Changes

Files Change Summary
CHANGELOG.md Updated to include the new DuckDB::PreparedStatement#bind_uint32 method.
ext/duckdb/prepared_statement.c
lib/duckdb/prepared_statement.rb
Added new binding methods: in C, _bind_uint16 and _bind_uint32 with proper error handling and registration, and in Ruby, a new public bind_uint32 method with range checks to support binding 32-bit unsigned integer values.
test/duckdb_test/prepared_statement_test.rb Introduced two new tests: one verifying that binding and retrieving a maximum-value uint32 works correctly, and another ensuring that binding a negative value raises a DuckDB::Error.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant PS as PreparedStatement (Ruby)
    participant CBind as _bind_uint32 (C)

    C->>PS: bind_uint32(index, val)
    PS->>PS: Validate val is within 0 to 4,294,967,295
    PS->>CBind: Call _bind_uint32(index, val)
    CBind-->>PS: Return binding result or error
    PS-->>C: Return final result
Loading

Possibly related PRs

Poem

I'm a little rabbit in the code parade,
Hopping through bits where numbers are laid,
Now uint32 joins with a cheerful bound,
Alongside its kin, new methods are found,
Carrots of code crunch on each joyful cascade!
🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aec4ff4 and d6c90a5.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • ext/duckdb/prepared_statement.c (3 hunks)
  • lib/duckdb/prepared_statement.rb (1 hunks)
  • test/duckdb_test/prepared_statement_test.rb (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: test (head, 1.1.3)
  • GitHub Check: test (3.4.2, 1.2.1)
  • GitHub Check: test (3.4.1, 1.1.1)
  • GitHub Check: test (3.3.6, 1.1.3)
  • GitHub Check: test (3.4.1, 1.1.3)
  • GitHub Check: test (3.3.6, 1.1.1)
  • GitHub Check: test (3.2.6, 1.1.1)
  • GitHub Check: test (ucrt, 1.1.3)
  • GitHub Check: test (ucrt, 1.2.1)
  • GitHub Check: test (mswin, 1.1.1)
  • GitHub Check: test (mingw, 1.1.1)
  • GitHub Check: test (3.3.6, 1.2.1)
  • GitHub Check: test (head, 1.1.3)
  • GitHub Check: test (3.4.1, 1.2.1)
  • GitHub Check: test (3.2.6, 1.1.3)
  • GitHub Check: test (3.1.6, 1.2.1)
  • GitHub Check: test (3.2.6, 1.2.1)
  • GitHub Check: test (3.1.6, 1.1.3)
  • GitHub Check: test (3.1.6, 1.1.1)
🔇 Additional comments (7)
CHANGELOG.md (1)

5-6: LGTM: Correctly documented new method in the changelog.

The addition of DuckDB::PreparedStatement#bind_uint32 to the changelog follows the established pattern and properly documents the new functionality alongside the existing bind_uint8 and bind_uint16 methods.

test/duckdb_test/prepared_statement_test.rb (2)

310-321: LGTM: Test case effectively verifies uint32 binding functionality.

The test correctly verifies binding the maximum uint32 value (2^32 - 1) to a UINTEGER column and confirms the data is properly retrieved. The test structure follows the established pattern seen in other data type binding tests.


323-328: LGTM: Proper validation of error handling for negative values.

This test correctly verifies that attempting to bind a negative value to a UINTEGER column raises the expected DuckDB::Error, ensuring that input validation works as intended.

lib/duckdb/prepared_statement.rb (1)

128-136: LGTM: Well-implemented method with proper range validation.

The bind_uint32 method follows the established pattern of the existing bind_uint8 and bind_uint16 methods. It correctly validates that the input value is within the expected range (0 to 4,294,967,295) before calling the private _bind_uint32 method, and raises an appropriate error message for out-of-range values.

ext/duckdb/prepared_statement.c (3)

31-32: LGTM: Proper function prototype declarations.

The function prototype declarations are correctly added in alphabetical order alongside the existing declarations.


394-406: LGTM: Correctly implemented binding function for uint32.

The implementation follows the established pattern of other binding functions, correctly:

  1. Retrieving the rubyDuckDBPreparedStatement struct
  2. Converting the Ruby Integer to a C uint32_t
  3. Calling the DuckDB C API duckdb_bind_uint32 function
  4. Raising a proper error if the binding fails

The error handling and parameter checking are consistent with the other binding methods.


562-562: LGTM: Method properly registered with Ruby.

The private method _bind_uint32 is correctly registered with the Ruby class, making it available for the public bind_uint32 method to call.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@suketa suketa merged commit 4702612 into main Apr 5, 2025
58 checks passed
@suketa suketa deleted the bind_uint32 branch April 5, 2025 01:04
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.

1 participant