Code cleanup.

Signed-off-by: Ole Ostergaard <ole.c.ostergaard@gmail.com>
This commit is contained in:
Ole Ostergaard 2019-02-26 14:08:55 +01:00
parent 63350423d4
commit 0d778fcc4e
5 changed files with 16 additions and 15 deletions

View File

@ -130,11 +130,11 @@ class Adapter {
/*
* @suppress SqlInjectionChecker
*/
public function insertIgnoreConflict($table, $input) : int {
public function insertIgnoreConflict(string $table,array $values) : int {
try {
$builder = $this->conn->getQueryBuilder();
$builder->insert($table);
foreach($input as $key => $value) {
foreach($values as $key => $value) {
$builder->setValue($key, $builder->createNamedParameter($value));
}
return $builder->execute();

View File

@ -39,15 +39,13 @@ class AdapterPgSql extends Adapter {
/*
* @suppress SqlInjectionChecker
*/
public function insertIgnoreConflict($table, $input) : int {
public function insertIgnoreConflict(string $table,array $values) : int {
$builder = $this->conn->getQueryBuilder();
$builder->insert($table)
->values($input);
foreach($input as $key => $value) {
$builder->insert($table);
foreach($values as $key => $value) {
$builder->setValue($key, $builder->createNamedParameter($value));
}
$queryString = $builder->getSQL() . ' ON CONFLICT DO NOTHING';
$inserts = array_values($input);
return $this->conn->executeUpdate($queryString, $inserts);
return $this->conn->executeUpdate($queryString, $builder->getParameters(), $builder->getParameterTypes());
}
}

View File

@ -257,8 +257,8 @@ class Connection extends ReconnectWrapper implements IDBConnection {
return $this->adapter->insertIfNotExist($table, $input, $compare);
}
public function insertIgnoreConflict($table, $input) : int {
return $this->adapter->insertIgnoreConflict($table, $input);
public function insertIgnoreConflict(string $table, array $values) : int {
return $this->adapter->insertIgnoreConflict($table, $values);
}
private function getType($value) {

View File

@ -131,10 +131,13 @@ class DBLockingProvider extends AbstractLockingProvider {
* @param int $lock
* @return int number of inserted rows
*/
protected function initLockField(string $path, int $lock = 0): int {
$expire = $this->getExpireTime();
return $this->connection->insertIgnoreConflict('file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire]);
return $this->connection->insertIgnoreConflict('file_locks', [
'key' => $path,
'lock' => $lock,
'ttl' => $expire
]);
}
/**

View File

@ -128,11 +128,11 @@ interface IDBConnection {
* Implementation is not fully finished and should not be used!
*
* @param string $table The table name (will replace *PREFIX* with the actual prefix)
* @param array $input data that should be inserted into the table (column name => value)
* @param array $values data that should be inserted into the table (column name => value)
* @return int number of inserted rows
* @since 17.0.0
* @since 16.0.0
*/
public function insertIgnoreConflict($table, $input) : int;
public function insertIgnoreConflict(string $table,array $values) : int;
/**
* Insert or update a row value