Class SqlHelpers
Contains various SQL helpers.
public static class SqlHelpers
- Inheritance
-
SqlHelpers
- Inherited Members
Fields
BlobMarker
public const char BlobMarker = 'X'
Field Value
DateFormat
public const string DateFormat = "yyyy-MM-dd"
Field Value
DateFormatQuoted
public const string DateFormatQuoted = "\\'yyyy-MM-dd\\'"
Field Value
DateTimeFormatMicrosecond
public const string DateTimeFormatMicrosecond = "yyyy-MM-dd HH:mm:ss.ffffff"
Field Value
DateTimeFormatMicrosecondQuoted
public const string DateTimeFormatMicrosecondQuoted = "\\'yyyy-MM-dd HH:mm:ss.ffffff\\'"
Field Value
DateTimeFormatTick
public const string DateTimeFormatTick = "yyyy-MM-dd HH:mm:ss.fffffff"
Field Value
DateTimeFormatTickQuoted
public const string DateTimeFormatTickQuoted = "\\'yyyy-MM-dd HH:mm:ss.fffffff\\'"
Field Value
DateTimeOffsetFormat
public const string DateTimeOffsetFormat = "yyyy-MM-dd HH:mm:ss.fffffffzzz"
Field Value
DateTimeOffsetFormatQuoted
public const string DateTimeOffsetFormatQuoted = "\\'yyyy-MM-dd HH:mm:ss.fffffffzzz\\'"
Field Value
DecimalFormat
public const string DecimalFormat = "0.0###########################"
Field Value
DecimalFormatQuoted
public const string DecimalFormatQuoted = "\\'0.0###########################\\'"
Field Value
DefaultNamesCreator
Default creator of SqlDefaultObjectNameProvider instances.
public static readonly SqlDefaultObjectNameProviderCreator<SqlDefaultObjectNameProvider> DefaultNamesCreator
Field Value
EmptyBlobLiteral
public const string EmptyBlobLiteral = "X''"
Field Value
EmptyTextLiteral
public const string EmptyTextLiteral = "''"
Field Value
ExecuteBoolScalarDelegate
Scalar IDbCommand executor delegate that returns bool value.
public static readonly Func<IDbCommand, bool> ExecuteBoolScalarDelegate
Field Value
ExecuteNonQueryDelegate
Non-query IDbCommand executor delegate.
public static readonly Func<IDbCommand, int> ExecuteNonQueryDelegate
Field Value
NameComparer
SQL object name comparer. Equivalent to OrdinalIgnoreCase.
public static readonly StringComparer NameComparer
Field Value
StackallocThreshold
public const int StackallocThreshold = 64
Field Value
TextDelimiter
public const char TextDelimiter = '\''
Field Value
TimeFormatMicrosecond
public const string TimeFormatMicrosecond = "HH:mm:ss.ffffff"
Field Value
TimeFormatMicrosecondQuoted
public const string TimeFormatMicrosecondQuoted = "\\'HH:mm:ss.ffffff\\'"
Field Value
TimeFormatTick
public const string TimeFormatTick = "HH:mm:ss.fffffff"
Field Value
TimeFormatTickQuoted
public const string TimeFormatTickQuoted = "\\'HH:mm:ss.fffffff\\'"
Field Value
VersionHistoryCommitDateUtcName
public const string VersionHistoryCommitDateUtcName = "CommitDateUtc"
Field Value
VersionHistoryCommitDurationInTicksName
public const string VersionHistoryCommitDurationInTicksName = "CommitDurationInTicks"
Field Value
VersionHistoryDescriptionName
public const string VersionHistoryDescriptionName = "Description"
Field Value
VersionHistoryName
public const string VersionHistoryName = "__VersionHistory"
Field Value
VersionHistoryOrdinalName
public const string VersionHistoryOrdinalName = "Ordinal"
Field Value
VersionHistoryVersionBuildName
public const string VersionHistoryVersionBuildName = "VersionBuild"
Field Value
VersionHistoryVersionMajorName
public const string VersionHistoryVersionMajorName = "VersionMajor"
Field Value
VersionHistoryVersionMinorName
public const string VersionHistoryVersionMinorName = "VersionMinor"
Field Value
VersionHistoryVersionRevisionName
public const string VersionHistoryVersionRevisionName = "VersionRevision"
Field Value
Methods
AssertForeignKey(SqlTableBuilder, SqlIndexBuilder, SqlIndexBuilder)
Validates foreign key constraint.
public static void AssertForeignKey(SqlTableBuilder table, SqlIndexBuilder originIndex, SqlIndexBuilder referencedIndex)
Parameters
tableSqlTableBuilderSqlTableBuilder that the foreign key belongs to.
originIndexSqlIndexBuilderSqlIndexBuilder from which the foreign key originates.
referencedIndexSqlIndexBuilderSqlIndexBuilder which the foreign key references.
Remarks
Indexes must not be the same. Origin index cannot contain expressions. Referenced index must be unique and cannot be partial, and cannot contain nullable or generated columns. Both origin and referenced index must contain the same number of columns and their runtime types must be sequentially equal.
Exceptions
- SqlObjectBuilderException
When foreign key is not considered valid.
AssertIndexColumns(SqlTableBuilder, SqlIndexBuilderColumns<SqlColumnBuilder>, bool)
Validates index constraint columns.
public static void AssertIndexColumns(SqlTableBuilder table, SqlIndexBuilderColumns<SqlColumnBuilder> columns, bool isUnique)
Parameters
tableSqlTableBuilderSqlTableBuilder that the index belongs to.
columnsSqlIndexBuilderColumns<SqlColumnBuilder>Collection of columns that belong to the index.
isUniqueboolSpecifies whether or not the index is unique.
Remarks
Index must contain at least one column and columns must be distinct. When index is unique, then it cannot contain expressions.
Exceptions
- SqlObjectBuilderException
When index columns are not considered valid.
AssertPrimaryKey(SqlTableBuilder, SqlIndexBuilder)
Validates primary key constraint.
public static void AssertPrimaryKey(SqlTableBuilder table, SqlIndexBuilder index)
Parameters
tableSqlTableBuilderSqlTableBuilder that the primary key belongs to.
indexSqlIndexBuilderSqlIndexBuilder that is the underlying index of the primary key.
Remarks
Underlying index must be unique and cannot be partial. It also cannot contain nullable columns or columns that are generated.
Exceptions
- SqlObjectBuilderException
When primary key is not considered valid.
CastOrThrow<T>(ISqlDatabaseBuilder, object)
Type casts the provided object to the desired type.
[Pure]
public static T CastOrThrow<T>(ISqlDatabaseBuilder database, object obj)
Parameters
databaseISqlDatabaseBuilderSQL database builder with which the object is associated.
objobjectObject to cast.
Returns
- T
objcast to the desired type.
Type Parameters
TDesired type.
Exceptions
- SqlObjectCastException
When
objis not of the desired type.
CastOrThrow<T>(SqlDialect, object)
Type casts the provided object to the desired type.
[Pure]
public static T CastOrThrow<T>(SqlDialect dialect, object obj)
Parameters
dialectSqlDialectSQL dialect with which the object is associated.
objobjectObject to cast.
Returns
- T
objcast to the desired type.
Type Parameters
TDesired type.
Exceptions
- SqlObjectCastException
When
objis not of the desired type.
CreateObjectBuilderException(ISqlDatabaseBuilder, Chain<string>)
Creates a new SqlObjectBuilderException instance.
[Pure]
public static SqlObjectBuilderException CreateObjectBuilderException(ISqlDatabaseBuilder database, Chain<string> errors)
Parameters
databaseISqlDatabaseBuilderSource SQL database builder.
errorsChain<string>Collection of error messages.
Returns
- SqlObjectBuilderException
New SqlObjectBuilderException instance.
CreateObjectBuilderException(ISqlDatabaseBuilder, string)
Creates a new SqlObjectBuilderException instance.
[Pure]
public static SqlObjectBuilderException CreateObjectBuilderException(ISqlDatabaseBuilder database, string error)
Parameters
databaseISqlDatabaseBuilderSource SQL database builder.
errorstringError message.
Returns
- SqlObjectBuilderException
New SqlObjectBuilderException instance.
CreateObjectCastException(ISqlDatabase, Type, Type)
Creates a new SqlObjectCastException instance.
[Pure]
public static SqlObjectCastException CreateObjectCastException(ISqlDatabase database, Type expected, Type actual)
Parameters
databaseISqlDatabaseSource SQL database.
expectedTypeExpected object type.
actualTypeActual object type.
Returns
- SqlObjectCastException
New SqlObjectCastException instance.
CreateObjectCastException(ISqlDatabaseBuilder, Type, Type)
Creates a new SqlObjectCastException instance.
[Pure]
public static SqlObjectCastException CreateObjectCastException(ISqlDatabaseBuilder database, Type expected, Type actual)
Parameters
databaseISqlDatabaseBuilderSource SQL database builder.
expectedTypeExpected object type.
actualTypeActual object type.
Returns
- SqlObjectCastException
New SqlObjectCastException instance.
GetDbLiteral(bool)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(bool value)
Parameters
valueboolValue to convert.
Returns
- string
"1" when
valueis equal to true, otherwise "0".
GetDbLiteral(char)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(char value)
Parameters
valuecharValue to convert.
Returns
GetDbLiteral(decimal)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(decimal value)
Parameters
valuedecimalValue to convert.
Returns
GetDbLiteral(double)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(double value)
Parameters
valuedoubleValue to convert.
Returns
GetDbLiteral(long)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(long value)
Parameters
valuelongValue to convert.
Returns
GetDbLiteral(ReadOnlySpan<byte>)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(ReadOnlySpan<byte> value)
Parameters
valueReadOnlySpan<byte>Value to convert.
Returns
GetDbLiteral(ReadOnlySpan<char>)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(ReadOnlySpan<char> value)
Parameters
valueReadOnlySpan<char>Value to convert.
Returns
Remarks
Escapes TextDelimiter occurrences.
GetDbLiteral(float)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(float value)
Parameters
valuefloatValue to convert.
Returns
GetDbLiteral(ulong)
Converts value to a DB literal.
[Pure]
public static string GetDbLiteral(ulong value)
Parameters
valueulongValue to convert.
Returns
GetDefaultCheckName(ISqlTableBuilder)
Creates a default check constraint name.
[Pure]
public static string GetDefaultCheckName(ISqlTableBuilder table)
Parameters
tableISqlTableBuilderISqlTableBuilder that the check belongs to.
Returns
- string
Default check constraint name.
GetDefaultForeignKeyName(ISqlIndexBuilder, ISqlIndexBuilder)
Creates a default foreign key constraint name.
[Pure]
public static string GetDefaultForeignKeyName(ISqlIndexBuilder originIndex, ISqlIndexBuilder referencedIndex)
Parameters
originIndexISqlIndexBuilderISqlIndexBuilder from which the foreign key originates.
referencedIndexISqlIndexBuilderISqlIndexBuilder which the foreign key references.
Returns
- string
Default foreign key constraint name.
GetDefaultIndexName(ISqlTableBuilder, SqlIndexBuilderColumns<ISqlColumnBuilder>, bool)
Creates a default index constraint name.
[Pure]
public static string GetDefaultIndexName(ISqlTableBuilder table, SqlIndexBuilderColumns<ISqlColumnBuilder> columns, bool isUnique)
Parameters
tableISqlTableBuilderISqlTableBuilder that the index belongs to.
columnsSqlIndexBuilderColumns<ISqlColumnBuilder>Collection of columns that belong to the index.
isUniqueboolSpecifies whether or not the index is unique.
Returns
- string
Default index constraint name.
GetDefaultPrimaryKeyName(ISqlTableBuilder)
Creates a default primary key constraint name.
[Pure]
public static string GetDefaultPrimaryKeyName(ISqlTableBuilder table)
Parameters
tableISqlTableBuilderISqlTableBuilder that the primary key belongs to.
Returns
- string
Default primary key constraint name.
GetFullName(string, string, char)
Returns the full name of an SQL object.
[Pure]
public static string GetFullName(string schemaName, string name, char separator = '.')
Parameters
schemaNamestringSQL schema name.
namestringSQL object name.
separatorcharName separator. Equal to . by default.
Returns
- string
Full SQL object name.
GetFullName(string, string, string, char, char)
Returns the full name of an SQL field.
[Pure]
public static string GetFullName(string schemaName, string recordSetName, string name, char firstSeparator = '.', char secondSeparator = '.')
Parameters
schemaNamestringSQL schema name.
recordSetNamestringSQL record set name.
namestringSQL field name.
firstSeparatorcharschemaNameandrecordSetNameseparator. Equal to . by default.secondSeparatorcharrecordSetNameandnameseparator. Equal to . by default.
Returns
- string
Full SQL field name.
GetReferencingObjectsInOrderOfCreation(SqlObjectBuilder, Func<SqlObjectBuilderReference<SqlObjectBuilder>, bool>?)
Extracts ReferencingObjects from the provided obj, on order of their creation.
public static RentedMemorySequence<SqlObjectBuilder> GetReferencingObjectsInOrderOfCreation(SqlObjectBuilder obj, Func<SqlObjectBuilderReference<SqlObjectBuilder>, bool>? filter = null)
Parameters
objSqlObjectBuilderSqlObjectBuilder instance to extract references from.
filterFunc<SqlObjectBuilderReference<SqlObjectBuilder>, bool>Optional SQL object builder reference filter. References that return false will be ignored. Equal to null by default.
Returns
- RentedMemorySequence<SqlObjectBuilder>
New RentedMemorySequence<T> instance.