XF 2.1 Does each finder->pluckForm make individual query?

abdfahim

Well-known member
I would like to get numeric arrays for each column of my database table. So, I am doing the following

PHP:
$date_q =  '2018-01-01';
$finder = $this->finder('Fahim:MyEntity');
$finder->where('date', '>', $date_q);

$colA = array_values($finder->pluckFrom('colA')->fetch()->toArray());
$colB = array_values($finder->pluckFrom('colB')->fetch()->toArray());
$colC = array_values($finder->pluckFrom('colC')->fetch()->toArray());

It works, but I have three questions:
1) Does each of the 3 pluckFrom lines generate separate SQL query?
2) Is there a better way of doing this?
3) I assume $finder takes care of SQL injection risk if $date_q is a user input. Am I correct? Or do I need to take preventive measure myself?

Also, wondering if it's okay to declare date field (in the database, stored as YYYY-MM-DD) as self::STR in my Entity

PHP:
public static function getStructure(Structure $structure)
    {
        $structure->table = 'xf_fahim_whatever';
        $structure->shortName = 'Fahim:MyEntity';
        $structure->primaryKey = 'id';
        $structure->columns = [
            'id' => ['type' => self::UINT, 'autoIncrement' => true, 'nullable' => true],
            'date' => ['type' => self::STR, 'required' => true],
            'colA' => ['type' => self::UINT, 'required' => true],
            'colB' => ['type' => self::STR, 'required' => true],
            'colC' => ['type' => self::UINT, 'required' => true]
        ];
        $structure->getters = [];
        return $structure;
    }


Thanks,
 
Last edited:
Top Bottom