MariaDB unexpected token near returning - mariadb

so I set up a new MariaDB Database and tried to insert some data into a table with this code:
INSERT INTO address VALUES (default, 'Test', 'Test', 'Test', 'Test', 'Test') RETURNING id;
This is my table structure:
The error I am getting is telling me that there is an unexpected token near "Returning id" and I really don't have any idea, what exactly is wrong here.
I am using: 10.4.22-MariaDB - mariadb.org binary distribution.
Can anyone help me out?
Thank you in advance.

Related

I am using QSqlTableModel in Qt, but select function is returning a false

I am having problems using the select function for QSqlTableModel. It always returns false and I have been unable to figure out why.
I have setup a SQL Database using PostgreSQL. I was able to add the database using QSqlDatabase::addDatabase and I have been able to use QSqlQuery to pull data from the database and create new tables and new rows to tables. I am now trying to display the database in a TableView. I found that you can create the QSqlTableModel to plug into the TableView. However, it is failing on the "select" step.
Here is the code I am running:
_database = loadDatabase();
qDebug()<<"table database name: "<<_database.databaseName()<<endl; //Returns: table database name: "postgres"
qDebug()<<"table database isOpen: "<<_database.isOpen()<<endl; //Returns: table database isOpen: true
qDebug()<<"table database tables: "<<_database.tables()<<endl; //Returns: table database tables: ("Test", "testtable")
qDebug()<<"last error: "<<_database.lastError().text()<<endl; //Returns: last error: " "
_tableModel = new QSqlTableModel(this,_database);
_tableModel->setTable(_database.tables().at(1));
_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
if(_tableModel->select()){
qDebug()<<"Table was selected!"<<endl;
}
else{
qDebug()<<"Table could not be selected"<<endl;
}
qDebug()<<"is database valid: "<<_database.isValid()<<endl; //Returns: is database valid: true
"_database" is defined as a QSqlDatabase. It always returns "Table could not be selected".
I found an answer on Stack Overflow that suggested to check whether the database isOpen(), the table name is correct, and if there is any error messages with lastError(). I included those answers in the debug statements in my code. Everything appears to be correct, but yet it returns a false.
Any help would be greatly appreciated. Thanks!
I figured it out. It is a problem with PostgreSQL. Specifically, versions later than 10 or 11 seem to not work with QSqlTableModel. I was using version 13. There was some kind of change in the code that broke this with Qt. Nonetheless, its reported as a Qt bug.
Here is the Qt bug report:
https://bugreports.qt.io/browse/QTBUG-79033
It looks like you can use a patch. I ended up reverting mine to an earlier version to fix it.
Thanks for the help!

Mariadb alter table column data type error, wrong column

I am having a bit of a problem with mariadb with the following query
ALTER TABLE archive_maindata CHANGE monthly_income monthly_income decimal(25,4) DEFAULT '0.0000';
but I got this error,
Additional information: Incorrect date value: '0000-00-00' for column 'expiry_date' at row 3'
I can't figure out what it is that I am doing wrong, I am not trying to change the expire_date column as you can see in the query. Any help would be appreciated
Thanks in advance
Sounds like you updated MariaDB at some point and the default SQL_MODE in the later version defaults to STRICT_TRANS_TABLES which will disallow a date/time that is all zeros. The default changed with MariaDB 10.2.4.
You need to either fix the dates so they are valid or change the SQL_MODE to disable STRICT_TRANS_TABLES. The error you are getting is MariaDB trying to help you by warning you that you have data that is not valid.

SQL : Error inserting email string into a row

I am writing a simple program in python that links to an SQL database for storing data, I have been testing all the queries that I want to run in the Sqlite3 shell before taking them across to python so that I know they work.
INSERT INTO Account (emailAddress, password) VALUES ('n.winspear1#gmail.com', 'testing');
I can't seem to get this one working it keeps throwing...
Error: near "#gmail": syntax error
I'm not sure what's wrong with the syntax, I'm assuming it's something quite simple, I am somewhat new to SQL so I don't know all the syntax.
Table Creation:
CREATE TABLE Account (
accountID INTEGER PRIMARY KEY AUTOINCREMENT,
emailAddress TEXT NOT NULL,
password TEXT NOT NULL);
Any help is appreciated.
Thanks :)
INSERT INTO Account (emailAddress, password) VALUES ("n.winspear1#gmail.com", "testing");

TERADATA HELP COLUMN

Database ua_dillards;
HELP TABLE deptinfo;
HELP COLUMN nullable FROM deptinfo;
.... writing these queries but always end up with this error:
... Error Code - 5628 Error Message - [Teradata Database] [TeraJDBC
15.10.00.05] [Error 5628] [SQLState HY000] Column nullable not found in UA_DILLARDS.deptinfo.,,,,, HELP!!
But column Nullable is present in data table... cross checked using HELP TABLE.
I am writing these queries in TERADATA VIEWPOINT.
for all the information about a column help column deptinfo.nullable;
or you may query the dbc-table directly
select ColumnName, Nullable from dbc.columnsV where databasename ='ua_dillards' and TableName = 'deptinfo'
Nullable is a column in the result set of a HELP TABLE.
The rows of that result are the columns in the table.
Btw, most people prefer SHOW TABLE over HELP TABLE.

SQL - PL/SQL Writing a basic function and running it to query a result

I have the table 'Company' populated with multiple tuples/rows. One of which is Microsoft for the 'Company_name' field and the 'City' field is populated as Redmond.
I have compiled this PL/SQL file.
-- Create a function that will return the city where company X is located.
-- X will be the parameter supplied by the caller.
-- Test your function with the company of your choice.
CREATE OR REPLACE FUNCTION company_location_city(x IN company.company_name%TYPE)
return company.city%TYPE IS
company_location company.city%TYPE;
BEGIN
select city into company_location
from company
where company_name = x;
return company_location;
END;
and ran it with this line.
select company_location_city('Microsoft') from dual;
I get this error, and I don't understand what it is trying to tell me. Of course we encountered select.
I am running the Oracle flavor.
Error(12,1): PLS-00103: Encountered the symbol "SELECT"
Also the query result showing an error should help.
ORA-06575: Package or function COMPANY_LOCATION_CITY is in an invalid state
06575. 00000 - "Package or function %s is in an invalid state"
*Cause: A SQL statement references a PL/SQL function that is in an
invalid state. Oracle attempted to compile the function, but
detected errors.
*Action: Check the SQL statement and the PL/SQL function for syntax
errors or incorrectly assigned, or missing, privileges for a
referenced object.
Error at Line: 16 Column: 8
The PLS prefix of the error says that it is pl\sql engine error. Hence it means that your sql code was treated as pl\sql because of the function ddl code which is pl\sql. You mixed up sql and pl/sql , you should split them by delimiter or remove one of the types of code.

Resources