Skip to content

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

  1. Start with the base select Count(*) statement for USER_PREFERENCE filtered by USER_ID and APP_NAME (SQL-007, USER_PREFERENCE).
  2. Create a SqlHelper.ScalarQuery<int>, reset the parameter list, and bind :userid as userId.ToLower() plus :appname as the application name (BR-001, SQL-007, USER_PREFERENCE).
  3. Apply optional page scoping (BR-003, SQL-007, USER_PREFERENCE).
  4. If pageName is empty, append and PAGE_NAME is NULL.
  5. If pageName is present, append and PAGE_NAME = :pagename and bind the page parameter.
  6. Attach the parameters and execute the scalar count request through the active portal (SQL-007, USER_PREFERENCE).
  7. Create the portal request in the SqlHelper.ScalarQuery<int> constructor.
  8. Add the bind variables to DataRequest through AddParms.
  9. Set DataRequest.RequestType to Scalar and DataRequest.SQLStatement to the count SQL.
  10. Call IDataPortalInfo.ProcessPortalRequest, then cast DataRequest.Result to int.

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 pageName scopes the count to rows whose PAGE_NAME is NULL.
  • 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.

Sources

  • SAIF.Framework.Preferences\PreferenceData.cs
  • SAIF.Framework.Core\V1\DataAccessLayer\SqlHelper.vb