Skip to content

fix: mysql ON UPDATE not taking an expression #586

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

Closed
wants to merge 2 commits into from

Conversation

Sibz
Copy link

@Sibz Sibz commented Aug 19, 2022

Attempt to resolve the #543, the PR resolves the issue however I was not sure on the test construction so there is currently a pending todo before this can be merged. As per my comments on #543 any assistance/guidance would be appreciated.

Also not sure the extra enum variant is the best way to do this, but wasn't able to pull the tokens and expr from DialectSpecific variant.

closes #543

@Sibz Sibz changed the title fix: mysql ON UPDATE not taking and expression fix: mysql ON UPDATE not taking an expression Aug 19, 2022
@Sibz Sibz force-pushed the fix-mysql-on-update branch from 2585a03 to 02f41c2 Compare August 19, 2022 21:44
@alamb
Copy link
Contributor

alamb commented Aug 31, 2022

I think the enum idea is a good one

@alamb
Copy link
Contributor

alamb commented Sep 27, 2022

FYI, I am planning to make a new sqlparser-rs release in the next day or two. This PR has some outstanding comments and appears to have have stalled

@alamb
Copy link
Contributor

alamb commented Oct 15, 2022

Marking as draft to signify this PR has been reviewed. Please mark this PR as ready for review when it is ready again.

@alamb alamb marked this pull request as draft October 15, 2022 11:43
@Sibz Sibz force-pushed the fix-mysql-on-update branch 3 times, most recently from 7180583 to 16b0dc5 Compare December 19, 2022 03:43
@Sibz Sibz force-pushed the fix-mysql-on-update branch from 16b0dc5 to 653cd2b Compare December 19, 2022 04:19
@Sibz
Copy link
Author

Sibz commented Dec 19, 2022

Commit updated:
Added verification the expr is one of 'CURRENT_TIMESTAMP', 'LOCALTIME', 'LOCALTIMESTAMP', 'NOW'.
Fixed test
Added test for invalid expr parser error

@Sibz Sibz marked this pull request as ready for review December 19, 2022 04:23
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @Sibz

@coveralls
Copy link

coveralls commented Dec 19, 2022

Pull Request Test Coverage Report for Build 3769028368

  • 37 of 40 (92.5%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 86.354%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser.rs 11 14 78.57%
Totals Coverage Status
Change from base Build 3720056662: 0.02%
Covered Lines: 12802
Relevant Lines: 14825

💛 - Coveralls

@Sibz Sibz requested a review from alamb December 21, 2022 01:13
@Sibz
Copy link
Author

Sibz commented Dec 21, 2022

@alamb Just had a quick review and found an improvement could be made, so added a refactor commit. If you would prefer I can squash into the primary commit and force push.

@Sibz Sibz force-pushed the fix-mysql-on-update branch 4 times, most recently from 8322d7f to c2a0559 Compare December 24, 2022 00:15
parse::check_on_update_expr_is_valid - using local const instead of vec for valid object names
@Sibz Sibz force-pushed the fix-mysql-on-update branch from c2a0559 to e6b0c64 Compare December 24, 2022 00:32
@Sibz
Copy link
Author

Sibz commented Dec 24, 2022

Added NOW keyword, included that in the parse time functions match arm
Fix check name to be case insensitive
Added test for lowercase now() fn use.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @Sibz -- this is looking very close.

Can you please remove the validation code? If so I think this PR is good to go.

@@ -6318,6 +6317,31 @@ impl<'a> Parser<'a> {
pub fn index(&self) -> usize {
self.index
}

fn check_on_update_expr_is_valid(expr: &Expr) -> Result<(), ParserError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

my preference is to leave this type of "semantic" check downstream -- so I would prefer that sqlparser accepts any expression in this place, and then downstream crates can enforce limits like the expr must be one of the specified time functions.

@AugustoFKL and I tried to explain this difference in the readme recently

https://github.com/sqlparser-rs/sqlparser-rs#extensible-sql-lexer-and-parser-for-rust

This crate provides only a syntax parser, and tries to avoid applying
any SQL semantics, and accepts queries that specific databases would
reject, even when using that Database's specific Dialect. For
example, CREATE TABLE(x int, x int) is accepted by this crate, even
though most SQL engines will reject this statement due to the repeated
column name x.

This crate avoids semantic analysis because it varies drastically
between dialects and implementations. If you want to do semantic
analysis, feel free to use this project as a base

Token::make_keyword("ON UPDATE"),
])))
let expr = self.parse_expr()?;
Self::check_on_update_expr_is_valid(&expr)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend just accepting expr here

@alamb alamb marked this pull request as draft December 28, 2022 13:29
@alamb
Copy link
Contributor

alamb commented Dec 28, 2022

Given #602 has something similar, perhaps I can try and push this one through

@alamb
Copy link
Contributor

alamb commented Dec 28, 2022

I believe this PR is no longer necessary after #685. Can you please confirm @Sibz ?

@alamb alamb closed this Dec 28, 2022
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

Successfully merging this pull request may close these issues.

MySQL - On Update not taking expression
3 participants