CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

Database tab in debug toolbar is not working when we use binary Uuid in queries.

Open atifriazmughal opened this issue 4 years ago • 2 comments

PHP Version

7.4

CodeIgniter4 Version

4.1.5

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

I have id fields type binary(16) in my all tables. To storing uuid i am using https://github.com/michalsn/codeigniter4-uuid package.

The issue I noticed is database tab in debug toolbar is not show when $query->debugToolbarDisplay(); return binary string in Display method of CodeIgniter\Debug\Toolbar\Collectors\Database.

I fixed it in my repo according to uuid package. OLD

public function display(): array
	{
		$data['queries'] = array_map(function (Query $query) {
			return [
				'duration' => ((float) $query->getDuration(5) * 1000) . ' ms',
				'sql'      => $query->debugToolbarDisplay(),
			];
		}, static::$queries);

		return $data;
	}

Changed

public function display(): array
    {
        
        $data['queries'] = array_map(static function (Query $query) {
            $uuidService=service('uuid');
            $FInalSQL=$query->debugToolbarDisplay();
            
            //geting single quoted values
            preg_match_all('/".*?"|\'.*?\'/', $FInalSQL, $matches);
            $replaceAble=[];
            
            foreach ($matches as $quoted) {
            
                if(!empty($quoted)){
                    foreach ($quoted as $Qvalue) {
                        $binstr=str_replace("'","",$Qvalue);
                        ///if values are binary then convert into uuid string
                        if(!ctype_print($binstr) && strlen($binstr)==16){
                            $replaceAble[]=['bin'=>$binstr,'str'=>$uuidService->fromBytes($binstr)->toString()];
                        }
                    }
                }
                
            }
            // replace binary values with uuid string
            
            foreach ($replaceAble as $value) {
                $FInalSQL=str_replace($value['bin'],'<b>'.$value['str'].'</b>',$FInalSQL);
            }
            
            return [
                'duration' => ((float) $query->getDuration(5) * 1000) . ' ms',
                'sql'      => $FInalSQL,
            ];
        }, static::$queries);
        
        return $data;
    }

Steps to Reproduce

  1. add column as binary(16) in any table
  2. insert uuid as binary string manually or by any uuid package
  3. see database queries list in debug toolbar

Expected Output

codeigniter should display debug toolbar even there is binary string.

Anything else?

No response

atifriazmughal avatar Dec 13 '21 10:12 atifriazmughal

I got: Screenshot 2021-12-15 11 41 20

6.86 ms | INSERT INTO `bin` (`text`, `bin`) VALUES ('test', '')
$model->insert(['text' => 'test', 'bin' => hex2bin('0102')]);

kenjis avatar Dec 15 '21 02:12 kenjis

@atifriazmughal

codeigniter should display debug toolbar even there is binary string.

I think CI4 displays binary string as it is in debug toolbar. But we can't see it...

kenjis avatar Dec 15 '21 02:12 kenjis