Update adapter.php

Modified insertIfNotExist() to support NULL values
This commit is contained in:
Jonny007-MKD 2013-08-23 16:30:41 +02:00 committed by Jörn Friedrich Dreyer
parent 19a6dc5420
commit 4161fd2408

View file

@ -51,13 +51,18 @@ class Adapter {
. str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative? . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative?
. 'FROM `' . $table . '` WHERE '; . 'FROM `' . $table . '` WHERE ';
$inserts = array_values($input);
foreach($input as $key => $value) { foreach($input as $key => $value) {
$query .= '`' . $key . '` = ? AND '; $query .= '`' . $key . '`';
if (is_null($value)) {
$query .= ' IS NULL AND ';
} else {
$inserts[] = $value;
$query .= ' = ? AND ';
}
} }
$query = substr($query, 0, strlen($query) - 5); $query = substr($query, 0, strlen($query) - 5);
$query .= ' HAVING COUNT(*) = 0'; $query .= ' HAVING COUNT(*) = 0';
$inserts = array_values($input);
$inserts = array_merge($inserts, $inserts);
try { try {
return $this->conn->executeUpdate($query, $inserts); return $this->conn->executeUpdate($query, $inserts);