using System.Data; using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; using System.Text.RegularExpressions; using NPoco; using Umbraco.Cms.Core.Persistence; using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations; using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions; namespace Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; /// /// Defines an SqlSyntaxProvider /// public interface ISqlSyntaxProvider { string Length { get; } string Substring { get; } string ProviderName { get; } string CreateTable { get; } string DropTable { get; } string AddColumn { get; } string DropColumn { get; } string AlterColumn { get; } string RenameColumn { get; } string RenameTable { get; } string CreateSchema { get; } string AlterSchema { get; } string DropSchema { get; } string CreateIndex { get; } string DropIndex { get; } string InsertData { get; } string UpdateData { get; } string DeleteData { get; } string TruncateTable { get; } string CreateConstraint { get; } string DeleteConstraint { get; } string DeleteDefaultConstraint { get; } /// /// Gets a regex matching aliased fields. /// /// /// Matches "(table.column) AS (alias)" where table, column and alias are properly escaped. /// Regex AliasRegex { get; } string ConvertIntegerToOrderableString { get; } string ConvertDateToOrderableString { get; } string ConvertDecimalToOrderableString { get; } /// /// Returns the default isolation level for the database /// IsolationLevel DefaultIsolationLevel { get; } string DbProvider { get; } IDictionary? ScalarMappers => null; DatabaseType GetUpdatedDatabaseType(DatabaseType current, string? connectionString) => current; // Default implementation. string EscapeString(string val); string GetWildcardPlaceholder(); string GetStringColumnEqualComparison(string column, int paramIndex, TextColumnType columnType); string GetStringColumnWildcardComparison(string column, int paramIndex, TextColumnType columnType); string GetConcat(params string[] args); string GetColumn(DatabaseType dbType, string tableName, string columnName, string columnAlias, string? referenceName = null, bool forInsert = false); string GetQuotedTableName(string? tableName); string GetQuotedColumnName(string? columnName); string GetQuotedName(string? name); bool DoesTableExist(IDatabase db, string tableName); string GetIndexType(IndexTypes indexTypes); string GetSpecialDbType(SpecialDbType dbType); string FormatDateTime(DateTime date, bool includeTime = true); string Format(TableDefinition table); string Format(IEnumerable columns); List Format(IEnumerable indexes); List Format(IEnumerable foreignKeys); string FormatPrimaryKey(TableDefinition table); string GetQuotedValue(string value); string Format(ColumnDefinition column); string Format(ColumnDefinition column, string tableName, out IEnumerable sqls); string Format(IndexDefinition index); string Format(ForeignKeyDefinition foreignKey); string FormatColumnRename(string? tableName, string? oldName, string? newName); string FormatTableRename(string? oldName, string? newName); void HandleCreateTable(IDatabase database, TableDefinition tableDefinition, bool skipKeysAndIndexes = false); Sql SelectTop(Sql sql, int top); bool SupportsClustered(); bool SupportsIdentityInsert(); IEnumerable GetTablesInSchema(IDatabase db); IEnumerable GetColumnsInSchema(IDatabase db); /// /// Returns all constraints defined in the database (Primary keys, foreign keys, unique constraints...) (does not /// include indexes) /// /// /// /// A Tuple containing: TableName, ConstraintName /// IEnumerable> GetConstraintsPerTable(IDatabase db); /// /// Returns all constraints defined in the database (Primary keys, foreign keys, unique constraints...) (does not /// include indexes) /// /// /// /// A Tuple containing: TableName, ColumnName, ConstraintName /// IEnumerable> GetConstraintsPerColumn(IDatabase db); /// /// Returns all defined Indexes in the database excluding primary keys /// /// /// /// A Tuple containing: TableName, IndexName, ColumnName, IsUnique /// IEnumerable> GetDefinedIndexes(IDatabase db); /// /// Tries to gets the name of the default constraint on a column. /// /// The database. /// The table name. /// The column name. /// The constraint name. /// A value indicating whether a default constraint was found. /// /// /// Some database engines may not have names for default constraints, /// in which case the function may return true, but is /// unspecified. /// /// bool TryGetDefaultConstraint(IDatabase db, string? tableName, string columnName, [MaybeNullWhen(false)] out string constraintName); bool DoesPrimaryKeyExist(IDatabase db, string tableName, string primaryKeyName) => throw new NotImplementedException(); string GetFieldNameForUpdate(Expression> fieldSelector, string? tableAlias = null); /// /// Appends the relevant ForUpdate hint. /// Sql InsertForUpdateHint(Sql sql); /// /// Appends the relevant ForUpdate hint. /// Sql AppendForUpdateHint(Sql sql); /// /// Handles left join with nested join /// Sql.SqlJoinClause LeftJoinWithNestedJoin( Sql sql, Func, Sql> nestedJoin, string? alias = null); }