getting mysql Error 1064 - mysql

I am build a basic application with golang, i am using github.com/go-sql-driver/mysql driver. I am connecting to clearDB mysql on heroku but every time i'm getting
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 'desc, price from product where id = ?' at line 1
I can't under stand why, this is the piece of code that i'm using for the query the product database.
id := c.Param("id")
row := db.QueryRow("select id, desc, price from product where id = ?;", id)
err := row.Scan(&product.Id, &product.desc, &product.price)

desc is a keyword so you get in trouble when you also named a column desc.
With MySQL you need to quote the name with backticks, like so:
"select id, `desc`, price from product where id = ?"

Related

Error in sql syntax value ? but it's showing the value?

the title isn't very specific but I don't know how to make it better. I've got this error in my sql telling me something is wrong but I don't understand why it's wrong, currently using mysql 8.0.24. If you wonder why it looks strange it's because I use it in lua
Sql:
local q = [[SELECT id, hex_id, steam_id, community_id, name, ip, rank FROM users WHERE hex_id = #id;]]
local v = {["id"] = hexId}
Error:
An error happens for query "SELECT id, hex_id, steam_id, community_id, name, ip, rank FROM users WHERE hex_id = ?; : ["steam:*****"]": ER_PARSE_ERROR: 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 'FROM users WHERE hex_id = 'steam:*****'' at line 1
RANK is a keyword in MySQL 8. You need to enclose it inside backticks:
SELECT id, hex_id, steam_id, community_id, name, ip, `rank` FROM users ...

MySQL syntax error when using sqlite3 query

I just wanted to switch from sqlite3 to using MySQL but I get errors in this query:
SELECT
metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
pro.latitude,
pro.longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM (metapp_notif
join (metapp_profil
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id) AS pro
ON metapp_notif.send_id = pro.user_id)
WHERE metapp_notif.rec_id =% d;
I'm getting this error:
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 'pro on metapp_notif.send_id=pro.user_id) where
metapp_notif.rec_id=2' at line 1
I was searching for differences between sqlite3 and mysql but can't figure out what is wrong.
Thanks in advance!
Try this syntax in Mysql
SELECT metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
latitude,
longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM metapp_profil
join metapp_notif
ON metapp_notif.send_id = metapp_profil.user_id
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id
WHERE metapp_notif.rec_id like '% d'; -- Not sure what you are trying to do here

MySQL Syntax With Simple Joins

I'm having trouble figuring out why this query does not work. Names have been sanitized as this is proprietary code.
QRY:
SELECT l.albert, o.ben, m.caleb, m.dennis, m.edgar
FROM octopus o, lorax l, monkey m
WHERE o.ben = l.ben
AND l.franklin= m.franklin
AND o.ben= :ben
ORDER BY l.albert DESC
LIMIT 1
Here is the error that I get:
MySQL Error: 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 'QRY: SELECT l.albert, o.ben, m.caleb, m.dennis, m' at line 1
It seems like you have
"QRY: "
at the beginning of your query. It should start with
"SELECT ...

Getting error in phpmyadmin stored procedure script

Im creating a stored procedure in phpmyadmin, which get the event category list. The condition im using, im sending a parameter 'e_range' where i get the list on the basis of whatever i set the range on this parameter 3, 4 etc. but im getting an error in while executing this script:
#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 'e_range; else select category_id, category_name, category_thumb from category' at line 4
CREATE PROCEDURE `sp_category_list`(IN e_range int)
BEGIN
if(e_range != 0 or null) then
select category_id, category_name, category_thumb from category_list order by category_name limit e_range;
else
select category_id, category_name, category_thumb from category_list order by category_name;
END if;
END$$
Now problem is that, this script working good in my localhost pc. but im getting these error on my webserver CPANEL's phpmyadmin.
the MySQL keyword 'LIMIT' is not taking the value through parameter. or maybe not recognizing it. but when i remove this parameter from the select command and set the static number on this, it will work:
select category_id, category_name, category_thumb from category_list order by category_name limit 5;
now what is the procedure, so i will get the list through my given parameter.
Thank you :)

error in updating mysql table with filters

i have a mysql table with the follwoing fields :
id, desc, value, people, amount, weight
in the above order i run the follwoing
update match1 set weight = 5 where desc = 'fat' and id != '6';
follwoing is the error message i get :
**#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 'desc = 'bat' and id = 6' at line 1
can someone please let me know whats wrong with this?
the column desc is a keyword in mysql. use backquotes i.e.
where `desc` = 'fat'