<commit_before><?php
/**
 * Give access to qgis mapLayer configuration.
 *
 * @author    3liz
 * @copyright 2013 3liz
 *
 * @see      http://3liz.com
 *
 * @license Mozilla Public License : http://www.mozilla.org/MPL/
 */
class qgisVectorLayer extends qgisMapLayer
{
    // layer type
    protected $type = 'vector';

    protected $fields = array();

    protected $aliases = array();

    protected $wfsFields = array();

    /**
     * @var null|object connection parameters
     */
    protected $dtParams;

    /**
     * @var null|jDbConnection
     */
    protected $connection;

    /** @var jDbFieldProperties[] */
    protected $dbFieldList;
    protected $dbFieldsInfo;

    // Map data type as geometry type
    private $geometryDatatypeMap = array(
        'point', 'linestring', 'polygon', 'multipoint',
        'multilinestring', 'multipolygon', 'geometrycollection', 'geometry',
    );

    /**
     * constructor.
     *
     * @param lizmapProject|qgisProject $project
     * @param array                     $propLayer list of properties values
     */
    public function __construct($project, $propLayer)
    {
        parent::__construct($project, $propLayer);
        $this->fields = $propLayer['fields'];
        $this->aliases = $propLayer['aliases'];
        $this->wfsFields = $propLayer['wfsFields'];
    }

    public function getFields()
    {
        return $this->fields;
    }

    public function getAliasFields()
    {
        return $this->aliases;
    }

    public function getWfsFields()
    {
        return $this->wfsFields;
    }

