Skip to content

Commit d1f779e

Browse files
swissspidyclaude
andauthored
Adapt SQLite support to sqlite-database-integration 3.0 (#344)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5f75759 commit d1f779e

4 files changed

Lines changed: 14 additions & 129 deletions

File tree

‎features/db-columns.feature‎

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

44-
@require-mysql-or-mariadb
4544
Scenario: Display information about a non default WordPress table
4645
Given a WP install
4746
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
@@ -51,14 +50,3 @@ Feature: Display information about a given table.
5150
| Field | Type | Null | Key | Default | Extra |
5251
| date | date | NO | PRI | | |
5352
| 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 | TEXT | NO | PRI | '' |
64-
| awesome_stuff | TEXT | YES | | |

‎features/db-tables.feature‎

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Feature: List database tables
22

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

@@ -36,40 +35,7 @@ Feature: List database tables
3635
wp_postmeta,wp_posts
3736
"""
3837

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-
wp_users
47-
wp_usermeta
48-
wp_termmeta
49-
wp_terms
50-
wp_term_taxonomy
51-
wp_term_relationships
52-
wp_commentmeta
53-
wp_comments
54-
wp_links
55-
wp_options
56-
wp_postmeta
57-
wp_posts
58-
"""
59-
60-
When I run `wp db tables --format=csv`
61-
Then STDOUT should contain:
62-
"""
63-
,wp_commentmeta,wp_comments,
64-
"""
65-
66-
When I run `wp db tables 'wp_post*' --format=csv`
67-
Then STDOUT should be:
68-
"""
69-
wp_postmeta,wp_posts
70-
"""
71-
72-
@require-wp-3.9 @require-mysql-or-mariadb
38+
@require-wp-3.9
7339
Scenario: List database tables on a multisite WordPress install
7440
Given a WP multisite install
7541

@@ -153,84 +119,6 @@ Feature: List database tables
153119
wp_posts
154120
"""
155121

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

‎src/DB_Command.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,10 +1942,6 @@ public function columns( $args, $assoc_args ) {
19421942

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

1945-
if ( $this->is_sqlite() ) {
1946-
$formatter_fields = [ 'Field', 'Type', 'Null', 'Key', 'Default' ];
1947-
}
1948-
19491945
$formatter_args = [
19501946
'format' => $format,
19511947
];

‎src/DB_Command_SQLite.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ protected function sqlite_query( $query, $assoc_args = [] ) {
221221
WP_CLI::error( 'SQLite database not available.' );
222222
}
223223

224+
/*
225+
* Strip redundant trailing semicolons and whitespace.
226+
*
227+
* The MySQL client silently ignores the empty statements they produce,
228+
* whereas the SQLite drop-in parses them as a multi-query and bails out
229+
* with "Multi-query is not supported.". Trim them for parity.
230+
*/
231+
$query = rtrim( $query, "; \t\n\r\0\x0B" );
232+
233+
if ( '' === $query ) {
234+
WP_CLI::error( 'No query specified.' );
235+
}
236+
224237
$skip_column_names = Utils\get_flag_value( $assoc_args, 'skip-column-names', false );
225238

226239
try {

0 commit comments

Comments
 (0)