anaqim
April 29, 2018, 12:43pm
1
Hi dev,
I’ve come across something strange.
I can work around it but wonder if you can check if its a bug or if my syntax is wrong?
core.mysql.dbQuery(db,“SELECT * FROM messages WHERE hash=’”…hash…"’ OR hash=0 ORDER BY ‘key’ DESC LIMIT 50")
The line doesnt produce any errors but result is always returend in ASC order.
Thx!
You are sorting the results by a constant value ‘key ’ (which is always the same) you want to sort by a column, so you need to specify the column.
Use backticks instead of single quotes near key
core.mysql.dbQuery(db,"SELECT \* FROM messages WHERE hash='"..hash.."' OR hash=0 ORDER BY `key` DESC LIMIT 50")
The rule of thumb is backticks (`) around column names, and single quotes (’) around strings.
I have found answer in google In the case you think I’m so smart hehe
ldurniat
anaqim
April 29, 2018, 1:35pm
3
Hi,
Works like a dream
Never paid much attention to that backtick.
Thought it was just a different keyboard version of the single quote.
Learned something today!
Thanks a million!
anaqim
Hi,
@Idurniat is correct, if you are writing plain queries you must use backticks and single quotes appropriately. This is done automatically when using EZ query methods.
You can see this in the string based query examples https://develephant.github.io/coronium-core-docs/server/modules/mysql/#string-based
-dev
You are sorting the results by a constant value ‘key ’ (which is always the same) you want to sort by a column, so you need to specify the column.
Use backticks instead of single quotes near key
core.mysql.dbQuery(db,"SELECT \* FROM messages WHERE hash='"..hash.."' OR hash=0 ORDER BY `key` DESC LIMIT 50")
The rule of thumb is backticks (`) around column names, and single quotes (’) around strings.
I have found answer in google In the case you think I’m so smart hehe
ldurniat
anaqim
April 29, 2018, 1:35pm
6
Hi,
Works like a dream
Never paid much attention to that backtick.
Thought it was just a different keyboard version of the single quote.
Learned something today!
Thanks a million!
anaqim
Hi,
@Idurniat is correct, if you are writing plain queries you must use backticks and single quotes appropriately. This is done automatically when using EZ query methods.
You can see this in the string based query examples https://develephant.github.io/coronium-core-docs/server/modules/mysql/#string-based
-dev