Beispiel #1
0
 /**
  * Check if a column value is not already in database if the column has a unique attribute constraint
  *
  * @param      string  $columnName  The column name
  * @param      mixed   $value       The column value
  *
  * @return     bool    True if the value is already in database and the column has a unique attribute constraint
  *                     else false
  *
  * @todo Move to EntityManager ?
  */
 public function checkUniqueField(string $columnName, $value) : bool
 {
     $alreadyInDatabase = false;
     if (strpos($this->constraints['unique'], $columnName) !== false) {
         $sqlMarks = 'SELECT count(*) FROM %s WHERE %s = ' . DB::quote($value);
         $sql = EntityManager::sqlFormat($sqlMarks, $this->tableName, $columnName);
         $alreadyInDatabase = (int) DB::query($sql)->fetchColumn() > 0;
     }
     return $alreadyInDatabase;
 }