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

Just a little cleanup in the C internals #472

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions ext/sqlite3/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,39 +145,40 @@ step(VALUE self)
case SQLITE_ROW: {
int i;
for (i = 0; i < length; i++) {
VALUE val;

switch (sqlite3_column_type(stmt, i)) {
case SQLITE_INTEGER:
rb_ary_push(list, LL2NUM(sqlite3_column_int64(stmt, i)));
val = LL2NUM(sqlite3_column_int64(stmt, i));
break;
case SQLITE_FLOAT:
rb_ary_push(list, rb_float_new(sqlite3_column_double(stmt, i)));
val = rb_float_new(sqlite3_column_double(stmt, i));
break;
case SQLITE_TEXT: {
VALUE str = rb_str_new(
val = rb_utf8_str_new(
(const char *)sqlite3_column_text(stmt, i),
(long)sqlite3_column_bytes(stmt, i)
);
rb_enc_associate_index(str, rb_utf8_encindex());
if (internal_encoding) {
str = rb_str_export_to_enc(str, internal_encoding);
val = rb_str_export_to_enc(val, internal_encoding);
}
rb_ary_push(list, str);
}
break;
case SQLITE_BLOB: {
VALUE str = rb_str_new(
val = rb_str_new(
(const char *)sqlite3_column_blob(stmt, i),
(long)sqlite3_column_bytes(stmt, i)
);
rb_ary_push(list, str);
}
break;
case SQLITE_NULL:
rb_ary_push(list, Qnil);
val = Qnil;
break;
default:
rb_raise(rb_eRuntimeError, "bad type");
}

rb_ary_store(list, (long)i, val);
}
}
break;
Expand Down