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

MYSQL single quote insert error #30

Closed
TomLDennison opened this issue Aug 17, 2018 · 2 comments
Closed

MYSQL single quote insert error #30

TomLDennison opened this issue Aug 17, 2018 · 2 comments

Comments

@TomLDennison
Copy link

When the SavetoMySQLPipeline class in the pipelines.py file tries to insert a record with a single quote, an error is being thrown and the record is rejected. This is because MySQL throws single quotes to begin and end a string value in its insert statement. In order to insert a string with a quote you must use '' (two single quotes in a row). The bad insert statement is being created on line 141 of the pipelines.py file. To fix this I updated the code on line 135:

text = item['text']

with the following code to replace each single quote with two single quotes:

text = item['text'].replace(''', '''')

This could be added to the other variables there for completeness, but wasn't necessary in my case.

Thanks for publishing this!

@saggel
Copy link

saggel commented Aug 18, 2018

I'm not sure if it's the same error, but I do get an error when using MySQL:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

the "near" part of the error is the tweet.

I tried the replacement you suggested @TomLDennison, btw the write way I think is:
text = item['text'].replace("'", "''")

but it doesn't solve the problem for me!

@saggel
Copy link

saggel commented Aug 19, 2018

update on this - I corrected the replacement code and now it works for me!

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

3 participants