Skip to content

Commit cf150e4

Browse files
committed
Reject in-memory SQLite databases
An in-memory database is discarded when the command exits. Import reported success without keeping any data, and export and table listing reported a missing database.
1 parent c0e7dfc commit cf150e4

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎features/sqlite-storage.feature‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,29 @@ Feature: SQLite database storage
160160
"""
161161
test_table
162162
"""
163+
164+
Scenario: Reject an in-memory database
165+
Given a SQL dump file named "test_import.sql" with content:
166+
"""
167+
CREATE TABLE test_table (id INTEGER PRIMARY KEY);
168+
"""
169+
When I run `wp config set DB_PATH ':memory:'`
170+
And I try `wp sqlite import test_import.sql`
171+
Then the return code should be 1
172+
And STDERR should contain:
173+
"""
174+
In-memory databases are not supported.
175+
"""
176+
When I try `wp sqlite export backup.sql`
177+
Then the return code should be 1
178+
And STDERR should contain:
179+
"""
180+
In-memory databases are not supported.
181+
"""
182+
And the backup.sql file should not exist
183+
When I try `wp sqlite tables`
184+
Then the return code should be 1
185+
And STDERR should contain:
186+
"""
187+
In-memory databases are not supported.
188+
"""

‎src/SQLiteDriverFactory.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ private static function get_database_path( $create_database_if_missing ) {
8989
if ( ! is_string( $database_path ) || '' === $database_path || false !== strpos( $database_path, "\0" ) ) {
9090
throw new RuntimeException( 'The SQLite database path is invalid.' );
9191
}
92+
if ( ':memory:' === $database_path ) {
93+
throw new RuntimeException( 'In-memory databases are not supported.' );
94+
}
9295
return $database_path;
9396
}
9497
}

0 commit comments

Comments
 (0)