Check preference existence¶
This internal read operation runs a scalar Count(*) query for the application/user/page scope and converts the returned count into the Boolean decision that SavePreferences uses to choose insert versus update.
| Field | Value |
|---|---|
| Operation ID | OP-PREF-007 |
| Trigger | SavePreferences calls DoesPrefExist(appName, pageName, userId). |
| Inputs | appName, pageName, userId |
| Outputs | true when the scoped count is greater than zero; otherwise false |
| Primary components | PreferenceData.DoesPrefExist, SqlHelper.ScalarQuery<int> |
| Entry point | SAIF.Framework.Preferences\PreferenceData.cs |
Steps¶
- Start with the base
select Count(*)statement for USER_PREFERENCE filtered byUSER_IDandAPP_NAME(SQL-007, USER_PREFERENCE). - Create a
SqlHelper.ScalarQuery<int>, reset the parameter list, and bind:useridasuserId.ToLower()plus:appnameas the application name (BR-001, SQL-007, USER_PREFERENCE). - Apply optional page scoping (BR-003, SQL-007, USER_PREFERENCE).
- If
pageNameis empty, appendand PAGE_NAME is NULL. - If
pageNameis present, appendand PAGE_NAME = :pagenameand bind the page parameter. - Attach the parameters and execute the scalar count request through the active portal (SQL-007, USER_PREFERENCE).
- Create the portal request in the
SqlHelper.ScalarQuery<int>constructor. - Add the bind variables to
DataRequestthroughAddParms. - Set
DataRequest.RequestTypetoScalarandDataRequest.SQLStatementto the count SQL. - Call
IDataPortalInfo.ProcessPortalRequest, then castDataRequest.Resulttoint.
Origin: Steps 4.1–4.4 are implemented by Execute a data portal request (
SAIF.Framework.Core) and executed on behalf of this operation. 5. Compare the returned count to zero and return the Boolean result. - On failure: portal and data-provider exceptions propagate because this method has no local recovery logic.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([DoesPrefExist called]) --> Scope[Apply page-specific count scope]
Scope --> Execute[Execute COUNT(*)]
Execute --> Found{Count > 0?}
Found -->|Yes| Yes([Return true])
Found -->|No| No([Return false])
Failure and edge-case behavior¶
- Empty
pageNamescopes the count to rows whosePAGE_NAMEisNULL. - Any positive count is treated as existence; the method does not verify or enforce that at most one row matches.
- Exceptions from portal execution are not handled locally and surface to the caller unmodified.
Related documentation¶
Sources¶
- SAIF.Framework.Preferences\PreferenceData.cs
- SAIF.Framework.Core\V1\DataAccessLayer\SqlHelper.vb