diff options
| -rw-r--r-- | adodb.inc.php | 44 | ||||
| -rw-r--r-- | drivers/adodb-postgres64.inc.php | 40 |
2 files changed, 69 insertions, 15 deletions
diff --git a/adodb.inc.php b/adodb.inc.php index 952aa2ba..b16c7b8b 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -3389,29 +3389,43 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 } /** - * List columns names in a table as an array. - * @param table table name to query + * List columns names in a table as an array + * + * @param string $table table name to query + * @param bool $numIndexes return numeric keys + * @param bool $useattnum discarded in base class * - * @return array of column names for current table. + * @return false|array of column names for current table. */ - function MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */) { + public function MetaColumnNames( + string $table, + bool $numIndexes=false, + bool $useattnum=false + ) : mixed { + $objarr = $this->MetaColumns($table); if (!is_array($objarr)) { return false; } - $arr = array(); - if ($numIndexes) { - $i = 0; - if ($useattnum) { - foreach($objarr as $v) - $arr[$v->attnum] = $v->name; - } else - foreach($objarr as $v) $arr[$i++] = $v->name; - } else - foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name; + if ($useattnum) { + /* + * Assume we want a numeric array to + * match the postgres option + */ + $numIndexes = true; + } - return $arr; + $columnNames = []; + foreach($objarr as $v) { + $columnNames[strtoupper($v->name)] = $v->name; + } + + if ($numIndexes) { + return array_values($columnNames); + } + + return $columnNames; } /** diff --git a/drivers/adodb-postgres64.inc.php b/drivers/adodb-postgres64.inc.php index b2b21213..57f6955c 100644 --- a/drivers/adodb-postgres64.inc.php +++ b/drivers/adodb-postgres64.inc.php @@ -648,6 +648,46 @@ class ADODB_postgres64 extends ADOConnection{ return $retarr ?: false; } + + /** + * List columns names in a table as an array. + * @param string $table table name to query + * @param bool $numIndexes return numeric keys + * @param bool $useattnum For postgres, use the attnum + * + * @return false|array of column names for current table. + */ + public function MetaColumnNames( + string $table, + bool $numIndexes=false, + bool $useattnum=false + ) : mixed { + + $objarr = $this->MetaColumns($table); + if (!is_array($objarr)) { + return false; + } + + $columnNames = []; + foreach($objarr as $v) { + if ($useattnum) { + /* + * overrides associative keys + */ + $columnNames[$v->attnum] = $v->name; + } else { + $columnNames[strtoupper($v->name)] = $v->name; + } + } + + if ($numIndexes && !$useattnum) { + return array_values($columnNames); + } + + return $columnNames; + + } + function param($name, $type='C') { if (!$name) { |
