SqlDialectBase

Ecng.Data

Base class for SQL dialect implementations.

Implements: ISqlDialect

Properties

BatchSeparator
public virtual string BatchSeparator { get; }
value = sqlDialectBase.BatchSeparator

Batch separator (e.g. GO for SQL Server). Empty when no separation is needed.

BooleanCastSqlType
public virtual string BooleanCastSqlType { get; }
value = sqlDialectBase.BooleanCastSqlType

SQL type name to cast a boolean expression to when materialising EXISTS(...) projections (e.g. bit on SQL Server). Return if the dialect represents booleans natively and no cast is needed (e.g. PostgreSQL).

CanAlterColumn
public virtual bool CanAlterColumn { get; }
value = sqlDialectBase.CanAlterColumn

Whether an existing column's type or nullability can be changed in place. SQLite cannot: such a change means rebuilding the table.

CanAlterColumnWithDependents
public virtual bool CanAlterColumnWithDependents { get; }
value = sqlDialectBase.CanAlterColumnWithDependents

Whether ALTER COLUMN can change a column that an index, a primary key or a foreign key depends on. SQL Server cannot: those have to be dropped before and recreated after.

ConcatOperator
public virtual string ConcatOperator { get; }
value = sqlDialectBase.ConcatOperator

SQL string concatenation operator.

DecimalComparisonCastSqlType
public virtual string DecimalComparisonCastSqlType { get; }
value = sqlDialectBase.DecimalComparisonCastSqlType

SQL type name used to cast decimal operands before comparisons when the dialect stores decimals in a non-numeric affinity. Return when no comparison cast is required.

EmptyBinaryLiteral
public virtual string EmptyBinaryLiteral { get; }
value = sqlDialectBase.EmptyBinaryLiteral

SQL literal for an empty binary value (e.g. 0x for SQL Server, X'' for the SQL standard, an empty bytea for PostgreSQL).

FalseLiteral
public virtual string FalseLiteral { get; }
value = sqlDialectBase.FalseLiteral

SQL literal for boolean false.

IsNullFunction
public virtual string IsNullFunction { get; }
value = sqlDialectBase.IsNullFunction

Function name for null-coalescing.

KeepsDecimalDigits
public virtual bool KeepsDecimalDigits { get; }
value = sqlDialectBase.KeepsDecimalDigits

Whether a decimal column keeps a declared precision and scale. A dialect that stores decimals as text keeps neither, so there is nothing to compare a declaration against.

LenFunction
public virtual string LenFunction { get; }
value = sqlDialectBase.LenFunction

Function name for string length.

MaxParameters
public abstract int MaxParameters { get; }
value = sqlDialectBase.MaxParameters

Maximum number of parameters allowed in a single statement. SQL Server: 2100, SQLite: 999, PostgreSQL: 65535, MySQL: 65535.

ParameterPrefix
public abstract string ParameterPrefix { get; }
value = sqlDialectBase.ParameterPrefix

Parameter prefix (e.g. @ for SQL Server, $ for PostgreSQL).

SupportsAddForeignKeyViaAlter
public virtual bool SupportsAddForeignKeyViaAlter { get; }
value = sqlDialectBase.SupportsAddForeignKeyViaAlter

True when this dialect can add a foreign key to an existing table via String). When false (SQLite), a foreign key can only be declared inline inside CREATE TABLE, so the migrator keeps new-table FKs inline and creates the referenced tables first.

SupportsInsertReturning
public virtual bool SupportsInsertReturning { get; }
value = sqlDialectBase.SupportsInsertReturning

True when this dialect can return a server-generated identity in the same statement via String); callers use it to choose between a single-statement INSERT…RETURNING and a two-statement INSERT + SELECT identity batch.

TrueLiteral
public virtual string TrueLiteral { get; }
value = sqlDialectBase.TrueLiteral

SQL literal for boolean true.

UnicodePrefix
public virtual string UnicodePrefix { get; }
value = sqlDialectBase.UnicodePrefix

Unicode string-literal prefix (e.g. N for SQL Server).

Methods

AppendAddColumn
public virtual void AppendAddColumn(StringBuilder sb, string tableName, string columnName, string columnDef)
sqlDialectBase.AppendAddColumn(sb, tableName, columnName, columnDef)

Appends ALTER TABLE ADD COLUMN.

