-
Notifications
You must be signed in to change notification settings - Fork 548
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
Add element reference operator #[] to Mysql2::Result using mysql_data_seek #345
base: master
Are you sure you want to change the base?
Conversation
The fourth changeset builds on the #[] changeset, adding support for: result = @client.query "SELECT 1 AS col UNION SELECT 2 AS col"
p result[1, 0]
[]
p result[1, 1]
[{"col" => 2}]
p result[-2, 2]
[{"col" => 1}, {"col" => 2}]
p result[1, {:symbolize_keys => true}]
{:col => 2}
p result[1, 1, {:symbolize_keys => true}]
[{:col => 2}] Now that I'm returning an array, I should probably support cacheRows, which means the code in result#[] is going to look a lot like result#each. More refactoring! |
288c3d7
to
5f0f545
Compare
Two years later - rebased yo! |
@@ -440,14 +444,121 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) { | |||
return wrapper->fields; | |||
} | |||
|
|||
static void rb_mysql_row_query_options(VALUE opts, ID *db_timezone, ID *app_timezone, int *symbolizeKeys, int *asArray, int *castBool, int *cast, int *cacheRows) { | |||
ID dbTz, appTz; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underindented by one?
8262aa4
to
1eea3e2
Compare
… Mysql2::Result using mysql_data_seek.
…opts hash}] and [offset, count, {opts hash}].
} | ||
|
||
if (!NIL_P(opts)) { | ||
opts = rb_funcall(defaults, intern_merge, 1, opts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this preamble could be implemented in ruby and would be much easier to read - why not do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually moved this further down the chain so that the same code is used by the variants of [] and each.
c1dcead
to
b77f237
Compare
b77f237
to
6fce37c
Compare
For #130 mysql_data_seek is wrapped behind the element reference operator #[]. You can jump directly to a particular result row:
Open for comment!