| 6 | ) |
| 7 | |
| 8 | func TestErrorMessageSourcePosition(t *testing.T) { |
| 9 | testCases := []struct { |
| 10 | name string |
| 11 | sql string |
| 12 | mode ParserMode |
| 13 | expectedErr string // The exact expected error message |
| 14 | }{ |
| 15 | // Single-line errors |
| 16 | { |
| 17 | name: "Typo in CREATE INDEX", |
| 18 | sql: "CREATE INDEXX idx_name ON users(name)", |
| 19 | mode: ParserModeMysql, |
| 20 | expectedErr: `found syntax error when parsing DDL "CREATE INDEXX idx_name ON users(name)": syntax error at line 1, column 15 near 'INDEXX' |
| 21 | CREATE INDEXX idx_name ON users(name) |
| 22 | ^`, |
| 23 | }, |
| 24 | { |
| 25 | name: "Missing comma between columns", |
| 26 | sql: "CREATE TABLE test (id INT name TEXT)", |
| 27 | mode: ParserModeSQLite3, |
| 28 | expectedErr: `found syntax error when parsing DDL "CREATE TABLE test (id INT name TEXT)": syntax error at line 1, column 32 near 'name' |
| 29 | CREATE TABLE test (id INT name TEXT) |
| 30 | ^`, |
| 31 | }, |
| 32 | // Multi-line errors |
| 33 | { |
| 34 | name: "Error on second line", |
| 35 | sql: `CREATE TABLE users ( |
| 36 | id INTEGER PRIMARY KEY |
| 37 | name TEXT NOT NULL |
| 38 | )`, |
| 39 | mode: ParserModeSQLite3, |
| 40 | expectedErr: `found syntax error when parsing DDL "CREATE TABLE users ( |
| 41 | id INTEGER PRIMARY KEY |
| 42 | name TEXT NOT NULL |
| 43 | )": syntax error at line 3, column 10 near 'name' |
| 44 | name TEXT NOT NULL |
| 45 | ^`, |
| 46 | }, |
| 47 | { |
| 48 | name: "Error on third line with LIKE", |
| 49 | sql: `CREATE TABLE task ( |
| 50 | id INT PRIMARY KEY |
| 51 | ); |
| 52 | CREATE TABLE task_log (LIKE task)`, |
| 53 | mode: ParserModePostgres, |
| 54 | expectedErr: `found syntax error when parsing DDL "CREATE TABLE task ( |
| 55 | id INT PRIMARY KEY |
| 56 | ); |
| 57 | CREATE TABLE task_log (LIKE task)": syntax error at line 4, column 8 near 'create' |
| 58 | CREATE TABLE task_log (LIKE task) |
| 59 | ^`, |
| 60 | }, |
| 61 | { |
| 62 | name: "Multi-statement with error in second", |
| 63 | sql: `CREATE TABLE users (id INT); |
| 64 | CREATE TABLEE posts (id INT)`, |
| 65 | mode: ParserModeMysql, |