Return the mapped field name for a column, if it exists. Otherwise return camelized version.

@param string $tableName
@param string $columnName
@param bool   $fk         Whether the column is a foreignkey or not.

@return string
357965
private function getFieldNameForColumn($tableName, $columnName, $fk = false)
    {
        if (isset($this->fieldNamesForColumns[$tableName], $this->fieldNamesForColumns[$tableName][$columnName])) {
            return $this->fieldNamesForColumns[$tableName][$columnName];
        }

        $columnName = strtolower($columnName);

        // Replace _id if it is a foreignkey column
        if ($fk) {
            $columnName = str_replace('_id', '', $columnName);
        }

        return Inflector::camelize($columnName);
    }
852366
static function columnNameToLabel($columnname)
    {
        $retstring = str_replace("_", " ", $columnname);
        if (!function_exists("mb_strtolower")) {
            $retstring = ucwords(strtolower($retstring));
        } else {
            $retstring = ucwords(mb_strtolower($retstring, ReporticoLocale::outputCharsetToPhpCharset(ReporticoApp::getConfig("output_encoding"))));
        }

        return $retstring;
    }
554151
private function mapFieldName($fieldName)
    {
        if (isset($this->fieldNameMapping[$fieldName])) {
            $fieldName = $this->fieldNameMapping[$fieldName];
        }

        return $fieldName;
    }
802682
public function GetColumnName($objectclass, $propertyname)
	{
		$fm = $this->GetFieldMap($objectclass, $propertyname);
		return $fm->ColumnName;
	}
690727
public function getColumnNames($tableName)
    {
        $colNames = array();
        foreach ($this->tableColumnTypes[$tableName] as $colName => $colType) {
            if ($colType['is_virtual']) {
                $this->dumpSettings['complete-insert'] = true;
                continue;
            } else {
                $colNames[] = "`${colName}`";
            }
        }
        return $colNames;
    }
713486
public static function getPrimaryKeyOfTable($tableName)
    {
        $schema = DB::getDoctrineSchemaManager();
        $column = $schema->listTableDetails($tableName)->getPrimaryKey();

        return $column ? $column->getColumns()[0] : '';
    }
973299
public function getTableColumns($tableName)
    {
        $db = $this->getDb();

        $allColumns = $db->fetchAll("SHOW COLUMNS FROM " . $tableName);

        $fields = array();
        foreach ($allColumns as $column) {
            $fields[trim($column['Field'])] = $column;
        }

        return $fields;
    }
421676
protected function checkForeignKeyOwnerTableName($foreign, $tablename)
    {
        return $this->checkReferenceTableName($foreign ? $foreign->getReferencedTable() : null, $tablename);
    }
320235
protected function buildForeignKeyName($foreignKey, $baseTable)
    {
        return (is_null($foreignKey)) ?
            Inflector::singularize($baseTable).self::DEFAULT_FOREIGN_KEY_SUFFIX :
            $foreignKey;
    }
1012258
public function getFields($tableName)
    {
        $this->initConnect(true);
        list($tableName) = explode(' ', $tableName);
        $sql             = "select a.column_name,data_type,DECODE (nullable, 'Y', 0, 1) notnull,data_default, DECODE (A .column_name,b.column_name,1,0) pk from all_tab_columns a,(select column_name from all_constraints c, all_cons_columns col where c.constraint_name = col.constraint_name and c.constraint_type = 'P' and c.table_name = '" . strtoupper($tableName) . "' ) b where table_name = '" . strtoupper($tableName) . "' and a.column_name = b.column_name (+)";
        $pdo             = $this->linkID->query($sql);
        $result          = $pdo->fetchAll(PDO::FETCH_ASSOC);
        $info            = [];
        if ($result) {
            foreach ($result as $key => $val) {
                $val                       = array_change_key_case($val);
                $info[$val['column_name']] = [
                    'name'    => $val['column_name'],
                    'type'    => $val['data_type'],
                    'notnull' => $val['notnull'],
                    'default' => $val['data_default'],
                    'primary' => $val['pk'],
                    'autoinc' => $val['pk'],
                ];
            }
        }
        return $this->fieldCase($info);
    }
