public function getTableFields($tableName = null)
{
// Make sure we have a list of tables in this db
if (empty(static::$tableCache)) {
static::$tableCache = $this->getDbo()->getTableList();
}
if (!$tableName) {
$tableName = $this->tableName;
}
// Try to load again column specifications if the table is not loaded OR if it's loaded and
// the previous call returned an error
if (!array_key_exists($tableName, static::$tableFieldCache) || isset(static::$tableFieldCache[$tableName]) && !static::$tableFieldCache[$tableName]) {
// Lookup the fields for this table only once.
$name = $tableName;
$prefix = $this->getDbo()->getPrefix();
if (substr($name, 0, 3) == '#__') {
$checkName = $prefix . substr($name, 3);
} else {
$checkName = $name;
}
// Iterate through all lower/uppercase permutations of the prefix if we have a prefix with at least one uppercase letter
if (!in_array($checkName, static::$tableCache) && preg_match('/[A-Z]/', $prefix) && substr($name, 0, 3) == '#__') {
$prefixPermutations = $this->getPrefixCasePermutations();
$partialCheckName = substr($name, 3);
foreach ($prefixPermutations as $permutatedPrefix) {
$checkName = $permutatedPrefix . $partialCheckName;
if (in_array($checkName, static::$tableCache)) {
break;
}
}
}
if (!in_array($checkName, static::$tableCache)) {
// The table doesn't exist. Return false.
static::$tableFieldCache[$tableName] = false;
} else {
$fields = $this->getDbo()->getTableColumns($name, false);
if (empty($fields)) {
$fields = false;
}
static::$tableFieldCache[$tableName] = $fields;
}
// PostgreSQL date type compatibility
if ($this->getDbo()->name == 'postgresql' && static::$tableFieldCache[$tableName] != false) {
foreach (static::$tableFieldCache[$tableName] as $field) {
if (strtolower($field->type) == 'timestamp without time zone') {
if (stristr($field->Default, '\'::timestamp without time zone')) {
list($date, ) = explode('::', $field->Default, 2);
$field->Default = trim($date, "'");
}
}
}
}
}
return static::$tableFieldCache[$tableName];
}