Skip to content

Commit 2b124ee

Browse files
committed
Validate the name length of BEGIN TRANSACTION statements
1 parent 46980bc commit 2b124ee

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/Dibix.Sdk/CodeAnalysis/Rules/NamingConventionSqlCodeAnalysisRule.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ protected override void BeginStatement(TSqlScript node)
2424
this._looseConstraintDeclarations.ReplaceWith(visitor.LooseConstraintDeclarations);
2525
}
2626

27+
public override void Visit(BeginTransactionStatement node)
28+
{
29+
if (node.Name == null)
30+
return;
31+
32+
string name = node.Name.Value;
33+
if (name.Length > 32)
34+
{
35+
Fail(node.Name, $"The identifier that starts with '{name}' is too long. Maximum length is 32.");
36+
}
37+
}
38+
2739
// Tables
2840
public override void Visit(CreateTableStatement node)
2941
{

tests/Dibix.Sdk.Tests.Database/CodeAnalysis/dbx_codeanalysis_error_017.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ CREATE TYPE [dbo].[dbx_codeanalysis_udt_error_017_success] AS TABLE ([id] INT NO
4444
GO
4545
CREATE PROCEDURE [dbo].[dbx_codeanalysis_error_017_param] @success BIT, @fAiL BIT
4646
AS
47-
PRINT @success + fail
47+
PRINT @success + @faiL
48+
GO
49+
CREATE PROCEDURE [dbo].[dbx_codeanalysis_error_017_length]
50+
AS
51+
BEGIN TRANSACTION [dbx_codeanalysis_error_017_len_s]
52+
ROLLBACK
53+
54+
BEGIN TRANSACTION [dbx_codeanalysis_error_017_len_fail]
55+
ROLLBACK

tests/Dibix.Sdk.Tests/Resources/CodeAnalysis/NamingConventionSqlCodeAnalysisRule.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@
6060
message="Function parameter '@fAiL' does not match naming convention '^@[a-z0-9_]+$'. Also make sure the name is all lowercase."
6161
line="45"
6262
column="73" />
63+
<error
64+
ruleid="17"
65+
message="The identifier that starts with 'dbx_codeanalysis_error_017_len_fail' is too long. Maximum length is 32."
66+
line="54"
67+
column="23" />
6368
</errors>

0 commit comments

Comments
 (0)