From: Florent Bruneau Date: Sat, 14 Feb 2009 17:16:19 +0000 (+0100) Subject: Helper function to format some queries. X-Git-Tag: core/1.0.1~20 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=0ef5bd4bceb37a6ed6a1afb719d403f25c71ef02;p=platal.git Helper function to format some queries. Signed-off-by: Florent Bruneau --- diff --git a/classes/xdb.php b/classes/xdb.php index 5f200d8..ea728d4 100644 --- a/classes/xdb.php +++ b/classes/xdb.php @@ -140,6 +140,22 @@ class XDB return self::_prepare(func_get_args()); } + // Produce the SQL statement for setting/unsetting a flag + public static function changeFlag($fieldname, $flagname, $state) + { + if ($state) { + return XDB::format($fieldname . ' = CONCAT({?}, \',\', ' . $fieldname . ')', $flagname); + } else { + return XDB::format($fieldname . ' = REPLACE(' . $fieldname . ', {?}, \'\')', $flagname); + } + } + + // Produce the SQL statement representing an array + public static function formatArray(array $array) + { + return '(' . implode(', ', array_map(array('XDB', 'escape'), $array)) . ')'; + } + public static function execute() { global $globals;