7.3 KiB
7.3 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-17T15:58:55.611952+00:00 | zai-org/GLM-5-FP8 | 1 | 971339938de11eb6 |
Documentation: DbAPI.Channels
1. Purpose
The DbAPI.Channels namespace provides the database access layer for managing channel-related data. It implements the IChannels interface to perform CRUD operations on Channels, ChannelCodes, and ChannelSettings tables via SQL stored procedures. This module acts as the bridge between the application's business logic and the database, handling user authentication validation, ADO.NET command construction, and hydration of data objects from query results.
2. Public Interface
The public functionality is defined by the IChannels interface and implemented by the internal Channels class.
Channel Code Operations
ulong ChannelCodesInsert(IUserDbRecord user, IConnectionDetails connection, IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode, out int id)- Inserts a new channel code record. Returns
ERROR_SUCCESS(0) on success; returns the new record's ID via theidout parameter.
- Inserts a new channel code record. Returns
ulong ChannelCodesUpdate(IUserDbRecord user, IConnectionDetails connection, IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode)- Updates an existing channel code record identified by
channelCode.Id.
- Updates an existing channel code record identified by
ulong ChannelCodesDelete(IUserDbRecord user, IConnectionDetails connection, int? id, string code, string name, int? codeType)- Deletes channel codes matching the provided criteria. All filter parameters are nullable; non-null parameters are used to filter the delete operation.
ulong ChannelCodesGet(IUserDbRecord user, IConnectionDetails connection, int? Id, string code, string name, ChannelEnumsAndConstants.ChannelCodeType? codeType, IReadOnlyDictionary<short, string> channelTypeLookup, out IChannelCode[] records)- Retrieves channel codes matching the criteria. Requires a
channelTypeLookupdictionary to map database IDs to enum types.
- Retrieves channel codes matching the criteria. Requires a
ulong ChannelCodeTypesGet(IUserDbRecord user, IConnectionDetails connection, short? id, string codeType, out Tuple<short, string>[] records)- Retrieves available channel code types (ID and string identifier).
Channel Settings Operations
ulong ChannelSettingsUpdate(IUserDbRecord user, IConnectionDetails connection, int settingId, string defaultValue)- Updates the default value for a specific channel setting.
ulong ChannelSettingsGet(IUserDbRecord user, IConnectionDetails connection, int? settingId, string settingName, out IChannelSettingRecord[] records)- Retrieves channel settings, filtered by ID or name.
Group Channel Settings Operations
ulong GroupChannelSettingsDelete(IUserDbRecord user, IConnectionDetails connection, long channelId, int? settingId)- Deletes settings for a specific channel. If
settingIdis null, all settings for the channel are deleted.
- Deletes settings for a specific channel. If
ulong GroupChannelSettingsInsert(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, long channelId, IGroupChannelSettingRecord record)- Inserts a new group channel setting record.
ulong GroupChannelSettingsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, List<long> channelIdList, out IGroupChannelSettingRecord[] records, out string[] errors)- Retrieves settings for a list of channels. Logic varies based on
clientDbVersion(see Gotchas).
- Retrieves settings for a list of channels. Logic varies based on
Channel Operations
ulong ChannelsInsert(IUserDbRecord user, IConnectionDetails connection, ref IChannelDbRecord channel)- Inserts a new channel. The
channelparameter is passed by reference; itsIdproperty is populated upon successful insertion.
- Inserts a new channel. The
ulong ChannelsUpdate(IUserDbRecord user, IConnectionDetails connection, IChannelDbRecord channel)- Updates an existing channel record.
ulong ChannelsGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, long? channelId, int? groupId, int? dasId, int? sensorId, int? testSetupId, string testSetupName, out IChannelDbRecord[] channels)- Retrieves channels based on various filter criteria.
ulong ChannelsDelete(IUserDbRecord user, IConnectionDetails connection, long id, out string errorString)- Deletes a channel by ID. Returns error details via the
errorStringout parameter.
- Deletes a channel by ID. Returns error details via the
3. Invariants
- Return Codes: All methods return a
ulongerror code. A value of0(ErrorCodes.ERROR_SUCCESS) indicates success; any non-zero value indicates failure. - Authentication: All public methods enforce authentication. They check
DbAPI.Connections.IsUserLoggedIn(user, connection)before executing database logic. If this check fails, methods returnErrorCodes.ERROR_ACCESS_DENIED. - Parameter Validation: Methods performing inserts/updates validate that specific parameters (e.g.,
channelCode.Code,channelCode.Name) are not null or empty. Failure results inErrorCodes.ERROR_MISSING_PARAMETER. - Database Connection: Methods rely on
ConnectionManager.GetSqlCommandto establish commands. TheChannelsclass itself does not manage connection pooling or opening logic directly but relies on these dependencies. - Resource Cleanup: All database commands are wrapped in
try/finallyblocks that dispose of theSqlCommandand itsConnection.
4. Dependencies
Internal Dependencies (DbAPI/DTS)
DbAPI.Connections: Used forIConnectionDetails,ConnectionManager, andIsUserLoggedInvalidation.DbAPI.Errors: ProvidesErrorCodesconstants.DbAPI.Logging: ProvidesLogManagerfor error logging.DbAPI.Database: Used forPrepareForDbAccessandGetStoredProcedureVersionCached.DTS.Common.Interface.Channels: Defines interfacesIChannelCode,IChannelSettingRecord,IGroupChannelSettingRecord,IChannelDbRecord.DTS.Common.Enums.Channels: DefinesChannelEnumsAndConstants.DTS.Common.Classes: Used forUtilityhelper methods (e.g.,GetShort,GetString).
External Dependencies
System.Data.SqlClient: Used heavily forSqlConnection,SqlCommand,SqlParameter, andSqlDataReader.System.Data: Used forCommandType,ParameterDirection,DataTable.
5. Gotchas
- Critical Bug in
ChannelsUpdate: In theChannelsUpdatemethod, the code checks the@errorNumberoutput parameter before callingcmd.ExecuteNonQuery(). This means the error check logic is effectively dead code; it checks uninitialized (or default) values, and the stored procedure is executed regardless of the check. The error logging for this method will not trigger correctly on database errors. - Hardcoded Business Logic in
ChannelsGet: TheChannelsGetmethod contains hardcoded filtering logic. It silently excludes any channel whereUserChannelNameends withDFConstantsAndEnums.USER_CHANNEL_NAME_HUMIDITY. This filtering happens client-side after retrieval, which may cause confusion if the database contains records that do not appear in the application layer. - Documentation Mismatch in
ChannelCodesInsert: The XML documentation forChannelCodesInsertstates "channel code is modified with a new id if successful." However, the implementation passeschannelCodeby value (notref) and does not