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
table
SqlTableBuilderSqlTableBuilder that the foreign key belongs to.
originIndex
SqlIndexBuilderSqlIndexBuilder from which the foreign key originates.
referencedIndex
SqlIndexBuilderSqlIndexBuilder 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
table
SqlTableBuilderSqlTableBuilder that the index belongs to.
columns
SqlIndexBuilderColumns<SqlColumnBuilder>Collection of columns that belong to the index.
isUnique
boolSpecifies 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
table
SqlTableBuilderSqlTableBuilder that the primary key belongs to.
index
SqlIndexBuilderSqlIndexBuilder 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
database
ISqlDatabaseBuilderSQL database builder with which the object is associated.
obj
objectObject to cast.
Returns
- T
obj
cast to the desired type.
Type Parameters
T
Desired type.
Exceptions
- SqlObjectCastException
When
obj
is 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
dialect
SqlDialectSQL dialect with which the object is associated.
obj
objectObject to cast.
Returns
- T
obj
cast to the desired type.
Type Parameters
T
Desired type.
Exceptions
- SqlObjectCastException
When
obj
is 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
database
ISqlDatabaseBuilderSource SQL database builder.
errors
Chain<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
database
ISqlDatabaseBuilderSource SQL database builder.
error
stringError 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
database
ISqlDatabaseSource SQL database.
expected
TypeExpected object type.
actual
TypeActual 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
database
ISqlDatabaseBuilderSource SQL database builder.
expected
TypeExpected object type.
actual
TypeActual object type.
Returns
- SqlObjectCastException
New SqlObjectCastException instance.
GetDbLiteral(bool)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(bool value)
Parameters
value
boolValue to convert.
Returns
- string
"1" when
value
is equal to true, otherwise "0".
GetDbLiteral(char)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(char value)
Parameters
value
charValue to convert.
Returns
GetDbLiteral(decimal)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(decimal value)
Parameters
value
decimalValue to convert.
Returns
GetDbLiteral(double)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(double value)
Parameters
value
doubleValue to convert.
Returns
GetDbLiteral(long)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(long value)
Parameters
value
longValue to convert.
Returns
GetDbLiteral(ReadOnlySpan<byte>)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(ReadOnlySpan<byte> value)
Parameters
value
ReadOnlySpan<byte>Value to convert.
Returns
GetDbLiteral(ReadOnlySpan<char>)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(ReadOnlySpan<char> value)
Parameters
value
ReadOnlySpan<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
value
floatValue to convert.
Returns
GetDbLiteral(ulong)
Converts value
to a DB literal.
[Pure]
public static string GetDbLiteral(ulong value)
Parameters
value
ulongValue to convert.
Returns
GetDefaultCheckName(ISqlTableBuilder)
Creates a default check constraint name.
[Pure]
public static string GetDefaultCheckName(ISqlTableBuilder table)
Parameters
table
ISqlTableBuilderISqlTableBuilder 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
originIndex
ISqlIndexBuilderISqlIndexBuilder from which the foreign key originates.
referencedIndex
ISqlIndexBuilderISqlIndexBuilder 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
table
ISqlTableBuilderISqlTableBuilder that the index belongs to.
columns
SqlIndexBuilderColumns<ISqlColumnBuilder>Collection of columns that belong to the index.
isUnique
boolSpecifies 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
table
ISqlTableBuilderISqlTableBuilder 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
schemaName
stringSQL schema name.
name
stringSQL object name.
separator
charName 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
schemaName
stringSQL schema name.
recordSetName
stringSQL record set name.
name
stringSQL field name.
firstSeparator
charschemaName
andrecordSetName
separator. Equal to . by default.secondSeparator
charrecordSetName
andname
separator. 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
obj
SqlObjectBuilderSqlObjectBuilder instance to extract references from.
filter
Func<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.