Skip to content

add DuckDB::PreparedStatement#bind_uint64#934

Merged
suketa merged 1 commit intomainfrom
bind_uint64
Apr 5, 2025
Merged

add DuckDB::PreparedStatement#bind_uint64#934
suketa merged 1 commit intomainfrom
bind_uint64

Conversation

@suketa
Copy link
Owner

@suketa suketa commented Apr 5, 2025

refs #705

Summary by CodeRabbit

  • New Features

    • Expanded prepared statement functionality to support binding 64-bit unsigned integer values, allowing for a broader range of numeric data in user queries.
  • Tests

    • Enhanced test coverage to ensure successful binding of maximum 64-bit values and proper error handling when invalid (e.g., negative) inputs are provided.

@coderabbitai
Copy link

coderabbitai bot commented Apr 5, 2025

Walkthrough

The pull request introduces the bind_uint64 method to the DuckDB prepared statement functionality. Documentation in the changelog is updated to include this new method, and corresponding changes are implemented in both Ruby and C layers, with proper error handling for out-of-range values. Additional tests verify successful binding of the maximum unsigned 64-bit integer value and proper error conditions when negative values are provided.

Changes

File(s) Change Summary
CHANGELOG.md, ext/…/prepared_statement.c, lib/duckdb/prepared_statement.rb Added the bind_uint64 method to the DuckDB::PreparedStatement class. The changes include updating documentation, implementing the C binding function _bind_uint64, and exposing the public bind_uint64 API in Ruby.
test/duckdb_test/prepared_statement_test.rb Added tests to validate binding of the maximum 64-bit unsigned integer and to check proper error handling for negative values.

Sequence Diagram(s)

sequenceDiagram
    participant R as Ruby PreparedStatement API
    participant C as C Binding Layer
    participant DB as DuckDB Engine

    R->>R: Validate uint64 value range
    R->>C: Call _bind_uint64(index, value)
    C->>C: Convert Ruby value to uint64\nand check index validity
    C->>DB: Call duckdb_bind_uint64(...)
    DB-->>C: Return binding result
    alt Binding Fails
        C->>R: Raise DuckDBError
    else Binding Succeeds
        C->>R: Return success
    end
Loading

Possibly related PRs

Poem

I'm a rabbit with hops so light,
Coding new methods deep into the night.
With bind_uint64, the numbers now soar,
In DuckDB's garden, they bind like never before.
My floppy ears dance with each new line,
Celebrating changes so clever and divine!
🐰✨


📜 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 4702612 and 249ec46.

📒 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 (20)
  • GitHub Check: test (3.3.7, 1.1.1)
  • GitHub Check: test (head, 1.1.3)
  • GitHub Check: test (head, 1.2.1)
  • GitHub Check: test (3.2.7, 1.1.1)
  • GitHub Check: test (3.4.2, 1.2.1)
  • GitHub Check: test (head, 1.1.1)
  • GitHub Check: test (mingw, 1.1.3)
  • GitHub Check: test (3.4.2, 1.1.3)
  • GitHub Check: test (head, 1.1.3)
  • GitHub Check: test (3.2.7, 1.2.1)
  • GitHub Check: test (mingw, 1.2.1)
  • GitHub Check: test (ucrt, 1.1.3)
  • GitHub Check: test (3.3.6, 1.1.3)
  • GitHub Check: test (3.3.6, 1.1.1)
  • GitHub Check: test (3.4.1, 1.2.1)
  • GitHub Check: test (3.4.1, 1.1.1)
  • GitHub Check: test (3.4.2, 1.2.1)
  • GitHub Check: test (3.4.2, 1.1.1)
  • GitHub Check: test (3.3.7, 1.1.3)
  • GitHub Check: test (3.1.6, 1.1.3)
🔇 Additional comments (7)
CHANGELOG.md (1)

6-6: LGTM! The changelog has been properly updated.

The bind_uint64 method has been correctly added to the list of uint binding methods, following the pattern of the existing methods.

ext/duckdb/prepared_statement.c (3)

33-33: LGTM! Function declaration follows naming convention.

The function declaration for duckdb_prepared_statement__bind_uint64 follows the existing pattern for binding methods.


409-421: LGTM! Implementation follows the established pattern.

The implementation for binding uint64 values correctly:

  • Gets the prepared statement context
  • Validates the parameter index
  • Converts the Ruby value to a uint64 using the appropriate NUM2ULL macro
  • Calls the DuckDB C API to bind the value
  • Returns self or raises an error if binding fails

This is consistent with the other binding methods in the file.


578-578: LGTM! Method registration is correct.

The function is properly registered as a private method _bind_uint64 with the correct parameter count.

lib/duckdb/prepared_statement.rb (1)

138-146: LGTM! Ruby implementation is well-designed.

The bind_uint64 method:

  • Has clear documentation explaining its purpose and parameter expectations
  • Properly validates that the input value is within the range of an unsigned 64-bit integer
  • Returns the result of the internal _bind_uint64 method for valid values
  • Raises a clear error message for invalid values

This implementation follows the pattern of the existing binding methods for other unsigned integer types.

test/duckdb_test/prepared_statement_test.rb (2)

345-356: LGTM! Test for successful binding is comprehensive.

The test correctly:

  • Creates a table with a UBIGINT column
  • Binds the maximum value of UINT64 ((2**64) - 1) to the prepared statement
  • Verifies that the inserted value matches the original value

This thoroughly tests the happy path for the new functionality.


358-363: LGTM! Test for error handling is appropriate.

The test validates that attempting to bind a negative value to a UBIGINT column raises the expected DuckDB::Error, ensuring that error handling is working properly.

✨ 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 e145c40 into main Apr 5, 2025
58 checks passed
@suketa suketa deleted the bind_uint64 branch April 5, 2025 03:00
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