Skip to content

Generate VB Enum member list

This operation reads code/code_descr reference rows from a caller-supplied table and turns each row into a VB enum-member line with an inline comment. It can optionally prepend a leading Null member, derives a legal VB identifier for every row, and disambiguates any identifier that repeats before returning the completed member list.

Field Value
Operation ID OP-CODEGEN-003
Trigger Caller invokes CreateEnumStatement(table, enumName, includeNull, ...)
Inputs table, enumName (accepted but unused), includeNull, optional useDescriptionAsCode, optional tabIndex
Outputs Generated VB source text containing enum-member lines and inline comments
Primary components CodeTableMap.CreateEnumStatement, CodeTableMap.GetResult, CodeTableMap.GetEnumValue
Entry point SAIF.Framework.CodeGen\CodeTableMap.vb

Steps

  1. CreateEnumStatement calls GetResult(table), which executes SQL-001 against CODE_TABLE (caller-supplied) — the same unfiltered code/code_descr lookup used by CreateCaseStatement.
  2. ResultSetQuery obtains a new portal request from m_dpi.NewPortalRequest() and marks it as a result-set request.
  3. Execute(sql) assigns the formatted SQL text to DataRequest.SQLStatement.
  4. Execute() calls m_dpi.ProcessPortalRequest(...) and returns the resulting clsResultSet.

Origin: Steps 1.1-1.3 are implemented in SAIF.Framework.Core's data-portal pipeline and execute on behalf of this operation; see SAIF.Framework.Core interaction model. 2. The method initializes an empty output buffer. 3. When includeNull = True, the method writes a single tab-indented Null member as the first line, before any database-driven entries are emitted. 4. The method initializes a Dictionary(Of String, Boolean) that tracks which identifiers have already been emitted. 5. For each row returned by the query, GetEnumValue derives a candidate member identifier. - When useDescriptionAsCode = True (the default), it strips every non-alphabetic character from row("code_descr") and uses what remains as the identifier (BR-003). - If the resulting candidate is purely numeric, it is prefixed with the literal Code so the emitted member name stays legal VB syntax (BR-002). 6. Before writing the line, the method checks whether the candidate identifier is already present in the dictionary. - If it is, the method appends the row's raw code value so the emitted member name becomes unique (BR-001). - It then records the final identifier in the dictionary, so subsequent rows are compared against every name emitted so far (BR-001). 7. The method appends one tab-indented enum-member line in the form {enumValue} ' {code}: {code_descr}. 8. Once every row has been processed, the method returns the accumulated buffer as the finished member list. - If SQL-001 returns zero rows from CODE_TABLE (caller-supplied), the result contains only the optional leading Null line, if requested. - The enumName parameter is accepted by the method signature but is never read inside this implementation, so it has no effect on the generated output. - No local exception handling surrounds query execution or string assembly, so any failure in either stage propagates directly to the caller.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Caller invokes CreateEnumStatement]) --> Query[Read code-table rows]
    Query --> NullOpt{includeNull?}
    NullOpt -->|Yes| AddNull[Emit Null member]
    NullOpt -->|No| Loop[For each row derive identifier]
    AddNull --> Loop
    Loop --> Dup{Identifier already used?}
    Dup -->|Yes| Disambiguate[Append raw code value]
    Dup -->|No| Emit[Emit enum-member line]
    Disambiguate --> Emit
    Emit --> More{More rows?}
    More -->|Yes| Loop
    More -->|No| EndOk([Return generated enum list])

Failure and edge-case behavior

  • Duplicate computed identifiers are disambiguated by appending the row's raw code value before the line is emitted, guaranteeing every member name in the generated list is unique (BR-001).
  • Description-derived identifiers have non-alphabetic characters stripped and are then prefixed with Code when the stripped result is purely numeric (BR-003, BR-002).
  • includeNull only controls whether the optional leading Null line is written; the enumName argument has no effect on the output because the method never reads it.
  • Query failures bubble up unhandled, because neither GetResult nor CreateEnumStatement wraps or catches exceptions raised while executing SQL-001.

Sources

  • SAIF.Framework.CodeGen\CodeTableMap.vb
  • SAIF.Framework.Core\V1\DataAccessLayer\SqlHelper.vb
  • SAIF.Framework.Core\V1\Interfaces\iDataPortalInfo.vb