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

support MySQL special character escape sequences #23

Open
lovasoa opened this issue Sep 14, 2018 · 5 comments
Open

support MySQL special character escape sequences #23

lovasoa opened this issue Sep 14, 2018 · 5 comments

Comments

@lovasoa
Copy link
Contributor

lovasoa commented Sep 14, 2018

Hi!
Thank you for this great library.
I am trying to use it to parse wikipedia dumps in my project wikipedia-externallinks-fast-extraction.
Unfortunately, they contain mysql escape characters that are currently not supported by this library.

Unsupported characters

The escape characters are:

\0
\'
\"
\b
\n
\r
\t
\Z
\\
\%
\_

Example

INSERT INTO externallinks VALUES (23481,120102,'http://home.arcor.de/jean-polmartin/aufsaetze/apliut.htm\'','http://de.arcor.home./jean-polmartin/aufsaetze/apliut.htm\'','http://de.arcor.home./jean-polmartin/aufsaetze/apliut.htm\'');
@lovasoa
Copy link
Contributor Author

lovasoa commented Sep 14, 2018

SQLite escape sequences don't seem to be supported either. According to the README:

We try to support both the SQLite and MySQL syntax; where they disagree, we choose MySQL. (It would be nice to support both via feature flags in the future.)

So I think :

  • '''' should parse as ' (sqlite-only)
  • '\' should parse as \ (sqlite-only)
  • '\\' should parse as \\ (it is a valid string in both SQLite and mysql, but with a different meaning)
  • '\'' should parse as ' (mysql-only)

@lovasoa
Copy link
Contributor Author

lovasoa commented Sep 14, 2018

It should not be difficult to implement using nom::escaped_transform

@ms705
Copy link
Owner

ms705 commented Sep 14, 2018

Good catch -- I actually independently ran into this issue last week (also parsing MySQL dumps) and made a mental note to fix it!

I originally looked at nom::escaped_transform for this, but didn't yet figure out exactly how to use it for this purpose. Looks like you ended up hand-rolling the parse rule instead, probably for good reasons.

I'll check out the PR 👍

@lovasoa
Copy link
Contributor Author

lovasoa commented Sep 16, 2018

I also tried to use nom::escaped_transform but with no success. I think this is because of that part of the documentation:

WARNING: if you do not use the verbose-errors feature, this combinator will currently fail to build because of a type inference error

@ms705
Copy link
Owner

ms705 commented Oct 3, 2018

I think we have all of them supported now, thanks to @lovasoa's work 👍

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

2 participants