Class MsSqlDialect
MS SQL Server implementation of ISqlDialect.
Uses SQL Server 2016+ features (JSON, STRING_SPLIT, sequences).
Parameters use , format (converted from $1, $2 in SqlRedbConnection).
public class MsSqlDialect : ISqlDialect
Inheritance
Implements
Derived
Properties
Methods
FormatArrayContains(string, string)
MSSQL uses IN with STRING_SPLIT for array containment.
public string FormatArrayContains(string column, string paramName)
FormatPagination(int?, int?)
MSSQL pagination: OFFSET n ROWS FETCH NEXT m ROWS ONLY.
public string FormatPagination(int? limit, int? offset)
FormatPvtColumn(long, string, string)
PVT via subquery with TOP 1 (MSSQL doesn't have array_agg FILTER).
public string FormatPvtColumn(long structureId, string dbColumn, string alias)
LazyLoader_GetObjectJson()
Get object as JSON via get_object_json. Params: $1=objectId, $2=maxDepth
public string LazyLoader_GetObjectJson()
LazyLoader_GetObjectJsonBatch()
Batch load Props JSON for multiple objects. Uses function call directly in SELECT.
public string LazyLoader_GetObjectJsonBatch()
LazyLoader_SelectObjectBase()
Get object base fields (without Props). Params: $1=objectId
public string LazyLoader_SelectObjectBase()
LazyLoader_SelectObjectHash()
Get object hash for cache validation. Params: $1=objectId
public string LazyLoader_SelectObjectHash()
ListItems_Insert()
INSERT list item. Params: $1=id, $2=idList, $3=value, $4=alias, $5=idObject
public string ListItems_Insert()
ListItems_SelectByListId()
SELECT list items by list ID. Params: $1=listId
public string ListItems_SelectByListId()
ListItems_SelectByListIdAndValue()
SELECT list item by list ID and value. Params: $1=listId, $2=value
public string ListItems_SelectByListIdAndValue()
ListItems_SelectByObjectId()
SELECT list items by object reference. Params: $1=objectId
public string ListItems_SelectByObjectId()
ListItems_Update()
UPDATE list item. Params: $1=value, $2=alias, $3=idObject, $4=id
public string ListItems_Update()
ListItems_UpdateAliasAndObject()
UPDATE list item alias and idObject. Params: $1=alias, $2=idObject, $3=id
public string ListItems_UpdateAliasAndObject()
Lists_IsUsedInStructures()
Check if list is used in structures. Params: $1=listId
public string Lists_IsUsedInStructures()
ObjectStorage_CheckObjectExists()
Check if object exists by ID. Params: $1=objectId
public string ObjectStorage_CheckObjectExists()
ObjectStorage_DeleteById()
DELETE object by ID. Params: $1=objectId
public string ObjectStorage_DeleteById()
ObjectStorage_DeleteByIds()
DELETE objects by IDs (bulk). Params: $1=objectIds (array)
public string ObjectStorage_DeleteByIds()
ObjectStorage_DeleteValuesByObjectId()
DELETE all values for object. Params: $1=objectId
public string ObjectStorage_DeleteValuesByObjectId()
ObjectStorage_GetObjectJson()
SELECT object as JSON. Params: $1=objectId, $2=depth
public string ObjectStorage_GetObjectJson()
ObjectStorage_GetObjectsJsonBulk()
Bulk get object JSON. Uses function call directly in SELECT.
public string ObjectStorage_GetObjectsJsonBulk()
ObjectStorage_InsertObject()
INSERT new object with all fields.
public string ObjectStorage_InsertObject()
ObjectStorage_LockObjectsForUpdate()
Lock objects for update (row locking). Params: $1=objectIds (array)
public string ObjectStorage_LockObjectsForUpdate()
ObjectStorage_SelectAllTypes()
SELECT all types (for cache preload). No params.
public string ObjectStorage_SelectAllTypes()
ObjectStorage_SelectExistingIds()
SELECT existing object IDs from array. Params: $1=objectIds (array)
public string ObjectStorage_SelectExistingIds()
ObjectStorage_SelectIdHash()
SELECT only Id and Hash for object. Params: $1=objectId
public string ObjectStorage_SelectIdHash()
ObjectStorage_SelectIdHashScheme()
SELECT Id, Hash, IdScheme for cache check. Params: $1=objectId
public string ObjectStorage_SelectIdHashScheme()
ObjectStorage_SelectObjectById()
SELECT all base fields for object by ID. Params: $1=objectId
public string ObjectStorage_SelectObjectById()
ObjectStorage_SelectObjectsByIds()
SELECT all base fields for objects by IDs. Params: $1=objectIds (array)
public string ObjectStorage_SelectObjectsByIds()
ObjectStorage_SelectSchemeById()
SELECT scheme by ID. Params: $1=schemeId
public string ObjectStorage_SelectSchemeById()
ObjectStorage_SelectSchemeIdByObjectId()
SELECT scheme ID for object. Params: $1=objectId
public string ObjectStorage_SelectSchemeIdByObjectId()
ObjectStorage_SelectSchemeIdsForObjects()
SELECT scheme IDs for objects. Params: $1=objectIds (array)
public string ObjectStorage_SelectSchemeIdsForObjects()
ObjectStorage_SelectSchemesByIds()
SELECT schemes by IDs. Params: $1=schemeIds (array)
public string ObjectStorage_SelectSchemesByIds()
ObjectStorage_SelectStructuresWithMetadata()
SELECT structure metadata by scheme ID. Params: $1=schemeId
public string ObjectStorage_SelectStructuresWithMetadata()
ObjectStorage_SelectStructureTypes()
SELECT structure types by IDs. Params: $1=structureIds (array)
public string ObjectStorage_SelectStructureTypes()
ObjectStorage_SelectTypeById()
SELECT type info by ID. Params: $1=typeId
public string ObjectStorage_SelectTypeById()
ObjectStorage_SelectValueById()
SELECT single value by ID. Params: $1=valueId
public string ObjectStorage_SelectValueById()
ObjectStorage_SelectValuesForObjects()
SELECT all values for object IDs (ChangeTracking). Params: $1=objectIds (array)
public string ObjectStorage_SelectValuesForObjects()
ObjectStorage_SelectValuesWithTypes()
SELECT existing values with types. Params: $1=objectId, $2=structureIds (array)
public string ObjectStorage_SelectValuesWithTypes()
ObjectStorage_UpdateObject()
UPDATE object with all fields.
public string ObjectStorage_UpdateObject()
Permissions_CountByRole()
SELECT COUNT of permissions by role. Params: $1=roleId
public string Permissions_CountByRole()
Permissions_CountByUser()
SELECT COUNT of permissions by user. Params: $1=userId
public string Permissions_CountByUser()
Permissions_Delete()
DELETE permission by ID. Params: $1=permissionId
public string Permissions_Delete()
Permissions_DeleteByRole()
DELETE permissions by role. Params: $1=roleId
public string Permissions_DeleteByRole()
Permissions_DeleteByUser()
DELETE all permissions by user. Params: $1=userId
public string Permissions_DeleteByUser()
Permissions_DeleteByUserRoleObject()
DELETE permission by user/role/object. Params: $1=userId, $2=roleId, $3=objectId
public string Permissions_DeleteByUserRoleObject()
Permissions_GetEffectiveForObject()
Uses MSSQL function get_user_permissions_for_object() from redb_permissions.sql.
public string Permissions_GetEffectiveForObject()
Permissions_Insert()
INSERT new permission. Params: $1=id, $2=userId, $3=roleId, $4=refId, $5=select, $6=insert, $7=update, $8=delete
public string Permissions_Insert()
Permissions_SelectById()
SELECT permission by ID. Params: $1=permissionId
public string Permissions_SelectById()
Permissions_SelectByObject()
SELECT permissions by object. Params: $1=objectId
public string Permissions_SelectByObject()
Permissions_SelectByRole()
SELECT permissions by role. Params: $1=roleId
public string Permissions_SelectByRole()
Permissions_SelectByUser()
SELECT permissions by user. Params: $1=userId
public string Permissions_SelectByUser()
Permissions_SelectByUserRoleObject()
MSSQL equivalent of IS NOT DISTINCT FROM.
public string Permissions_SelectByUserRoleObject()
Permissions_SelectReadableObjectIds()
SELECT readable object IDs for user. Params: $1=userId
public string Permissions_SelectReadableObjectIds()
Permissions_SelectUserRoleIds()
SELECT user's role IDs. Params: $1=userId
public string Permissions_SelectUserRoleIds()
Permissions_Update()
UPDATE permission flags. Params: $1=select, $2=insert, $3=update, $4=delete, $5=permissionId
public string Permissions_Update()
Query_AggregateArrayGroupedSql()
SQL for array grouped aggregation.
public string Query_AggregateArrayGroupedSql()
Query_AggregateBatchPreviewSql()
SQL for aggregate batch preview.
public string Query_AggregateBatchPreviewSql()
Query_BigintArrayCast()
Bigint array cast. PostgreSQL: "::bigint[]"
public string Query_BigintArrayCast()
Query_CheckPermissionSql()
SQL for checking user permission on object.
public string Query_CheckPermissionSql()
Query_CountTemplate()
MSSQL uses EXEC and OPENJSON for JSON parameters.
public string Query_CountTemplate()
Query_GetIdsWithAncestorsSql(string)
MSSQL: Get all IDs with their ancestors using recursive CTE.
public string Query_GetIdsWithAncestorsSql(string idsString)
Query_GetParentIdsFromDescendantsSql(string, int)
MSSQL: WITH (without RECURSIVE) for traversing ancestors.
public string Query_GetParentIdsFromDescendantsSql(string idsString, int depthLimit)
Query_HasAncestorNormalSql(string)
HasAncestor with normal function (6 params) - MSSQL captures EXEC result in temp table.
public string Query_HasAncestorNormalSql(string functionName)
Query_HasAncestorTreeSql(string)
HasAncestor with tree function (8 params) - MSSQL captures EXEC result in temp table.
public string Query_HasAncestorTreeSql(string functionName)
Query_HasDescendantSql(string)
HasDescendant with normal function (6 params) - MSSQL captures EXEC result in temp table.
public string Query_HasDescendantSql(string functionName)
Query_JsonCast()
MSSQL doesn't need explicit JSON cast - it's handled by function signature.
public string Query_JsonCast()
Query_LoadObjectsByIdsSql(string, int)
MSSQL: Load objects by IDs as JSON using get_object_json function.
public string Query_LoadObjectsByIdsSql(string idsString, int maxDepth)
Query_ProjectionByIdsTemplate(string)
SQL for projection by structure IDs query.
public string Query_ProjectionByIdsTemplate(string structureIdsArray)
Query_ProjectionByPathsTemplate()
SQL for projection by paths query.
public string Query_ProjectionByPathsTemplate()
Query_SearchFullTemplate()
MSSQL always uses _base version, but C# passes 8 params when useLazyLoading=false.
public string Query_SearchFullTemplate()
Query_SearchObjectsBaseFunction()
Name of the search function for objects base fields only (lazy loading).
public string Query_SearchObjectsBaseFunction()
Query_SearchObjectsFunction()
Name of the search function for objects with facets (eager loading).
public string Query_SearchObjectsFunction()
Query_SearchObjectsProjectionByIdsFunction()
Name of the search function with projection by IDs.
public string Query_SearchObjectsProjectionByIdsFunction()
Query_SearchObjectsProjectionByPathsFunction()
Name of the search function with projection by paths.
public string Query_SearchObjectsProjectionByPathsFunction()
Query_SearchObjectsSimpleSql()
Simple search for Delete operations - uses search_objects_with_facets with minimal params.
public string Query_SearchObjectsSimpleSql()
Query_SearchTemplate()
MSSQL uses EXEC for stored procedures. Procedure returns 'result' column.
public string Query_SearchTemplate()
Query_SearchTreeObjectsBaseFunction()
Name of the tree search function base fields only (lazy loading).
public string Query_SearchTreeObjectsBaseFunction()
Query_SearchTreeObjectsFunction()
Name of the tree search function (eager loading).
public string Query_SearchTreeObjectsFunction()
Query_SearchWithDistinctTemplate()
SQL template for search query with distinct. Params: functionName
public string Query_SearchWithDistinctTemplate()
Query_SqlPreviewBaseFunction()
SQL preview function name for base (lazy loading) search.
public string Query_SqlPreviewBaseFunction()
Query_SqlPreviewFunction()
SQL preview function name for regular search.
public string Query_SqlPreviewFunction()
Query_TextArrayCast()
MSSQL uses STRING_SPLIT instead of array cast.
public string Query_TextArrayCast()
Query_TreeCountNormalSql(string)
For Tree procedures, we use temp table to capture EXEC result and extract total_count.
public string Query_TreeCountNormalSql(string functionName)
Query_TreeCountWithParentIdsSql(string)
MSSQL: capture EXEC result and extract total_count.
public string Query_TreeCountWithParentIdsSql(string functionName)
Query_TreeSearchNormalSql(string)
SQL for tree search query (normal search).
public string Query_TreeSearchNormalSql(string functionName)
Query_TreeSearchWithParentIdsSql(string)
Tree search with parent_ids array (8 params).
public string Query_TreeSearchWithParentIdsSql(string functionName)
Query_TreeSqlPreviewBaseFunction()
SQL preview function name for tree base (lazy loading) search.
public string Query_TreeSqlPreviewBaseFunction()
Query_TreeSqlPreviewFunction()
SQL preview function name for tree search.
public string Query_TreeSqlPreviewFunction()
Query_TreeSqlPreviewTemplate(string)
SQL for tree SQL preview.
public string Query_TreeSqlPreviewTemplate(string functionName)
QuoteIdentifier(string)
Identifier escaping: "name" for PostgreSQL, [name] for MSSQL
public string QuoteIdentifier(string name)
Roles_ExistsByName()
Check if role name exists (excluding role). Params: $1=name, $2=excludeId (optional)
public string Roles_ExistsByName()
Roles_ExistsByNameExcluding()
Check if role name exists excluding specific role. Params: $1=name, $2=excludeId
public string Roles_ExistsByNameExcluding()
Roles_SelectAll()
SELECT all roles ordered by name. Returns: Id, Name, IdConfiguration
public string Roles_SelectAll()
Roles_SelectById()
SELECT role by ID. Returns: Id, Name, IdConfiguration
public string Roles_SelectById()
Roles_SelectByName()
SELECT role by name. Returns: Id, Name, IdConfiguration
public string Roles_SelectByName()
Roles_SelectConfigurationId()
SELECT role configuration ID. Params: $1=roleId
public string Roles_SelectConfigurationId()
Roles_UpdateConfiguration()
UPDATE role configuration. Params: $1=configId, $2=roleId
public string Roles_UpdateConfiguration()
Schemes_ExistsByName()
Check scheme exists by name. Params: $1=name
public string Schemes_ExistsByName()
Schemes_GetStructureTree()
Get structure tree JSON. Params: $1=schemeId
public string Schemes_GetStructureTree()
Schemes_Insert()
INSERT new scheme. Params: $1=id, $2=name, $3=alias, $4=type
public string Schemes_Insert()
Schemes_InsertObject()
INSERT Object scheme. Params: $1=id, $2=name, $3=type
public string Schemes_InsertObject()
Schemes_MigrateStructureType()
Migrate structure type. Params: $1=structureId, $2=oldType, $3=newType, $4=dryRun
public string Schemes_MigrateStructureType()
Schemes_SelectHashById()
SELECT scheme hash by ID. Params: $1=schemeId
public string Schemes_SelectHashById()
Schemes_SelectObjectByName()
SELECT Object scheme by name and type. Params: $1=name, $2=type
public string Schemes_SelectObjectByName()
Schemes_SyncMetadataCache()
Sync metadata cache for scheme. Uses MSSQL stored procedure.
public string Schemes_SyncMetadataCache()
Schemes_UpdateHash()
UPDATE scheme structure hash. Params: $1=hash, $2=schemeId
public string Schemes_UpdateHash()
SoftDelete_ClaimOrphanedTask()
Atomically claim an orphaned task for processing.
public string SoftDelete_ClaimOrphanedTask()
SoftDelete_GetDeletionProgress()
Gets deletion progress for a specific trash container.
public string SoftDelete_GetDeletionProgress()
SoftDelete_GetOrphanedTasks()
Gets orphaned deletion tasks for recovery at startup.
public string SoftDelete_GetOrphanedTasks()
SoftDelete_GetUserActiveDeletions()
Gets all active deletions for a user.
public string SoftDelete_GetUserActiveDeletions()
SoftDelete_MarkForDeletion()
Calls sp_mark_for_deletion procedure to soft-delete objects.
public string SoftDelete_MarkForDeletion()
SoftDelete_PurgeTrash()
Calls sp_purge_trash procedure to physically delete objects from trash.
public string SoftDelete_PurgeTrash()
Structures_DeleteByIds(IEnumerable<long>)
DELETE structures by IDs. Params: dynamic IN clause
public string Structures_DeleteByIds(IEnumerable<long> ids)
Structures_SelectByScheme()
SELECT full structures by scheme. Params: $1=schemeId
public string Structures_SelectByScheme()
Structures_SelectBySchemeCacheable()
SELECT structures with cache fields by scheme. Params: $1=schemeId
public string Structures_SelectBySchemeCacheable()
Structures_SelectBySchemeShort()
SELECT structures short fields by scheme. Params: $1=schemeId
public string Structures_SelectBySchemeShort()
Structures_UpdateAlias()
UPDATE structure alias. Params: $1=alias, $2=structureId
public string Structures_UpdateAlias()
Structures_UpdateAllowNotNull()
UPDATE structure allow_not_null. Params: $1=allowNotNull, $2=structureId
public string Structures_UpdateAllowNotNull()
Structures_UpdateCollectionType()
UPDATE structure collection type. Params: $1=collectionType, $2=structureId
public string Structures_UpdateCollectionType()
Structures_UpdateKeyType()
UPDATE structure key type. Params: $1=keyType, $2=structureId
public string Structures_UpdateKeyType()
Structures_UpdateType()
UPDATE structure type. Params: $1=typeId, $2=structureId
public string Structures_UpdateType()
Tree_DeleteObjectsByIds()
DELETE objects by IDs. Params: $1=objectIds (array)
public string Tree_DeleteObjectsByIds()
Tree_DeleteValuesByObjectIds()
DELETE values by object IDs. Params: $1=objectIds (array)
public string Tree_DeleteValuesByObjectIds()
Tree_GetObjectJson()
Get object as JSON. Params: $1=objectId, $2=depth
public string Tree_GetObjectJson()
Tree_SelectChildrenBase()
SELECT all children base fields by parent (Pro PVT polymorphic mode).
public string Tree_SelectChildrenBase()
Tree_SelectChildrenBySchemeBase()
SELECT children base fields by parent and scheme (Pro PVT mode).
public string Tree_SelectChildrenBySchemeBase()
Tree_SelectChildrenJson()
SELECT children with JSON by parent and scheme. Params: $1=parentId, $2=schemeId
public string Tree_SelectChildrenJson()
Tree_SelectParentId()
SELECT parent_id by object ID. Params: $1=objectId
public string Tree_SelectParentId()
Tree_SelectPolymorphicChildren()
SELECT polymorphic children with scheme. Params: $1=parentId
public string Tree_SelectPolymorphicChildren()
Tree_SelectSchemeAndJson()
SELECT scheme and JSON for object. Params: $1=objectId
public string Tree_SelectSchemeAndJson()
Tree_UpdateParent()
UPDATE object parent (move). Params: $1=newParentId, $2=dateModify, $3=whoChangeId, $4=objectId
public string Tree_UpdateParent()
Types_SelectAll()
SELECT all types. Returns: _id, _name, _db_type, _type
public string Types_SelectAll()
Users_ExistsByLoginExcluding()
Check login exists excluding user. Params: $1=login, $2=excludeUserId
public string Users_ExistsByLoginExcluding()
Users_SelectByLogin()
SELECT all user fields by login. Params: $1=login
public string Users_SelectByLogin()
Users_SelectConfigurationId()
SELECT user configuration ID. Params: $1=userId
public string Users_SelectConfigurationId()
Users_SelectIdByLogin()
SELECT user by login. Params: $1=login. Returns: Id
public string Users_SelectIdByLogin()
Users_SoftDelete()
UPDATE user for soft delete. Params: $1=newLogin, $2=newName, $3=enabled, $4=dateDismiss, $5=userId
public string Users_SoftDelete()
Users_UpdateConfiguration()
UPDATE user configuration. Params: $1=configId, $2=userId
public string Users_UpdateConfiguration()
Users_UpdatePassword()
UPDATE user password. Params: $1=hashedPassword, $2=userId
public string Users_UpdatePassword()
Users_UpdateStatus()
UPDATE user enabled status. Params: $1=enabled, $2=dateDismiss, $3=userId
public string Users_UpdateStatus()
UsersRoles_CountByRole()
SELECT COUNT of users for role. Params: $1=roleId
public string UsersRoles_CountByRole()
UsersRoles_Delete()
DELETE user-role assignment. Params: $1=userId, $2=roleId
public string UsersRoles_Delete()
UsersRoles_DeleteByRole()
DELETE all user-role assignments for role. Params: $1=roleId
public string UsersRoles_DeleteByRole()
UsersRoles_DeleteByUser()
DELETE all user-role assignments for user. Params: $1=userId
public string UsersRoles_DeleteByUser()
UsersRoles_Exists()
Check if user-role assignment exists. Params: $1=userId, $2=roleId
public string UsersRoles_Exists()
UsersRoles_Insert()
INSERT user-role assignment. Params: $1=id, $2=userId, $3=roleId
public string UsersRoles_Insert()
UsersRoles_SelectRolesByUser()
SELECT roles for user. Params: $1=userId. Returns: Id, Name, IdConfiguration
public string UsersRoles_SelectRolesByUser()
UsersRoles_SelectUsersByRole()
SELECT users for role. Params: $1=roleId. Returns user fields
public string UsersRoles_SelectUsersByRole()
Validation_SelectAllTypes()
SELECT all types for validation.
public string Validation_SelectAllTypes()
Validation_SelectSchemeByName()
SELECT scheme by name. Params: $1=schemeName
public string Validation_SelectSchemeByName()
Validation_SelectStructuresBySchemeId()
SELECT structures by scheme ID. Params: $1=schemeId
public string Validation_SelectStructuresBySchemeId()
Warmup_AllMetadataCaches()
MSSQL uses stored procedure, returns same columns as PostgreSQL function.
public string Warmup_AllMetadataCaches()
WrapSubquery(string, string)
Subquery wrapper: (subquery) AS alias
public string WrapSubquery(string subquery, string alias)