-1

Table Structure:

CREATE TABLE `setup_int` (
    `key` VARCHAR(50) NOT NULL,
    `val` INT(11) NOT NULL,
    PRIMARY KEY (`key`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB

As you can see the fields are NOT NULL-Fields and have no default value.

We updated to MariaDB 10.1.21 and have the following issue now: The following query fails without any error message!

INSERT INTO `setup_int` (`key`) VALUES ('test');

The reason seems to be the missing default value.

  • If I add an default value to the table, the insert is successfull.
  • If I change the NOT NULL to NULL, the insert is successfull.
  • IF I do it on MariaDB 10.1.20, the insert is successfull.
  • If I do the insert with both fields the insert is successfull.

This works:

INSERT INTO `setup_int` (`key`,`val`) VALUES ('test',0);

The question is: What can I do (some setting, or something else) to make mariadb 10.1.21 to handle this situation like before. I cannot alter all tables right now and i cannot downgrade right now.

The main issue is that the query executed by PHP returns true although the insert failed!

steven
  • 4,868
  • 2
  • 28
  • 58
  • 1
    I fail to see what the problem is here. If you setup a table and tell it that `val` cannot be NULL then you have to provide a value for `val` on every insert. So if you cannot provide that value remove the `NOT NULL` or add a DEFAULT – RiggsFolly Feb 16 '17 at 09:32
  • @RiggsFolly I agree, this behavior seems normal and expected. – Tim Biegeleisen Feb 16 '17 at 09:32
  • If leaving `val` empty worked in 10.1.20 then there must have been a bug in 10.1.20, so reverting will mean you can ever again upgrade the database – RiggsFolly Feb 16 '17 at 09:33
  • Yes ist is correct, I agree, but it is not the same behaviour as before. – steven Feb 16 '17 at 09:33
  • Please show the missing PHP code. Which API you use, PDO, MySQLi,... – Daniel W. Feb 16 '17 at 09:39
  • This may explain that 10.1.20 had a bug in this area https://jira.mariadb.org/browse/MDEV-11698 – RiggsFolly Feb 16 '17 at 09:41
  • _The question is: What can I do (some setting, or something else) to make mariadb 10.1.21 to handle this situation like before._ You are asking us how to reapply a bug! You are going to have to fix all your tables as you do not want this bug re-applied – RiggsFolly Feb 16 '17 at 09:42
  • @RiggsFolly Yes, I am asking this. I am not happy with this. And it is just a quick fix. I will change the table structure as fast as possible. But I searched for solution which is aplicable for lot of customers and lot of tables quickly. – steven Feb 16 '17 at 09:47
  • @RiggsFolly But can you confirm that the failed query should return a query-error message instead not being executed and not throwing an error. This seems to be a another bug. – steven Feb 16 '17 at 09:58
  • Well that depends on your PHP code, and whether you are actually checking for an error or just ignoring it. – RiggsFolly Feb 16 '17 at 10:01
  • @RiggsFolly I am not talking about an php error but about an mysql-error. There is no error or warning when trying to insert via console directly. – steven Feb 16 '17 at 11:43

2 Answers2

1

Take a look here: https://stackoverflow.com/a/2503938/1973205

And then you can set the variables like this: https://mariadb.com/kb/en/mariadb/sql-mode/

As a pure logic fact, it's correct that the query fails.

Community
  • 1
  • 1
Theraloss
  • 700
  • 2
  • 7
  • 30
  • Thanks for this. But I think there is no Mode-Value for the given behaviour. As I think you wrote the closest answer to my question i will accept it. It seems to be the case that i have to update all my table structures right now. Thanks anyway. – steven Feb 16 '17 at 09:51
0

Basically you set a constraint that the value of val must not be NULL and it fails because you try to set it NULL.

(0 is not the same as NULL.)

The default value is set during CREATE:

CREATE TABLE `setup_int` (
    `key` VARCHAR(50) NOT NULL,
    `val` INT(11) NOT NULL DEFAULT 0,
    PRIMARY KEY (`key`)
)
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 1
    Yes, I know this. But that wasn't the question. The question was: what else can i do to make it working but changing the stucture of my tables. – steven Feb 16 '17 at 09:35