IDS catalog lookup for describe table

@param string $tableName
@param string $schemaName OPTIONAL
@return array
436564
public function describeTable($tableName, $schemaName = null)
    {
        // this is still a work in progress

        $sql= "SELECT DISTINCT t.owner, t.tabname, c.colname, c.colno, c.coltype,
               d.default, c.collength, t.tabid
               FROM syscolumns c
               JOIN systables t ON c.tabid = t.tabid
               LEFT JOIN sysdefaults d ON c.tabid = d.tabid AND c.colno = d.colno
               WHERE "
                . $this->_adapter->quoteInto('UPPER(t.tabname) = UPPER(?)', $tableName);
        if ($schemaName) {
            $sql .= $this->_adapter->quoteInto(' AND UPPER(t.owner) = UPPER(?)', $schemaName);
        }
        $sql .= " ORDER BY c.colno";

        $desc = array();
        $stmt = $this->_adapter->query($sql);

        $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);

        /**
         * The ordering of columns is defined by the query so we can map
         * to variables to improve readability
         */
        $tabschema      = 0;
        $tabname        = 1;
        $colname        = 2;
        $colno          = 3;
        $typename       = 4;
        $default        = 5;
        $length         = 6;
        $tabid          = 7;

        $primaryCols = null;

        foreach ($result as $key => $row) {
            $primary = false;
            $primaryPosition = null;

            if (!$primaryCols) {
                $primaryCols = $this->_getPrimaryInfo($row[$tabid]);
            }

            if (array_key_exists($row[$colno], $primaryCols)) {
                $primary = true;
                $primaryPosition = $primaryCols[$row[$colno]];
            }

            $identity = false;
            if ($row[$typename] == 6 + 256 ||
                $row[$typename] == 18 + 256) {
                $identity = true;
            }

            $desc[$this->_adapter->foldCase($row[$colname])] = array (
                'SCHEMA_NAME'       => $this->_adapter->foldCase($row[$tabschema]),
                'TABLE_NAME'        => $this->_adapter->foldCase($row[$tabname]),
                'COLUMN_NAME'       => $this->_adapter->foldCase($row[$colname]),
                'COLUMN_POSITION'   => $row[$colno],
                'DATA_TYPE'         => $this->_getDataType($row[$typename]),
                'DEFAULT'           => $row[$default],
                'NULLABLE'          => (bool) !($row[$typename] - 256 >= 0),
                'LENGTH'            => $row[$length],
                'SCALE'             => ($row[$typename] == 5 ? $row[$length]&255 : 0),
                'PRECISION'         => ($row[$typename] == 5 ? (int)($row[$length]/256) : 0),
                'UNSIGNED'          => false,
                'PRIMARY'           => $primary,
                'PRIMARY_POSITION'  => $primaryPosition,
                'IDENTITY'          => $identity
            );
        }

        return $desc;
    }
260633
public function getColumnDetails( $tablename, $columnname )
	{
		$sql = "
			SELECT *
			FROM INFORMATION_SCHEMA.COLUMNS
			WHERE TABLE_SCHEMA = ?
				AND TABLE_NAME = ?
				AND COLUMN_NAME = ?
		";

		$stmt = $this->_conn->create( $sql );
		$stmt->bind( 1, $this->_dbname );
		$stmt->bind( 2, $tablename );
		$stmt->bind( 3, $columnname );
		$result = $stmt->execute();

		if( ( $record = $result->fetch() ) === false ) {
			throw new MW_Setup_Exception( sprintf( 'Unknown column "%1$s" in table "%2$s"', $tablename, $columnname ) );
		}

		return $this->_createColumnItem( $record );
	}
21132
public Object[] findIdsByColumn(String schemaName, String tableName, String pKeyName, String columnName,
            Object columnValue, Class entityClazz)
    {
        // TODO Auto-generated method stub
        return null;
    }
