lib/db/cortex.php
public function sql_quoteCondition($cond, $db) {
		// https://www.debuggex.com/r/6AXwJ1Y3Aac8aocQ/3
		// https://regex101.com/r/yM5vK4/1
		// this took me lots of sleepless nights
		$out = preg_replace_callback('/'.
			'\w+\((?:(?>[^()]+)|\((?:(?>[^()]+)|^(?R))*\))*\)|'. // exclude SQL function names "foo("
			'(?:(\b(?<!:)'. // exclude bind parameter ":foo"
				'[a-zA-Z_](?:[\w\-_.]+\.?))'. // match only identifier, exclude values
			'(?=[\s<>=!)]|$))/i', // only when part of condition or within brackets
			function($match) use($db) {
				if (!isset($match[1]))
					return $match[0];
				if (preg_match('/\b(AND|OR|IN|LIKE|NOT)\b/i',$match[1]))
					return $match[1];
				return $db->quotekey($match[1]);
			}, $cond);
		return $out ?: $cond;
	}
public function sql_quoteCondition($cond, $db) {
		// https://www.debuggex.com/r/6AXwJ1Y3Aac8aocQ/3
		// https://regex101.com/r/yM5vK4/1
		// this took me lots of sleepless nights
		$out = preg_replace_callback('/'.
			'\w+\((?:(?>[^()]+)|\((?:(?>[^()]+)|^(?R))*\))*\)|'. // exclude SQL function names "foo("
			'(?:(\b(?<!:)'. // exclude bind parameter ":foo"
				'[a-zA-Z_](?:[\w\-_.]+\.?))'. // match only identifier, exclude values
			'(?=[\s<>=!)]|$))/i', // only when part of condition or within brackets
			function($match) use($db) {
				if (!isset($match[1]))
					return $match[0];
				if (preg_match('/\b(AND|OR|IN|LIKE|NOT)\b/i',$match[1]))
					return $match[1];
				return $db->quotekey($match[1]);
			}, $cond);
		return $out ?: $cond;
	}
public function sql_quoteCondition ( $ cond , $ db ) { // https://www.debuggex.com/r/6AXwJ1Y3Aac8aocQ/3 // https://regex101.com/r/yM5vK4/1 // this took me lots of sleepless nights $ out = preg_replace_callback ( '/' . '\w+\((?:(?>[^()]+)|\((?:(?>[^()]+)|^(?R))*\))*\)|' . // exclude SQL function names "foo(" '(?:(\b(?<!:)' . // exclude bind parameter ":foo" '[a-zA-Z_](?:[\w\-_.]+\.?))' . // match only identifier, exclude values '(?=[\s<>=!)]|$))/i' , // only when part of condition or within brackets function ( $ match ) use ( $ db ) { if ( ! isset ( $ match [ 1 ] ) ) return $ match [ 0 ] ; if ( preg_match ( '/\b(AND|OR|IN|LIKE|NOT)\b/i' , $ match [ 1 ] ) ) return $ match [ 1 ] ; return $ db -> quotekey ( $ match [ 1 ] ) ; } , $ cond ) ; return $ out ? : $ cond ; }
quote identifiers in condition
@param string $cond
@param object $db
@return string
quote identifiers in condition