Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Deadlock removed and idents done right
  • Loading branch information
obel1x authored Nov 6, 2018
commit 855357e696c19691d99b608f877d75aea37559ce
72 changes: 36 additions & 36 deletions lib/private/DB/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,46 +90,46 @@ public function unlockTable() {
* @throws \Doctrine\DBAL\DBALException
*/
public function insertIfNotExist($table, $input, array $compare = null) {
if (empty($compare)) {
$compare = array_keys($input);
};

//Search for given compare-fields
$query_select = 'SELECT * FROM `' . $table . '` WHERE 1=1';
foreach($compare as $key) {
$query_select .= ' AND `' . $key . '`';
if (is_null($input[$key])) {
$query_select .= ' IS NULL';
} else {
$query_select .= ' = "' . $input[$key] .'"';
};
};
$result = $this->conn->executeQuery($query_select);
$data = $result->fetch();
//took this from cache.php:
//FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO
//PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false
if ($data === null) {
$data = false;
}
if ($data) {
return 0; //Data already there, only empty result returned
};
if (empty($compare)) {
$compare = array_keys($input);
}

//Do update
$inserts = array_values($input);
$query_insert = 'INSERT INTO `' .$table . '` (`'
. implode('`,`', array_keys($input))
. '`) VALUES ('
. str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative?
. ')';
return $this->conn->executeUpdate($query_insert, $inserts);
//Search for given compare-fields
$query_select = 'SELECT * FROM `' . $table . '` WHERE 1=1';
foreach($compare as $key) {
$query_select .= ' AND `' . $key . '`';
if (is_null($input[$key])) {
$query_select .= ' IS NULL';
} else {
$query_select .= ' = "' . $input[$key] .'"';
};
};
$result = $this->conn->executeQuery($query_select);
$data = $result->fetch();
//took this from cache.php:
//FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO
//PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false
if ($data === null) {
$data = false;
}
if ($data) {
return 0; //Data already there, only empty result returned
};

/* $query = 'INSERT INTO `' .$table . '` (`'
//Do update
$inserts = array_values($input);
$query = 'INSERT INTO `' .$table . '` (`'
. implode('`,`', array_keys($input))
. '`) VALUES ('
. str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative?
. ')';
/* This coding caused Deadlocks with some DB-Setups an was replaced
$query = 'INSERT INTO `' .$table . '` (`'
. implode('`,`', array_keys($input)) . '`) SELECT '
. str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative?
. 'FROM `' . $table . '` WHERE ';

$inserts = array_values($input);
foreach($compare as $key) {
$query .= '`' . $key . '`';
if (is_null($input[$key])) {
Expand All @@ -141,7 +141,7 @@ public function insertIfNotExist($table, $input, array $compare = null) {
}
$query = substr($query, 0, -5);
$query .= ' HAVING COUNT(*) = 0';
return $this->conn->executeUpdate($query, $inserts);
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the whole comment - that's what we have version control for. 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, thanks for the hint. Lack of me beeing new to github. Will do this if we agree if the changes can be done that way. Currently i don't know someone can do it better.

}
return $this->conn->executeUpdate($query, $inserts);
}
}