?
avatar phalouvas
phalouvas
6 Dec 2017

Steps to reproduce the issue

Run below code in any model file.

$db = $this->getDbo();
$db->setQuery(
   "INSERT INTO " . $destination_db->qn('#__categories') .
    " (id)" .
    " VALUES (0)"
);
try {
  $destination_db->execute();
} catch (\RuntimeException $exc) {
   echo $exc->getMessage();
}

Expected result

Create an empty new row in table categories

Actual result

You get error message:
Field 'description' doesn't have a default value

System information (as much as possible)

I attach php Info of my system, even though, that does not seem to be relevant.
phpInfo.pdf

Additional comments

When I run above SQL directly from phpMyAdmin it runs without problems.

As a temporary solution, if you run below:

$db->setQuery("set @@sql_mode = ''");
$db->execute();

before the execution of the insert, then it runs as expected.

If you run :

$db->setQuery('SELECT @@GLOBAL.sql_mode;');
echo "Global: ".$db->loadResult()."<br>";
$db->setQuery('SELECT @@SESSION.sql_mode;');
echo "Session: ".$db->loadResult();

then you get:
Global: NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Session: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

The STRICT_TRANS_TABLES should not be there.

This was problem back in 2010 and is described here: MySQL strict mode incompatibility

Up to Joomla 3.5 no such problem exists, but it reappear in Joomla 4, so something is wrong with MySQLi adapter.

avatar phalouvas phalouvas - open - 6 Dec 2017
avatar joomla-cms-bot joomla-cms-bot - change - 6 Dec 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 6 Dec 2017
avatar joomla-cms-bot joomla-cms-bot - edited - 6 Dec 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 6 Dec 2017
Category com_categories SQL
avatar stutteringp0et
stutteringp0et - comment - 6 Dec 2017

In J4:
libraries/vendor/joomla/database/src/Mysqli/MysqliDriver.php
libraries/vendor/joomla/database/src/Mysql/MysqlDriver.php

both set STRICT_TRANS_TABLES

It isn't in J3.8.2

avatar stutteringp0et
stutteringp0et - comment - 6 Dec 2017

In 3.8.2 - the mysqli driver sets sql_mode:
// Set sql_mode to non_strict mode
mysqli_query($this->connection, "SET @@SESSION.sql_mode = '';");

and the mysql driver sets sql_mode:
// Set sql_mode to non_strict mode
mysql_query("SET @@SESSION.sql_mode = '';", $this->connection);

avatar franz-wohlkoenig franz-wohlkoenig - change - 6 Dec 2017
Status New Discussion
avatar brianteeman
brianteeman - comment - 6 Dec 2017
avatar phalouvas
phalouvas - comment - 6 Dec 2017

I don't get it. Will this be changed, or we have to manually remove strict mode each time we need to insert an empty row to any table?

avatar mbabker
mbabker - comment - 6 Dec 2017

The query in the OP should rightfully fail as it's not inserting a valid record into the database. IMO that is not a good example to be basing this issue off of.

IIRC it was a deliberate decision to enable strict mode because of changes in the MySQL platform. I honestly don't remember the full conversation anymore though.

avatar brianteeman
brianteeman - comment - 5 Jan 2018

Closed as stated above

avatar brianteeman brianteeman - change - 5 Jan 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-01-05 21:58:58
Closed_By brianteeman
avatar brianteeman brianteeman - close - 5 Jan 2018

Add a Comment

Login with GitHub to post a comment