MariaDB problem inserting NULL date
-
Hi SGaist, if I comment this line: Query.bindValue(":data_dimissione", Dimissione); I haven't errors.
I this the correct way? -
I would have tested with the equivalent of:
INSERT INTO Assunzioni (Dipendenti_id, Livelli_id, Scadenze_id, data_assunzione) VALUES(2, 1, 1, 20201114)
So no mention of
data_dimissione
in the query at all. -
Ah ok!
Without data_dimissione works fine. -
Hi SGaist, if I comment this line: Query.bindValue(":data_dimissione", Dimissione); I haven't errors.
I this the correct way?@Stefanoxjx said in MariaDB problem inserting NULL date:
Query.bindValue(":data_dimissione", Dimissione);
What's the value of Dimissione in this case?
-
@Stefanoxjx said in MariaDB problem inserting NULL date:
Query.bindValue(":data_dimissione", Dimissione);
What's the value of Dimissione in this case?
@Christian-Ehrlicher said in MariaDB problem inserting NULL date:
@Stefanoxjx said in MariaDB problem inserting NULL date:
Query.bindValue(":data_dimissione", Dimissione);
What's the value of Dimissione in this case?
If Dimissione is (for example) 20201115 all works fine.
If Dimissione is NULL I've an error. -
@Stefanoxjx said in MariaDB problem inserting NULL date:
If Dimissione is NULL I've an error.
Since it's a QVariant, it can't be 'NULL' - only QVariant::isNull() or isValid() can return true. Do you mean than QVariant::isNull() returned true?
-
@Stefanoxjx said in MariaDB problem inserting NULL date:
If Dimissione is NULL I've an error.
Since it's a QVariant, it can't be 'NULL' - only QVariant::isNull() or isValid() can return true. Do you mean than QVariant::isNull() returned true?
@Christian-Ehrlicher
Doubtless you are right, and this will prove the nub of the issue, but the OP said originally:INSERT INTO Assunzioni (Dipendenti_id, Livelli_id, Scadenze_id, data_assunzione, data_dimissione) VALUES(2, 1, 1, 20201114, NULL)
and
Incorrect date value: 'NULL' for column
db.
assunzioni.
data_dimissioneat row 1
but you'd think that
NULL
at the end implied that the statement had been generated as desired? -
I'm not sure if the prepared statement quotes strings so it can still be NULL as string, therefore my question. And if it's really QVariant::isNull() then a simple reproducable example would be nice.
-
Reading your reply, I tought that my error was to have defined Dimissione as QString.
Then, I've tried this solution:if(...condition...) QVariant Dimissione = QVariant(); qDebug() << "QVariant::IsNull " << Dimissione.isNull(); ... Query.bindValue(":data_dimissione", Dimissione); ...
So, QVarinat::IsNull return true, and I haven't errors in Query.exec()
I learned a new thing :)
Thanks for your invaluable help.
-
Reading your reply, I tought that my error was to have defined Dimissione as QString.
Then, I've tried this solution:if(...condition...) QVariant Dimissione = QVariant(); qDebug() << "QVariant::IsNull " << Dimissione.isNull(); ... Query.bindValue(":data_dimissione", Dimissione); ...
So, QVarinat::IsNull return true, and I haven't errors in Query.exec()
I learned a new thing :)
Thanks for your invaluable help.
@Stefanoxjx Nice to hear, can you please mark this topic as solved then?