892550
protected function getColumnCreateId($schema, $table, $columnName)
    {
        $result = $this->getColumnCreate($schema, $table, $columnName);
        $output = [];
        $output[] = sprintf("%sif (\$this->table('%s')->hasColumn('%s')) {", $this->ind2, $result[0], $result[1]);
        $output[] = sprintf("%s\$this->table(\"%s\")->changeColumn('%s', '%s', %s)->update();", $this->ind3, $result[0],
            $result[1], $result[2], $result[3]);
        $output[] = sprintf("%s} else {", $this->ind2);
        $output[] = sprintf("%s\$this->table(\"%s\")->addColumn('%s', '%s', %s)->update();", $this->ind3, $result[0],
            $result[1], $result[2], $result[3]);
        $output[] = sprintf("%s}", $this->ind2);

        return implode($this->nl, $output);
    }
963166
public function Fields($Tablename = FALSE) {
      if (!$Tablename)
         $Tablename = $this->CurrentTable;

      return $this->_Schema[$Tablename];
   }
905221
def lookupChdbid( tableName, dbid=nil )
      getSchema(dbid) if dbid
      unmodifiedTableName = tableName.dup
      @chdbid = findElementByAttributeValue( @chdbids, "name", formatChdbidName( tableName ) )
      if @chdbid
         @dbid = @chdbid.text
         return @dbid
      end
      if @chdbids
         chdbidArray = findElementsByAttributeName( @chdbids, "name" )
         chdbidArray.each{ |chdbid|
            if chdbid.has_text?
               dbid = chdbid.text
               getSchema( dbid )
               name = getResponseElement( "table/name" )
               if name and name.has_text? and name.text.downcase == unmodifiedTableName.downcase
                  @chdbid = chdbid
                  @dbid = dbid
                  return @dbid
               end
            end
         }
      end
      nil
   end
272745
public function schemas($schemaName = null)
    {
        if (is_null($schemaName)) {
            $url = $this->url('schema-list');
            return $this->request('get', $url);
        }

        return $this->schema($schemaName);
    }
109536
public function GetTableColumnsMeta($tableName, $columnNames) {
        $tableColumnsMetadata = array();
        foreach ($columnNames as $columnName) {
            $this->setDbConfigList(array());
            $dbConfig = new \Puzzlout\Framework\Dal\DbStatementConfig(null, \Puzzlout\Framework\Dal\DbExecutionType::COLUMNMETAS, new \Puzzlout\Framework\Dal\DbQueryFilters());
            $dbConfig->setQuery("SHOW COLUMNS FROM `$tableName` WHERE `Field` = '$columnName';");
            $this->addDbConfigItem($dbConfig);
            $tableColumnsMetadata[$columnName] = $this->BindParametersAndExecute();
        }
        return $tableColumnsMetadata;
    }
1014976
public function getForeignKeys($tableName): array {

		if (!isset($this->definitions[$tableName]['foreignKeys'])) {
			
			// old-style join because of speedness
			$query =
				'SELECT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`,' .
				' k.`REFERENCED_COLUMN_NAME`, r.`UPDATE_RULE`, r.`DELETE_RULE`' .
				' FROM information_schema.`KEY_COLUMN_USAGE` AS k' .
				' JOIN information_schema.`REFERENTIAL_CONSTRAINTS` AS r' .
				' WHERE k.`CONSTRAINT_NAME` != "PRIMARY"' .
				' AND k.`TABLE_SCHEMA` = ? AND k.`TABLE_NAME` = ?' .
				' AND r.`CONSTRAINT_SCHEMA` = ? AND r.`TABLE_NAME` = ?' .
				' AND k.`CONSTRAINT_NAME` = r.`CONSTRAINT_NAME`';
			
			$this->definitions[$tableName]['foreignKeys'] = self::load($query, [DB_NAME, $tableName, DB_NAME, $tableName]);

		}
		
		return $this->definitions[$tableName]['foreignKeys'];
		
	}
1149762
public function tableInfo($tableName, $schema = null)
    {
        return $this->_associateTableMeta($this->fetchAll('SELECT `column_name` as `name`, `data_type` AS `dataType`, `character_maximum_length` AS `maxLength`, `is_nullable` AS `null`, `column_default` AS `default`, `extra` AS `extra`, `column_key` AS `column_key` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `table_name` = :name AND `table_schema` = :schema ORDER BY `ordinal_position`', [
                    ':name' => $tableName,
                    ':schema' => $this->_config->name
        ]));
    }
