Skip to content

Promote queryAndCheck/execOrThrow to a shared DB utility class #1667

@mambax7

Description

@mambax7

Context

Two complementary DB helper patterns exist across the codebase:

  1. queryAndCheck() — for SELECTs: wraps $db->query(), checks isResultSet(), returns typed \mysqli_result or throws. Currently duplicated in each module's Common/SysUtility.php.

  2. execOrThrow() — for DDL/DML: wraps $db->exec(), checks for false return, throws \RuntimeException. Currently local to htdocs/modules/system/include/update.php as system_menu_exec_or_throw().

Both eliminate the repetitive isResultSet() + instanceof \mysqli_result guard pattern and the unchecked exec() fire-and-forget pattern.

Proposal

Consolidate both into a shared utility, either:

  • A static helper class (e.g., Xoops\Database\Helper)
  • Methods on XoopsMySQLDatabase itself
  • An XMF utility

This would:

  • Remove duplication across modules
  • Standardize error handling for DB calls
  • Make update/migration scripts fail-fast by default

Current locations

  • queryAndCheck(): multiple modules in class/Common/SysUtility.php
  • execOrThrow(): htdocs/modules/system/include/update.php (as system_menu_exec_or_throw)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions