issue with order syntax on opencart - opencart

We are getting the below error while fetching the orders on opencart.
error:
{"status":200,"data":"\"Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDBserver version for the right syntax to use near 'order ORDER BY order_id DESC' at line 1<br \\\/>Error No: 1064<br \\\/>SELECT * FROM order ORDER BY order_id DESC\""}
please help
I am using opencart 3.0.3.8
I am new to opencart, still learning it so I didn't find a solution for the same. I need help here.

Your SQL contains the word "order" for the order table. However, order is a keyword. You need to put it in backticks - ie `order`

It's conflicting with the predefined word ORDER BY
So you need to change it to be order

Related

Cannot use distinct w/ a different Order by using Django ORM

I have seen a few posts that reference this issue on Stackoverflow, but I cannot figure out how to get the business need solved, if the query changes.
I am trying to get the last 10 contacts that have sent a message to the organization
messages = (Message.objects.order_by('-created_at').distinct('contact_id'))
However, I get this error:
SELECT DISTINCT ON expressions must match initial ORDER BY expressions
LINE 1: SELECT DISTINCT ON ("messages"."contact_id") "messages"."id"...
I see that the distinct column must match the order by column, but a distinct created_at, isn't what the business needs to solve the problem.
Any suggestions?
The field in distinct() must be included and must be the first one in order_by(), in your case contact_id:
Message.objects.order_by('contact_id', '-created_at').distinct('contact_id')
Docs: https://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct

How to perform NATURALLEFTOUTERJOIN without having the same name in both tables?

I tried to make same column in both tables but end up receiving error "An incompatible join column, (''[WeekName]) was detected. 'NATURALLEFTOUTERJOIN' doesn't support joins by using columns with different data types or lineage".
LeftOuterJoin = NATURALLEFTOUTERJOIN(
SELECTCOLUMNS(GROUPBY(DateTime,DateTime[yDayFullName],
"WEEKCOUNT", COUNTX(CURRENTGROUP(),DateTime[yDayFullName])),
"WeekName", DateTime[yDayFullName], "WEEKCOUNT",[WEEKCOUNT]),
SELECTCOLUMNS(GROUPBY(FILTER(Mergetable,Mergetable[noShow]<>"true"),Mergetable[WeekDayName],
"TOTALDURATION", SUMX(CURRENTGROUP(),Mergetable[MeetingDurationInHours])),
"WeekName",Mergetable[WeekDayName],"TOTALDURATION",[TOTALDURATION]))
Can you please change the code to following and see if it works
"WeekName", DateTime[yDayFullName]&""
and
"WeekName",Mergetable[WeekDayName]&""
Also, please make sure that DateTime[yDayFullName] and Mergetable[WeekDayName] has the same data type.
I have assumed that both of them are string and I guess you are trying to join on WeekName.

Classic report issue with multiple inputs with IN statement

