Skip to content

Commit 1ab8410

Browse files
committed
More fixes
1 parent 0e1637e commit 1ab8410

File tree

5 files changed

+162
-6
lines changed

5 files changed

+162
-6
lines changed

features/db-columns.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Feature: Display information about a given table.
4141
Couldn't find any tables matching: wp_foobar
4242
"""
4343

44+
@require-mysql-or-mariadb
4445
Scenario: Display information about a non default WordPress table
4546
Given a WP install
4647
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
@@ -50,3 +51,14 @@ Feature: Display information about a given table.
5051
| Field | Type | Null | Key | Default | Extra |
5152
| date | date | NO | PRI | | |
5253
| awesome_stuff | text | YES | | | |
54+
55+
@require-sqlite
56+
Scenario: Display information about a non default WordPress table
57+
Given a WP install
58+
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
59+
60+
When I try `wp db columns not_wp`
61+
Then STDOUT should be a table containing rows:
62+
| Field | Type | Null | Key | Default |
63+
| date | date | NO | PRI | |
64+
| awesome_stuff | text | YES | | |

features/db-export.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Feature: Export a WordPress database
5555
-- Dump completed on
5656
"""
5757

58+
@require-mysql-or-mariadb
5859
Scenario: Export database with passed-in options
5960
Given a WP install
6061

@@ -72,6 +73,24 @@ Feature: Export a WordPress database
7273
"""
7374
And STDOUT should be empty
7475

76+
@require-sqlite
77+
Scenario: Export database with passed-in options
78+
Given a WP install
79+
80+
When I run `wp db export - --skip-comments`
81+
Then STDOUT should not contain:
82+
"""
83+
-- Table structure
84+
"""
85+
86+
# dbpass has no effect on SQLite
87+
When I try `wp db export - --dbpass=no_such_pass`
88+
Then the return code should be 0
89+
And STDERR should not contain:
90+
"""
91+
Access denied
92+
"""
93+
7594
@require-mysql-or-mariadb
7695
Scenario: MySQL defaults are available as appropriate with --defaults flag
7796
Given a WP install

features/db-tables.feature

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Feature: List database tables
22

3+
@require-mysql-or-mariadb
34
Scenario: List database tables on a single WordPress install
45
Given a WP install
56

@@ -35,7 +36,42 @@ Feature: List database tables
3536
wp_postmeta,wp_posts
3637
"""
3738

38-
@require-wp-3.9
39+
@require-sqlite
40+
Scenario: List database tables on a single WordPress install
41+
Given a WP install
42+
43+
When I run `wp db tables`
44+
Then STDOUT should contain:
45+
"""
46+
_mysql_data_types_cache
47+
wp_users
48+
sqlite_sequence
49+
wp_usermeta
50+
wp_termmeta
51+
wp_terms
52+
wp_term_taxonomy
53+
wp_term_relationships
54+
wp_commentmeta
55+
wp_comments
56+
wp_links
57+
wp_options
58+
wp_postmeta
59+
wp_posts
60+
"""
61+
62+
When I run `wp db tables --format=csv`
63+
Then STDOUT should contain:
64+
"""
65+
,wp_commentmeta,wp_comments,
66+
"""
67+
68+
When I run `wp db tables 'wp_post*' --format=csv`
69+
Then STDOUT should be:
70+
"""
71+
wp_postmeta,wp_posts
72+
"""
73+
74+
@require-wp-3.9 @require-mysql-or-mariadb
3975
Scenario: List database tables on a multisite WordPress install
4076
Given a WP multisite install
4177

@@ -119,6 +155,86 @@ Feature: List database tables
119155
wp_posts
120156
"""
121157

158+
@require-sqlite
159+
Scenario: List database tables on a multisite WordPress install
160+
Given a WP multisite install
161+
162+
When I run `wp db tables`
163+
Then STDOUT should contain:
164+
"""
165+
_mysql_data_types_cache
166+
wp_users
167+
sqlite_sequence
168+
wp_usermeta
169+
wp_termmeta
170+
wp_terms
171+
wp_term_taxonomy
172+
wp_term_relationships
173+
wp_commentmeta
174+
wp_comments
175+
wp_links
176+
wp_options
177+
wp_postmeta
178+
wp_posts
179+
wp_blogs
180+
wp_blogmeta
181+
wp_registration_log
182+
wp_site
183+
wp_sitemeta
184+
wp_signups
185+
"""
186+
187+
When I run `wp site create --slug=foo`
188+
And I run `wp db tables --url=example.com/foo`
189+
Then STDOUT should contain:
190+
"""
191+
wp_users
192+
"""
193+
And STDOUT should contain:
194+
"""
195+
wp_usermeta
196+
"""
197+
And STDOUT should contain:
198+
"""
199+
wp_2_posts
200+
"""
201+
202+
When I run `wp db tables --url=example.com/foo --scope=global`
203+
Then STDOUT should not contain:
204+
"""
205+
wp_2_posts
206+
"""
207+
208+
When I run `wp db tables --all-tables-with-prefix`
209+
Then STDOUT should contain:
210+
"""
211+
wp_2_posts
212+
"""
213+
And STDOUT should contain:
214+
"""
215+
wp_posts
216+
"""
217+
218+
When I run `wp db tables --url=example.com/foo --all-tables-with-prefix`
219+
Then STDOUT should contain:
220+
"""
221+
wp_2_posts
222+
"""
223+
And STDOUT should not contain:
224+
"""
225+
wp_posts
226+
"""
227+
228+
When I run `wp db tables --url=example.com/foo --network`
229+
Then STDOUT should contain:
230+
"""
231+
wp_2_posts
232+
"""
233+
And STDOUT should contain:
234+
"""
235+
wp_posts
236+
"""
237+
122238
Scenario: Listing a site's tables should only list that site's tables
123239
Given a WP multisite install
124240

src/DB_Command.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,12 @@ public function size( $args, $assoc_args ) {
11761176

11771177
// Get the table size.
11781178
if ( $is_sqlite ) {
1179-
// For SQLite, we cannot get individual table sizes easily.
1180-
// Just report 0 as a placeholder.
1181-
$table_bytes = 0;
1179+
$table_bytes = $wpdb->get_var(
1180+
$wpdb->prepare(
1181+
'SELECT SUM(pgsize) as size_in_bytes FROM dbstat where name = %s LIMIT 1',
1182+
$table_name
1183+
)
1184+
);
11821185
} else {
11831186
$table_bytes = $wpdb->get_var(
11841187
$wpdb->prepare(
@@ -1840,7 +1843,12 @@ public function columns( $args, $assoc_args ) {
18401843
);
18411844

18421845
$formatter_fields = [ 'Field', 'Type', 'Null', 'Key', 'Default', 'Extra' ];
1843-
$formatter_args = [
1846+
1847+
if ( $this->is_sqlite() ) {
1848+
$formatter_fields = [ 'Field', 'Type', 'Null', 'Key', 'Default' ];
1849+
}
1850+
1851+
$formatter_args = [
18441852
'format' => $format,
18451853
];
18461854

src/DB_Command_SQLite.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ protected function sqlite_import( $file ) {
412412
}
413413

414414
if ( '-' === $file ) {
415-
$sql = stream_get_contents( STDIN );
415+
$sql = stream_get_contents( STDIN );
416+
$file = 'STDIN';
416417
} else {
417418
if ( ! is_readable( $file ) ) {
418419
WP_CLI::error( sprintf( 'Import file missing or not readable: %s', $file ) );

0 commit comments

Comments
 (0)