database/sql: NextResultSet API always return false

473 views
Skip to first unread message

sagar puneria

unread,
Jan 31, 2019, 1:23:43 AM1/31/19
to golang-nuts

I just want to know in which case NextResultSet return true?


I tried all the cases it is always returning false. If so then what is use case of implementing NextResultSet?
Could you please give me at least one case where NextResultSet return true.


Before giving your answer, i would suggest you to do sample program on NextResultSet where it can return true case.

I hope you got my Question.

Lutz Horn

unread,
Jan 31, 2019, 3:07:01 AM1/31/19
to golan...@googlegroups.com
Hi,

> I just want to know in which case NextResultSet
> <https://golang.org/pkg/database/sql/#Rows.NextResultSet> return true?

This method works as expected using github.com/lib/pq for PostgreSQL.
Take a lookt at this:

https://gist.github.com/lutzhorn/1aa7de538d1edd0b3904799b5bb972fd

The output is:

{'\x01' "cmelling0"}
{'\x02' "mbarkess1"}
{'\x03' "ssquibb2"}
{'\x04' "akirk3"}
{'\x05' "kelcomb4"}
{'\x06' "lcoldbathe5"}
{'\a' "ibutcher6"}
{'\b' "wdarnbrook7"}
{'\t' "bcoraini8"}
{'\n' "wplews9"}


Lutz

Message has been deleted

sagar puneria

unread,
Jan 31, 2019, 3:54:02 AM1/31/19
to golang-nuts
Then why this method is not works as expected using github.com/go-sql-driver/mysql for MySQL. 
Take a look at this: https://play.golang.org/p/tCLKxiXPZ5e

Lutz Horn

unread,
Jan 31, 2019, 4:17:42 AM1/31/19
to golan...@googlegroups.com
> Then why this method is not works as expected using
> github.com/go-sql-driver/mysql for MySQL.

It would have helped me if you'd have mentioned MySQL in your question.
Your question was incomplete. Please take alook at

http://www.catb.org/esr/faqs/smart-questions.html

> Take a look at this: https://play.golang.org/p/tCLKxiXPZ5e

I can reproduce this problem for MySQL. Sadly I don't find any issue
about NextResultSet always returning false:

https://github.com/go-sql-driver/mysql/search?q=NextResultSet&type=Issues

Lutz

Naoki INADA

unread,
Feb 1, 2019, 4:31:35 AM2/1/19
to golang-nuts
Hello, I'm one of maintainer of go-sql-driver/mysql.

When there is only one result set, you don't need NextResultSet().
See this example.


Then, when you have multi result set, you need to call NextResultSet() once to get 2nd result set.
See this example.


After reading Lutz's sample code.  I found lib/pq has different semantics.
I'm not sure which is the right semantics, intended by database/sql APIs.

Regards,

Inada Naoki

unread,
Feb 1, 2019, 4:39:08 AM2/1/19
to golang-nuts
After reading Lutz's sample code.  I found lib/pq has different semantics.
I'm not sure which is the right semantics, intended by database/sql APIs.



        // NextResultSet advances the driver to the next result set even
        // if there are remaining rows in the current result set. 

After calling db.Query(), the first result set is the "current" result set.
So I believe `NextResultSet()` should return false when there is only one result set.

Lutz Horn

unread,
Feb 1, 2019, 4:43:26 AM2/1/19
to golan...@googlegroups.com
> After reading Lutz's sample code. I found lib/pq has different semantics.
> I'm not sure which is the right semantics, intended by database/sql APIs.

That's interesting!

Does the code of NextResultSet from sql.go shed any light on this?

https://golang.org/src/database/sql/sql.go?s=76505:76541#L2684

Lutz


INADA Naoki

unread,
Feb 1, 2019, 5:01:54 AM2/1/19
to Lutz Horn, golan...@googlegroups.com
>
> That's interesting!
>
> Does the code of NextResultSet from sql.go shed any light on this?
>
> https://golang.org/src/database/sql/sql.go?s=76505:76541#L2684
>
> Lutz

No. I read it multiple times already.

I found test for NextResultSet() in lib/pq.

https://github.com/lib/pq/blob/0ac245bc3be505fde6900e1ca0f957c0845cbfa2/go18_test.go#L12

They don't intend calling `NextResultSet()` before reading first result set.
They read first result set before calling NextResultSet().

So your example may be unexpected behavior (or bug) of lib/pq.

Please file an issue report on lib/pq.
--
INADA Naoki <songof...@gmail.com>

Lutz Horn

unread,
Feb 1, 2019, 5:31:57 AM2/1/19
to golan...@googlegroups.com
> So your example may be unexpected behavior (or bug) of lib/pq.
>
> Please file an issue report on lib/pq.

Done: https://github.com/lib/pq/issues/828

Lutz



sagar puneria

unread,
Feb 2, 2019, 5:34:37 AM2/2/19
to golang-nuts
Thank you for investigating.
Reply all
Reply to author
Forward
0 new messages