'Syntax Error' when using Database Navigator for PyCharm - mysql

I have a project with a MySQL database to which I connected using the Database Navigator plugin.
Now when I open the DB Browser window, select the database and click on "Open DB console" and insert the query
SELECT CAST('2017-08-29' AS DATE);
for one, the IDE highlights CAST as an unknown identifier:
and, additionally, when I try to execute the statement, I get the error
Error executing SELECT statement. 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 - Connection: test: 112ms
However, to my knowledge, this is valid MySQL, at least this page suggests so.
I am also able to perform MySQL queries with casts from a python script that builds the connection itself.
What am I doing wrong here? Do I have to configure the dialect for Database Navigator?

Related

Why I can't use "source" in MySQL bench?

I am at the very beginning of mysql, trying to insert data into a new schema called crashcourse.
My code is:
use crashcourse;
source /Users/chenxinyu/Downloads/mysql_scripts/create.sql ;
source /Users/chenxinyu/Downloads/mysql_scripts/populate.sql ;
But it turns out that "11:35:24 source /Users/chenxinyu/Downloads/mysql_scripts/create.sql 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 'source /Users/chenxinyu/Downloads/mysql_scripts/create.sql' at line 1 0.00031 sec", so how can I solve this problem?
There are a number of commands, including source, that are only recognized by the MySQL command-line client. See https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
These commands are parsed and handled by that client, and are not sent to the MySQL Server. This makes them different from all other SQL statements, which are sent to the server to be parsed and executed.
Other clients, such as MySQL Workbench, phpmyadmin, and other developer tools, would need to implement support for those special client-side commands themselves. Few of them do.
Likewise when you write code to use the MySQL API in your own applications, unless you pre-check the SQL statement and handle the special client-only commands yourself, they are not supported.

Strange syntax error in simple CREATE TABLE command - PostgreSQL, MySQL, & SQLite

I am getting a syntax error with PostgreSQL, MySQL, & SQLite that I don't understand. It occurs when the same CREATE TABLE command is run from Python and as a Query in pgAdmin4 and MySQL WorkBench. The same command works perfectly on SQL Server, using MS SQL Server Management Studio.
The command is:
create table asDataSpecs ( NumField1 integer, CharField1 char(30), CharField2 char(30) )
pgAdmin4 displays the error message:
LINE 1: ...e asDataSpecs ( NumField1 integer, CharField1 char(30), Char...
^
SQL state: 42601
Character: 62
MySQL generates an "Error Code: 1064" at the same point:
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 '(30), CharField2 char(30) )' at line 1
PostgreSQL & MySQL understandably fail at the same point when this command is run in Python - as a .execute() on a cursor connected to the appropriate back-end and database.
SQLite (run using .execute() in the same Python program) produces an error presumably at the same point:
Failed 'Try' while attempting to create the 'asDataSpecs' table
near "(": syntax error
Why do PostgreSQL, MySQL, & SQLite accept the "integer" field, but reject the first "char" one - yet MS SQL Server runs it OK?
(I don't think it is a credentials issue, as I successfully used ODBC with the same credentials to create other tables in the same database - in all four backends. I would expect different error messages, if credentials were the issue - and it should not accept the numeric field.)
That was it - funky hidden characters. (There was some high-ASCII character instead of a normal space (ASCII 32) between the field name and data type.)
All platforms now work as expected, both in the Python program and the respective back-end management consoles.
For anyone who is interested, even NotePad++ displayed this as a space. But basic Windows NotePad revealed the mystery.
Thanks again, "sticky bit".

Error code: 1064 in MySQL when create SOURCE?

I want to use my SQL'book_data2' file from the desktop E drive as a 'SOURCE'. But I am getting an error code 1064 in MySQL workbench. Could you help me for that issue? I am giving the code and action output below.
Code:
SOURCE E:\DataPractice\Practice\book_data2.sql;
Action Output:
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 'SOURCE E:\DataPractice\Practice\book_data2.sql' at
line 1 0.000 sec
There are a number of commands that are supported by the mysql client (that is, the command-line client, not MySQL Workbench), but they are parsed in the client, not sent to the server as SQL statements. The MySQL Server does not recognize these commands.
It can be confusing, but remember both the client and the server may process commands. You just have to read the documentation to learn which commands are in the list of client-only commands:
https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
(Except USE, which is recognized by both mysql client and server, just to make sure there's an exception to every rule!)
If you want to use MySQL Workbench to "source" an SQL file, in other words load a file, read the SQL commands in that file, and execute them, Workbench does support this action, but they call it Data Import/Restore. It's documented here: https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html

Sql Syntax error with Doctrine, probably because of change of Mysql version

I've programmed a project in symfony and mysql 5.6. then I uploaded my project to a remote server on 1&1. the remote server has mysql 5.7 version. All doctrine queries run ok and without problem. But when a user searches something, a request will be sent to the server and a doctrine query will be executed. Here it returns the following error:
SQLSTATE[42000]: Syntax error or access violation: 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 'integer)
BETWEEN 1940 AND 2002) AND u0_.id <> 2' at line 1
I think, it is probably because of different versions of mysql. Because on localhost it runs without problem
Can you please help me how to solve it? is there a way to regenerate all the migrations according the new mysql version? or may be there is another solution?
thanks
I was using CAST('number' as integer) in mysql 5.6. It did ok. However in mysql 5.7 and I do not know why, it does not run ok. So I changed it to CAST('number' as UNSIGNED) and it works ok

Error when SQL query called from C program

I want to execute SOURCE data/keyw.sql from C program. This query works fine when I execute from the command line but gives the following error on executing mysql_query(con, "SOURCE data/keyw.sql")
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 'SOURCE data/keyw.sql' at line 1
Any help would be highly appreciated.
The SOURCE command is not executed on the MySQL server. It is interpreted by the mysql Client, and is basically just a convenience.
Quote from MySQL documentation:
mysql sends each SQL statement that you issue to the server to be executed. There is also a set of commands that mysql itself interprets. For a list of these commands, type help or \h at the mysql> prompt:
Note that source is one of those listed. If you want to know how it works, then have a look at the source code for the mysql Client.
If your source to be executed contains more than one MySQL statement then your connection will need to support multiple statement execution, or alternatively you need to parse the SQL into individual statements yourself.