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

Add prepared statements support for Mysql2Adapter #22415

Merged
merged 1 commit into from Nov 26, 2015

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Nov 26, 2015

Reopen #22352 because mysql2 0.4.2 is released.

@rails-bot
Copy link

r? @matthewd

(@rails-bot has picked a reviewer for you, use r? to override)

sgrif added a commit that referenced this pull request Nov 26, 2015
…adapter

Add prepared statements support for `Mysql2Adapter`
@sgrif sgrif merged commit e3bac3f into rails:master Nov 26, 2015
@sgrif
Copy link
Contributor

sgrif commented Nov 26, 2015

@kamipo Looks like this causes an intermittent test failure (possibly order dependent, unsure). I'm going to revert for now, can you look into it? It looks like it might even be a bug in the mysql2 gem. https://travis-ci.org/rails/rails/jobs/93407920

@kamipo
Copy link
Member Author

kamipo commented Nov 26, 2015

It seems that this is caused by brianmario/mysql2#694. I'll investigating the cause, thanks!

affected_rows = stmt.affected_rows
result = stmt.result_metadata
ret = yield stmt, result
result.free if result

stmt.free_result
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this freeing the result twice? Edit: no, for prepared statements, result is the result metadata

Copy link
Member Author

Choose a reason for hiding this comment

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

No.

result.free calls mysql_free_result.
https://github.com/luislavena/mysql-gem/blob/master/ext/mysql_api/mysql.c#L1112-L1121

static VALUE res_free(VALUE obj)
{
    struct mysql_res* resp = DATA_PTR(obj);
    check_free(obj);
    mysql_free_result(resp->res);
    resp->freed = Qtrue;
    store_result_count--;
    return Qnil;
}

stmt.free_result calls mysql_stmt_free_result.
https://github.com/luislavena/mysql-gem/blob/master/ext/mysql_api/mysql.c#L1610-L1618

static VALUE stmt_free_result(VALUE obj)
{
    struct mysql_stmt* s = DATA_PTR(obj);
    check_stmt_closed(obj);
    if (mysql_stmt_free_result(s->stmt))
    mysql_stmt_raise(s->stmt);
    return obj;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I didn't see your reply before I edited my own comment :) I'd forgotten that the result set and the result metadata are separate items.

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.

None yet

5 participants