From ce6571996614c796e83f118ac57ea7b31280430a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 16 May 2023 19:04:14 -0700 Subject: [PATCH] (REF) CRM_Utils_SQL - Extract common implementation of escapeString() --- CRM/Utils/SQL/BaseParamQuery.php | 9 +-------- CRM/Utils/SQL/EscapeStringTrait.php | 14 ++++++++++++++ CRM/Utils/SQL/Insert.php | 12 +----------- 3 files changed, 16 insertions(+), 19 deletions(-) create mode 100644 CRM/Utils/SQL/EscapeStringTrait.php diff --git a/CRM/Utils/SQL/BaseParamQuery.php b/CRM/Utils/SQL/BaseParamQuery.php index e2f5fe5fe5..d8bd343f83 100644 --- a/CRM/Utils/SQL/BaseParamQuery.php +++ b/CRM/Utils/SQL/BaseParamQuery.php @@ -138,14 +138,7 @@ class CRM_Utils_SQL_BaseParamQuery implements ArrayAccess { } } - /** - * @param string|null $value - * @return string - * SQL expression, e.g. "it\'s great" (with-quotes) or NULL (without-quotes) - */ - public function escapeString($value) { - return $value === NULL ? 'NULL' : '"' . CRM_Core_DAO::escapeString($value) . '"'; - } + use CRM_Utils_SQL_EscapeStringTrait; /** * Set one (or multiple) parameters to interpolate into the query. diff --git a/CRM/Utils/SQL/EscapeStringTrait.php b/CRM/Utils/SQL/EscapeStringTrait.php new file mode 100644 index 0000000000..4f64da25bd --- /dev/null +++ b/CRM/Utils/SQL/EscapeStringTrait.php @@ -0,0 +1,14 @@ +