1284164
public function getTableOid($schema, $table)
    {
        $sql = <<<SQL
select
  c.oid as oid
from
    pg_catalog.pg_class c
        left join pg_catalog.pg_namespace n on n.oid = c.relnamespace
where
{condition}
SQL;

        $where = Where::create('n.nspname =  $*', [$schema])
            ->andWhere('c.relname = $*', [$table])
            ;

        $iterator = $this->executeSql($sql, $where);

        return $iterator->isEmpty() ? null : $iterator->current()['oid'];
    }
1353348
protected function getIndexes($tableName)
    {
        $indexes = [];
        $rows = $this->fetchAll(sprintf('SHOW INDEXES FROM %s', $this->quoteTableName($tableName)));
        foreach ($rows as $row) {
            if (!isset($indexes[$row['Key_name']])) {
                $indexes[$row['Key_name']] = ['columns' => []];
            }
            $indexes[$row['Key_name']]['columns'][] = strtolower($row['Column_name']);
        }

        return $indexes;
    }
65079
protected function getForeignKeys(string $tableName): ?array
    {
        $sql = sprintf("SELECT
                cols.TABLE_NAME,
                cols.COLUMN_NAME,
                cRefs.CONSTRAINT_NAME,
                refs.REFERENCED_TABLE_NAME,
                refs.REFERENCED_COLUMN_NAME,
                cRefs.UPDATE_RULE,
                cRefs.DELETE_RULE
            FROM INFORMATION_SCHEMA.COLUMNS AS cols
            LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS refs
                ON refs.TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND refs.REFERENCED_TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND refs.TABLE_NAME=cols.TABLE_NAME
                AND refs.COLUMN_NAME=cols.COLUMN_NAME
            LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS cons
                ON cons.TABLE_SCHEMA=cols.TABLE_SCHEMA
                AND cons.TABLE_NAME=cols.TABLE_NAME
                AND cons.CONSTRAINT_NAME=refs.CONSTRAINT_NAME
            LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS cRefs
                ON cRefs.CONSTRAINT_SCHEMA=cols.TABLE_SCHEMA
                AND cRefs.CONSTRAINT_NAME=refs.CONSTRAINT_NAME
            WHERE
                cols.TABLE_NAME = %s
                AND cols.TABLE_SCHEMA = DATABASE()
                AND refs.REFERENCED_TABLE_NAME IS NOT NULL
                AND cons.CONSTRAINT_TYPE = 'FOREIGN KEY'
            ;", $this->quote($tableName));

        $rows = $this->queryFetchAll($sql);

        if (empty($rows)) {
            return null;
        }

        $result = [];
        foreach ($rows as $row) {
            $result[$row['CONSTRAINT_NAME']] = $row;
        }

        return $result;
    }
113828
protected function getIndexes($tableName): array
    {
        $sql = sprintf('SHOW INDEX FROM %s', $this->ident($tableName));
        $rows = $this->queryFetchAll($sql);
        $result = [];
        foreach ($rows as $row) {
            if (isset($row['Cardinality'])) {
                unset($row['Cardinality']);
            }
            $name = $row['Key_name'];
            $seq = $row['Seq_in_index'];
            $result[$name][$seq] = $row;
        }

        return $result;
    }
1190549
public function listTableDetails($tableName)
    {
        $columns     = $this->listTableColumns($tableName);
        $foreignKeys = [];
        if ($this->_platform->supportsForeignKeyConstraints()) {
            $foreignKeys = $this->listTableForeignKeys($tableName);
        }
        $indexes = $this->listTableIndexes($tableName);

        return new Table($tableName, $columns, $indexes, $foreignKeys);
    }
854123
public function getTableRows(string $tableName)
    {
        $statement = $this->connection->prepare("SELECT * FROM information_schema.columns WHERE table_catalog = :database AND table_name = :table");
        $statement->execute([
            ':database' => $this->Databaser->database,
            ':table'    => $tableName
        ]);

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
81625
private function getExtendsSchemas(SchemaDescriptor $schema)
    {
        $schemaIds = [];

        $check = $schema->getExtends();
        while ($check) {
            $schemaIds[] = $check->getId()->getCurieWithMajorRev();

            $check = $check->getExtends();
        }

        return $schemaIds;
    }