---
title: Code table management
summary: Manages the imaging reference code tables (category, document name, document type, file type) that constrain image indexing values.
status: draft
owner: <owner>
last_reviewed: 2026-07-30
library: SAIF.Business.Imaging
reference_type: package
operation_id: OP-IMG-06
trigger: Caller creates, retrieves, updates, or deletes a code-table business object or its collection
---

# Code table management

The imaging library defines four parallel code-table families — category, document name, document type, and file type — each with a single-object business class and a matching collection class. These tables constrain the valid values used during [image indexing](image-indexing.md), and this operation covers their shared CRUD pattern.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-IMG-06 |
| **Trigger** | Caller creates, retrieves (single or collection), updates, or deletes a code-table object: `clsImageCategoryCode`, `clsImageDocumentNameCode`, `clsImageDocumentTypeCode`, or `clsImageFileCode` (and their `*Collection` counterparts) |
| **Inputs** | Code, description, and file/category/type context fields specific to each code table |
| **Outputs** | Persisted or retrieved code-table rows |
| **Primary components** | `clsImageCategoryCode`, `clsImageCategoryCodeCollection`, `clsImageDocumentNameCode`, `clsImageDocumentTypeCode`, `clsImageDocumentTypeCodeCollection`, `clsImageFileCode`, `clsImageFileCodeCollection` |
| **Entry point** | `Business\SAIF.Business.Imaging\clsImageCategoryCode.vb`, `Business\SAIF.Business.Imaging\clsImageDocumentNameCode.vb`, `Business\SAIF.Business.Imaging\clsImageDocumentTypeCode.vb`, `Business\SAIF.Business.Imaging\clsImageFileCode.vb` |

## Steps

1. **Caller provides a code, description, and context fields** (e.g., `ImageFileCode`, `ImageCategoryCode`) to a code-table business object, such as `clsImageDocumentNameCode`.
2. **Insert the code row.** `BeforeInsert` executes the relevant insert statement for the object — [SQL-005](../sql/SQL-005-saif-business-imaging.md) for document-name codes.
3. **Verify the insert.** `AfterInsert` confirms exactly one row was affected.
   - On failure: an error message is raised.
4. **Retrieve a single code row.** Single-object classes filter by their specific key fields — [SQL-019](../sql/SQL-019-saif-business-imaging.md) (category code by code and file code), [SQL-023](../sql/SQL-023-saif-business-imaging.md) (document type code by key), [SQL-025](../sql/SQL-025-saif-business-imaging.md) (file code by code).
5. **Retrieve all rows of a code table.** Collection classes' `BeforeRetrieve` returns the full table — [SQL-020](../sql/SQL-020-saif-business-imaging.md) (all category codes), [SQL-024](../sql/SQL-024-saif-business-imaging.md) (all document type codes), [SQL-026](../sql/SQL-026-saif-business-imaging.md) (all file codes).
6. **Update or delete a code row.** Update and delete paths exist for each object but may be incomplete in live code: `clsImageDocumentNameCode.UpdateSQL` ([SQL-034](../sql/SQL-034-saif-business-imaging.md)) and `DeleteSQL` ([SQL-040](../sql/SQL-040-saif-business-imaging.md)) each concatenate a base statement with a separately-assignable `WhereSqlStatement` that defaults to the bare literal `" Where "` with no predicate appended.**
   - If `WhereSqlStatement` is never set to a real predicate before use: the resulting SQL ends in a dangling `WHERE` clause, which would fail at execution or (depending on the database driver) match unintended rows.**

## Process flow

The following diagram visualizes the shared code-table CRUD pattern.

```mermaid
flowchart TD
	Start([Caller provides code,<br>description, context fields]) --> Which{Which action?}
	Which -->|Create| Insert[BeforeInsert: INSERT row]
	Insert --> Check{AfterInsert:<br>exactly 1 row?}
	Check -->|No| Error([Error raised])
	Check -->|Yes| DoneI([Code row created])
	Which -->|Retrieve one| RetrieveOne[BeforeRetrieve by key]
	RetrieveOne --> DoneR([Code row loaded])
	Which -->|Retrieve all| RetrieveAll[BeforeRetrieve: all rows]
	RetrieveAll --> DoneRC([Collection loaded])
	Which -->|Update/Delete| UpdDel[BeforeUpdate/BeforeDelete:<br>base SQL + WhereSqlStatement]
	UpdDel --> WhereCheck{WhereSqlStatement<br>set to real predicate?}
	WhereCheck -->|No| Dangling([Dangling WHERE clause:<br>likely execution failure])
	WhereCheck -->|Yes| DoneUD([Code row updated/deleted])
```

## Failure and edge-case behavior

- `clsImageDocumentNameCode.UpdateSQL` and `DeleteSQL` end with a bare `WHERE` clause unless `WhereSqlStatement` is separately assigned by the caller, suggesting those paths are incomplete or dead code in current usage.**
- `AfterInsert` row-count verification exists across the code-table classes but not uniformly for update/delete lifecycle methods; behavior on a failed update/delete varies by class.*

## Related documentation

- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts. Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources

- `Business\SAIF.Business.Imaging\clsImageCategoryCode.vb`
- `Business\SAIF.Business.Imaging\clsImageCategoryCodeCollection.vb`
- `Business\SAIF.Business.Imaging\clsImageDocumentNameCode.vb`
- `Business\SAIF.Business.Imaging\clsImageDocumentTypeCode.vb`
- `Business\SAIF.Business.Imaging\clsImageDocumentTypeCodeCollection.vb`
- `Business\SAIF.Business.Imaging\clsImageFileCode.vb`
- `Business\SAIF.Business.Imaging\clsImageFileCodeCollection.vb`
