Skip to content

Commit c424d64

Browse files
committed
sql_parser: error message with position number
1 parent 12223f0 commit c424d64

17 files changed

+188
-68
lines changed

src/parser/drop/drop_index.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,25 @@ mod drop_index_tests {
9090
fn drop_index_missing_index_keyword() {
9191
run_rainy_day_test(
9292
"DROP my_index;",
93-
ParsingError::UnexpectedToken("my_index".into()),
93+
ParsingError::UnexpectedToken("my_index at position 5".into()),
9494
);
9595
}
9696

9797
#[test]
9898
fn drop_index_invalid_syntax() {
9999
run_rainy_day_test(
100100
"DROP INDEX IF my_index;",
101-
ParsingError::UnexpectedToken("Expected Exists keyword, got: my_index".into()),
101+
ParsingError::UnexpectedToken(
102+
"Expected Exists keyword, got: my_index at position 14".into(),
103+
),
102104
)
103105
}
104106

105107
#[test]
106108
fn drop_index_extra_tokens() {
107109
run_rainy_day_test(
108110
"DROP INDEX my_index extra;",
109-
ParsingError::UnexpectedToken("extra".into()),
111+
ParsingError::UnexpectedToken("extra at position 20".into()),
110112
);
111113
}
112114

src/parser/drop/drop_table.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,25 @@ mod drop_table_tests {
8686
fn drop_table_missing_table_keyword() {
8787
run_rainy_day_test(
8888
"DROP my_table",
89-
ParsingError::UnexpectedToken("my_table".to_string()),
89+
ParsingError::UnexpectedToken("my_table at position 5".to_string()),
9090
);
9191
}
9292

9393
#[test]
9494
fn drop_table_invalid_syntax() {
9595
run_rainy_day_test(
9696
"DROP TABLE IF my_table;",
97-
ParsingError::UnexpectedToken("Expected Exists keyword, got: my_table".to_string()),
97+
ParsingError::UnexpectedToken(
98+
"Expected Exists keyword, got: my_table at position 14".to_string(),
99+
),
98100
)
99101
}
100102

101103
#[test]
102-
fn drop_table_extra_tokens() {
104+
fn drop_table_extra_token() {
103105
run_rainy_day_test(
104106
"DROP TABLE my_table extra;",
105-
ParsingError::UnexpectedToken("extra".to_string()),
107+
ParsingError::UnexpectedToken("extra at position 20".to_string()),
106108
);
107109
}
108110

src/parser/drop/drop_trigger.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,25 @@ mod drop_trigger_tests {
8686
fn drop_trigger_missing_trigger_keyword() {
8787
run_rainy_day_test(
8888
"DROP my_trigger;",
89-
ParsingError::UnexpectedToken("my_trigger".into()),
89+
ParsingError::UnexpectedToken("my_trigger at position 5".into()),
9090
);
9191
}
9292

9393
#[test]
9494
fn drop_trigger_invalid_syntax() {
9595
run_rainy_day_test(
9696
"DROP TRIGGER IF my_trigger;",
97-
ParsingError::UnexpectedToken("Expected Exists keyword, got: my_trigger".into()),
97+
ParsingError::UnexpectedToken(
98+
"Expected Exists keyword, got: my_trigger at position 16".into(),
99+
),
98100
)
99101
}
100102

101103
#[test]
102104
fn drop_trigger_extra_tokens() {
103105
run_rainy_day_test(
104106
"DROP TRIGGER my_trigger extra;",
105-
ParsingError::UnexpectedToken("extra".into()),
107+
ParsingError::UnexpectedToken("extra at position 24".into()),
106108
);
107109
}
108110

src/parser/drop/drop_view.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,25 @@ mod drop_view_tests {
9191
fn drop_view_missing_view_keyword() {
9292
run_rainy_day_test(
9393
"DROP my_view;",
94-
ParsingError::UnexpectedToken("my_view".into()),
94+
ParsingError::UnexpectedToken("my_view at position 5".into()),
9595
);
9696
}
9797

9898
#[test]
9999
fn drop_view_invalid_syntax() {
100100
run_rainy_day_test(
101101
"DROP VIEW IF my_view;",
102-
ParsingError::UnexpectedToken("Expected Exists keyword, got: my_view".into()),
102+
ParsingError::UnexpectedToken(
103+
"Expected Exists keyword, got: my_view at position 13".into(),
104+
),
103105
)
104106
}
105107

106108
#[test]
107109
fn drop_view_extra_tokens() {
108110
run_rainy_day_test(
109111
"DROP VIEW my_view extra;",
110-
ParsingError::UnexpectedToken("extra".into()),
112+
ParsingError::UnexpectedToken("extra at position 18".into()),
111113
);
112114
}
113115

src/parser/expression/cast_expr.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ mod cast_expression_tests {
9797
// "SELECT CAST(1 AS DOUBLE PRECISION) as 1;",
9898
// &cast_expression(
9999
// numeric_literal_expression("1"),
100-
// DataType::BoundedDataType("DOUBLE PRECISION".to_string(), "1".to_string(), "10".to_string()),
100+
// DataType::BoundedDataType(
101+
// "DOUBLE PRECISION".to_string(),
102+
// "1".to_string(),
103+
// "10".to_string(),
104+
// ),
101105
// ),
102106
// );
103107
// }

src/parser/expression/raise_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod raise_expression_tests {
100100
fn test_expression_raise_fail_with_empty_string() {
101101
run_rainy_day_test(
102102
"SELECT RAISE(FAIL);",
103-
ParsingError::UnexpectedToken(")".to_string()),
103+
ParsingError::UnexpectedToken(") at position 17".to_string()),
104104
);
105105
}
106106
}

src/parser/select/column/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ mod test_select_result_columns {
9292
fn select_distinct_all() {
9393
run_rainy_day_test(
9494
"SELECT DISTINCT ALL column1",
95-
ParsingError::UnexpectedToken("All".to_string()),
95+
ParsingError::UnexpectedToken("All at position 16".to_string()),
9696
);
9797

9898
run_rainy_day_test(
9999
"SELECT ALL DISTINCT column1",
100-
ParsingError::UnexpectedToken("Distinct".to_string()),
100+
ParsingError::UnexpectedToken("Distinct at position 11".to_string()),
101101
);
102102
}
103103

src/parser/sqlite/attach.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,28 @@ mod detach_statements_tests {
119119
#[test]
120120
fn detach_missing_schema_name() {
121121
let sql = "DETACH DATABASE;";
122-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(";".into()));
122+
run_rainy_day_test(
123+
sql,
124+
ParsingError::UnexpectedToken("; at position 15".to_string()),
125+
);
123126
}
124127

125128
#[test]
126129
fn detach_missing_schema_name_no_database() {
127130
let sql = "DETACH;";
128-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(";".into()));
131+
run_rainy_day_test(
132+
sql,
133+
ParsingError::UnexpectedToken("; at position 6".to_string()),
134+
);
129135
}
130136

131137
#[test]
132138
fn detach_invalid_syntax_extra_token() {
133139
let sql = "DETACH DATABASE schema_name extra;";
134-
run_rainy_day_test(sql, ParsingError::UnexpectedToken("extra".into()));
140+
run_rainy_day_test(
141+
sql,
142+
ParsingError::UnexpectedToken("extra at position 28".to_string()),
143+
);
135144
}
136145

137146
#[test]
@@ -191,7 +200,10 @@ mod detach_statements_tests {
191200
#[test]
192201
fn detach_invalid_schema_name_no_quotes() {
193202
let sql = "DETACH DATABASE schema name;";
194-
run_rainy_day_test(sql, ParsingError::UnexpectedToken("name".into()));
203+
run_rainy_day_test(
204+
sql,
205+
ParsingError::UnexpectedToken("name at position 23".to_string()),
206+
);
195207
}
196208

197209
#[test]

src/parser/sqlite/pragma.rs

+49-13
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,37 @@ mod pragma_statements_tests {
175175
#[test]
176176
fn pragma_with_invalid_schema() {
177177
let sql = "PRAGMA invalid..cache_size;";
178-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(".".into()));
178+
run_rainy_day_test(
179+
sql,
180+
ParsingError::UnexpectedToken(". at position 15".to_string()),
181+
);
179182
}
180183

181184
#[test]
182185
fn pragma_with_multiple_dots() {
183186
let sql = "PRAGMA main.db.cache_size;";
184-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(".".into()));
187+
run_rainy_day_test(
188+
sql,
189+
ParsingError::UnexpectedToken(". at position 14".to_string()),
190+
);
185191
}
186192

187193
#[test]
188194
fn pragma_missing_name() {
189195
let sql = "PRAGMA;";
190-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(";".into()));
196+
run_rainy_day_test(
197+
sql,
198+
ParsingError::UnexpectedToken("; at position 6".to_string()),
199+
);
191200
}
192201

193202
#[test]
194203
fn pragma_missing_value_after_equals() {
195204
let sql = "PRAGMA cache_size =;";
196-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(";".into()));
205+
run_rainy_day_test(
206+
sql,
207+
ParsingError::UnexpectedToken("; at position 19".to_string()),
208+
);
197209
}
198210

199211
#[test]
@@ -242,20 +254,26 @@ mod pragma_statements_tests {
242254
fn pragma_with_reserved_keyword_as_name() {
243255
run_rainy_day_test(
244256
"PRAGMA select;",
245-
ParsingError::UnexpectedToken("Select".into()),
257+
ParsingError::UnexpectedToken("Select at position 7".to_string()),
246258
);
247259
}
248260

249261
#[test]
250262
fn pragma_with_numeric_pragma_name() {
251263
let sql = "PRAGMA 123;";
252-
run_rainy_day_test(sql, ParsingError::UnexpectedToken("123".into()));
264+
run_rainy_day_test(
265+
sql,
266+
ParsingError::UnexpectedToken("123 at position 7".to_string()),
267+
);
253268
}
254269

255270
#[test]
256271
fn pragma_with_invalid_syntax_extra_token() {
257272
let sql = "PRAGMA cache_size = 1000 EXTRA;";
258-
run_rainy_day_test(sql, ParsingError::UnexpectedToken("EXTRA".into()));
273+
run_rainy_day_test(
274+
sql,
275+
ParsingError::UnexpectedToken("EXTRA at position 25".to_string()),
276+
);
259277
}
260278

261279
#[test]
@@ -296,37 +314,55 @@ mod pragma_statements_tests {
296314
#[test]
297315
fn pragma_with_reserved_keyword_as_value() {
298316
let sql = "PRAGMA cache_size = select;";
299-
run_rainy_day_test(sql, ParsingError::UnexpectedToken("Select".into()));
317+
run_rainy_day_test(
318+
sql,
319+
ParsingError::UnexpectedToken("Select at position 20".to_string()),
320+
);
300321
}
301322

302323
#[test]
303324
fn pragma_with_no_value_after_equal() {
304325
let sql = "PRAGMA cache_size =;";
305-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(";".into()));
326+
run_rainy_day_test(
327+
sql,
328+
ParsingError::UnexpectedToken("; at position 19".to_string()),
329+
);
306330
}
307331

308332
#[test]
309333
fn pragma_with_no_value_in_parentheses() {
310334
let sql = "PRAGMA cache_size();";
311-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(")".into()));
335+
run_rainy_day_test(
336+
sql,
337+
ParsingError::UnexpectedToken(") at position 18".to_string()),
338+
);
312339
}
313340

314341
#[test]
315342
fn pragma_with_schema_missing_pragma_name() {
316343
let sql = "PRAGMA main.;";
317-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(";".into()));
344+
run_rainy_day_test(
345+
sql,
346+
ParsingError::UnexpectedToken("; at position 12".to_string()),
347+
);
318348
}
319349

320350
#[test]
321351
fn pragma_missing_pragma_name() {
322352
let sql = "PRAGMA;";
323-
run_rainy_day_test(sql, ParsingError::UnexpectedToken(";".into()));
353+
run_rainy_day_test(
354+
sql,
355+
ParsingError::UnexpectedToken("; at position 6".to_string()),
356+
);
324357
}
325358

326359
#[test]
327360
fn pragma_with_unexpected_token_after_parentheses() {
328361
let sql = "PRAGMA cache_size(1000) EXTRA;";
329-
run_rainy_day_test(sql, ParsingError::UnexpectedToken("EXTRA".into()));
362+
run_rainy_day_test(
363+
sql,
364+
ParsingError::UnexpectedToken("EXTRA at position 24".to_string()),
365+
);
330366
}
331367

332368
#[test]

src/parser/sqlite/reindex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ mod reindex_statements_tests {
161161
fn reindex_invalid_syntax_extra_token() {
162162
run_rainy_day_test(
163163
"REINDEX extra_token extra;",
164-
ParsingError::UnexpectedToken("extra".into()),
164+
ParsingError::UnexpectedToken("extra at position 20".to_string()),
165165
);
166166
}
167167

src/parser/sqlite/vacuum.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -95,41 +95,47 @@ mod vacuum_statements_tests {
9595
fn vacuum_invalid_syntax() {
9696
run_rainy_day_test(
9797
"VACUUM INTO;",
98-
ParsingError::UnexpectedToken(";".to_string()),
98+
ParsingError::UnexpectedToken("; at position 11".to_string()),
9999
);
100100
}
101101

102102
#[test]
103103
fn vacuum_missing_filename() {
104-
run_rainy_day_test("VACUUM INTO", ParsingError::UnexpectedToken(";".into()));
104+
run_rainy_day_test(
105+
"VACUUM INTO",
106+
ParsingError::UnexpectedToken("; at position 11".to_string()),
107+
);
105108
}
106109

107110
#[test]
108111
fn vacuum_invalid_filename() {
109112
run_rainy_day_test(
110113
"VACUUM INTO backup.db;",
111-
ParsingError::UnexpectedToken(".".to_string()),
114+
ParsingError::UnexpectedToken(". at position 18".to_string()),
112115
);
113116
}
114117

115118
#[test]
116119
fn vacuum_unexpected_token() {
117-
run_rainy_day_test("VACUUM 123;", ParsingError::UnexpectedToken("123".into()));
120+
run_rainy_day_test(
121+
"VACUUM 123;",
122+
ParsingError::UnexpectedToken("123 at position 7".to_string()),
123+
);
118124
}
119125

120126
#[test]
121127
fn vacuum_extra_tokens() {
122128
run_rainy_day_test(
123129
"VACUUM main INTO 'backup.db' extra;",
124-
ParsingError::UnexpectedToken("extra".to_string()),
130+
ParsingError::UnexpectedToken("extra at position 29".to_string()),
125131
);
126132
}
127133

128134
#[test]
129135
fn vacuum_schema_missing_into() {
130136
run_rainy_day_test(
131137
"VACUUM main 'backup.db';",
132-
ParsingError::UnexpectedToken("'backup.db'".to_string()),
138+
ParsingError::UnexpectedToken("'backup.db' at position 12".to_string()),
133139
);
134140
}
135141

0 commit comments

Comments
 (0)