AppendAddForeignKey
public virtual void AppendAddForeignKey(StringBuilder sb, string tableName, string columnName, string refTableName, string refColumnName)
sqlDialectBase.AppendAddForeignKey(sb, tableName, columnName, refTableName, refColumnName)

Appends an ALTER TABLE ADD CONSTRAINT for a new foreign key.

AppendAlterColumn
public virtual void AppendAlterColumn(StringBuilder sb, string tableName, string columnName, Type clrType, bool isNullable, int maxLength, int precision, int scale, DbColumnInfo live)
sqlDialectBase.AppendAlterColumn(sb, tableName, columnName, clrType, isNullable, maxLength, precision, scale, live)

Appends ALTER TABLE ALTER COLUMN that gives a column the declared type and nullability.

sb
Where the statement goes.
tableName
The table.
columnName
The column.
clrType
The property type the column holds.
isNullable
Whether the column should allow NULLs.
maxLength
The declared length, 0 for the default.
precision
The declared precision, 0 for the default.
scale
The declared scale.
live
The column as the database holds it, or null for a column this script has just added; a dialect uses it to keep what the declaration does not decide, and to convert the stored values.
AppendAlterNullability
public virtual void AppendAlterNullability(StringBuilder sb, string tableName, string columnName, bool isNullable, DbColumnInfo live)
sqlDialectBase.AppendAlterNullability(sb, tableName, columnName, isNullable, live)

Makes a column nullable or not, leaving its type as the database holds it.

sb
Where the statement goes.
tableName
The table.
columnName
The column.
isNullable
Whether the column should allow NULLs.
live
The column as the database holds it.
AppendCreateIndex
public virtual void AppendCreateIndex(StringBuilder sb, string indexName, string tableName, string columnName, bool unique)
sqlDialectBase.AppendCreateIndex(sb, indexName, tableName, columnName, unique)

Appends a CREATE INDEX (or CREATE UNIQUE INDEX) on a single column.

AppendCreateTable
public abstract void AppendCreateTable(StringBuilder sb, string tableName, string columnDefs)
sqlDialectBase.AppendCreateTable(sb, tableName, columnDefs)

Appends CREATE TABLE [IF NOT EXISTS] statement.

AppendDateAdd
public virtual void AppendDateAdd(StringBuilder sb, string part, string amountSql, string sourceSql)
sqlDialectBase.AppendDateAdd(sb, part, amountSql, sourceSql)

Appends a DATEADD-style expression.

AppendDateDiff
public virtual void AppendDateDiff(StringBuilder sb, string part, string startSql, string endSql)
sqlDialectBase.AppendDateDiff(sb, part, startSql, endSql)

Appends a DATEDIFF-style expression computing minus , expressed in units.

sb
Target builder.
part
Unit of the result: year, month, week, day, hour, minute, second or millisecond.
startSql
SQL of the start date.
endSql
SQL of the end date.
AppendDatePartClose
public virtual void AppendDatePartClose(StringBuilder sb)
sqlDialectBase.AppendDatePartClose(sb)

Closes a date-part extraction expression opened by String).

AppendDatePartOpen
public virtual void AppendDatePartOpen(StringBuilder sb, string part)
sqlDialectBase.AppendDatePartOpen(sb, part)

Opens a date-part extraction expression (closed by StringBuilder)).

AppendDecimalModulo
public virtual void AppendDecimalModulo(StringBuilder sb, string dividendSql, string divisorSql)
sqlDialectBase.AppendDecimalModulo(sb, dividendSql, divisorSql)

Appends the remainder of dividing one decimal value by another, fraction included and with the sign of the dividend, as the C# % operator gives it.

sb
Target builder.
dividendSql
SQL of the dividend.
divisorSql
SQL of the divisor.
AppendDeleteBy
public virtual void AppendDeleteBy(StringBuilder sb, string tableName, string[] whereColumns)
sqlDialectBase.AppendDeleteBy(sb, tableName, whereColumns)

Appends a DELETE … WHERE statement.

AppendDropColumn
public virtual void AppendDropColumn(StringBuilder sb, string tableName, string columnName)
sqlDialectBase.AppendDropColumn(sb, tableName, columnName)

Appends ALTER TABLE DROP COLUMN.

AppendDropForeignKey
public virtual void AppendDropForeignKey(StringBuilder sb, string tableName, string constraintName)
sqlDialectBase.AppendDropForeignKey(sb, tableName, constraintName)

Appends an ALTER TABLE DROP CONSTRAINT for an existing foreign key.

AppendDropIndex
public virtual void AppendDropIndex(StringBuilder sb, string tableName, string indexName)
sqlDialectBase.AppendDropIndex(sb, tableName, indexName)

Appends DROP INDEX.

AppendDropTable
public abstract void AppendDropTable(StringBuilder sb, string tableName)
sqlDialectBase.AppendDropTable(sb, tableName)

Appends DROP TABLE [IF EXISTS] statement.

AppendFallbackOrderBy
public virtual void AppendFallbackOrderBy(StringBuilder sb)
sqlDialectBase.AppendFallbackOrderBy(sb)

Appends a fallback ORDER BY clause when there is neither explicit ordering nor an identity column. SQL Server requires ORDER BY for OFFSET/FETCH; other dialects may emit a deterministic shim or nothing at all.

AppendGreatest
public virtual void AppendGreatest(StringBuilder sb, string leftSql, string rightSql)
sqlDialectBase.AppendGreatest(sb, leftSql, rightSql)

Appends the larger of two values, the way Decimal) picks it: a scalar function of two arguments, not the MAX aggregate.

sb
Target builder.
leftSql
SQL of the first value.
rightSql
SQL of the second value.
AppendInsertReturningClause
public virtual void AppendInsertReturningClause(StringBuilder sb, string idColumn)
sqlDialectBase.AppendInsertReturningClause(sb, idColumn)

Appends a dialect-specific RETURNING clause to an INSERT, scoped to the given identity column. PostgreSQL emits RETURNING "Id"; SQL Server and SQLite have other identity-read mechanisms and emit nothing here.

AppendLeast
public virtual void AppendLeast(StringBuilder sb, string leftSql, string rightSql)
sqlDialectBase.AppendLeast(sb, leftSql, rightSql)

Appends the smaller of two values, the way Decimal) picks it: a scalar function of two arguments, not the MIN aggregate.

sb
Target builder.
leftSql
SQL of the first value.
rightSql
SQL of the second value.
AppendPagination
public abstract void AppendPagination(StringBuilder sb, long? skip, long? take, bool hasOrderBy)
sqlDialectBase.AppendPagination(sb, skip, take, hasOrderBy)

Appends literal pagination (LIMIT/OFFSET or OFFSET/FETCH) with values.

AppendPaginationParams
public virtual void AppendPaginationParams(StringBuilder sb, string skipParamExpr, string takeParamExpr)
sqlDialectBase.AppendPaginationParams(sb, skipParamExpr, takeParamExpr)

Appends parameterised pagination with already-prefixed parameter expressions (e.g. @skip, @take).

AppendRound
public virtual void AppendRound(StringBuilder sb, string valueSql, string digitsSql, MidpointRounding mode)
sqlDialectBase.AppendRound(sb, valueSql, digitsSql, mode)

Appends an expression that rounds a value the way MidpointRounding) does with the given mode.

sb
Target builder.
valueSql
SQL of the value.
digitsSql
SQL of the number of fractional digits to keep, or to round to a whole number.
mode
How the value is rounded; ToZero truncates.
AppendSetCompression
public virtual void AppendSetCompression(StringBuilder builder, string tableName, DataCompressions compression)
sqlDialectBase.AppendSetCompression(builder, tableName, compression)

Writes the statement that repacks a table.

builder
Where the statement is written.
tableName
Table to repack.
compression
The packing to apply.
AppendTrimClose
public virtual void AppendTrimClose(StringBuilder sb)
sqlDialectBase.AppendTrimClose(sb)

Closes a TRIM expression opened by StringBuilder).

AppendTrimOpen
public virtual void AppendTrimOpen(StringBuilder sb)
sqlDialectBase.AppendTrimOpen(sb)

Opens a TRIM expression (closed by StringBuilder)).

AppendTruncate
protected virtual void AppendTruncate(StringBuilder sb, string valueSql, string digitsSql)
sqlDialectBase.AppendTruncate(sb, valueSql, digitsSql)

Appends an expression that drops the digits of a value beyond , rounding toward zero.

sb
Target builder.
valueSql
SQL of the value.
digitsSql
SQL of the number of fractional digits to keep, or for a whole number.
AppendUpdateBy
public virtual void AppendUpdateBy(StringBuilder sb, string tableName, string[] setColumns, string[] whereColumns)
sqlDialectBase.AppendUpdateBy(sb, tableName, setColumns, whereColumns)

Appends an UPDATE … SET … WHERE statement.

