@@ -43,3 +43,131 @@ Feature: WP-CLI SQLite Import Command
4343 Success: Imported from 'STDIN'.
4444 """
4545 And the SQLite database should contain the imported data
46+
47+ @require-sqlite
48+ Scenario : Import a file with escape sequences
49+ Given a SQL dump file named "test_import.sql" with content:
50+ """
51+ SET sql_mode='NO_BACKSLASH_ESCAPES';
52+ CREATE TABLE test_table (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
53+ INSERT INTO test_table (name) VALUES ('Test that escaping a backslash \\ works');
54+ INSERT INTO test_table (name) VALUES ('Test that escaping multiple backslashes \\\\\\ works');
55+ INSERT INTO test_table (name) VALUES ('Test that escaping a character \a works');
56+ INSERT INTO test_table (name) VALUES ('Test that escaping a backslash followed by a character \\a works');
57+ INSERT INTO test_table (name) VALUES ('Test that escaping a backslash and a character \\\a works');
58+ """
59+ When I run `wp sqlite --enable-ast-driver import test_import.sql`
60+ Then STDOUT should contain:
61+ """
62+ Success: Imported from 'test_import.sql'.
63+ """
64+ And the SQLite database should contain a table named "test_table"
65+ And the "test_table" should contain a row with name "Test that escaping a backslash \\ works"
66+ And the "test_table" should contain a row with name "Test that escaping multiple backslashes \\\\\\ works"
67+ And the "test_table" should contain a row with name "Test that escaping a character \a works"
68+ And the "test_table" should contain a row with name "Test that escaping a backslash followed by a character \\ a works"
69+ And the "test_table" should contain a row with name "Test that escaping a backslash and a character \\\a works"
70+
71+ @require-sqlite
72+ Scenario : Import a file with newlines in strings
73+ Given a SQL dump file named "test_import.sql" with content:
74+ """
75+ CREATE TABLE test_table (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
76+ INSERT INTO test_table (name) VALUES ('Test that a string containing
77+ a newline character and some whitespace works');
78+ """
79+ When I run `wp sqlite --enable-ast-driver import test_import.sql`
80+ Then STDOUT should contain:
81+ """
82+ Success: Imported from 'test_import.sql'.
83+ """
84+ And the SQLite database should contain a table named "test_table"
85+ And the "test_table" should contain a row with name:
86+ """
87+ Test that a string containing
88+ a newline character and some whitespace works
89+ """
90+
91+ @require-sqlite
92+ Scenario : Import a file with comments
93+ Given a SQL dump file named "test_import.sql" with content:
94+ """
95+ CREATE TABLE test_table (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
96+ -- This is an inline comment.
97+ # This is an inline comment.
98+ INSERT INTO test_table (name) VALUES ('one'); -- This is an inline comment.
99+ /* This is a block comment */
100+ INSERT INTO test_table (name) VALUES ('two'); /* This
101+ is a block comment
102+ on multiple lines */ INSERT INTO test_table (name) VALUES ('three');
103+ INSERT INTO test_table (name) VALUES ('fo -- this looks like a comment ur');
104+ INSERT INTO test_table (name) VALUES ('fi/* this looks like a comment */ve');
105+ """
106+ When I run `wp sqlite --enable-ast-driver import test_import.sql`
107+ Then STDOUT should contain:
108+ """
109+ Success: Imported from 'test_import.sql'.
110+ """
111+ And the SQLite database should contain a table named "test_table"
112+ And the "test_table" should contain a row with name "one"
113+ And the "test_table" should contain a row with name "two"
114+ And the "test_table" should contain a row with name "three"
115+ And the "test_table" should contain a row with name "fo -- this looks like a comment ur"
116+ And the "test_table" should contain a row with name "fi/* this looks like a comment */ve"
117+
118+ @require-sqlite
119+ Scenario : Import a file quoted strings
120+ Given a SQL dump file named "test_import.sql" with content:
121+ """
122+ CREATE TABLE test_table (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
123+ INSERT INTO test_table (name) VALUES ('a single-quoted string with \' '' some " tricky ` chars');
124+ INSERT INTO test_table (name) VALUES ("a double-quoted string with ' some \" "" tricky ` chars");
125+ """
126+ When I run `wp sqlite --enable-ast-driver import test_import.sql`
127+ Then STDOUT should contain:
128+ """
129+ Success: Imported from 'test_import.sql'.
130+ """
131+ And the SQLite database should contain a table named "test_table"
132+ And the "test_table" should contain a row with name:
133+ """
134+ a single-quoted string with ' ' some " tricky ` chars
135+ """
136+ And the "test_table" should contain a row with name:
137+ """
138+ a double-quoted string with ' some " " tricky ` chars
139+ """
140+
141+ @require-sqlite
142+ Scenario : Import a file backtick-quoted identifiers
143+ Given a SQL dump file named "test_import.sql" with content:
144+ """
145+ CREATE TABLE `a'strange``identifier\\name` (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
146+ """
147+ When I run `wp sqlite --enable-ast-driver import test_import.sql`
148+ Then STDOUT should contain:
149+ """
150+ Success: Imported from 'test_import.sql'.
151+ """
152+
153+ 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"
0 commit comments