Skip to content

Conversation

@Hackwar
Copy link
Member

@Hackwar Hackwar commented Aug 1, 2019

This hopefully changes all datetime values for com_content from the pseudo-null-date 0000-00-00 00:00:00 to a real null value.

@joomla-cms-bot joomla-cms-bot added NPM Resource Changed This Pull Request can't be tested by Patchtester PR-4.0-dev labels Aug 1, 2019
@richard67
Copy link
Member

richard67 commented Aug 1, 2019

@Hackwar I don't think the database schema checker/fixer understands this in the schema update for MySQL:

ALTER TABLE #__content
MODIFY created DATETIME NULL DEFAULT NULL,
MODIFY modified DATETIME NULL DEFAULT NULL,
MODIFY publish_up DATETIME NULL DEFAULT NULL,
MODIFY publish_down DATETIME NULL DEFAULT NULL;

I think it needs a single line statement for each column for the database schema checker/fixer:

ALTER TABLE #__content MODIFY created DATETIME NULL DEFAULT NULL;
ALTER TABLE #__content MODIFY modified DATETIME NULL DEFAULT NULL;
ALTER TABLE #__content MODIFY publish_up DATETIME NULL DEFAULT NULL;
ALTER TABLE #__content MODIFY publish_down DATETIME NULL DEFAULT NULL;

You could see that here:

https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Schema/ChangeItem/MysqlChangeItem.php#L149-L175

@richard67
Copy link
Member

@Hackwar Regarding my comment above: I mean that the database checker will only check the first column modification if you have all in 1 alter table statement. But when the check shows for the first column that the statement has not run yet, it will run the complete statement.

So it is formally not correct to have all in 1 statement.

On the other hand, it might be necessary that we do it like this in MySQL 8, and maybe also lower, if strict mode is on. I noticed on MySQL 8 that when running such statement for a single column in PhpMyAdmin on MySQL8, I get an SQL error complaining about the other column not having a valid default value.

If it turns out we have to do that and so betray the database checker a bit (but it would work), then we have to do that everywhere where this change for real null columns has been made already, because I've seen in schema updates of those PR that they did it like I suggested, with 1 alter table statement for every column.

@richard67
Copy link
Member

@Hackwar When running in PhpMyAdmin on MySQL 5.7 with strict mode on, I even have to add the checked_out_time column to make it work, and I have to do all with 1 statement:

ALTER TABLE #__content
MODIFY created DATETIME NULL DEFAULT NULL,
MODIFY modified DATETIME NULL DEFAULT NULL,
MODIFY checked_out_time DATETIME NULL DEFAULT NULL,
MODIFY publish_up DATETIME NULL DEFAULT NULL,
MODIFY publish_down DATETIME NULL DEFAULT NULL;

@richard67
Copy link
Member

@Hackwar I've just tested, it needs 1 statement for each column. I will make PR against your repo.

Question is: Don't you want to do the checked_out_time here, too, and close the other PR which does checked_out_time for all?


$advClause[] = '(c2.publish_up = ' . $nullDate . ' OR c2.publish_up <= ' . $nowDate . ')';
$advClause[] = '(c2.publish_down = ' . $nullDate . ' OR c2.publish_down >= ' . $nowDate . ')';
$advClause[] = '(ISNULL(c2.publish_up) OR c2.publish_up <= ' . $nowDate . ')';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ISNULL(...) will not work on PostgreSQL @alikon Confirmed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meanwhile I've researched and am sure, there is no isnull function in postgresql, it is a mysql special, so you can't use it. I've added the correction to my against your repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Quy Sure? Does it also work with real NULL values?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Quy I see, it does work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Quy But there are places like the one above where ther is not really used a query object used. Should he do that there, too, and use a query object for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the initial PR #21901 that did this way to base off of.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for postgresql there are 2 choices
SELECT (Field IS NULL) FROM ...
or
COALESCE() which is ISO/ANSI SQL standards

@Hackwar
Copy link
Member Author

Hackwar commented Aug 1, 2019

I'm going to change the ISNULL to IS NULL and see where the issue in the install SQL is. I would keep the original PR for checked_out and simply provide PRs for everything else and then we can merge everything.

@Hackwar
Copy link
Member Author

Hackwar commented Aug 1, 2019

I will of course do the getNullDateTime() call.

@richard67
Copy link
Member

Which issue in the install SQL?

@alikon
Copy link
Contributor

alikon commented Aug 2, 2019

some work (for prepared statement) has been done even if in draft wip pr #25179 maybe can help

case 'SERVER_UTC':
// Convert a date to UTC based on the server timezone.
if ($this->value && $this->value != Factory::getDbo()->getNullDate())
if ($this->value && strlen($this->value) && $this->value != Factory::getDbo()->getNullDate())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this fit better?
if ($this->value !== NULL && $this->value != Factory::getDbo()->getNullDate())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the value could be an empty string, which isn't null.

break;
}

if ($return == '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($return == '')
if ($return === '')


// Check the publish down date is not earlier than publish up.
if ($this->publish_down < $this->publish_up && $this->publish_down > $this->_db->getNullDate())
if (!is_null($this->publish_up) && !is_null($this->publish_up) && $this->publish_up > $this->publish_down)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use === NULL not is_null in code style or?

Suggested change
if (!is_null($this->publish_up) && !is_null($this->publish_up) && $this->publish_up > $this->publish_down)
if ($this->publish_up !== NULL && $this->publish_up !== NULL && $this->publish_up > $this->publish_down)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HLeithner We use both it seems, but is_null() we use by far more often.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc @mbabker changed it in the frame work from is_null to !== NULL I'm and sure if the coding style says anything about this. At least we should use the same in all places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_null() is slower. Also null must be in lowercase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our codestyle has no rules regarding that. If you want us to refactor to that, then I would ask to make a separate issue for that. You might want to bring that up in the ATT. 😉

@Quy
Copy link
Contributor

Quy commented Oct 14, 2019

Replaced by #26295.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/25760.

@richard67
Copy link
Member

@Quy Same for PR #25715 , will be replaced by #26491 and #26490 .

@Hackwar Hackwar deleted the j4mysql8content branch October 23, 2020 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NPM Resource Changed This Pull Request can't be tested by Patchtester

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants