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

editing a row and using 'insert as new row' uses primary key 0 #15187

Closed
aschuch247 opened this issue Apr 13, 2019 · 12 comments · Fixed by #15896
Closed

editing a row and using 'insert as new row' uses primary key 0 #15187

aschuch247 opened this issue Apr 13, 2019 · 12 comments · Fixed by #15896
Assignees
Labels
Bug A problem or regression with an existing feature has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete
Projects
Milestone

Comments

@aschuch247
Copy link

Describe the bug

If editing a row with an autoincrement primary key and using the option 'insert as new row', the new row will get the primary key 0 assigned.

To Reproduce

Steps to reproduce the behaviour:

  1. Have the database server using SQL mode NO_AUTO_VALUE_ON_ZERO (https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_auto_value_on_zero).
  2. Create a table with an autoincrement primary key id and a string name.
  3. Insert some rows to the table.
  4. Click on one row and select edit.
  5. The bottom dialogue by default has save selected. Select insert as new row.
  6. The column id now is automatically set to 0.
  7. Press go to edit the row.

Expected behaviour

My intention is to edit a row and insert it as a new row. This works if the automatically added 0 to the column id is manually removed. I expect to not have an automatically filled out 0 in the column id as soon as I select insert as new row.

Server configuration

  • Database version: MySQL 5.6 with NO_AUTO_VALUE_ON_ZERO enabled
  • phpMyAdmin version: 4.8.5

Additional context

The SQL mode NO_AUTO_VALUE_ON_ZERO needs to be enabled in order to not interpret the given primary key 0 as a literal zero instead of an instruction to create a new primary key.

@williamdes williamdes added Bug A problem or regression with an existing feature enhancement A feature request for improving phpMyAdmin labels Apr 16, 2019
@aschuch247
Copy link
Author

If the primary key NULL is used, a new autoincrement value will be created regardless of NO_AUTO_VALUE_ON_ZERO set. So the fool-proof way is to always provide NULL when inserting a new primary key (or do not specify the field at all).

@williamdes williamdes added this to To be sorted in issues May 2, 2019
@williamdes williamdes moved this from To be sorted to Reproduced in issues May 4, 2019
@aschuch247
Copy link
Author

I can still reproduce the error.

  • phpMyAdmin: 4.9.1
  • browser: Firefox 69.0 (64-bit)
  • operating system: KDE neon

@yashrajbothra
Copy link
Contributor

yashrajbothra commented Feb 2, 2020

Hey @aschuch247 can u please tell me how u changed the SQL_MODE

As I am unable to reproduce the issue

ezgif com-video-to-gif

OR

You just dont want 0 in id when we click on Insert as new Row

@aschuch247
Copy link
Author

I can still reproduce the error.

  • phpMyAdmin: 4.9.4
  • browser: Firefox 72.0.1 (64-bit)
  • operating system: KDE neon

@aschuch247
Copy link
Author

aschuch247 commented Feb 2, 2020

@yashrajbothra: See the documentation at https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_auto_value_on_zero.

SET GLOBAL sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

And actually, I want the primary key to either not be present in the created SQL statement, so that MySQL will create a new primary key and thus a new row, or that the used primary key is NULL, so that MySQL will create a new primary key and thus a new row.

@yashrajbothra
Copy link
Contributor

Thanks you @aschuch247 :)

I think NULL will be good solution as it creates New primary key for every new row even in 'NO_AUTO_VALUE_ON_ZERO' mode.

Hey @williamdes is it Okay if we replace 0 to NULL for evey Insert new Row??

@williamdes
Copy link
Member

Hey @yashrajbothra I think it would be okay but I need some documentation proof from MySQl and MariaDB to approve such a change

Can you please do some research?

@williamdes
Copy link
Member

"NO_AUTO_VALUE_ON_ZERO affects handling of AUTO_INCREMENT columns. Normally, you generate the next sequence number for the column by inserting either NULL or 0 into it. NO_AUTO_VALUE_ON_ZERO suppresses this behavior for 0 so that only NULL generates the next sequence number."

Approved change for MySQL

@yashrajbothra
Copy link
Contributor

For MariaDB : Docs
image

cc @williamdes

@williamdes
Copy link
Member

Thank you!
I think a PR can be made and merged into next patch version

@yashrajbothra
Copy link
Contributor

yashrajbothra commented Feb 2, 2020

Okay then I will Open a PR soon 👍

yashrajbothra added a commit to yashrajbothra/phpmyadmin that referenced this issue Feb 2, 2020
Signed-off-by: Yash Bothra <yashrajbothra786@gmail.com>
@williamdes williamdes added has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete and removed enhancement A feature request for improving phpMyAdmin labels Feb 3, 2020
@williamdes williamdes added this to the 5.0.2 milestone Feb 9, 2020
yashrajbothra added a commit to yashrajbothra/phpmyadmin that referenced this issue Feb 9, 2020
Signed-off-by: Yash Bothra <yashrajbothra786@gmail.com>
yashrajbothra added a commit to yashrajbothra/phpmyadmin that referenced this issue Feb 9, 2020
Signed-off-by: Yash Bothra <yashrajbothra786@gmail.com>
@williamdes williamdes self-assigned this Feb 10, 2020
williamdes added a commit that referenced this issue Feb 10, 2020
Signed-off-by: William Desportes <williamdes@wdes.fr>
issues automation moved this from Reproduced to Closed Feb 10, 2020
@aschuch247
Copy link
Author

@williamdes: Is there any chance this one-line fix can be backported to phpMyAdmin 4.9 and released with any further security fix (in case such a security fix is ever required)?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A problem or regression with an existing feature has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete
Projects
issues
  
Closed
Development

Successfully merging a pull request may close this issue.

3 participants