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

Statement parser doesn't break on hyphen #563

Closed
marekhanzlik opened this issue Sep 27, 2018 · 6 comments
Closed

Statement parser doesn't break on hyphen #563

marekhanzlik opened this issue Sep 27, 2018 · 6 comments
Labels

Comments

@marekhanzlik
Copy link

Hi i have some problems when switching from Mysql.Data to MySqlConnector

var insertProductCmd = new MySqlCommand($"INSERT INTO {Tables.PlayerProductsTable} (product_id, player_id, product_count) VALUES (@productID, @playerID, 0) " + $"ON DUPLICATE KEY " + $"UPDATE product_count=GREATEST(0, product_count-@productCount)", conn, transaction);

This command throws an product_count cannot be null
This doesnt happen on MySql.Data, what am i missing?

Second problem is #562

@bgrainger
Copy link
Member

Please provide a more complete sample (e.g., that shows parameter values, full exception message & call stack).

@marekhanzlik
Copy link
Author

Whole command code
Whole Command Code

Exception MySql.Data.MySqlClient.MySqlException: 'Column 'product_count' cannot be null'
Parameter values are:
@productID = 1
@playerID = 597
@productCount = 11

Values in database
Database values

@bgrainger bgrainger changed the title Column cannot be null when INSERT ON DUPLICATE KEY UPDATE Statement parser doesn't break on operators Sep 28, 2018
@bgrainger bgrainger added the bug label Sep 28, 2018
@bgrainger
Copy link
Member

This is a bug in MySqlConnector's parameter interpolation logic. You can work around it for now by changing your statement to the following (adding spaces around the minus sign):

$"UPDATE product_count=GREATEST(0, product_count - @productCount)"

@marekhanzlik
Copy link
Author

Thanks for info, i'll have to wait for fix instead of using workaround, this can show up on so many places in project it's not worth the risk of missing something

@bgrainger bgrainger changed the title Statement parser doesn't break on operators Statement parser doesn't break on hyphen Sep 29, 2018
@bgrainger
Copy link
Member

Fixed in 0.45.1.

@marekhanzlik
Copy link
Author

Thank you very much 😊

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

No branches or pull requests

2 participants