fix(serialization): Remove legacy BinaryFormatter support
SonarQube Analysis / sonarqube (pull_request) Successful in 4m42s
SonarQube Analysis / sonarqube (pull_request) Successful in 4m42s
The `[Serializable]` attribute and corresponding `[OnDeserialized]` methods have been removed from various breakdown classes. This eliminates reliance on `BinaryFormatter`, which is a deprecated and insecure serialization mechanism in modern .NET. This change also resolves SonarQube rule S5766 warnings by removing the context in which they apply, leading to cleaner and more secure code.
This commit is contained in:
@@ -14,7 +14,6 @@ namespace Strata.SqlTools.Breakdowns.LinqToSql;
|
|||||||
/// SELECT, WHERE, JOIN, GROUP BY, and ORDER BY clauses, making them accessible
|
/// SELECT, WHERE, JOIN, GROUP BY, and ORDER BY clauses, making them accessible
|
||||||
/// through the QueryBreakdown interface.
|
/// through the QueryBreakdown interface.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Serializable]
|
|
||||||
public class LinqQueryBreakdown : QueryBreakdown
|
public class LinqQueryBreakdown : QueryBreakdown
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using Strata.SqlTools.SqlBreakdown.Expressions;
|
using Strata.SqlTools.SqlBreakdown.Expressions;
|
||||||
using Strata.SqlTools.SqlBreakdown.Interfaces.Core;
|
using Strata.SqlTools.SqlBreakdown.Interfaces.Core;
|
||||||
using CommandVisitor = Strata.SqlTools.Visitors.PostgreSql.CommandVisitor;
|
using CommandVisitor = Strata.SqlTools.Visitors.PostgreSql.CommandVisitor;
|
||||||
@@ -15,7 +14,6 @@ namespace Strata.SqlTools.Breakdowns.PostgreSql;
|
|||||||
/// Represents a PostgreSQL query breakdown with all clauses, following PostgreSQL SQL standards.
|
/// Represents a PostgreSQL query breakdown with all clauses, following PostgreSQL SQL standards.
|
||||||
/// Handles positional parameters using $1, $2, ... syntax for parameterized queries.
|
/// Handles positional parameters using $1, $2, ... syntax for parameterized queries.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class QueryBreakdown : SqlServerQueryBreakdown
|
public class QueryBreakdown : SqlServerQueryBreakdown
|
||||||
{
|
{
|
||||||
private const string ExpressionNullErrorMessage = "Expression cannot be null.";
|
private const string ExpressionNullErrorMessage = "Expression cannot be null.";
|
||||||
@@ -89,14 +87,6 @@ public class QueryBreakdown : SqlServerQueryBreakdown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the breakdown's clause state (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context) => RevalidateBreakdownState();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a parameter to the query using PostgreSQL's positional parameter format ($1, $2, ...).
|
/// Adds a parameter to the query using PostgreSQL's positional parameter format ($1, $2, ...).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||||
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
||||||
@@ -13,7 +12,6 @@ namespace Strata.SqlTools.Breakdowns.PostgreSql;
|
|||||||
/// including support for PostgreSQL features like schema-qualified identifiers,
|
/// including support for PostgreSQL features like schema-qualified identifiers,
|
||||||
/// LIMIT/OFFSET clauses, parameterized queries using $1, $2 syntax, and CTEs.
|
/// LIMIT/OFFSET clauses, parameterized queries using $1, $2 syntax, and CTEs.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Serializable]
|
|
||||||
public class QueryBreakdownCollection : SqlBreakdownCollection
|
public class QueryBreakdownCollection : SqlBreakdownCollection
|
||||||
{
|
{
|
||||||
private readonly List<QueryBreakdown> _queryBreakdowns;
|
private readonly List<QueryBreakdown> _queryBreakdowns;
|
||||||
@@ -36,20 +34,6 @@ public class QueryBreakdownCollection : SqlBreakdownCollection
|
|||||||
_queryBreakdowns = queryBreakdowns?.ToList() ?? new List<QueryBreakdown>();
|
_queryBreakdowns = queryBreakdowns?.ToList() ?? new List<QueryBreakdown>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates that the backing list survived deserialization, since deserialization bypasses
|
|
||||||
/// the constructors that normally initialize it (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context)
|
|
||||||
{
|
|
||||||
if (_queryBreakdowns is null)
|
|
||||||
{
|
|
||||||
throw new SerializationException("Deserialized QueryBreakdownCollection is missing its backing list.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the collection of QueryBreakdown objects.
|
/// Gets the collection of QueryBreakdown objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using SqlServerDeleteBreakdown = Strata.SqlTools.Breakdowns.SqlServer.DeleteBreakdown;
|
using SqlServerDeleteBreakdown = Strata.SqlTools.Breakdowns.SqlServer.DeleteBreakdown;
|
||||||
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
||||||
@@ -9,7 +8,6 @@ namespace Strata.SqlTools.Breakdowns.Snowflake;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a DELETE SQL statement breakdown with FROM and WHERE clauses for Snowflake.
|
/// Represents a DELETE SQL statement breakdown with FROM and WHERE clauses for Snowflake.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class DeleteBreakdown : SqlServerDeleteBreakdown
|
public class DeleteBreakdown : SqlServerDeleteBreakdown
|
||||||
{
|
{
|
||||||
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
||||||
@@ -41,14 +39,6 @@ public class DeleteBreakdown : SqlServerDeleteBreakdown
|
|||||||
WhereClause.Comment = whereComments.Count > 0 ? string.Join(" ", whereComments) : null;
|
WhereClause.Comment = whereComments.Count > 0 ? string.Join(" ", whereComments) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the breakdown's clause state (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context) => RevalidateBreakdownState();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the SQL breakdown as a string for Snowflake.
|
/// Gets the SQL breakdown as a string for Snowflake.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using Strata.SqlTools.SqlBreakdown.Utilities;
|
using Strata.SqlTools.SqlBreakdown.Utilities;
|
||||||
using SqlServerInsertBreakdown = Strata.SqlTools.Breakdowns.SqlServer.InsertBreakdown;
|
using SqlServerInsertBreakdown = Strata.SqlTools.Breakdowns.SqlServer.InsertBreakdown;
|
||||||
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
||||||
@@ -9,7 +8,6 @@ namespace Strata.SqlTools.Breakdowns.Snowflake;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an INSERT SQL statement breakdown with column and value clauses for Snowflake.
|
/// Represents an INSERT SQL statement breakdown with column and value clauses for Snowflake.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class InsertBreakdown : SqlServerInsertBreakdown
|
public class InsertBreakdown : SqlServerInsertBreakdown
|
||||||
{
|
{
|
||||||
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
||||||
@@ -66,14 +64,6 @@ public class InsertBreakdown : SqlServerInsertBreakdown
|
|||||||
ValuesClause.Clause = string.Join(",", valuesList);
|
ValuesClause.Clause = string.Join(",", valuesList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the breakdown's clause state (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context) => RevalidateBreakdownState();
|
|
||||||
|
|
||||||
#region Parse Methods
|
#region Parse Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using SqlServerProcedureBreakdown = Strata.SqlTools.Breakdowns.SqlServer.ProcedureBreakdown;
|
using SqlServerProcedureBreakdown = Strata.SqlTools.Breakdowns.SqlServer.ProcedureBreakdown;
|
||||||
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
||||||
@@ -9,7 +8,6 @@ namespace Strata.SqlTools.Breakdowns.Snowflake;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a Snowflake stored procedure call breakdown with procedure name and parameters.
|
/// Represents a Snowflake stored procedure call breakdown with procedure name and parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class ProcedureBreakdown : SqlServerProcedureBreakdown
|
public class ProcedureBreakdown : SqlServerProcedureBreakdown
|
||||||
{
|
{
|
||||||
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
||||||
@@ -47,15 +45,6 @@ public class ProcedureBreakdown : SqlServerProcedureBreakdown
|
|||||||
Parameters = parameters ?? new Dictionary<string, string>();
|
Parameters = parameters ?? new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the procedure name and parameter collection
|
|
||||||
/// (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context) => RevalidateBreakdownState();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the SQL breakdown as a string for Snowflake.
|
/// Gets the SQL breakdown as a string for Snowflake.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||||
using Strata.SqlTools.SqlBreakdown.Expressions;
|
using Strata.SqlTools.SqlBreakdown.Expressions;
|
||||||
@@ -19,7 +18,6 @@ namespace Strata.SqlTools.Breakdowns.Snowflake;
|
|||||||
/// Represents a Snowflake SQL query breakdown with all clauses, following Snowflake SQL standards.
|
/// Represents a Snowflake SQL query breakdown with all clauses, following Snowflake SQL standards.
|
||||||
/// Handles both :parameter and @parameter syntax for Snowflake compatibility.
|
/// Handles both :parameter and @parameter syntax for Snowflake compatibility.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class QueryBreakdown : SqlServerQueryBreakdown
|
public class QueryBreakdown : SqlServerQueryBreakdown
|
||||||
{
|
{
|
||||||
private const string ExpressionNullErrorMessage = "Expression cannot be null.";
|
private const string ExpressionNullErrorMessage = "Expression cannot be null.";
|
||||||
@@ -86,14 +84,6 @@ public class QueryBreakdown : SqlServerQueryBreakdown
|
|||||||
OrderByClause.Comment = orderByComments.Count > 0 ? string.Join(" ", orderByComments) : null;
|
OrderByClause.Comment = orderByComments.Count > 0 ? string.Join(" ", orderByComments) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the breakdown's clause state (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context) => RevalidateBreakdownState();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a parameter to the query using Snowflake's :param format.
|
/// Adds a parameter to the query using Snowflake's :param format.
|
||||||
/// Also adds @param format for compatibility.
|
/// Also adds @param format for compatibility.
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||||
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
||||||
@@ -14,7 +13,6 @@ namespace Strata.SqlTools.Breakdowns.Snowflake;
|
|||||||
/// time travel, snowflake-specific parameters (:parameter and @parameter syntax),
|
/// time travel, snowflake-specific parameters (:parameter and @parameter syntax),
|
||||||
/// and proper batch handling.
|
/// and proper batch handling.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Serializable]
|
|
||||||
public class QueryBreakdownCollection : SqlBreakdownCollection
|
public class QueryBreakdownCollection : SqlBreakdownCollection
|
||||||
{
|
{
|
||||||
private readonly List<QueryBreakdown> _queryBreakdowns;
|
private readonly List<QueryBreakdown> _queryBreakdowns;
|
||||||
@@ -37,20 +35,6 @@ public class QueryBreakdownCollection : SqlBreakdownCollection
|
|||||||
_queryBreakdowns = new List<QueryBreakdown>(queryBreakdowns ?? Enumerable.Empty<QueryBreakdown>());
|
_queryBreakdowns = new List<QueryBreakdown>(queryBreakdowns ?? Enumerable.Empty<QueryBreakdown>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates that the backing list survived deserialization, since deserialization bypasses
|
|
||||||
/// the constructors that normally initialize it (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context)
|
|
||||||
{
|
|
||||||
if (_queryBreakdowns is null)
|
|
||||||
{
|
|
||||||
throw new SerializationException("Deserialized QueryBreakdownCollection is missing its backing list.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the collection of QueryBreakdown objects.
|
/// Gets the collection of QueryBreakdown objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using SqlServerUpdateBreakdown = Strata.SqlTools.Breakdowns.SqlServer.UpdateBreakdown;
|
using SqlServerUpdateBreakdown = Strata.SqlTools.Breakdowns.SqlServer.UpdateBreakdown;
|
||||||
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
using StatementParser = Strata.SqlTools.Statements.Snowflake.StatementParser;
|
||||||
@@ -9,7 +8,6 @@ namespace Strata.SqlTools.Breakdowns.Snowflake;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an UPDATE SQL statement breakdown with SET, FROM, and WHERE clauses for Snowflake.
|
/// Represents an UPDATE SQL statement breakdown with SET, FROM, and WHERE clauses for Snowflake.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class UpdateBreakdown : SqlServerUpdateBreakdown
|
public class UpdateBreakdown : SqlServerUpdateBreakdown
|
||||||
{
|
{
|
||||||
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
private static readonly StatementParser SnowflakeParserInstance = new StatementParser();
|
||||||
@@ -46,14 +44,6 @@ public class UpdateBreakdown : SqlServerUpdateBreakdown
|
|||||||
WhereClause.Comment = whereComments.Count > 0 ? string.Join(" ", whereComments) : null;
|
WhereClause.Comment = whereComments.Count > 0 ? string.Join(" ", whereComments) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the breakdown's clause state (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context) => RevalidateBreakdownState();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the SQL breakdown as a string for Snowflake.
|
/// Gets the SQL breakdown as a string for Snowflake.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ namespace Strata.SqlTools.SqlBreakdown.Classes;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a query parameter with a name and value.
|
/// Represents a query parameter with a name and value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public sealed class QueryParam : IQueryParam
|
public sealed class QueryParam : IQueryParam
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ namespace Strata.SqlTools.SqlBreakdown.Classes;
|
|||||||
/// This class is primarily used for batch SQL parsing where raw statements need to be stored
|
/// This class is primarily used for batch SQL parsing where raw statements need to be stored
|
||||||
/// without detailed clause breakdown. Actual clause parsing can be performed separately.
|
/// without detailed clause breakdown. Actual clause parsing can be performed separately.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Serializable]
|
|
||||||
public class RawSqlBreakdown : ISqlBreakdown
|
public class RawSqlBreakdown : ISqlBreakdown
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ namespace Strata.SqlTools.SqlBreakdown.Classes;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for SQL query breakdowns that provides common setup/finish clause handling and cloning.
|
/// Base class for SQL query breakdowns that provides common setup/finish clause handling and cloning.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public abstract class SqlBreakdownBase : ISqlBreakdown
|
public abstract class SqlBreakdownBase : ISqlBreakdown
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -48,18 +47,6 @@ public abstract class SqlBreakdownBase : ISqlBreakdown
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsUsingFinishClause => FinishClauses.Count > 0;
|
public bool IsUsingFinishClause => FinishClauses.Count > 0;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes the invariants normally guaranteed by the constructors after the object
|
|
||||||
/// is reconstructed by deserialization. Deserialization bypasses constructors, so the
|
|
||||||
/// collection state must be re-validated to avoid a partially-initialized object
|
|
||||||
/// (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
protected void RevalidateBreakdownState()
|
|
||||||
{
|
|
||||||
SetupClauses ??= new List<string>();
|
|
||||||
FinishClauses ??= new ArrayList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the SQL breakdown as a string. Must be implemented by derived classes.
|
/// Gets the SQL breakdown as a string. Must be implemented by derived classes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
||||||
using Strata.SqlTools.SqlBreakdown.Interfaces.QueryEngine;
|
using Strata.SqlTools.SqlBreakdown.Interfaces.QueryEngine;
|
||||||
@@ -13,7 +12,6 @@ namespace Strata.SqlTools.SqlBreakdown.Classes;
|
|||||||
/// allowing efficient management and retrieval of multiple SQL breakdowns as a unified collection.
|
/// allowing efficient management and retrieval of multiple SQL breakdowns as a unified collection.
|
||||||
/// Implements ICollection<ISqlBreakdown> to provide standard collection semantics and LINQ support.
|
/// Implements ICollection<ISqlBreakdown> to provide standard collection semantics and LINQ support.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Serializable]
|
|
||||||
public class SqlBreakdownCollection : ICollection<ISqlBreakdown>
|
public class SqlBreakdownCollection : ICollection<ISqlBreakdown>
|
||||||
{
|
{
|
||||||
private readonly List<ISqlBreakdown> _breakdowns;
|
private readonly List<ISqlBreakdown> _breakdowns;
|
||||||
@@ -36,20 +34,6 @@ public class SqlBreakdownCollection : ICollection<ISqlBreakdown>
|
|||||||
_breakdowns = new List<ISqlBreakdown>(breakdowns ?? Enumerable.Empty<ISqlBreakdown>());
|
_breakdowns = new List<ISqlBreakdown>(breakdowns ?? Enumerable.Empty<ISqlBreakdown>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates that the backing list survived deserialization, since deserialization bypasses
|
|
||||||
/// the constructors that normally initialize it (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context)
|
|
||||||
{
|
|
||||||
if (_breakdowns is null)
|
|
||||||
{
|
|
||||||
throw new SerializationException("Deserialized SqlBreakdownCollection is missing its backing list.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the collection of SQL breakdowns.
|
/// Gets the collection of SQL breakdowns.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Strata.SqlTools.SqlBreakdown.Interfaces.Core;
|
using Strata.SqlTools.SqlBreakdown.Interfaces.Core;
|
||||||
|
|
||||||
@@ -8,7 +7,6 @@ namespace Strata.SqlTools.SqlBreakdown.Classes;
|
|||||||
/// Represents a SQL filter with an expression and parameters.
|
/// Represents a SQL filter with an expression and parameters.
|
||||||
/// Implements SQL appendable and SQL interfaces for query building.
|
/// Implements SQL appendable and SQL interfaces for query building.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class SqlFilter : ISqlAppendable
|
public class SqlFilter : ISqlAppendable
|
||||||
{
|
{
|
||||||
private readonly StringBuilder _sqlExpression;
|
private readonly StringBuilder _sqlExpression;
|
||||||
@@ -59,21 +57,6 @@ public class SqlFilter : ISqlAppendable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates that the expression and parameter state survived deserialization, since
|
|
||||||
/// deserialization bypasses the constructors that normally initialize them and enforce the
|
|
||||||
/// even parameter-name/value pairing (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context)
|
|
||||||
{
|
|
||||||
if (_sqlExpression is null || _parameterValues is null)
|
|
||||||
{
|
|
||||||
throw new SerializationException("Deserialized SqlFilter is missing its expression or parameter state.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the SQL expression.
|
/// Gets or sets the SQL expression.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a DELETE SQL statement breakdown with FROM and WHERE clauses for SQL Server.
|
/// Represents a DELETE SQL statement breakdown with FROM and WHERE clauses for SQL Server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class DeleteBreakdown : SqlBreakdownBase
|
public class DeleteBreakdown : SqlBreakdownBase
|
||||||
{
|
{
|
||||||
protected readonly StatementParser Parser;
|
protected readonly StatementParser Parser;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an INSERT SQL statement breakdown with column and value clauses for SQL Server.
|
/// Represents an INSERT SQL statement breakdown with column and value clauses for SQL Server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class InsertBreakdown : SqlBreakdownBase
|
public class InsertBreakdown : SqlBreakdownBase
|
||||||
{
|
{
|
||||||
protected readonly StatementParser Parser;
|
protected readonly StatementParser Parser;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||||
@@ -10,7 +9,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a SQL Server stored procedure call breakdown with procedure name and parameters.
|
/// Represents a SQL Server stored procedure call breakdown with procedure name and parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class ProcedureBreakdown : SqlBreakdownBase
|
public class ProcedureBreakdown : SqlBreakdownBase
|
||||||
{
|
{
|
||||||
protected readonly StatementParser Parser;
|
protected readonly StatementParser Parser;
|
||||||
@@ -46,20 +44,6 @@ public class ProcedureBreakdown : SqlBreakdownBase
|
|||||||
Parameters = parameters ?? new Dictionary<string, string>();
|
Parameters = parameters ?? new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the procedure name and parameter collection
|
|
||||||
/// (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context)
|
|
||||||
{
|
|
||||||
RevalidateBreakdownState();
|
|
||||||
ProcedureName ??= new SqlClause();
|
|
||||||
Parameters ??= new Dictionary<string, string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the stored procedure name.
|
/// Gets or sets the stored procedure name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||||
using Strata.SqlTools.SqlBreakdown.Expressions;
|
using Strata.SqlTools.SqlBreakdown.Expressions;
|
||||||
@@ -14,7 +13,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a SELECT query breakdown with all clauses (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY).
|
/// Represents a SELECT query breakdown with all clauses (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
#pragma warning disable S2325 // Methods and properties that don't access instance data should be static - False positive: These members access instance fields
|
#pragma warning disable S2325 // Methods and properties that don't access instance data should be static - False positive: These members access instance fields
|
||||||
public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
|
public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
|
||||||
{
|
{
|
||||||
@@ -108,28 +106,6 @@ public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Re-establishes invariants after deserialization, since deserialization bypasses the
|
|
||||||
/// constructors that normally initialize the parameter, WITH-clause, and clause backing
|
|
||||||
/// fields (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context)
|
|
||||||
{
|
|
||||||
RevalidateBreakdownState();
|
|
||||||
|
|
||||||
_parameterList ??= new List<IQueryParam>();
|
|
||||||
_withClauses ??= new List<IWithClause>();
|
|
||||||
_selectClause ??= new SqlExpressionClause(splitOnComma: true);
|
|
||||||
_fromClause ??= new SqlClause();
|
|
||||||
_whereClause ??= new SqlExpressionClause(splitOnComma: false);
|
|
||||||
_groupByClause ??= new SqlExpressionClause(splitOnComma: true);
|
|
||||||
_havingClause ??= new SqlExpressionClause(splitOnComma: false);
|
|
||||||
_orderByClause ??= new SqlExpressionClause(splitOnComma: true);
|
|
||||||
_clausesCacheDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Strata.SqlTools.SqlBreakdown.Classes;
|
using Strata.SqlTools.SqlBreakdown.Classes;
|
||||||
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
using Strata.SqlTools.SqlBreakdown.Interfaces;
|
||||||
@@ -12,7 +11,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
|||||||
/// This class extends SqlBreakdownCollection with SQL Server-specific functionality,
|
/// This class extends SqlBreakdownCollection with SQL Server-specific functionality,
|
||||||
/// including support for T-SQL features like batches (GO), temporary tables, stored procedures, and CTEs.
|
/// including support for T-SQL features like batches (GO), temporary tables, stored procedures, and CTEs.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Serializable]
|
|
||||||
public class QueryBreakdownCollection : SqlBreakdownCollection
|
public class QueryBreakdownCollection : SqlBreakdownCollection
|
||||||
{
|
{
|
||||||
private readonly List<QueryBreakdown> _queryBreakdowns;
|
private readonly List<QueryBreakdown> _queryBreakdowns;
|
||||||
@@ -34,20 +32,6 @@ public class QueryBreakdownCollection : SqlBreakdownCollection
|
|||||||
_queryBreakdowns = new List<QueryBreakdown>(queryBreakdowns ?? Enumerable.Empty<QueryBreakdown>());
|
_queryBreakdowns = new List<QueryBreakdown>(queryBreakdowns ?? Enumerable.Empty<QueryBreakdown>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Validates that the backing list survived deserialization, since deserialization bypasses
|
|
||||||
/// the constructors that normally initialize it (SonarQube rule S5766).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The streaming context for the deserialization operation.</param>
|
|
||||||
[OnDeserialized]
|
|
||||||
private void OnDeserialized(StreamingContext context)
|
|
||||||
{
|
|
||||||
if (_queryBreakdowns is null)
|
|
||||||
{
|
|
||||||
throw new SerializationException("Deserialized QueryBreakdownCollection is missing its backing list.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the collection of QueryBreakdown objects.
|
/// Gets the collection of QueryBreakdown objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ namespace Strata.SqlTools.Breakdowns.SqlServer;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an UPDATE SQL statement breakdown with SET, FROM, and WHERE clauses for SQL Server.
|
/// Represents an UPDATE SQL statement breakdown with SET, FROM, and WHERE clauses for SQL Server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
|
||||||
public class UpdateBreakdown : SqlBreakdownBase
|
public class UpdateBreakdown : SqlBreakdownBase
|
||||||
{
|
{
|
||||||
protected readonly StatementParser Parser;
|
protected readonly StatementParser Parser;
|
||||||
|
|||||||
Reference in New Issue
Block a user