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¶
CreateCaseStatementcallsGetResult(table), which builds aSqlHelper.ResultSetQuery, formatsselect code, code_descr from {table}against the caller-supplied table name, and executes it as SQL-001 against CODE_TABLE (caller-supplied).- The formatted SQL carries no bind parameters, filter, or ordering clause; the table name is the only value the caller controls (SQL-001).
- The delegated query object routes that SQL through the shared portal handle established by Establish/refresh Oracle data connection.
ResultSetQueryobtains a new portal request fromm_dpi.NewPortalRequest()and marks it as a result-set request.Execute(sql)assigns the formatted SQL text toDataRequest.SQLStatement.Execute()callsm_dpi.ProcessPortalRequest(...)and returns the resultingclsResultSettoGetResult.
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.CreateCaseStatementinitializes an empty output buffer and aDictionary(Of String, Boolean)that tracks which identifiers have already been emitted. 4. For each row returned by the query,GetEnumValuederives a candidate member identifier. - It starts from the row's rawcodevalue. - WhenuseDescriptionAsCode = True(the default), it instead strips every non-alphabetic character fromrow("code_descr")and uses what remains (BR-003). - If the resulting candidate is purely numeric, it is prefixed with the literalCodeso 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 rawcodevalue 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 byMe.Add(rowItem, enumName.enumValue, row("code_descr").ToString). 7. Once every row has been processed, the method returns the accumulated buffer as the finishedCaseblock. - 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
codevalue 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
Codewhen the stripped result is purely numeric (BR-003, BR-002). - The emitted
Me.Add(...)line embeds the literal expressionrow("code_descr").ToStringas generated VB text; it does not substitute the actual description value at generation time. - Query failures bubble up unhandled, because neither
GetResultnorCreateCaseStatementwraps or catches exceptions raised while executing SQL-001.
Related documentation¶
Sources¶
- SAIF.Framework.CodeGen\CodeTableMap.vb
- SAIF.Framework.Core\V1\DataAccessLayer\SqlHelper.vb
- SAIF.Framework.Core\V1\Interfaces\iDataPortalInfo.vb