Context
Two complementary DB helper patterns exist across the codebase:
-
queryAndCheck() — for SELECTs: wraps $db->query(), checks isResultSet(), returns typed \mysqli_result or throws. Currently duplicated in each module's Common/SysUtility.php.
-
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
Context
Two complementary DB helper patterns exist across the codebase:
queryAndCheck()— for SELECTs: wraps$db->query(), checksisResultSet(), returns typed\mysqli_resultor throws. Currently duplicated in each module'sCommon/SysUtility.php.execOrThrow()— for DDL/DML: wraps$db->exec(), checks forfalsereturn, throws\RuntimeException. Currently local tohtdocs/modules/system/include/update.phpassystem_menu_exec_or_throw().Both eliminate the repetitive
isResultSet()+instanceof \mysqli_resultguard pattern and the uncheckedexec()fire-and-forget pattern.Proposal
Consolidate both into a shared utility, either:
Xoops\Database\Helper)XoopsMySQLDatabaseitselfThis would:
Current locations
queryAndCheck(): multiple modules inclass/Common/SysUtility.phpexecOrThrow():htdocs/modules/system/include/update.php(assystem_menu_exec_or_throw)Related
system_menu_exec_or_throw()after repeated review feedback about uncheckedexec()calls