AppendUpdateWhereNull
public virtual void AppendUpdateWhereNull(StringBuilder sb, string tableName, string columnName, string defaultLiteral)
sqlDialectBase.AppendUpdateWhereNull(sb, tableName, columnName, defaultLiteral)

Appends UPDATE … SET column = literal WHERE column IS NULL — used during migrations to fill default values before altering nullability.

AppendUpsert
public abstract void AppendUpsert(StringBuilder sb, string tableName, string[] allColumns, string[] keyColumns)
sqlDialectBase.AppendUpsert(sb, tableName, allColumns, keyColumns)

Appends a UPSERT statement (MERGE on SQL Server, INSERT … ON CONFLICT on PostgreSQL/SQLite).

ConvertFromDbValue
public virtual object ConvertFromDbValue(object value, Type targetType)
result = sqlDialectBase.ConvertFromDbValue(value, targetType)

Converts a database value to the requested CLR target type.

ConvertToDbValue
public virtual object ConvertToDbValue(object value, Type clrType)
result = sqlDialectBase.ConvertToDbValue(value, clrType)

Converts a CLR value to the form a database driver expects.

FormatDecimal
protected static string FormatDecimal(string typeName, int precision, int scale)
result = SqlDialectBase.FormatDecimal(typeName, precision, scale)

A decimal type with the declared digits, DefaultDecimalPrecision standing in for an undeclared precision.

FormatSkip
public virtual string FormatSkip(string skip)
result = sqlDialectBase.FormatSkip(skip)

Renders a SKIP/OFFSET clause from a parameter expression.

FormatTake
public virtual string FormatTake(string take)
result = sqlDialectBase.FormatTake(take)

Renders a TAKE/FETCH clause from a parameter expression.

GetColumnDefinition
public virtual string GetColumnDefinition(Type clrType, bool isNullable, int maxLength, int precision, int scale)
result = sqlDialectBase.GetColumnDefinition(clrType, isNullable, maxLength, precision, scale)

Full column definition: SQL type + NULL/NOT NULL.

GetColumnTypeName
public virtual string GetColumnTypeName(Type clrType, int maxLength, int precision, int scale)
result = sqlDialectBase.GetColumnTypeName(clrType, maxLength, precision, scale)

The SQL type a column is created with: the type name together with its length, precision or scale. A decimal that declares only a scale gets DefaultDecimalPrecision; one that declares a precision keeps its scale as declared, zero included.

GetDefaultLiteral
public virtual string GetDefaultLiteral(Type clrType)
result = sqlDialectBase.GetDefaultLiteral(clrType)

Returns a SQL literal representing the default value for the given CLR type. Used during migrations to backfill NOT NULL columns.

GetForeignKeyConstraint
public virtual string GetForeignKeyConstraint(string tableName, string columnName, string refTableName, string refColumnName)
result = sqlDialectBase.GetForeignKeyConstraint(tableName, columnName, refTableName, refColumnName)

Inline FOREIGN KEY constraint clause for use inside CREATE TABLE.

GetIdentityColumnSuffix
public virtual string GetIdentityColumnSuffix(string pkConstraintName)
result = sqlDialectBase.GetIdentityColumnSuffix(pkConstraintName)

Same as GetIdentityColumnSuffix, but names the PRIMARY KEY constraint. Without a name the database invents one — PK__Table__hash on SQL Server, table_pkey on PostgreSQL — which no naming convention can match.

pkConstraintName
Constraint name, normally from String).

Returns: The column-definition suffix carrying the named constraint.

GetIdentityColumnSuffix
public abstract string GetIdentityColumnSuffix()
result = sqlDialectBase.GetIdentityColumnSuffix()

Suffix for an identity (auto-increment primary key) column definition.

GetIdentitySelect
public virtual string GetIdentitySelect(string idCol)
result = sqlDialectBase.GetIdentitySelect(idCol)

SQL expression that returns the identity value of the last insert.

GetIntegerToDecimalCastSqlType
public virtual string GetIntegerToDecimalCastSqlType(int precision)
result = sqlDialectBase.GetIntegerToDecimalCastSqlType(precision)

SQL type a whole number is cast to when a query converts it to Decimal.

precision
Number of digits the source integer type can hold.

Returns: The SQL type name.

GetSqlTypeName
public abstract string GetSqlTypeName(Type clrType)
result = sqlDialectBase.GetSqlTypeName(clrType)

Returns the SQL type name for a CLR type.

GetSqlTypeName
public virtual string GetSqlTypeName(Type clrType, int maxLength)
result = sqlDialectBase.GetSqlTypeName(clrType, maxLength)

Canonical SQL type name with length applied. Dialects override when the type differs by length (e.g. PostgreSQL TEXT vs VARCHAR(N)).

GetStoredMaxLength
public virtual int GetStoredMaxLength(Type clrType, int maxLength)
result = sqlDialectBase.GetStoredMaxLength(clrType, maxLength)

The length the database reports for a column created with the declared length: -1 when the dialect stores it unbounded, as SQL Server does past NVARCHAR(4000) and VARBINARY(8000).

NewId
public virtual string NewId()
result = sqlDialectBase.NewId()

Generates a new unique identifier.

NormalizeDbType
public virtual string NormalizeDbType(string dbTypeName)
result = sqlDialectBase.NormalizeDbType(dbTypeName)

Normalises a raw database type name to the canonical form used by this dialect.

Now
public virtual string Now()
result = sqlDialectBase.Now()

Current local date/time.

PrepareParameter
public virtual void PrepareParameter(DbParameter parameter)
sqlDialectBase.PrepareParameter(parameter)

Final-stage massaging of a fully populated DbParameter before it leaves the ORM layer. Lets a dialect adjust provider-specific type metadata that the generic DbType hint can't express — e.g. PostgreSQL needs timestamptz binding for UTC-kind DateTime values, which only Npgsql's own NpgsqlDbType property can express. Default is a no-op.

QuoteIdentifier
public abstract string QuoteIdentifier(string identifier)
result = sqlDialectBase.QuoteIdentifier(identifier)

Quotes an identifier (table name, column name).

ReadDbCompressionsAsync
public virtual Task<IReadOnlyList<DbTableCompressionInfo>> ReadDbCompressionsAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlDialectBase.ReadDbCompressionsAsync(connection, tableSchema, cancellationToken)

Reads how each table is packed on disk. Databases without the concept report every table as None, which matches an entity that declares nothing.

connection
An open database connection.
tableSchema
Schema name; dialect default when .
cancellationToken
Cancellation token.

Returns: One row per table.

ReadDbForeignKeysAsync
public virtual Task<IReadOnlyList<DbForeignKeyInfo>> ReadDbForeignKeysAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlDialectBase.ReadDbForeignKeysAsync(connection, tableSchema, cancellationToken)

Reads foreign-key metadata from a live database. Used by the schema migrator to detect missing/extra FK constraints on tables that already exist.

connection
An open database connection.
tableSchema
Schema name (e.g. "dbo" or "public"); dialect default when .
cancellationToken
Cancellation token.

Returns: One row per FK column — compound FKs surface as multiple rows.

ReadDbIndexesAsync
public virtual Task<IReadOnlyList<DbIndexInfo>> ReadDbIndexesAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlDialectBase.ReadDbIndexesAsync(connection, tableSchema, cancellationToken)

Reads index metadata from a live database. Used by the schema migrator to detect missing entity-declared [Index] / [Unique] attributes on tables that already exist. Composite indexes are returned as multiple rows sharing IndexName with ascending ColumnOrdinal.

connection
An open database connection.
tableSchema
Schema name (e.g. "dbo" or "public"); dialect default when .
cancellationToken
Cancellation token.

Returns: One row per indexed column — composite indexes surface as multiple rows.

ReadDbSchemaAsync
public virtual Task<IReadOnlyList<DbColumnInfo>> ReadDbSchemaAsync(DbConnection connection, string tableSchema, CancellationToken cancellationToken)
result = sqlDialectBase.ReadDbSchemaAsync(connection, tableSchema, cancellationToken)

Reads column metadata from a live database.

SysNow
public virtual string SysNow()
result = sqlDialectBase.SysNow()

System local date/time with offset.

SysUtcNow
public virtual string SysUtcNow()
result = sqlDialectBase.SysUtcNow()

System UTC date/time with offset.

UtcNow
public virtual string UtcNow()
result = sqlDialectBase.UtcNow()

Current UTC date/time.

Fields

DefaultDecimalPrecision
public const int DefaultDecimalPrecision
value = SqlDialectBase.DefaultDecimalPrecision

The precision of the default decimal type, and the one a decimal column gets when it declares only a scale.

DefaultDecimalScale
public const int DefaultDecimalScale
value = SqlDialectBase.DefaultDecimalScale

The scale of the default decimal type.