Skip to content

Commit 077e53c

Browse files
committed
instead of upsert, fallback to default query on PgSQL <= 9.4
because there is no upsert yet Signed-off-by: Arthur Schiwon <[email protected]>
1 parent 4986241 commit 077e53c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/private/DB/AdapterPgSql.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424

2525
namespace OC\DB;
2626

27+
use Doctrine\DBAL\DBALException;
28+
2729
class AdapterPgSql extends Adapter {
30+
protected $compatModePre9_5 = null;
31+
2832
public function lastInsertId($table) {
2933
return $this->conn->fetchColumn('SELECT lastval()');
3034
}
@@ -40,12 +44,29 @@ public function fixupStatement($statement) {
4044
* @suppress SqlInjectionChecker
4145
*/
4246
public function insertIgnoreConflict(string $table,array $values) : int {
47+
if($this->isPre9_5CompatMode() === true) {
48+
return parent::insertIgnoreConflict($table, $values);
49+
}
50+
51+
// "upsert" is only available since PgSQL 9.5, but the generic way
52+
// would leave error logs in the DB.
4353
$builder = $this->conn->getQueryBuilder();
4454
$builder->insert($table);
45-
foreach($values as $key => $value) {
55+
foreach ($values as $key => $value) {
4656
$builder->setValue($key, $builder->createNamedParameter($value));
4757
}
4858
$queryString = $builder->getSQL() . ' ON CONFLICT DO NOTHING';
4959
return $this->conn->executeUpdate($queryString, $builder->getParameters(), $builder->getParameterTypes());
5060
}
61+
62+
protected function isPre9_5CompatMode(): bool {
63+
if($this->compatModePre9_5 !== null) {
64+
return $this->compatModePre9_5;
65+
}
66+
67+
$version = $this->conn->fetchColumn('SHOW SERVER_VERSION');
68+
$this->compatModePre9_5 = version_compare($version, '9.5', '<');
69+
70+
return $this->compatModePre9_5;
71+
}
5172
}

lib/private/legacy/util.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,9 @@ public static function checkDatabaseVersion() {
978978
$data = $result->fetchRow();
979979
if (isset($data['server_version'])) {
980980
$version = $data['server_version'];
981-
if (version_compare($version, '9.5.0', '<')) {
981+
if (version_compare($version, '9.0.0', '<')) {
982982
$errors[] = array(
983-
'error' => $l->t('PostgreSQL >= 9.5 required'),
983+
'error' => $l->t('PostgreSQL >= 9 required'),
984984
'hint' => $l->t('Please upgrade your database version')
985985
);
986986
}

0 commit comments

Comments
 (0)