Skip to content

Add Multi-Results support #537

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

Merged
merged 4 commits into from
Mar 23, 2017
Merged

Add Multi-Results support #537

merged 4 commits into from
Mar 23, 2017

Conversation

jszwec
Copy link
Contributor

@jszwec jszwec commented Jan 10, 2017

  • Implemented driver.RowsNextResultSet interface

Fixes #420

@methane
Copy link
Member

methane commented Jan 10, 2017

Does this patch support query like this?

db.Query("DO 42; SELECT 42")

How about removing emptyRows completely?

@jszwec
Copy link
Contributor Author

jszwec commented Jan 10, 2017

Does this patch support query like this?

I double checked, currently it works only with selects, I will fix it.

How about removing emptyRows completely?

Good point, thanks!

- support for binary protocol
- support statements returning no results
- remove emptyRows
}

if rows.NextResultSet() {
dbt.Error("unexpected next result set")
Copy link
Member

Choose a reason for hiding this comment

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

Why next result set is unexpected?
What happens for DO 1; DO 2; DO 3; SELECT 42?
I expect

if !rows.NextResultSet() { dbt.Error("expect 4 resultset, got 1") }
if !rows.NextResultSet() { dbt.Error("expect 4 resultset, got 2") }
if !rows.NextResultSet() { dbt.Error("expect 4 resultset, got 3") }
var v int64
if err := rows.Scan(&v); err != nil {
    dbt.Error(err)
}
if v != 42 {
   dbt.Error("expected 42; got ", v)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the example from the std:
https://tip.golang.org/pkg/database/sql/#example_DB_Query_multipleResultSets

which seems to ignore the empty results sets.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I got it.

Choose a reason for hiding this comment

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

So what would happen if I have SELECT 1 FROM DUAL WHERE 1 = 0; SELECT 1,2 FROM DUAL WHERE 1 = 1;? That is the first query returns no rows, but the second query does.

I would expect

if !rows.NextResultSet() { dbt.Error("expect 2 resultset, got 1") }

That is, I might not know which query has no resultset. So, I have to go through them all to map processing them correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joegrasse, sorry - "empty results sets" was inaccurate. Result set is present if column count > 0.
So, in the example that you provided it would work as you expected - it would return two result sets, first would be empty, the other one would have one row.

Copy link
Member

@methane methane left a comment

Choose a reason for hiding this comment

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

Query() and NextResultSet() has very similar code.
It seems it can be exported to method later.
But it's OK for first implementation.

LGTM, except recursion.
Go optimimze tail call only in very limited situation.
I prefer simple loop over tail call recursion.

if resLen == 0 {
rows.rs.done = true
return rows.NextResultSet()
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't like recursion.
Would you rewrite this to loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I just pushed a fix


if resLen == 0 {
rows.rs.done = true
return rows.NextResultSet()
Copy link
Member

Choose a reason for hiding this comment

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

same.

* rows.Close() would hang on readUntilEOF if some results were ignored before calling NextResultSet()
- get rid of a recursive call
@jrallison
Copy link

jrallison commented Feb 24, 2017

Any chance of getting this merged soon now that go1.8 has been released (which adds support for this)?

Thanks!

@julienschmidt julienschmidt added this to the v1.4 milestone Mar 17, 2017
@methane methane merged commit ffa70d4 into go-sql-driver:master Mar 23, 2017
@methane
Copy link
Member

methane commented Mar 23, 2017

This cause Travis test fail: https://travis-ci.org/methane/mysql/jobs/214213219
@jszwec any ideas?

@methane
Copy link
Member

methane commented Mar 23, 2017

I'm sorry, it was my mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants