Skip to content

Generate VB Case statement block

This operation reads code/code_descr reference rows from a caller-supplied table and turns each row into a pair of VB source lines shaped for a Case-based mapping method. Along the way it derives a legal VB identifier for every row, disambiguates any identifier that repeats, and preserves the caller's requested indentation before returning the finished text.

Field Value
Operation ID OP-CODEGEN-002
Trigger Caller invokes CreateCaseStatement(table, enumName, rowItem, ...)
Inputs table, enumName, rowItem, optional useDescriptionAsCode, optional tabIndex
Outputs Generated VB source text containing Case lines and Me.Add(...) calls
Primary components CodeTableMap.CreateCaseStatement, CodeTableMap.GetResult, CodeTableMap.GetEnumValue
Entry point SAIF.Framework.CodeGen\CodeTableMap.vb

Steps

  1. CreateCaseStatement calls GetResult(table), which builds a SqlHelper.ResultSetQuery, formats select code, code_descr from {table} against the caller-supplied table name, and executes it as SQL-001 against CODE_TABLE (caller-supplied).
  2. The formatted SQL carries no bind parameters, filter, or ordering clause; the table name is the only value the caller controls (SQL-001).
  3. The delegated query object routes that SQL through the shared portal handle established by Establish/refresh Oracle data connection.
  4. ResultSetQuery obtains a new portal request from m_dpi.NewPortalRequest() and marks it as a result-set request.
  5. Execute(sql) assigns the formatted SQL text to DataRequest.SQLStatement.
  6. Execute() calls m_dpi.ProcessPortalRequest(...) and returns the resulting clsResultSet to GetResult.

Origin: Steps 2.1-2.3 are implemented in SAIF.Framework.Core's data-portal pipeline and execute on behalf of this operation; see SAIF.Framework.Core interaction model. 3. CreateCaseStatement initializes an empty output buffer and a Dictionary(Of String, Boolean) that tracks which identifiers have already been emitted. 4. For each row returned by the query, GetEnumValue derives a candidate member identifier. - It starts from the row's raw code value. - When useDescriptionAsCode = True (the default), it instead strips every non-alphabetic character from row("code_descr") and uses what remains (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). 5. Before writing the row, 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 to the candidate so the emitted name becomes unique (BR-001). - It then records the final identifier in the dictionary, so subsequent rows are compared against every name already emitted, not just the immediately preceding one (BR-001). 6. The method appends two tab-indented lines to the output buffer for the row: Case "{code}" followed by Me.Add(rowItem, enumName.enumValue, row("code_descr").ToString). 7. Once every row has been processed, the method returns the accumulated buffer as the finished Case block. - If SQL-001 returns zero rows from CODE_TABLE (caller-supplied), the loop body never executes and the method returns an empty string. - 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 CreateCaseStatement]) --> Query[Read code-table rows]
    Query --> Loop[For each row derive identifier]
    Loop --> Dup{Identifier already used?}
    Dup -->|Yes| Disambiguate[Append raw code value]
    Dup -->|No| Emit[Emit Case and Me.Add lines]
    Disambiguate --> Emit
    Emit --> More{More rows?}
    More -->|Yes| Loop
    More -->|No| EndOk([Return generated Case block])

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 block 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).
  • The emitted Me.Add(...) line embeds the literal expression row("code_descr").ToString as generated VB text; it does not substitute the actual description value at generation time.
  • Query failures bubble up unhandled, because neither GetResult nor CreateCaseStatement 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