Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions features/db-columns.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Feature: Display information about a given table.
Couldn't find any tables matching: wp_foobar
"""

@require-mysql-or-mariadb
Scenario: Display information about a non default WordPress table
Given a WP install
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
Expand All @@ -51,14 +50,3 @@ Feature: Display information about a given table.
| Field | Type | Null | Key | Default | Extra |
| date | date | NO | PRI | | |
| awesome_stuff | text | YES | | | |

@require-sqlite
Scenario: Display information about a non default WordPress table
Given a WP install
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`

When I try `wp db columns not_wp`
Then STDOUT should be a table containing rows:
| Field | Type | Null | Key | Default |
| date | TEXT | NO | PRI | '' |
| awesome_stuff | TEXT | YES | | |
114 changes: 1 addition & 113 deletions features/db-tables.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Feature: List database tables

@require-mysql-or-mariadb
Scenario: List database tables on a single WordPress install
Given a WP install

Expand Down Expand Up @@ -36,40 +35,7 @@ Feature: List database tables
wp_postmeta,wp_posts
"""

@require-sqlite
Scenario: List database tables on a single WordPress install
Given a WP install

When I run `wp db tables`
Then STDOUT should contain:
"""
wp_users
wp_usermeta
wp_termmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
"""

When I run `wp db tables --format=csv`
Then STDOUT should contain:
"""
,wp_commentmeta,wp_comments,
"""

When I run `wp db tables 'wp_post*' --format=csv`
Then STDOUT should be:
"""
wp_postmeta,wp_posts
"""

@require-wp-3.9 @require-mysql-or-mariadb
@require-wp-3.9
Scenario: List database tables on a multisite WordPress install
Given a WP multisite install

Expand Down Expand Up @@ -153,84 +119,6 @@ Feature: List database tables
wp_posts
"""

@require-sqlite
Scenario: List database tables on a multisite WordPress install
Given a WP multisite install

When I run `wp db tables`
Then STDOUT should contain:
"""
wp_users
wp_usermeta
wp_termmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
wp_blogs
wp_blogmeta
wp_registration_log
wp_site
wp_sitemeta
wp_signups
"""

When I run `wp site create --slug=foo`
And I run `wp db tables --url=example.com/foo`
Then STDOUT should contain:
"""
wp_users
"""
And STDOUT should contain:
"""
wp_usermeta
"""
And STDOUT should contain:
"""
wp_2_posts
"""

When I run `wp db tables --url=example.com/foo --scope=global`
Then STDOUT should not contain:
"""
wp_2_posts
"""

When I run `wp db tables --all-tables-with-prefix`
Then STDOUT should contain:
"""
wp_2_posts
"""
And STDOUT should contain:
"""
wp_posts
"""

When I run `wp db tables --url=example.com/foo --all-tables-with-prefix`
Then STDOUT should contain:
"""
wp_2_posts
"""
And STDOUT should not contain:
"""
wp_posts
"""

When I run `wp db tables --url=example.com/foo --network`
Then STDOUT should contain:
"""
wp_2_posts
"""
And STDOUT should contain:
"""
wp_posts
"""

# AUTO_INCREMENT doesn't work with SQLite.
@require-mysql-or-mariadb
Scenario: Listing a site's tables should only list that site's tables
Expand Down
4 changes: 0 additions & 4 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1942,10 +1942,6 @@ public function columns( $args, $assoc_args ) {

$formatter_fields = [ 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra' ];

if ( $this->is_sqlite() ) {
$formatter_fields = [ 'Field', 'Type', 'Null', 'Key', 'Default' ];
}

$formatter_args = [
'format' => $format,
];
Expand Down
13 changes: 13 additions & 0 deletions src/DB_Command_SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ protected function sqlite_query( $query, $assoc_args = [] ) {
WP_CLI::error( 'SQLite database not available.' );
}

/*
* Strip redundant trailing semicolons and whitespace.
*
* The MySQL client silently ignores the empty statements they produce,
* whereas the SQLite drop-in parses them as a multi-query and bails out
* with "Multi-query is not supported.". Trim them for parity.
*/
$query = rtrim( $query, "; \t\n\r\0\x0B" );

if ( '' === $query ) {
WP_CLI::error( 'No query specified.' );
}

$skip_column_names = Utils\get_flag_value( $assoc_args, 'skip-column-names', false );

try {
Expand Down