diff options
author | Christian Schneider | 2021-01-13 16:13:25 +0100 |
---|---|---|
committer | Christian Schneider | 2021-01-13 16:13:25 +0100 |
commit | 81e5fda87626dfe94d46be511ebc546076b1975b (patch) | |
tree | 9669ecb252500e514ff932df2e1036ab13cf8008 /it_dbi_postgres.class | |
parent | 1f57cc663c83ec44ec292256147f9811945e260a (diff) | |
download | itools-81e5fda87626dfe94d46be511ebc546076b1975b.tar.gz itools-81e5fda87626dfe94d46be511ebc546076b1975b.tar.bz2 itools-81e5fda87626dfe94d46be511ebc546076b1975b.zip |
Unified brace and else if style
Diffstat (limited to 'it_dbi_postgres.class')
-rw-r--r-- | it_dbi_postgres.class | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/it_dbi_postgres.class b/it_dbi_postgres.class index 46c0393..7ea3139 100644 --- a/it_dbi_postgres.class +++ b/it_dbi_postgres.class @@ -26,19 +26,23 @@ static $_global_key = 'it_dbi_postgres'; // override base class to get our own s function _where($params) { - if ($params['LIMIT'] && ($m = it::match('^\s*(\d+)\s*,\s*(\d+)\s*$', $params['LIMIT']))) { + if ($params['LIMIT'] && ($m = it::match('^\s*(\d+)\s*,\s*(\d+)\s*$', $params['LIMIT']))) + { unset($params['LIMIT']); $params[] = " OFFSET $m[0] LIMIT $m[1]"; } + return parent::_where($params); } function replace($tags = []) { - foreach (array_keys($this->_fields) as $k) { + foreach (array_keys($this->_fields) as $k) + { $escaped = $this->escape_name($k); $strings[] = $escaped . '= EXCLUDED.' . $escaped; } + $this->insert(array_merge($tags, [' ON CONFLICT (' . $this->escape_name($this->_p['keyfield']) . ') DO UPDATE SET ' . implode(', ', $strings)])); } @@ -57,7 +61,8 @@ function _get_field_defs() // recreate Key column of mysql show columns $res = $this->query('SELECT column_name,constraint_type,ordinal_position FROM information_schema.table_constraints AS t JOIN information_schema.key_column_usage USING (constraint_name, constraint_schema, constraint_catalog) ' . $where); - while ($res && ($row = $this->_fetch_assoc($res))) { + while ($res && ($row = $this->_fetch_assoc($res))) + { if ($row['constraint_type'] == 'PRIMARY KEY') $keys[$row['column_name']] = 'PRI'; else if ($row['ordinal_position'] == 1) @@ -65,9 +70,8 @@ function _get_field_defs() } $res = $this->query('SELECT * FROM information_schema.columns AS t ' . $where); - while ($res && ($field = $this->_fetch_assoc($res))) { + while ($res && ($field = $this->_fetch_assoc($res))) $result[$field['column_name']] = ['Field' => $field['column_name'], 'Type' => $field['data_type'], 'Extra' => it::match('^nextval\(', $field['column_default']) ? 'auto_increment' : '', 'Key' => $keys[$field['column_name']]]; - } return $result; } @@ -98,10 +102,12 @@ function _connect_db($p) { function _query($query, $p) { - if ($this->_p['keyfield'] && it::match('^INSERT ', $query)) { + if ($this->_p['keyfield'] && it::match('^INSERT ', $query)) + { $isinsert = true; $query .= ' RETURNING ' . $this->_escape_name($this->_p['keyfield']); } + if (!($result = pg_query($this->_link, $query)) && $p['safety']) { /* TODO |