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

LastInsertId always returns 0 #251

Closed
eqinox76 opened this issue Dec 29, 2020 · 12 comments
Closed

LastInsertId always returns 0 #251

eqinox76 opened this issue Dec 29, 2020 · 12 comments

Comments

@eqinox76
Copy link

When running several insert commands like

result, err := db.Exec("INSERT INTO mytable SET number = 18;")
id, err := result.LastInsertId()

Against a simple table like

CREATE TABLE IF NOT EXISTS mytable (
id int unsigned NOT NULL AUTO_INCREMENT,
number int unsigned DEFAULT NULL,
PRIMARY KEY (id),
) DEFAULT CHARSET=utf8;

the returned id is always 0. While the go-mysql-driver returns the correct pkey.

Used libraries:
github.com/dolthub/go-mysql-server v0.6.1-0.20201228192939-415fc40f3a71
github.com/go-sql-driver/mysql v1.5.0

@zachmu
Copy link
Member

zachmu commented Jan 8, 2021

Thanks for the bug report.

LastInsertId is not currently populated into the query response, which is why it's always 0.

It shouldn't be that hard to fix. I'll take a look and get back to you.

@Drabuna
Copy link

Drabuna commented Mar 9, 2021

Any updates on this one?

@karagog
Copy link

karagog commented Mar 24, 2021

I'm also blocked by this issue. This is a pretty fundamental gap in functionality which prevents this from being a "drop-in replacement" for a real MySQL server. Can this be highly prioritized?

I also just noticed that ROW_COUNT() is not implemented, so we can't tell the number of rows affected by the last query either. Is this also related to not populating the query response?

@zachmu
Copy link
Member

zachmu commented Mar 24, 2021

Hi folks,

We have this in our docket now, should be part of a release coming pretty soon. Sorry for the lack of updates!

Zach

@zachmu
Copy link
Member

zachmu commented Apr 2, 2021

ROW_COUNT(), FOUND_ROWS(), and LAST_INSERT_ID() are all implemented in the latest release:

https://github.com/dolthub/go-mysql-server/releases/tag/v0.9.0

The lastInsertId field on the OK response packet is still not populated, but this value can now be fetched with select last_insert_id(). This will be fixed in an upcoming patch release, but please use the workaround if possible for now. I'll keep this open until it's fully implemented.

@eqinox76
Copy link
Author

eqinox76 commented Apr 2, 2021

Wuhu thank you very much for adding this feature!

@paralin
Copy link
Contributor

paralin commented Apr 24, 2021

I've tried to work around this a few ways, but it would be much easier of LastInsertId was filled

@timsehn
Copy link
Contributor

timsehn commented Apr 25, 2021

@paralin , we prioritize features as they impact our main project Dolt.

You have some options to get this prioritized:

  1. Make an open source contribution to this project.
  2. GitHub Sponsor the DoltHub organization to move it up our priority stack
  3. Wait until a paying customer has this feature request in Dolt
  4. Wait until we have slack to implement this in our small engineering team

We'll eventually get to everything as long as we can stay in business.

@paralin
Copy link
Contributor

paralin commented Apr 25, 2021

Hi @timsehn thanks for your great work. I'm already aware of your business model, my comment was less a "hurry up" and more a "yes this is relevant to me," and I'll most likely end up submitting a PR with the fix soon.

@timsehn
Copy link
Contributor

timsehn commented Apr 25, 2021 via email

@zachmu
Copy link
Member

zachmu commented Jun 2, 2021

This is fixed in the latest release. Grab v0.10.0 to get it.

@zachmu zachmu closed this as completed Jun 2, 2021
@paralin
Copy link
Contributor

paralin commented Jun 2, 2021

Thanks!

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

No branches or pull requests

6 participants