Escape identifier (column, table) with backtick

@see: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

@param string $value
@param string $quote
@return string identifier escaped string
481370
public function ident($value, $quote = '`')
    {
        $value = preg_replace('/[^A-Za-z0-9_]+/', '', $value);
        if (strpos($value, '.') !== false) {
            $values = explode('.', $value);
            $value = $quote . implode($quote . '.' . $quote, $values) . $quote;
        } else {
            $value = $quote . $value . $quote;
        }

        return $value;
    }
1062341
public function escapeSpecialChars($value)
    {
        $payPalEscape = oxNew(\OxidEsales\PayPalModule\Core\Escape::class);

        return $payPalEscape->escapeSpecialChars($value);
    }
554943
public function escapeString(string $input, bool $quote = true): string
    {
        $resourceType = $this->resource->getType();
        $resourceObject = $this->resource->getObject();
        if ($resourceType == Resource::TYPE_MYSQL_LINK) {
            $input = $resourceObject->escape_string($input);
        } elseif ($resourceType == Resource::TYPE_PGSQL_LINK) {
            $input = pg_escape_string($resourceObject, $input);
        }

        if ($quote) {
            $input = $this->quote($input);
        }

        return $input;
    }
200982
public function quote($value)
    {
        if( null === $value ) {
            return 'NULL';
        } else if( is_bool($value) ) {
            return ( $value ? '1' : '0' );
        } else if( $value instanceof Expression ) {
            return (string) $value;
        } else if( is_integer($value) ) {
            return sprintf('%d', $value);
        } else if( is_float($value) ) {
            return sprintf('%f', $value); // @todo make sure precision is right
        } else {
            return "'" . $this->getConnection()->real_escape_string($value) . "'";
        }
    }
607725
def escape(value, quote=True):
    '''
    
    '''
    def escape_one(match):
        return SPECIAL_CHARS[match.group(0)]

    if isinstance(value, string_types):
        value = SPECIAL_CHARS_REGEX.sub(escape_one, value)
        if quote:
            value = "'" + value + "'"
    return text_type(value)
873740
public static function escape( $value, $escapeNull = true )
    {

        if( $value === null ) {
            return $escapeNull ? self::ESCAPE_CHARACTER . self::NULL_CHARACTER : '';
        }

        $value = str_replace( self::ESCAPE_CHARACTER, self::ESCAPE_CHARACTER . self::ESCAPE_CHARACTER, $value );
        $value = str_replace( self::RANGE_SEPARATOR, self::ESCAPE_CHARACTER . self::RANGE_SEPARATOR, $value );
        $value = str_replace( self::INTERVAL_SEPARATOR, self::ESCAPE_CHARACTER . self::INTERVAL_SEPARATOR, $value );

        return $value;

    }
1374713
static function quoteIfNeeded( $value )
    {
        $quote = '';
        if ( strpos( $value, ' ' ) !== false )
        {
            $quote = '"';
            if ( strpos( trim( $value ), '(' ) === 0 )
            {
                $quote = '';
            }
        }
        return $quote . $value . $quote;
    }
157924
public static function escapeString($value)
    {
        if (version_compare(VERSION, '4.0', '<'))
        {
            $db = \Contao\Database::getInstance();

            if ($db instanceof \Contao\Database\Mysqli)
            {
                $db    = Contao3MysqliHelper::getInstance();
                $value = "'" . $db->getConnection()->real_escape_string($value) . "'";
            }
            else
            {
                if ($db instanceof \Contao\Database\Mysql)
                {
                    $db    = Contao3MysqlHelper::getInstance();
                    $value = "'" . mysql_real_escape_string($value, $db->getConnection()) . "'";
                }
            }
        }
        else
        {
            $connection = System::getContainer()->get('database_connection');
            $value      = $connection->quote($value);
        }

        return $value;
    }
81765
public function escapeLikeString(string $input, bool $quote = true, bool $escape = true): string
    {
        if ($escape) {
            $input = $this->escapeString($input, $quote);
        }

        return addcslashes($input, '%_');
    }
663029
private function getSanitisedValue($value)
    {
        if ($this->beginsWithQuote($value)) {

            $quote = $value[0];

            $regexPattern = sprintf(
                '/^
                %1$s          # match a quote at the start of the value
                (             # capturing sub-pattern used
                 (?:          # we do not need to capture this
                  [^%1$s\\\\] # any character other than a quote or backslash
                  |\\\\\\\\   # or two backslashes together
                  |\\\\%1$s   # or an escaped quote e.g \"
                 )*           # as many characters that match the previous rules
                )             # end of the capturing sub-pattern
                %1$s          # and the closing quote
                .*$           # and discard any string after the closing quote
                /mx',
                $quote
            );

            $value = preg_replace($regexPattern, '$1', $value);
            $value = str_replace("\\$quote", $quote, $value);
            $value = str_replace('\\\\', '\\', $value);

            return $value;
        }

        $parts = explode(' #', $value, 2);
        $value = trim($parts[0]);

        if (preg_match('/\s+/', $value) > 0) {
            throw new InvalidArgumentException('DotEnv values containing spaces must be surrounded by quotes.');
        }

        return $value;
    }
1125035
public static String escape(String value, char quote) {
    Map<CharSequence, CharSequence> lookupMap = new HashMap<>();
    lookupMap.put(Character.toString(quote), "\\" + quote);
    lookupMap.put("\\", "\\\\");

    final CharSequenceTranslator escape =
        new LookupTranslator(lookupMap)
                .with(new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE))
                .with(JavaUnicodeEscaper.outsideOf(32, 0x7f));

    return quote + escape.translate(value) + quote;
  }
1320187
def _quote_escape(item):
    '''
    
    '''

    rex_sqlquote = re.compile("'", re.M)

    return rex_sqlquote.sub("''", item)
978907
public String escapeValue(String value) {
		StringBuilder sb = new StringBuilder(value.length() + 4);
		databaseType.appendEscapedWord(sb, value);
		return sb.toString();
	}
89002
public function value($value)
    {
        //terminal case
        if (!is_array($value)) {
            if (strpbrk($value, Lexer::ESCAPED_STRING) !== false) {
                if (!(substr($value, 0, 1) == '"' && substr($value, -1) == '"')) {
                    return '(' . addcslashes($value, Lexer::ESCAPED_STRING_PAREN_ENCAPSED) . ')';
                }
            }
            return $value;
        }

        //composite value case
        $pairs = array();
        foreach ($value as $key => $subval) {
            $pairs[] = "{$this->identifier($key)} = {$this->value($subval)}";
        }

        return '(' . implode(', ', $pairs) . ')';
    }
1212964
public static function escape(string $value): string
    {
        if (self::$use_white_list) {
            $preg = '/<(\s*\/?\s*[^(?:'. implode(',', self::$white_list) .')]\s*)>/i';
        } elseif (self::$use_black_list) {
            $preg = '/<(\s*\/?\s*(?:'.  implode(',', self::$black_list) .')\s*)>/i';
        } else {
            $preg = '/<(\s*\/?\s*(?:'. implode(',', self::$default_tags) .')\s*)>/i';
        }

        $value = preg_replace($preg, '&lt;$1&gt;', $value);

        return $value;
    }
1160233
protected function _prepareValue($value, SQL $SQL, $identifier = false){

		// Identifier should be string (purely a sanity-check, enforced elsewhere)

		assert('!(!is_string($value) && $identifier)');

		// String

		if(is_string($value)){

			// NULL

			if(strtoupper($value) == 'NULL'){

				$value = 'NULL';
			}

			// Identifier string

			elseif($identifier){

				/*
				 * Surround the identifier with "identifier quote characters"
				 * (either backtick or double quote, depending on SQL mode) and
				 * escape all further occurences of said character with itself.
				 */

				$quote = self::IDENTIFIER_QUOTE;
				$value = str_replace($quote, $quote . $quote, $value);

				$value = $quote . $value . $quote;
			}

			// Regular string

			else{

				$value = '\'' . $SQL->escapeString($value) . '\'';
			}
		}

		// Integer

		elseif(is_int($value)){

			$value = (string) $value;
		}

		// Floating-point

		elseif(is_float($value)){

			$value = (string) $value;

			// Ensure no (other) invalid characters are present

			assert('!preg_match(\'/[^\d.e+\-]/i\', $value)');
			$value = preg_replace('/[^\d.e+\-]/i', '', $value);
		}

		// Boolean (interpreted as INT(1))

		elseif(is_bool($value)){

			// Don't convert directly to string, (int) false === ''!

			$value = (string) ((int) $value);
		}

		// NULL

		elseif($value === null){

			$value = 'NULL';
		}

		// Array (interpret either as SET or as a list of ID's)

		elseif(is_array($value)){

			$is_string = null;

			$callback = function($value) use($SQL, &$is_string){

				// Values should be either string or integer

				assert('is_string($value) || is_int($value)');
				if(!is_int($value)) $value = (string) $value;

				// All values should be of the same type, no "mixed bags"

				assert('$is_string === null || is_string($value) === $is_string');

				if(is_string($value)) $is_string = true;

				return $SQL->escapeString($value);
			};

			array_map($callback, $value);

			$value = implode(',', $value);

			if($is_string) $value = "'{$value}'";
		}

		// Object

		elseif(is_object($value)){

			$value = '\'' . $SQL->escapeString(serialize($value)) . '\'';
		}

		// Invalid

		else{

			throw new QueryBuilderException('Data of type "' . gettype($value)
				. '" cannot be used in an SQL-query');
		}

		return $value;
	}
668062
static public function formatText($value)
    {
        $value = static::filter_xss($value);
        $value = static::sql_encode($value);
        $value = static::filter_html($value);
        
        return $value;
    }