ScriptDom interprets ambiguously the next word right after transaction control statement
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
Piste de recherche
Commencez par reproduire les exemples de BEGIN, SAVE, COMMIT et ROLLBACK avec les niveaux de compatibilité 150 et 160 de ScriptDom. Examinez la manière dont les noms de transactions et les instructions suivantes d’un seul mot sont classifiés, puis définissez le comportement attendu pour des cas tels que THROW et CONTINUE ; l’issue est terminée lorsque l’ambiguïté est résolue ou qu’un avertissement est fourni de manière cohérente.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
- ScriptDom Version: 161.8910.0
- CompatibilityLevel used for parsing: 150, 160
Some keywords written right next to the transaction control statement are treated as transaction name and some as a separate command/next statement. This may lead to significant misunderstanding of what the code will actually do.
Statements:
- BEGIN TRAN
- SAVE TRAN
- COMMIT TRAN
- ROLLBACK TRAN
Examples of keywords/statements treated as valid identifier for transaction name:
- THROW
- RECEIVE
- SEND
Steps to Reproduce:
If you write BEGIN TRAN THROW - here THROW will be treated as a valid transaction name. However in BEGIN TRAN CONTINUE the CONTINUE will be treated as a separate command. BEGIN/COMMIT/ROLLBACK behave similarly - they can take modern keywords/commands as a valid tran name but "ignore" "oldschool" keywords/commands and treat them as a separate statement even if no statement terminator is present between them. SAVE TRAN unlikely mentioned statements requires transaction name to be provided and if the next word is parsed as an invalid tran identifier candidate the parsing fails with syntax error.
Examples of ambiguity:
COMMIT TRAN CONTINUE
COMMIT TRAN BREAK
COMMIT TRAN THROW -- tran name
COMMIT TRAN RECEIVE -- tran name
COMMIT TRAN SEND -- tran name
COMMIT TRAN RETURN
COMMIT TRAN COMMIT
COMMIT TRAN ROLLBACK
in all lines not marked with comment the last word is treated as a separate statement.
SAVE TRAN requires third word in statement and in all lines except marked with comment parser would say that syntax is broken:
The most ambiguous case to me is this one:
BEGIN TRY
BEGIN TRAN
SELECT 1 / 0
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
THROW -- "Divide by zero" error will not be rethrown here
-- new error will be generated:
-- Cannot roll back THROW. No transaction or savepoint of that name was found
END CATCH
On ROLLBACK TRAN docs page it is said that transaction name must be a valid identifier, identifier is valid if it does not match any of reserved words and THROW is not listed there. On THROW docs page it is said that preceding statement must end with semicolon. Thus ROLLBACK TRAN THROW in the example above behaves expectedly speaking of the docs. But it is an error so easy to make and you need so much to remember to avoid it while coding.
It would be great if
- all one-word statements were included into reserved keywords (especially
THROW); maybe in future compatibility levels - SSDT/DacFx would show at least a warning in such cases and recommend to put semicolon before
THROWor choose another identifier for transaction name
As a workaround I'm developing another rule for our custom linter which would detect such suspicious cases.
(DacFx/SqlPackage/SSMS/Azure Data Studio)
- Langage dominant
- GAP
- Étoiles
- 277
- Forks
- 43
- Merge moyen
- 9 j 23 h
- PR mergées (30 j)
- 2
Préparer son environnement
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/SqlScriptDOM
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
microsoft/SqlScriptDOM#228 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
microsoft/SqlScriptDOM#183 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 56/100
microsoft/SqlScriptDOM#226 · 1 réaction ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
microsoft/SqlScriptDOM#225 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
microsoft/SqlScriptDOM#224 ·
Toutes les issues de microsoft/SqlScriptDOM
Issues similaires
-
After `require "openssl"`, a top-level `Digest` is `OpenSSL::Digest`, not the `Digest` moduleOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
yhirose/cpp-peglib#344 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
build-problem llvm:adt
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
llvm/llvm-project#228475 ·
Les mainteneurs répondent en général sous 1 jour