Skip to content

Conversation

@flavorjones
Copy link
Member

Fix a regression in v2.0.0 that caused Database#execute_batch to raise an encoding exception when passed some non-ASCII strings. As a result of this fix, Database#prepare now ensures the "remainder" string will always be encoded as UTF-8.

Closes #524

timespecclear(&db_ctx->stmt_deadline);

return rb_str_new2(tail);
return rb_utf8_str_new_cstr(tail);
Copy link

Choose a reason for hiding this comment

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

Would it be better to reuse the encoding of the original string?

Copy link
Member Author

Choose a reason for hiding this comment

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

Regardless of the original encoding, the query ends up encoded as UTF-8 in Statement#initialize and the remainder string being returned from sqlite_prepare is also UTF-8.

This call isn't re-encoding anything, it's just telling Ruby that the C string is in fact UTF-8 (the default is otherwise ASCII-8BIT which is what led to the problem you reported).

Copy link

Choose a reason for hiding this comment

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

Ah, I see. Alright, thanks for fixing this!

Fix a regression in v2.0.0 that caused `Database#execute_batch` to
raise an encoding exception when passed some non-ASCII strings. As a
result of this fix, `Database#prepare` now ensures the "remainder"
string will always be encoded as UTF-8.

Closes #524
@flavorjones flavorjones force-pushed the 524-utf8-execute-batch branch from 3c67c7b to f4c326e Compare April 20, 2024 02:11
@flavorjones flavorjones enabled auto-merge April 20, 2024 02:18
@flavorjones flavorjones merged commit 3ba4a15 into main Apr 20, 2024
@flavorjones flavorjones deleted the 524-utf8-execute-batch branch April 20, 2024 02:43
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.

SQLite3::Database#execute_batch fails with non-ASCII characters

2 participants