CodeIgniter Forums
BaseBuilder::testMode() instead getCompiled....() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: BaseBuilder::testMode() instead getCompiled....() (/showthread.php?tid=82565)



BaseBuilder::testMode() instead getCompiled....() - iRedds - 07-24-2022

Hi all.
It seems to me that it would be more convenient to have unified SQL code generation if the place of the getComplied(Select/Update/etc) methods is to use the testMode() method.

Currently, depending on the method (update/delete/etc), using testMode() returns SQL code or true. Which, in my opinion, causes a light butthurt due to the ambiguity of behavior.

The BaseBuilder::testMode() method, for example, could affect the BaseConnection class and, depending on the passed value, the SQL code is returned or executed.

PHP Code:
$db->table('table')->update(...); // normal behavior
$db->table('table')->testMode()->update(...); // return sql 

$db->table('table')->insertBatch(...); // normal behavior
$db->table('table')->testMode()->insertBatch(...); // return sql 

$db->query(...); // normal behavior
$db->testMode()->query(...); // return sql 



RE: BaseBuilder::testMode() instead getCompiled....() - kenjis - 07-25-2022

I am not a fan of methods that change behavior,
but in this case, the proposed APIs seem more consistent and better.


RE: BaseBuilder::testMode() instead getCompiled....() - MGatner - 07-28-2022

What about a wrapping class that works sort of like ReflectionClass and can be used with any Connection to extract various debug info, like resultant SQL?