Skip to content

Commit 3c4372a

Browse files
authored
Merge pull request #63 from wp-cli/bigint_primary_key
Allow for BIGINTs in esc_sql_value().
2 parents b447337 + 7ef4af5 commit 3c4372a

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

features/search-replace.feature

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -983,27 +983,50 @@ Feature: Do global search/replace
983983
Given a WP install
984984
And a test_db.sql file:
985985
"""
986-
DROP TABLE IF EXISTS `wp_123_test`;
987986
CREATE TABLE `wp_123_test` (
988987
`name` varchar(50),
989988
`value` varchar(5000),
990989
`created_at` datetime NOT NULL,
991990
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
992991
PRIMARY KEY (`name`)
993992
) ENGINE=InnoDB;
994-
INSERT INTO `wp_123_test` VALUES ('test_val','off','2016-11-15 14:41:33','2016-11-15 21:41:33');
995-
INSERT INTO `wp_123_test` VALUES ('123.','off','2016-11-15 14:41:33','2016-11-15 21:41:33');
996-
INSERT INTO `wp_123_test` VALUES ('quote\'quote','off','2016-11-15 14:41:33','2016-11-15 21:41:33');
997-
INSERT INTO `wp_123_test` VALUES ('0','off','2016-11-15 14:41:33','2016-11-15 21:41:33');
998-
INSERT INTO `wp_123_test` VALUES ('','off','2016-11-15 14:41:33','2016-11-15 21:41:33');
999-
"""
993+
INSERT INTO `wp_123_test` VALUES ('test_val','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
994+
INSERT INTO `wp_123_test` VALUES ('123.','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
995+
INSERT INTO `wp_123_test` VALUES ('quote\'quote','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
996+
INSERT INTO `wp_123_test` VALUES ('0','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
997+
INSERT INTO `wp_123_test` VALUES ('','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
998+
INSERT INTO `wp_123_test` VALUES ('18446744073709551616','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
999+
INSERT INTO `wp_123_test` VALUES ('-18446744073709551615','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
1000+
INSERT INTO `wp_123_test` VALUES ('123456789012345678801234567890','wp_123_test_value_X','2016-11-15 14:41:33','2016-11-15 21:41:33');
10001001
1001-
When I run `wp db query "SOURCE test_db.sql;"`
1002-
Then STDERR should be empty
1002+
CREATE TABLE `wp_123_test2` (`bigint_unsigned_key` BIGINT UNSIGNED NOT NULL, `value` VARCHAR(255), PRIMARY KEY (`bigint_unsigned_key`) );
1003+
INSERT INTO `wp_123_test2` VALUES ('18446744073709551615','wp_123_test2_value_X');
1004+
1005+
CREATE TABLE `wp_123_test3` (`bigint_signed_key` BIGINT SIGNED NOT NULL, `value` VARCHAR(255), PRIMARY KEY (`bigint_signed_key`) );
1006+
INSERT INTO `wp_123_test3` VALUES ('-9223372036854775808','wp_123_test3_value_X');
1007+
"""
1008+
And I run `wp db query "SOURCE test_db.sql;"`
10031009

10041010
When I run `wp search-replace --dry-run --regex 'mytestdomain.com\/' 'mytestdomain2.com/' --all-tables-with-prefix --skip-columns=guid,domain`
1005-
Then STDERR should be empty
1006-
And STDOUT should contain:
1011+
Then STDOUT should contain:
10071012
"""
10081013
Success: 0 replacements to be made.
10091014
"""
1015+
1016+
When I run `wp search-replace --dry-run --regex 'wp_123_test_value_X' 'wp_123_test_value_Y' --all-tables-with-prefix`
1017+
Then STDOUT should contain:
1018+
"""
1019+
Success: 8 replacements to be made.
1020+
"""
1021+
1022+
When I run `wp search-replace --dry-run --regex 'wp_123_test2_value_X' 'wp_123_test2_value_Y' --all-tables-with-prefix`
1023+
Then STDOUT should contain:
1024+
"""
1025+
Success: 1 replacement to be made.
1026+
"""
1027+
1028+
When I run `wp search-replace --dry-run --regex 'wp_123_test3_value_X' 'wp_123_test3_value_Y' --all-tables-with-prefix`
1029+
Then STDOUT should contain:
1030+
"""
1031+
Success: 1 replacement to be made.
1032+
"""

src/Search_Replace_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ private static function esc_sql_ident( $idents ) {
658658
private static function esc_sql_value( $values ) {
659659
$quote = function ( $v ) {
660660
// Don't quote integer values to avoid MySQL's implicit type conversion.
661-
if ( (string)(int) $v === (string) $v ) {
661+
if ( preg_match( '/^[+-]?[0-9]{1,20}$/', $v ) ) { // MySQL BIGINT UNSIGNED max 18446744073709551615 (20 digits).
662662
return esc_sql( $v );
663663
}
664664

0 commit comments

Comments
 (0)