fix(editor): Format SQL uppercases words inside string literals, quoted identifiers and comments
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Dart
- Sterne
- 23
- Forks
- 1
- Ø Merge
- 35 Min.
- Gemergte PRs (30 T.)
- 497
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus QueryaHub/Querya-Desktop
-
enhancement ui
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
QueryaHub/Querya-Desktop#1689 ·
Maintainer antworten meist innerhalb von 1 Tag
-
ui(dialogs): make destructive query and DML preview dialogs adaptive and prevent table name overflowOffenbug frontend
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
QueryaHub/Querya-Desktop#1642 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug error-handling settings
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 78/100
QueryaHub/Querya-Desktop#1637 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
QueryaHub/Querya-Desktop#1636 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement marketplace
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
QueryaHub/Querya-Desktop#1635 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in QueryaHub/Querya-Desktop
Ähnliche Issues
-
[Bug] 附近设备权限未申请Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
bggRGjQaUbCoE/PiliPlus#3369 ·
Maintainer antworten meist innerhalb von 1 Tag
-
auto-implement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
bannzai/kashakeibo#143 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
[lsp] Remove DartAnalysisServerService.serverReadyForRequest() from EnableDartSupportForModuleOffenP1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
flutter/flutter-intellij#9177 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
AOSSIE-Org/Ell-ena#356 ·
Maintainer antworten meist innerhalb von 1 Tag