<commit_before><?php
namespace LazyRecord\TableParser;
use PDO;
use Exception;

class PgsqlTableParser extends BaseTableParser
{

    public function getTables()
    {
        $stm = $this->connection->query('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\';');
        $rows = $stm->fetchAll( PDO::FETCH_NUM);
        return array_map(function($row) { return $row[0]; },$rows);
    }

    public function getTableSchema($table)
    {
        /**
         * postgresql information schema column descriptions
         *
         * @see http://www.postgresql.org/docs/8.1/static/infoschema-columns.html
         */
        $sql = "SELECT * FROM information_schema.columns WHERE table_name = '$table';";
        $stm = $this->connection->query($sql);
        $schema = new Schema\SchemaDeclare;
        $schema->columnNames = $schema->columns = array();
        $rows = $stm->fetchAll( PDO::FETCH_OBJ );

        /**
         * more detailed attributes
         *
         * > select * from pg_attribute, pg_type where typname = 'addresses';
         * > select * from pg_attribute, pg_type where typname = 'addresses' and attname not in ('cmin','cmax','ctid','oid','tableoid','xmin','xmax');
         *
         * > SELECT
         *      a.attname as "Column",
         *      pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
         *  FROM
         *      pg_catalog.pg_attribute a
         *  WHERE
         *      a.attnum > 0
         *      AND NOT a.attisdropped
         *      AND a.attrelid = (
         *          SELECT c.oid
         *          FROM pg_catalog.pg_class c
         *              LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
         *          WHERE c.relname ~ '^(books)$'  
         *              AND pg_catalog.pg_table_is_visible(c.oid)<commit_msg>Fix pgsql table parser<commit_after><?php
namespace LazyRecord\TableParser;
use PDO;
use Exception;
use LazyRecord\Schema\SchemaDeclare;

class PgsqlTableParser extends BaseTableParser
{

    public function getTables()
    {
        $stm = $this->connection->query('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\';');
        $rows = $stm->fetchAll( PDO::FETCH_NUM);
        return array_map(function($row) { return $row[0]; },$rows);
    }

    public function getTableSchema($table)
    {
        /**
         * postgresql information schema column descriptions
         *
         * @see http://www.postgresql.org/docs/8.1/static/infoschema-columns.html
         */
        $sql = "SELECT * FROM information_schema.columns WHERE table_name = '$table';";
        $stm = $this->connection->query($sql);
        $schema = new SchemaDeclare;
        $schema->columnNames = $schema->columns = array();
        $rows = $stm->fetchAll( PDO::FETCH_OBJ );

        /**
         * more detailed attributes
         *
         * > select * from pg_attribute, pg_type where typname = 'addresses';
         * > select * from pg_attribute, pg_type where typname = 'addresses' and attname not in ('cmin','cmax','ctid','oid','tableoid','xmin','xmax');
         *
         * > SELECT
         *      a.attname as "Column",
         *      pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
         *  FROM
         *      pg_catalog.pg_attribute a
         *  WHERE
         *      a.attnum > 0
         *      AND NOT a.attisdropped
         *      AND a.attrelid = (
         *          SELECT c.oid
         *          FROM pg_catalog.pg_class c
         *              LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
         *          WHERE c.relname ~ '^(books)$'  
         *              AND pg_catalog.pg_table_is_visible(c.oid)
{'fraction_non_alphanumeric': 0.12174845803164387, 'fraction_numerical': 0.002145347278090641, 'mean_word_length': 2.034987794955248, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4145448', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1106, 'n_words': 236}