src/Context/SQLHandler.php
protected function requiredTableColumns($table)
    {
        // If the DBSCHEMA is not set, try using the database name if provided with the table.
        if (! $this->params['DBSCHEMA']) {
            preg_match('/(.*)\./', $table, $db);

            if (isset($db[1])) {
                $this->params['DBSCHEMA'] = $db[1];
            }
        }

        // Parse out the table name.
        $table = preg_replace('/(.*\.)/', '', $table);
        $table = trim($table, '`');

        // Statement to extract all required columns for a table.
        $sqlStatement = "
            SELECT 
                column_name, data_type 
            FROM 
                information_schema.columns 
            WHERE 
                is_nullable = 'NO'
            AND 
                table_name = '%s'
            AND 
                table_schema = '%s';";

        // Get not null columns
        $sql = sprintf(
            $sqlStatement,
            $table,
            $this->params['DBSCHEMA']
        );

        $statement = $this->execute($sql);
        $this->throwExceptionIfErrors($statement);
        $result = $statement->fetchAll();

        if (! $result) {
            return [];
        }

        $cols = [];
        foreach ($result as $column) {
            $cols[$column['column_name']] = $column['data_type'];
        }

        // Dont populate primary key, let db handle that
        unset($cols['id']);

        return $cols;
    }
protected function requiredTableColumns($table)
    {
        // If the DBSCHEMA is not set, try using the database name if provided with the table.
        if (! $this->params['DBSCHEMA']) {
            preg_match('/(.*)\./', $table, $db);

            if (isset($db[1])) {
                $this->params['DBSCHEMA'] = $db[1];
            }
        }

        // Parse out the table name.
        $table = preg_replace('/(.*\.)/', '', $table);
        $table = trim($table, '`');

        // Statement to extract all required columns for a table.
        $sqlStatement = "
            SELECT 
                column_name, data_type 
            FROM 
                information_schema.columns 
            WHERE 
                is_nullable = 'NO'
            AND 
                table_name = '%s'
            AND 
                table_schema = '%s';";

        // Get not null columns
        $sql = sprintf(
            $sqlStatement,
            $table,
            $this->params['DBSCHEMA']
        );

        $statement = $this->execute($sql);
        $this->throwExceptionIfErrors($statement);
        $result = $statement->fetchAll();

        if (! $result) {
            return [];
        }

        $cols = [];
        foreach ($result as $column) {
            $cols[$column['column_name']] = $column['data_type'];
        }

        // Dont populate primary key, let db handle that
        unset($cols['id']);

        return $cols;
    }
protected function requiredTableColumns ( $ table ) { // If the DBSCHEMA is not set, try using the database name if provided with the table. if ( ! $ this -> params [ 'DBSCHEMA' ] ) { preg_match ( '/(.*)\./' , $ table , $ db ) ; if ( isset ( $ db [ 1 ] ) ) { $ this -> params [ 'DBSCHEMA' ] = $ db [ 1 ] ; } } // Parse out the table name. $ table = preg_replace ( '/(.*\.)/' , '' , $ table ) ; $ table = trim ( $ table , '`' ) ; // Statement to extract all required columns for a table. $ sqlStatement = "
            SELECT 
                column_name, data_type 
            FROM 
                information_schema.columns 
            WHERE 
                is_nullable = 'NO'
            AND 
                table_name = '%s'
            AND 
                table_schema = '%s';" ; // Get not null columns $ sql = sprintf ( $ sqlStatement , $ table , $ this -> params [ 'DBSCHEMA' ] ) ; $ statement = $ this -> execute ( $ sql ) ; $ this -> throwExceptionIfErrors ( $ statement ) ; $ result = $ statement -> fetchAll ( ) ; if ( ! $ result ) { return [ ] ; } $ cols = [ ] ; foreach ( $ result as $ column ) { $ cols [ $ column [ 'column_name' ] ] = $ column [ 'data_type' ] ; } // Dont populate primary key, let db handle that unset ( $ cols [ 'id' ] ) ; return $ cols ; }
Gets a column list for a table with their type.
Gets a column list for a table with their type .