318660
public function withRelatedIdAs(string $columnName)
    {
        call_user_func($this->callback,
                function ($idString, Table $parentTable) use ($columnName) {
                    $mapper = call_user_func($this->mapperLoader);

                    return new ManyToOneRelation(
                            $idString,
                            $this->loadIds
                                    ? new ToOneRelationIdentityReference($mapper, $this->bidirectionalRelationProperty)
                                    : new ToOneRelationObjectReference($mapper, $this->bidirectionalRelationProperty),
                            $parentTable,
                            $columnName
                    );
                },
                // Dont create foreign key if bidirectional property is set
                // because it will be created by the inverse bidirectional relation
                /** @see OneToManyRelationDefiner::withParentIdAs() */
                /** @see ToOneRelationDefiner::withParentIdAs() */
                $this->bidirectionalRelationProperty ? null : function (Table $parentTable) use ($columnName) {
                    /** @var IEntityMapper $mapper */
                    $mapper = call_user_func($this->mapperLoader);

                    return ForeignKey::createWithNamingConvention(
                            $parentTable->getName(),
                            [$columnName],
                            $mapper->getPrimaryTableName(),
                            [$mapper->getPrimaryTable()->getPrimaryKeyColumnName()],
                            $this->onDeleteMode,
                            ForeignKeyMode::CASCADE
                    );
                });
    }
364176
public ForeignkeyDef getForeignkey(String name, String tableName)
    {
        String        realName = (name == null ? "" : name);
        ForeignkeyDef def      = null;

        for (Iterator it = getForeignkeys(); it.hasNext();)
        {
            def = (ForeignkeyDef)it.next();
            if (realName.equals(def.getName()) &&
                def.getTableName().equals(tableName))
            {
                return def;
            }
        }
        return null;
    }
370790
public function columns($columnNames) : ForeignKeyReferencedColumnsDefiner
    {
        return new ForeignKeyReferencedColumnsDefiner(
                $this->callback,
                is_array($columnNames) ? $columnNames : [$columnNames]
        );
    }
467804
public static function tableForeignKeys($tableName)
    {
        $result = ['inner' => [], 'outer' => []];
        foreach (Yii::$app->db->schema->tableSchemas as $table) {
            $foreignKeys = static::findConstraints($table);
            /** @var TableSchema $table */
            if ($table->name == $tableName) {
                $result['inner'] = $foreignKeys;
                continue;
            }
            foreach ($foreignKeys as $foreignKey) {
                if ($foreignKey['ftable'] == $tableName) {
                    $result['outer'][] = $foreignKey;
                }
            }
        }
        return $result;
    }
691873
public function getColumns($tableName)
    {
        if (!isset($this->cache[$tableName])) {
            $columns = $this->entityManager->getConnection()->getSchemaManager()->listTableColumns($tableName);
            if ('leads' === $tableName) {
                if (!$this->extendedFieldAliases) {
                    // Hacked this query into here to avoid a recursive dependency in 2.15.0
                    $fq = $this->entityManager->getConnection()->createQueryBuilder();
                    $fq->select('f.alias')
                        ->from(MAUTIC_TABLE_PREFIX.'lead_fields', 'f')
                        ->where(
                            $fq->expr()->orX(
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedField')),
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedFieldSecure'))
                            )
                        );
                    foreach ($fq->execute()->fetchAll() as $result) {
                        $this->extendedFieldAliases[$result['alias']] = 'extendedField - This is never used as an actual column object';
                    }
                }
                if ($this->extendedFieldAliases) {
                    $columns = array_merge($columns, $this->extendedFieldAliases);
                }
            }
            $this->cache[$tableName] = $columns ?: [];
        }

        return $this->cache[$tableName];
    }
345943
public function getForeignKey($constraintName)
    {
        $constraintName = $this->normalizeIdentifier($constraintName);
        if (! $this->hasForeignKey($constraintName)) {
            throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
        }

        return $this->_fkConstraints[$constraintName];
    }
631789
protected function getForeignKeyCreate($table, $fkName)
    {
        $foreignKeys = $this->dba->getForeignKeys($table);
        $fkData = $foreignKeys[$fkName];
        $columns = "'" . $fkData['COLUMN_NAME'] . "'";
        $referencedTable = "'" . $fkData['REFERENCED_TABLE_NAME'] . "'";
        $referencedColumns = "'" . $fkData['REFERENCED_COLUMN_NAME'] . "'";
        $options = $this->getForeignKeyOptions($fkData, $fkName);

        $output = [];
        $output[] = sprintf("%s\$this->table(\"%s\")->addForeignKey(%s, %s, %s, %s)->save();", $this->ind2, $table,
            $columns, $referencedTable, $referencedColumns, $options);

        $result = implode($this->nl, $output);

        return $result;
    }