diff --git a/lib/private/db/adapter.php b/lib/private/db/adapter.php
index 975b94322866f5d1d15f7b59ed951789af28f22f..6742ccdbb453de1ce5b3c3239ef9631b4dc53c78 100644
--- a/lib/private/db/adapter.php
+++ b/lib/private/db/adapter.php
@@ -51,13 +51,18 @@ class Adapter {
 			. str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative?
 			. 'FROM `' . $table . '` WHERE ';
 
+		$inserts = array_values($input);
 		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 .= ' HAVING COUNT(*) = 0';
-		$inserts = array_values($input);
-		$inserts = array_merge($inserts, $inserts);
 
 		try {
 			return $this->conn->executeUpdate($query, $inserts);
diff --git a/lib/private/db/adaptersqlite.php b/lib/private/db/adaptersqlite.php
index fa6d308ae328c85d73c2ac1ff16485797aa1c09f..5b9c5a437da98152212ed17b7ecd9033f5f061ee 100644
--- a/lib/private/db/adaptersqlite.php
+++ b/lib/private/db/adaptersqlite.php
@@ -21,13 +21,21 @@ class AdapterSqlite extends Adapter {
 		// NOTE: For SQLite we have to use this clumsy approach
 		// otherwise all fieldnames used must have a unique key.
 		$query = 'SELECT COUNT(*) FROM `' . $table . '` WHERE ';
-		foreach($input as $key => $value) {
-			$query .= '`' . $key . '` = ? AND ';
+		$inserts = array();
+		foreach ($input as $key => $value) {
+			$query .= '`' . $key . '`';
+			if (is_null($value)) {
+				$query .= ' IS NULL AND ';
+			} else {
+				$inserts[] = $value;
+				$query .= ' = ? AND ';
+			}
 		}
 		$query = substr($query, 0, strlen($query) - 5);
+
 		try {
 			$stmt = $this->conn->prepare($query);
-			$result = $stmt->execute(array_values($input));
+			$result = $stmt->execute($inserts);
 		} catch(\Doctrine\DBAL\DBALException $e) {
 			$entry = 'DB Error: "'.$e->getMessage() . '"<br />';
 			$entry .= 'Offending command was: ' . $query . '<br />';
diff --git a/tests/lib/db.php b/tests/lib/db.php
index 4b1a474c4efa5ab7d1d1c205b150b8c51af36e71..1f62413cbe42164f11acd445eb0ca6fcfdb9bdb1 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -125,6 +125,28 @@ class Test_DB extends PHPUnit_Framework_TestCase {
 		$this->assertEquals(4, count($result->fetchAll()));
 	}
 
+	public function testInsertIfNotExistNull() {
+		$categoryentries = array(
+			array('addressbookid' => 123, 'fullname' => null, 'expectedResult' => 1),
+			array('addressbookid' => 123, 'fullname' => null, 'expectedResult' => 0),
+			array('addressbookid' => 123, 'fullname' => 'test', 'expectedResult' => 1),
+		);
+
+		foreach($categoryentries as $entry) {
+			$result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2,
+				array(
+					'addressbookid' => $entry['addressbookid'],
+					'fullname' => $entry['fullname'],
+				));
+			$this->assertEquals($entry['expectedResult'], $result);
+		}
+
+		$query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table2.'`');
+		$result = $query->execute();
+		$this->assertTrue((bool)$result);
+		$this->assertEquals(2, count($result->fetchAll()));
+	}
+
 	public function testinsertIfNotExistDontOverwrite() {
 		$fullname = 'fullname test';
 		$uri = 'uri_1';