Beispiel #1
0
 /**
  * Escape a value into SQL format
  * @param string|int $str
  * @return string
  */
 function escape($str)
 {
     if ($str === null) {
         return 'NULL';
     }
     if (is_numeric($str) && (int) $str == $str) {
         return $str;
     }
     if (is_array($str)) {
         throw new \BadMethodCallException('cant escape an array');
     }
     if (is_object($str)) {
         if (method_exists($str, 'toEscaped')) {
             //depreciated
             return $str->toEscaped();
         } elseif ($str instanceof IToSQL) {
             return $str->toSQL();
         } elseif (method_exists($str, '__toString')) {
             $str = (string) $str;
         } else {
             throw new \BadMethodCallException('cant escape this object, non escapable');
         }
     }
     return '\'' . $this->adapter->Escape($str) . '\'';
 }