*/
class CRM_Utils_SQL {
+ /**
+ * Given a string like "UPDATE some_table SET !field = @value", replace "!field" and "@value".
+ *
+ * This is syntactic sugar for using CRM_Utils_SQL_*::interpolate() without an OOP representation of the query.
+ *
+ * @param string $expr SQL expression
+ * @param null|array $args a list of values to insert into the SQL expression; keys are prefix-coded:
+ * prefix '@' => escape SQL
+ * prefix '#' => literal number, skip escaping but do validation
+ * prefix '!' => literal, skip escaping and validation
+ * if a value is an array, then it will be imploded
+ *
+ * PHP NULL's will be treated as SQL NULL's. The PHP string "null" will be treated as a string.
+ *
+ * @return string
+ */
+ public static function interpolate($expr, $args) {
+ if (!isset(Civi::$statics[__CLASS__][__FUNCTION__])) {
+ Civi::$statics[__CLASS__][__FUNCTION__] = new class extends CRM_Utils_SQL_BaseParamQuery {
+
+ public function __construct() {
+ $this->mode = CRM_Utils_SQL_BaseParamQuery::INTERPOLATE_INPUT;
+ $this->strict();
+ }
+
+ };
+ }
+ /** @var \CRM_Utils_SQL_BaseParamQuery $qb */
+ $qb = Civi::$statics[__CLASS__][__FUNCTION__];
+ return $qb->strict()->interpolate($expr, $args);
+ }
+
/**
* Helper function for adding the permissioned subquery from one entity onto another
*