fix(editor): Format SQL uppercases words inside string literals, quoted identifiers and comments
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 48/100
Direção de pesquisa
Read lib/core/actions/sql_script_format.dart and the existing scanner in lib/core/database/destructive_sql_detector.dart, then review test/core/actions/sql_script_format_test.dart and SqlQueryTabSession.formatSql in lib/features/workspace/sql_query_tab_session.dart. Coordinate with issue #1511 because it touches the same detector. Done means formatting changes SQL keywords only in code segments, preserves the caret position, and the listed literal, identifier, comment, escape, and unterminated-literal cases are covered by tests.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Problem
Format SQL Query (command palette, Shift+Alt+F) calls formatSqlScript (lib/core/actions/sql_script_format.dart:64), which runs one regex over the whole text and uppercases every word found in _kSqlKeywords. It does not know about string literals, quoted identifiers or comments:
| Before | After | Effect |
|---|---|---|
WHERE status = 'not null' |
WHERE status = 'NOT NULL' |
query now matches different rows |
SELECT "order", "desc" FROM t |
SELECT "ORDER", "DESC" FROM t |
PostgreSQL: quoted identifiers are case-sensitive, the query fails (column does not exist) |
SELECT `limit` FROM t (MySQL) |
SELECT `LIMIT` FROM t |
changes the identifier on case-sensitive table names |
$$ ... begin ... end $$ (function body) |
body rewritten | changes stored code |
-- set in prod |
-- SET IN prod |
cosmetic |
The only test (test/core/actions/sql_script_format_test.dart) checks a literal with no keywords inside.
Also in SqlQueryTabSession.formatSql (lib/features/workspace/sql_query_tab_session.dart:102-108) the caret always jumps to the end of the document after formatting.
Fix
- Format only code segments. Scanning logic already exists in
DestructiveSqlDetector.stripCommentsAndStrings(lib/core/database/destructive_sql_detector.dart:213:--,/* */,$tag$,'...'), but it drops the segments and does not know"..."/`...`. Extract one lexical scanner that yields segments (code, string, quoted identifier, comment, dollar-quoted body) and use it in the formatter (and later in the stripper / splitter; coordinate with #1511 which touches the same detector). - Keep the caret where it was, mapped onto the new text. Keywords keep their length, so the offset is unchanged.
- Tests: each row of the table above, plus nested
''escapes and an unterminated literal.
- Linguagem predominante
- Dart
- Estrelas
- 23
- Forks
- 1
- Merge médio
- 31min
- PRs com merge (30d)
- 570
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de QueryaHub/Querya-Desktop
-
enhancement ui
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
QueryaHub/Querya-Desktop#1689 ·
Mantenedores costumam responder em até 1 dia
-
ui(dialogs): make destructive query and DML preview dialogs adaptive and prevent table name overflowAbertabug frontend
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
QueryaHub/Querya-Desktop#1642 ·
Mantenedores costumam responder em até 1 dia
-
bug error-handling settings
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 78/100
QueryaHub/Querya-Desktop#1637 ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
QueryaHub/Querya-Desktop#1636 ·
Mantenedores costumam responder em até 1 dia
-
enhancement marketplace
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
QueryaHub/Querya-Desktop#1635 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de QueryaHub/Querya-Desktop
Issues semelhantes
-
Standalone dash flashes as its own RSVP step (e.g. Russian dialogue)Talvez já em andamento @bezig01 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
daniel-pimenta-cc/ledor#53 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
Iteration CounterAbertaenhancement firebase
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
brysonddelozier/scribbles#24 ·
-
bug good first issue P2-Medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
basictech01/uniun#305 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
daohoangson/flutter_widget_from_html#1657 ·
Mantenedores costumam responder em até 3 dias