    /**
     * @return object
     */
    public function getDatasourceParameters()
    {
        if ($this->dtParams) {
            return $this->dtParams;
        }

        // Get datasource information from QGIS
        $datasourceMatch = preg_match(
            "#(?:dbname='([^ ]+)' )?(?:service='([^ ]+)' )?(?:host=([^ ]+) )?(?:port=([0-9]+) )?(?:user='([^ ]+)' )?(?:password='([^ ]+)' )?(?:sslmode=([^ ]+) )?(?:key='([^ ]+)' )?(?:estimatedmetadata=([^ ]+) )?(?:selectatid=([^ ]+) )?(?:srid=([0-9]+) )?(?:type=([a-zA-Z]+) )?(?:table=\"([^ ]+)\" )?(?:\\()?(?:([^ ]+)\\) )?(?:sql=(.*))?#s",
            $this->datasource,
            $dt
        );

        if ($dt[13] == '') {
            // if table not found, try again for complex tables, such as table="(SELECT count(*) FROM table WHERE bla)"
            $datasourceMatch = preg_match(
                "#(?:dbname='([^ ]+)' )?(?:service='([^ ]+)' )?(?:host=([^ ]+) )?(?:port=([0-9]+) )?(?:user='([^ ]+)' )?(?:password='([^ ]+)' )?(?:sslmode=([^ ]+) )?(?:key='([^ ]+)' )?(?:estimatedmetadata=([^ ]+) )?(?:selectatid=([^ ]+) )?(?:srid=([0-9]+) )?(?:type=([a-zA-Z]+) )?(?:table=\"(.+)\" )?(?:\\()?(?:([^ ]+)\\) )?(?:sql=(.*))?#s",
                $this->datasource,
                $dt
            );
        }
        $ds = array(
            'dbname' => $dt[1],
            'service' => $dt[2],
            'host' => $dt[3],
            'port' => $dt[4],
            'user' => $dt[5],
            'password' => $dt[6],
            'sslmode' => $dt[7],
            'key' => $dt[8],
            'estimatedmetadata' => $dt[9],
            'selectatid' => $dt[10],
            'srid' => $dt[11],
            'type' => $dt[12],
            'table' => $dt[13],
            'geocol' => $dt[14],
            'sql' => $dt[15],
        );

        $table = $ds['table'];
        $tableAlone = $table;
        $schema = '';
        if (preg_match('#"."#', $table)) {
            $table = '"'.$table.'"';
            $exp = explode('.', str_replace('"', '', $table));
            $tableAlone = $exp[1];
            $schema = $exp[0];
        }
        // Handle subqueries
        if (substr($table, 0, 1) == '(' and substr($table, -1) == ')') {
            $table = $tableAlone = $table.' fooliz';
            // remove \" which escapes table and schema names in QGIS WML within subquery
            $table = str_replace('\"', '"', $table);
        }<commit_msg>[BUGFIX] qgisVectorLayer - Add checkPrimaryKeyUnicity property when parsing datasource (added in QGIS3)<commit_after><?php
/**
 * Give access to qgis mapLayer configuration.
 *
 * @author    3liz
 * @copyright 2013 3liz
 *
 * @see      http://3liz.com
 *
 * @license Mozilla Public License : http://www.mozilla.org/MPL/
 */
class qgisVectorLayer extends qgisMapLayer
{
    // layer type
    protected $type = 'vector';

    protected $fields = array();

    protected $aliases = array();

    protected $wfsFields = array();

    /**
     * @var null|object connection parameters
     */
    protected $dtParams;

    /**
     * @var null|jDbConnection
     */
    protected $connection;

    /** @var jDbFieldProperties[] */
    protected $dbFieldList;
    protected $dbFieldsInfo;

    // Map data type as geometry type
    private $geometryDatatypeMap = array(
        'point', 'linestring', 'polygon', 'multipoint',
        'multilinestring', 'multipolygon', 'geometrycollection', 'geometry',
    );

    /**
     * constructor.
     *
     * @param lizmapProject|qgisProject $project
     * @param array                     $propLayer list of properties values
     */
    public function __construct($project, $propLayer)
    {
        parent::__construct($project, $propLayer);
        $this->fields = $propLayer['fields'];
        $this->aliases = $propLayer['aliases'];
        $this->wfsFields = $propLayer['wfsFields'];
    }

    public function getFields()
    {
        return $this->fields;
    }

    public function getAliasFields()
    {
        return $this->aliases;
    }

    public function getWfsFields()
    {
        return $this->wfsFields;
    }

    /**
     * @return object
     */
    public function getDatasourceParameters()
    {
        if ($this->dtParams) {
            return $this->dtParams;
        }

        // Get datasource information from QGIS
        $datasourceMatch = preg_match(
            "#(?:dbname='([^ ]+)' )?(?:service='([^ ]+)' )?(?:host=([^ ]+) )?(?:port=([0-9]+) )?(?:user='([^ ]+)' )?(?:password='([^ ]+)' )?(?:sslmode=([^ ]+) )?(?:key='([^ ]+)' )?(?:estimatedmetadata=([^ ]+) )?(?:selectatid=([^ ]+) )?(?:srid=([0-9]+) )?(?:type=([a-zA-Z]+) )?(?:checkPrimaryKeyUnicity='([0-1]+)' )?(?:table=\"([^ ]+)\" )?(?:\\()?(?:([^ ]+)\\) )?(?:sql=(.*))?#s",
            $this->datasource,
            $dt
        );

        if (count($dt) < 14 or $dt[14] == '') {
            // if table not found, try again for complex tables, such as table="(SELECT count(*) FROM table WHERE bla)"
            $datasourceMatch = preg_match(
                "#(?:dbname='([^ ]+)' )?(?:service='([^ ]+)' )?(?:host=([^ ]+) )?(?:port=([0-9]+) )?(?:user='([^ ]+)' )?(?:password='([^ ]+)' )?(?:sslmode=([^ ]+) )?(?:key='([^ ]+)' )?(?:estimatedmetadata=([^ ]+) )?(?:selectatid=([^ ]+) )?(?:srid=([0-9]+) )?(?:type=([a-zA-Z]+) )?(?:checkPrimaryKeyUnicity='([0-1]+)' )?(?:table=\"(.+)\" )?(?:\\()?(?:([^ ]+)\\) )?(?:sql=(.*))?#s",
                $this->datasource,
                $dt
            );
        }
        $ds = array(
            'dbname' => $dt[1],
            'service' => $dt[2],
            'host' => $dt[3],
            'port' => $dt[4],
            'user' => $dt[5],
            'password' => $dt[6],
            'sslmode' => $dt[7],
            'key' => $dt[8],
            'estimatedmetadata' => $dt[9],
            'selectatid' => $dt[10],
            'srid' => $dt[11],
            'type' => $dt[12],
            'checkPrimaryKeyUnicity' => $dt[13],
            'table' => $dt[14],
            'geocol' => $dt[15],
            'sql' => $dt[16],
        );

        $table = $ds['table'];
        $tableAlone = $table;
        $schema = '';
        if (preg_match('#"."#', $table)) {
            $table = '"'.$table.'"';
            $exp = explode('.', str_replace('"', '', $table));
            $tableAlone = $exp[1];
            $schema = $exp[0];
        }
        // Handle subqueries
        if (substr($table, 0, 1) == '(' and substr($table, -1) == ')') {
            $table = $tableAlone = $table.' fooliz';
            // remove \" which escapes table and schema names in QGIS WML within subquery
            $table = str_replace('\"', '"', $table);
        }
{'fraction_non_alphanumeric': 0.23439785470502195, 'fraction_numerical': 0.011579717211116529, 'mean_word_length': 2.136467889908257, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 54, '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': '673535', 'n_tokens_mistral': 2801, 'n_tokens_neox': 2670, 'n_words': 527}