Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid default values in show create output #141

Merged

Conversation

jeroenpf
Copy link
Contributor

This PR addresses an issue where the output of show create table is incorrect when the table has a NULL column without a default value.

Here is an example:

-- Original MySQL query

CREATE TABLE `wp_usermeta` (
	`umeta_id` bigint(20) unsigned NOT NULL auto_increment,
	`user_id` bigint(20) unsigned NOT NULL default '0',
	`meta_key` varchar(255) default NULL,
	`meta_value` longtext,
	PRIMARY KEY  (`umeta_id`),
	KEY `user_id` (`user_id`),
	KEY `meta_key` (`meta_key`(191))
)

-- Output by `SHOW CREATE TABLE` via SQLite plugin

CREATE TABLE `wp_usermeta` (
	`umeta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
	`user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
	`meta_key` varchar(255) DEFAULT NULL,
	`meta_value` longtext DEFAULT , -- Default value missing
	PRIMARY KEY (`umeta_id`),
	KEY `meta_key` (`meta_key`),
	KEY `user_id` (`user_id`)
);

-- After this fix

CREATE TABLE `wp_usermeta` (
	`umeta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
	`user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
	`meta_key` varchar(255) DEFAULT NULL,
	`meta_value` longtext,
	PRIMARY KEY (`umeta_id`),
	KEY `meta_key` (`meta_key`),
	KEY `user_id` (`user_id`)
);

@jeroenpf jeroenpf changed the title Fix show create returning invalid create statement for NULL columns w… Fix invalid default values in show create output Jul 30, 2024
Copy link
Member

@aristath aristath left a comment

Choose a reason for hiding this comment

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

Great catch!
Fix looks good 👍

@aristath aristath merged commit c2d9d32 into WordPress:develop Jul 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants