/**
  * {@inheritdoc}
  */
 public function escapeValue($unescaped)
 {
     // Date value
     if ($unescaped instanceof DateValue) {
         return "'" . $this->link->real_escape_string($unescaped->format('Y-m-d')) . "'";
         // Date time value (including DateTimeValue)
     } elseif ($unescaped instanceof DateTime) {
         return "'" . $this->link->real_escape_string($unescaped->format('Y-m-d H:i:s')) . "'";
         // Float
     } else {
         if (is_float($unescaped)) {
             return "'" . str_replace(',', '.', (double) $unescaped) . "'";
             // replace , with . for locales where comma is used by the system (German for example)
             // Boolean (maps to TINYINT(1))
         } else {
             if (is_bool($unescaped)) {
                 return $unescaped ? "'1'" : "'0'";
                 // NULL
             } else {
                 if ($unescaped === null) {
                     return 'NULL';
                     // Escape first cell of each row
                 } else {
                     if ($unescaped instanceof ResultInterface) {
                         if ($unescaped->count() < 1) {
                             throw new InvalidArgumentException("Empty results can't be escaped");
                         }
                         $escaped = [];
                         foreach ($unescaped as $v) {
                             $escaped[] = $this->escapeValue(array_shift($v));
                         }
                         return '(' . implode(',', $escaped) . ')';
                         // Escape each array element
                     } else {
                         if (is_array($unescaped)) {
                             if (empty($unescaped)) {
                                 throw new InvalidArgumentException("Empty arrays can't be escaped");
                             }
                             $escaped = [];
                             foreach ($unescaped as $v) {
                                 $escaped[] = $this->escapeValue($v);
                             }
                             return '(' . implode(',', $escaped) . ')';
                             // Regular string and integer escape
                         } else {
                             if (is_scalar($unescaped)) {
                                 return "'" . $this->link->real_escape_string($unescaped) . "'";
                             } else {
                                 throw new InvalidArgumentException('Value is expected to be scalar, array, or instance of: DateTime or Result');
                             }
                         }
                     }
                 }
             }
         }
     }
 }