I am trying to refresh a report with dynamic action. And get the following errors:
{'dialogue': {'uv': true, 'line': [{'V': "failure of Widget}]}}
ORA-20876: stop the engine of the APEX.
classic_report"}]}}
I think its an issue with string which can't take and ST.ID IN (:P11_ROW_PK) in sql query.
Please suggest a workaround for the same.
This question requires the context you've provided in
https://stackoverflow.com/a/63627447/527513
If P11_ROW_PK is a delimited list of IDs, then you must structure your query accordingly, not expect the IN statement to deconstruct a bind variable containing a string.
Try this instead
select * from your_table
where st.id in (select column_value from apex_string.split(:P11_ROW_PK))
where REGEXP_LIKE(CUSTOMER_ID, '^('|| REPLACE(:P4_SEARCH,',','|') ||')$')
Above code will act same as APEX_STRING only if you are using lower version Apex

Amazon Athena: no viable alternative at input

While creating a table in Athena; it gives me following exception:
no viable alternative at input
hyphens are not allowed in table name.. ( though wizard allows it ) .. Just remove hyphen and it works like a charm
Unfortunately, at the moment the syntax validation error messages are not very descriptive in Athena, this error may mean "almost" any possible syntax errors on the create table statement.
Although this is annoying at the moment you will need to check if the syntax follows the Create table documentation
Some examples are:
Backticks not in place (as already pointed out)
Missing/extra commas (remember that the last column doesn't need the comma after column definition
Missing spaces
More ..
This error generally occurs when the syntax of DDL has some silly errors.There are several answers that explain different errors based on there state.The simple solution to this problem is to patiently look into DDL and verify following points line by line:-
Check for missing commas
Unbalanced `(backtick operator)
Incompatible datatype not supported by HIVE(HIVE DATA TYPES REFERENCE)
Unbalanced comma
Hypen in table name
In my case, it was because of a trailing comma after the last column in the table. For example:
CREATE EXTERNAL TABLE IF NOT EXISTS my_table (
one STRING,
two STRING,
) LOCATION 's3://my-bucket/some/path';
After I removed the comma at the end of two STRING, it worked fine.
My case: it was an external table and the location had a typo (hence didn't exist)
Couple of tips:
Click the "Format query" button so you can spot errors easily
Use the example at the bottom of the documentation - it works - and modify it with your parameters: https://docs.aws.amazon.com/athena/latest/ug/create-table.html
Slashes. Mine was slashes. I had the DDL from Athena, saved as a python string.
WITH SERDEPROPERTIES (
'escapeChar'='\\',
'quoteChar'='\"',
'separatorChar'=',')
was changed to
WITH SERDEPROPERTIES (
'escapeChar'='\',
'quoteChar'='"',
'separatorChar'=',')
And everything fell apart.
Had to make it:
WITH SERDEPROPERTIES (
'escapeChar'='\\\\',
'quoteChar'='\\\"',
'separatorChar'=',')
In my case, it was an extra comma in PARTITIONED BY section,
In my case, I was missing the singlequotes for the S3 URL
In my case, it was that one of the table column names was enclosed in single quotes, as per the AWS documentation :( ('bucket')
As other users have noted, the standard syntax validation error message that Athena provides is not particularly helpful. Thoroughly checking the required DDL syntax (see HIVE data types reference) that other users have mentioned can be pretty tedious since it is fairly extensive.
So, an additional troubleshooting trick is to let AWS's own data parsing engine (AWS Glue) give you a hint about where your DDL may be off. The idea here is to let AWS Glue parse the data using its own internal rules and then show you where you may have made your mistake.
Specifically, here are the steps that worked for me to troubleshoot my DDL statement, which was giving me lots of trouble:
create a data crawler in AWS Glue; AWS and lots of other places go through the very detailed steps this requires so I won't repeat it here
point the crawler to the same data that you wanted (but failed) to upload into Athena
set the crawler output to a table (in an Athena database you've already created)
run the crawler and wait for the table with populated data to be created
find the newly-created table in the Athena Query Editor tab, click on the three vertical dots (...), and select "Generate Create Table DLL":
this will make Athena create the DLL for this table that is guaranteed to be valid (since the table was already created using that DLL)
take a look at this DLL and see if/where/how it differs from the DLL that you originally wrote. Naturally, this automatically-generated DLL will not have the exact choices for the data types that you may find useful, but at least you will know that it is 100% valid
finally, update your DLL based on this new Glue/Athena-generated-DLL, adjusting the column/field names and data types for your particular use case
After searching and following all the good answers here.
My issue was that working in Node.js i needed to remove the optional
ESCAPED BY '\' used in the Row settings to get my query to work. Hope this helps others.
Something that wasn't obvious for me the first time I used the UI is that if you get an error in the create table 'wizard', you can then cancel and there should be the query used that failed written in a new query window, for you to edit and fix.
My database had a hypen, so I added backticks in the query and rerun it.
This happened to me due to having comments in the query.
I realized this was a possibility when I tried the "Format Query" button and it turned the entire thing into almost 1 line, mostly commented out. My guess is that the query parser runs this formatter before sending the query to Athena.
Removed the comments, ran the query, and an angel got its wings!

References function in rails 4

I'm just not understand the new references() function in Rails 4
I'm reading the definition here : http://apidock.com/rails/ActiveRecord/QueryMethods/references
It's meaby a english problem, but it's still not clear for me.
What is the goal of this new feature? (code was working well without it before).
Must I always add a reference for each table of my includes() ?
Thanks
When using includes, Rails will usually load the results separately. For example, if you do
Post.includes(:comments)
it will issue a query to load the post(s) and then another to load the comments with the post_id of the post(s).
It will generate a join, if, for example, you want to do
Post.includes(:comments).where(comments: { user_id: 44})
Where one of the conditions is dependent on a related table. If, however, you were to use
Post.includes(:comments).where('comments.user_id = ?', 44)
You will get an error in Rails 4. Any time that you're referencing a relationship in a conditional using a SQL snippet, you will have to use references. To fix the above, we would do
Post.includes(:comments).where('comments.user_id = ?', 44).references(:comments)
The other option, of course, is to not use SQL snippets in your conditionals, like the second code example, but it's not always possible to avoid them.
I think this is intended for when you're eager loading an association and you're using a string condition. Because Rails doesn't want to have to parse raw SQL in where clauses to figure out what you're doing, so references is intended to make it more explicit what is going on in your query.
Group.includes(:users).where('users.first_name = ?', 'John')
You should get some kind of deprecation warning if you do this. But if you use a hash syntax you should not get the deprecation warning:
Group.includes(:users).where(users: { first_name: 'John' })
So to fix the deprecation warning on the first one, you would add references(:users) to it.
Group.includes(:users).where('users.first_name = ?', 'John').references(:users)
The query method references is used to indicate that an association is referenced by a SQL string and therefore be joined over being loaded separately. As of Rails 4.1, adding a string condition of an included reference will result in an exception being raised.
Here is an example that selects all Teams which have a member named Nishant:
>> Team.includes(:members).where('members.name = ?', 'Nishant')
SQLite3::SQLException: no such column: members.name: SELECT "teams".*
FROM "teams" WHERE (members.name = 'Nishant')
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column:
members.name: SELECT "teams".* FROM "teams" WHERE (members.name =
'Nishant')
...
To get the above example to work in Rails 4.1, we must include query method references with the name of the association to join
Team.includes(:members).where("members.name = ?", 'Nishant').references(:members)
However, if you were using the hash syntax with association conditions, it would still perform a LEFT OUTER JOIN without any exception being raised:
Team.includes(:members).where(members: { name: 'Nishant' })
Note that ordering string SQL snippets on included associations will still work the same way without the need
of references:
Team.includes(:members).order('members.name')
I hope this will help you.