File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -151,3 +151,23 @@ Feature: WP-CLI SQLite Import Command
151151 """
152152
153153 And the SQLite database should contain a table named "a'strange`identifier\n ame"
154+
155+ @require-sqlite
156+ Scenario : Import a file with whitespace and empty lines
157+ Given a SQL dump file named "test_import.sql" with content:
158+ """
159+
160+ CREATE TABLE test_table (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
161+
162+
163+ INSERT INTO test_table (name) VALUES ('Test Name');
164+
165+ """
166+ When I run `wp sqlite --enable-ast-driver import test_import.sql`
167+ Then STDOUT should contain:
168+ """
169+ Success: Imported from 'test_import.sql'.
170+ """
171+
172+ And the SQLite database should contain a table named "test_table"
173+ And the "test_table" should contain a row with name "Test Name"
Original file line number Diff line number Diff line change @@ -139,7 +139,10 @@ public function parse_statements( $sql_file_path ) {
139139
140140 // Process statement end
141141 if ( '; ' === $ ch && null === $ starting_quote ) {
142- yield trim ( $ buffer );
142+ $ buffer = trim ( $ buffer );
143+ if ( ! empty ( $ buffer ) ) {
144+ yield $ buffer ;
145+ }
143146 $ buffer = '' ;
144147 } else {
145148 $ buffer .= $ ch ;
@@ -148,8 +151,9 @@ public function parse_statements( $sql_file_path ) {
148151 }
149152
150153 // Handle any remaining buffer content
154+ $ buffer = trim ( $ buffer );
151155 if ( ! empty ( $ buffer ) ) {
152- yield trim ( $ buffer ) ;
156+ yield $ buffer ;
153157 }
154158
155159 fclose ( $ handle );
You can’t perform that action at this time.
0 commit comments