Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-SB committed Apr 23, 2020
2 parents b676794 + c5e2b8c commit d644f46
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .horde.yml
Expand Up @@ -2,7 +2,7 @@
id: Db
name: Db
full: Database abstraction library
description: Horde database/SQL abstraction layer
description: Database access and SQL abstraction layer.
list: dev
type: library
homepage: https://www.horde.org/libraries/Horde_Db
Expand Down
16 changes: 12 additions & 4 deletions .travis.yml
@@ -1,17 +1,25 @@
sudo: false
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
matrix:
jobs:
fast_finish: true
allow_failures:
- php: nightly
include:
- addons:
postgres: 9.4
- addons:
postgres: 9.5
- addons:
postgres: 9.6
- addons:
postgres: 10
services:
- mysql
- postgresql
Expand Down
10 changes: 7 additions & 3 deletions doc/Horde/Db/CHANGES
@@ -1,6 +1,10 @@
----------
v2.4.1-git
----------
------
v2.4.1
------

[mjr] Fix connecting over SSL with MySQLi driver (PR #2, PaulSzymanski
<PaulSzymanski@users.noreply.github.com>).



------
Expand Down
4 changes: 3 additions & 1 deletion doc/Horde/Db/changelog.yml
Expand Up @@ -8,7 +8,9 @@
license:
identifier: BSD-2-Clause
uri: http://www.horde.org/licenses/bsd
notes:
notes: |
[jan] Fix sequences on PostgreSQL 10+ (Ivan Sergio Borgonovo <mail@webthatworks.it>, PR #3).
[mjr] Fix connecting over SSL with MySQLi driver (PR #2, PaulSzymanski <PaulSzymanski@users.noreply.github.com>).
2.4.0:
api: 2.4.0
state:
Expand Down
2 changes: 1 addition & 1 deletion lib/Horde/Db/Adapter/Mysqli.php
Expand Up @@ -128,7 +128,7 @@ public function connect()
);
$mysqli->real_connect(
$config['host'], $config['username'], $config['password'],
$config['dbname'], $config['port'], $config['socket']);
$config['dbname'], $config['port'], $config['socket'], MYSQLI_CLIENT_SSL);
} else {
$mysqli = new mysqli(
$config['host'], $config['username'], $config['password'],
Expand Down
43 changes: 32 additions & 11 deletions lib/Horde/Db/Adapter/Postgresql/Schema.php
Expand Up @@ -1061,14 +1061,33 @@ public function resetPkSequence($table, $pk = null, $sequence = null)
if ($sequence) {
$quotedSequence = $this->quoteSequenceName($sequence);
$quotedTable = $this->quoteTableName($table);
$quotedPk = $this->quoteColumnName($pk);
$sql = sprintf('SELECT setval(%s, (SELECT COALESCE(MAX(%s) + (SELECT increment_by FROM pg_sequences where schemaname= ANY (CURRENT_SCHEMAS(false)) and sequencename=%s), (SELECT min_value FROM pg_sequences where schemaname= ANY (CURRENT_SCHEMAS(false)) and sequencename=%s)) FROM %s), false)',
$quotedSequence,
$quotedPk,
$quotedSequence,
$quotedSequence,
$quotedTable);

$quotedPk = $this->quoteColumnName($pk);
if ($this->postgresqlVersion() >= 100000) {
$sql = sprintf('
SELECT setval(
%s,
(SELECT COALESCE(
MAX(%s) + (SELECT increment_by FROM pg_sequences WHERE schemaname=ANY(CURRENT_SCHEMAS(false)) AND sequencename=%s),
(SELECT min_value FROM pg_sequences WHERE schemaname=ANY(CURRENT_SCHEMAS(false)) AND sequencename=%s)
) FROM %s),
false
)',
$quotedSequence,
$quotedPk,
$quotedSequence,
$quotedSequence,
$quotedTable
);
} else {
$sql = sprintf(
'SELECT setval(%s, (SELECT COALESCE(MAX(%s) + (SELECT increment_by FROM %s), (SELECT min_value FROM %s)) FROM %s), false)',
$quotedSequence,
$quotedPk,
$sequence,
$sequence,
$quotedTable
);
}
$this->selectValue($sql, 'Reset sequence');
} else {
if ($this->_logger) {
Expand Down Expand Up @@ -1130,6 +1149,10 @@ public function pkAndSequenceFor($table)
$result = $this->selectOne($sql, 'PK and custom sequence');
}

if (!$result) {
return array(null, null);
}

// [primary_key, sequence]
return array($result['attname'], $result['relname']);
}
Expand All @@ -1143,9 +1166,7 @@ public function postgresqlVersion()
{
if (!$this->_version) {
try {
$version = $this->selectValue('SELECT version()');
if (preg_match('/PostgreSQL (\d+)\.(\d+)\.(\d+)/', $version, $matches))
$this->_version = ($matches[1] * 10000) + ($matches[2] * 100) + $matches[3];
$this->_version = $this->selectValue('SHOW server_version_num');
} catch (Exception $e) {
return 0;
}
Expand Down

0 comments on commit d644f46

Please sign in to comment.