Skip to content

fix upsert sql statement for pgsql #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions config/db_schema.pgsql
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ INSERT INTO ocp_system_config (assoc_id, name, "desc") values (1,'System 0','Def
CREATE SEQUENCE ocp_tools_config_id_seq;
CREATE TABLE ocp_tools_config (
id integer Primary KEY DEFAULT nextval('ocp_tools_config_id_seq'),
module text NOT NULL UNIQUE,
param text NOT NULL UNIQUE,
module text NOT NULL,
param text NOT NULL,
value text DEFAULT NULL,
box_id text DEFAULT '' UNIQUE
box_id text DEFAULT '',
UNIQUE(module, param, box_id)
);

-- --------------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion web/tools/admin/tools_config/tools_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@
}
continue;
}
$sql = "INSERT INTO ".$table." (module, param, value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE module=?,param=?,value=?";

if ($config->db_driver == "mysql") {
$sql = "INSERT INTO ".$table." (module, param, value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE module=?,param=?,value=?";
} else if ($config->db_driver == "pgsql") {
$sql = "INSERT INTO ".$table." (module, param, value) VALUES (?,?,?) ON CONFLICT(module, param, box_id) DO UPDATE SET module=?,param=?,value=?";
}

$stm = $link->prepare($sql);
if ($stm === false) {
die('Failed to issue query ['.$sql.'], error message : ' . print_r($link->errorInfo(), true));
Expand Down