Mysql syntax error in scrapy - mysql

Hi i am working on scrapy and writing a pipeline and in that i had a query which should write the data in to mysql database
tx.execute("""INSERT INTO example_table (book_name,price)
VALUES (%s,%s)""",
(item['book_name'],
item['price'],)
)
I am getting the following errors two errors below
(1064, "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 2")
(1241, 'Operand should contain 1 column(s)')
I dont know whats wrong in this query but i am unable to save the data in to database.
Can any one have a idea of this.

You forgot to add % while executing
x.execute("""INSERT INTO example_table (book_name,price)
VALUES (%s,%s)""",%
(item['book_name'],
item['price'])
)

You have added an additional comma at last remove it. following is the correct statement. Kindly try.
x.execute("""INSERT INTO example_table (book_name,price)
VALUES (%s,%s,%s,%s,%s,%s)""",
(item['book_name'],
item['price'])
)

Related

'Cant get attributes from Select' while setting up Query for export data task in DBeaver

Hey so I'm trying to set up an export data task in DBeaver, because I want to export some data to another database and I want to query the date in beforehand. So I'm trying to use this SELECT statement
SELECT *
FROM resource
WHERE assignedteamid = 2 AND active;
which works fine on its own but when I'm trying to add this query in the Task setup screen and click on continue I get this Error
Can't get attributes from `SELECT * FROM resource WHERE assignedteamid = 2 AND active;`
Reason: SQL Error [1064] [42000]: 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 'LIMIT 0, 1' at line 4
I already tried to change up the query but I have no clue what I need to do to fix this problem. I appreciate any help.
Thank you!

Unable to determine cause of syntax error

I am running an insert query to add data into my database but I get the following error
"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' at line 1")"
I have reviewed the code but unable to determine why
cursor.execute("INSERT IGNORE INTO footballtest(`codmeci` ,`datameci`,`orameci` ,`sezonul` ,`etapa` ,`txtechipa1`,`txtechipa2` ,`scor1` ,`scor2` ,`scorp1` ,`scorp2` ,`codechipa1` ,`codechipa2` ,`cotaa` ,`cotae`,`cotad`,`cotao` ,`cotau` ,`suth` ,`suta` ,`sutht`,`sutat` ,`corh` ,`cora` ,`foulsh` ,`foulsa` ,`yellowh`,`yellowa` ,`ballph`,`ballpa` ,`mgolh` ,`mgola` ,`mgol`) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"), (row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[13],row[14],row[16],row[17],row[18],row[19],row[20],row[29],row[30],row[31],row[32],row[33],row[34],row[35],row[36],row[37],row[38],row[39],row[40],row[57],row[58],row[59])
Sometimes taking a large problem and simplifying it can reveal what the problem is. Here is your insert, but using only three columns:
sql = "INSERT IGNORE INTO footballtest(codmeci, datameci, orameci) VALUES (%s,%s,%s)"
cursor.execute(sql, (row[0], row[1], row[2]))
Note carefully that the pattern is:
cursor.execute(<some SQL string>, (some CSV tuple of values to bind))

Getting SQL error for replace function

I'm not to sure why this is happening and i've been trying to figure it out now for a while.
I've got the follow code
SELECT (MAX(replace(replace(replace(`sku`,'PA1-',''),'TES-',''),'BOX-',''))+1) AS maxValue FROM `product` WHERE `sku` LIKE '%PA1-TES-BOX%'
This was working a while back and nothing has changed code wise, I can only assume that a server changes has caused this to return the following error:
#1064 - 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 'maxValue FROM ``product`` WHERE ``sku`` LIKE '%PA1-TES-BOX%'
Basically this SQL was built to find the first 3 section of this SKU code and return the ending + 1 so 002 would then return 003 to ensure unique sku codes.
Maybe the replace function has changed, i'm not entirely sure.
Does anyone have any ideas why this suddenly is throwing the error above?
I don't see an obvious syntax error. But assuming the number is the last hyphenated item in the sku, the code could more easily be written as:
select (substring_index(sku, '-', -1) + 1) as maxvalue
. . .
One possibility for the syntax error is that an unprintable character crept in around the as.

web application got a error mysql query

select b1.blog_id, blog_name, blog_desc, b1.blog_date, blog_author, blog_img, ifnull(count(blog_cmt),0) AS blog_cmt
from blog b1, user_blog b2"
I got a error in this:
Error Code: 1064. 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
Error #1064 means that MySQL can't understand your command. To fix it:
Read the error message. It tells you exactly where in your command
MySQL got confused.
Check the manual. By comparing against what MySQL
expected at that point, the problem is often obvious.
Check for reserved words. If the error occurred on an object identifier, check
that it isn't a reserved word (and, if it is, ensure that it's
properly quoted).
You need to remove the quotes at the end and run your query. Looks like there is a typo, you intended a ; instead.
select b1.blog_id, blog_name, blog_desc, b1.blog_date, blog_author, blog_img, ifnull(count(blog_cmt),0) AS blog_cmt
from blog b1, user_blog b2;

load SQL and ignore duplicates

I want to import an SQL file using PHPMyAdmin where I know duplicates exist. I am using the syntax:
LOAD DATA INFILE 'C:\Documents and Settings\...\db_settings_extends.sql' ignore;
I receive the error:
#1064 - 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
How do I correct this?
From the error message, it looks like duplicates are not the problem. It seems to not like your string value or something next to it.