Error in mysql database in Qt - mysql

I wrote this sql codes in qt5 in ubuntu. I want to update a table. But I received following error:
QSqlError(1065, "QMYSQL: Unable to execute query", "Query was empty")
This is my sql code:
query4.prepare("update food_main set cost=:material_cost,"+material+"=:material_num where name='"+material_name+"'");
query4.bindValue(":material_cost",material_cost);
query4.bindValue(":material_num",material__num);
query4.exec();
I must say that my table updates every time I run my code but I have the error too. Table and columns and variables were made in right method. What should I do?

Related

Pentaho "Couldn't get row from result set" error

When I run this query on my MySql client (DBVisualizer) it runs. (It functions and works 100%)
SELECT
MAX(birth_date) AS max_bd
INTO
#bd_max
FROM
employees.birthdays
WHERE
gender= 'male';
When I run it in Pentaho, in a "Execute SQL script" I get this error
2018/11/04 10:44:08 - job_update_birthdays - ERROR (version 7.1.0.0-12, build 1 from 2017-05-16 17.18.02 by buildguy) : An error occurred executing this job entry :
2018/11/04 10:44:08 - job_update_birthdays - Couldn't get row from result set
2018/11/04 10:44:08 - job_update_birthdays - ResultSet is from UPDATE. No Data.
P.S. I am using the same credentials for both Pentaho and my Mysql client.
You're using a command that doesn't acutally returns data. In SQL, the INTO command will copy the data from the SELECT, INTO another table, what SQL is doing is probably just showing you the data that was copied to the target table.
Remove the INTO #bd_max clause from the query and run it.

MySQL error "An alias was previously found" when an alias isn't in the query

I have a very odd error while trying to perform an update on a database. This is on an Ubuntu 16.04 server using MySQL 5.7.19-0ubuntu0.16.04.1. The query is:
UPDATE athlet_teamseason SET offkeyreturners = 'test' WHERE athlet_teamseason.id = 29701;
The MySQL error is:
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 'offkeyreturners = 'test' WHERE athlet_teamseason.id = 29701' at line 1
I am doing this in phpMyAdmin, and it gives a bit more information:
2 errors were found during analysis.
An alias was previously found. (near " " at position 50)
An alias was previously found. (near "'test'" at position 51)
If I try this update directly in the phpMyAdmin user interface (search for record, edit field value, submit form) it works, and the query shown is:
UPDATE athlet_teamseason SET offkeyreturners = 'test' WHERE athlet_teamseason.id = 29701;
which appears to be identical. HOWEVER, if I do a string comparison between the two I get:
So while they appear to be the same, there is a difference somewhere.
The queries were created from a table in a database, using concatenation and referencing cells in a source table. For example:
="UPDATE athlet_teamseason SET offkeyreturners = '"&data!I2&"' WHERE athlet_teamseason.id = "&data!A2&";"
I have thousands of these and they all produce the same error. I've done this dozens of times in older servers, might be an issue with MySQL 5.7?
Thanks to Uueerdo, I eliminated non-printing characters in my query.

Error While importing Schema in sql

Hey guys im trying to import schema from mysql vesion 5.0 to 5.1. Every time i'm trying to import schema I got this error:
Error near Drop Proceduer service_tt_yes'
MySql.Data.MySqlClient.MySqlException: Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted.
I try to skip that procedure but error occur in next procedure.
Any solution!
You can probably use following command in MySQL Client
USE DATABASE_NAME; SOURCE [QUALIFIED-LOCATION]IMPORTED_SCHEMA.sql
Like if you have IMPORTED_SCHEMA.sql in D: drive then fire following command. Note there is no semi colon in the end
SOURCE D:\IMPORTED_SCHEMA.sql

SSIS Execute SQL Task SQL Command Issue

I have the following insert statement in my execute sql task in SSIS:
INSERT INTO dbo.SSISLogTest
(NodeID, BusinessDate, StartDate, StopDate, StepName, RecordCount, Message, Status, UserID)
VALUES (?,?,?,?,?,?,?,?,?)
When I run it within the task providing parameters it executes fine and inserts a record in the table.
When I run the package, this step fails with the following error:
"[Execute SQL Task] Error: Executing the query "INSERT INTO
dbo.SSISLogTest
..." failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with the
query, "ResultSet" property not set correctly, parameters not set
correctly, or connection not established correctly. "
Different connection providers require different syntax - all of the following must be set correctly:
The connection type (i.e. OLE DB, ADO...) Your choice, but aim to use the same throughout your application.
The number and specifics (Variable Name, Direction, Data Type, Parameter Name, Parameter Size) of parameters on the "Parameter Mapping" dialog.
The parameter syntax in the SQL query (i.e. your question marks.)
Please see an OLEDB example in the screenshots below and refer to Working with Parameters and Return Codes in the Execute SQL Task for details.

Cannot use a MySQL UDF function

I have loaded an UDF function into MySQL (without having selected any particular DB). It used to work well during my session but now I get the error "ERROR 1305 (42000): FUNCTION currentdatabase.myfunction does not exist" when I try to use the function with the following sql statement :
select myfunction('aaa');
I then tried to drop the function and I got the same error code :
mysql> drop function myfunction;
ERROR 1305 (42000): FUNCTION database.myfunction does not exist
if a DB is selected.
Another error code otherwise :
ERROR 1046 (3D000): No database selected
So I decided to specify again the function and I got the following error code :
CREATE FUNCTION myfunction RETURNS INT SONAME 'myfunction.so';
ERROR 1125 (HY000): Function 'myfunction' already exists
My question is: how to use again my function ?
Thanks in advance.
Note: there is no space problem like ("select myfunction ('aaa');") as reported on several other websites.
I recently encountered this issue my self and I put together a quick blog post about it:
When installing a UDF recently I got an
annoying error message, which didn't seem to want to go away. Deleting
the function before attempting to remove it did not work so I used the
following set of escalating commands to attempt to get it to
install. But back to the error for a moment:
bash > mysql -u user -p < installdb.sql
Enter password:
ERROR 1125 (HY000) at line 7: Function 'lib_mysqludf_ssdeep_info' already exists This can be
solved really simply with the following options:
Attempt
to delete the function and then reinstall it Delete the
function row from the mysql.func table and then reinstall it
Stop the MySQL server (after trying option 2), start it again and
then reinstall it
From my testing you do not need to have backups of your binary database files as #jmcejuela suggests in his answer.
Source: http://simonholywell.com/post/2012/01/mysql-udf-install-error-function-already-exists.html
I believe the problem comes from removing the .so library before dropping the function/s. The server still believes it has the functions since they appear in SELECT * FROM mysql.func but of course calling these functions fail. Somehow DROP doesn't simply remove entries in this table but also checks whether the libraries are found which makes this fail. CREATE supposedly just check first the func table which makes this fail...
The solution is to restore the func table (func.MYI, func.MYD, func.frm files under your mysql's data/mysql) to the point everything matches.
Luckily I had a backup of these files. Otherwise you will have to backup them from a new mysql installation (you could simply install locally a new server not to remove your current one)
Bottom line: do not remove the .so libraries before dropping the functions.
Got some of these errors when swapping out (not dropping) the .so library before dropping the function(s).
Restarting the server eliminated the error messages, whether the functions were successfully dropped or not. Mysqld just looked at the mysql.func table and loaded functions from the (new) .so. I know restarting the server is not always an option, but if it is, it's fast and complete.