mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-17020 dml: native pgsql driver - fixed error detection on connect
This commit is contained in:
parent
1fe1d10454
commit
9a4f9e334a
1 changed files with 6 additions and 4 deletions
|
@ -102,10 +102,12 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = pg_connection_status($this->pgsql);
|
$status = pg_connection_status($this->pgsql);
|
||||||
if ($status === PGSQL_CONNECTION_BAD) {
|
|
||||||
|
if ($status === false or $status === PGSQL_CONNECTION_BAD) {
|
||||||
$this->pgsql = null;
|
$this->pgsql = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pg_set_client_encoding($this->pgsql, 'utf8');
|
pg_set_client_encoding($this->pgsql, 'utf8');
|
||||||
// find out the bytea oid
|
// find out the bytea oid
|
||||||
$sql = "SELECT oid FROM pg_type WHERE typname = 'bytea'";
|
$sql = "SELECT oid FROM pg_type WHERE typname = 'bytea'";
|
||||||
|
@ -238,7 +240,7 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||||
|
|
||||||
$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, d.adsrc
|
$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, d.adsrc
|
||||||
FROM pg_catalog.pg_class c
|
FROM pg_catalog.pg_class c
|
||||||
JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
|
JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
|
||||||
JOIN pg_catalog.pg_type t ON t.oid = a.atttypid
|
JOIN pg_catalog.pg_type t ON t.oid = a.atttypid
|
||||||
LEFT JOIN pg_catalog.pg_attrdef d ON (d.adrelid = c.oid AND d.adnum = a.attnum)
|
LEFT JOIN pg_catalog.pg_attrdef d ON (d.adrelid = c.oid AND d.adnum = a.attnum)
|
||||||
WHERE relkind = 'r' AND c.relname = '$tablename' AND c.reltype > 0 AND a.attnum > 0
|
WHERE relkind = 'r' AND c.relname = '$tablename' AND c.reltype > 0 AND a.attnum > 0
|
||||||
|
@ -622,7 +624,7 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||||
|
|
||||||
$return = pg_fetch_all_columns($result, 0);
|
$return = pg_fetch_all_columns($result, 0);
|
||||||
pg_free_result($result);
|
pg_free_result($result);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,7 +680,7 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||||
$count = count($params);
|
$count = count($params);
|
||||||
for ($i=1; $i<=$count; $i++) {
|
for ($i=1; $i<=$count; $i++) {
|
||||||
$values[] = "\$".$i;
|
$values[] = "\$".$i;
|
||||||
}
|
}
|
||||||
$values = implode(',', $values);
|
$values = implode(',', $values);
|
||||||
|
|
||||||
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($values) $returning";
|
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($values) $returning";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue