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;
	}