Skip to content

Commit 5c08fcf

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 a49c4de commit 5c08fcf

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
@@ -140,3 +140,29 @@ Feature: SQLite database storage
140140
"""
141141
test_table
142142
"""
143+
144+
Scenario: Reject an in-memory database
145+
Given a SQL dump file named "test_import.sql" with content:
146+
"""
147+
CREATE TABLE test_table (id INTEGER PRIMARY KEY);
148+
"""
149+
When I run `wp config set DB_PATH ':memory:'`
150+
And I try `wp sqlite import test_import.sql`
151+
Then the return code should be 1
152+
And STDERR should contain:
153+
"""
154+
In-memory databases are not supported.
155+
"""
156+
When I try `wp sqlite export backup.sql`
157+
Then the return code should be 1
158+
And STDERR should contain:
159+
"""
160+
In-memory databases are not supported.
161+
"""
162+
And the backup.sql file should not exist
163+
When I try `wp sqlite tables`
164+
Then the return code should be 1
165+
And STDERR should contain:
166+
"""
167+
In-memory databases are not supported.
168+
"""

‎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)