Created
August 5, 2022 11:48
-
-
Save cs278/099e529e46df35ba023b5d237562a709 to your computer and use it in GitHub Desktop.
Generate mysql truth table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Process\Process; | |
require 'vendor/autoload.php'; | |
$comparisons = ['AND', 'OR']; | |
$expressions = ['NULL', '0', '1']; | |
$sql = []; | |
foreach ($comparisons as $comparison) { | |
foreach ($expressions as $x) { | |
foreach ($expressions as $y) { | |
$_sql = <<<'EOT' | |
SELECT '%1$s' x, '%2$s' op, '%3$s' y, (%1$s %2$s %3$s) result | |
EOT; | |
$sql[] = sprintf($_sql, $x, $comparison, $y); | |
} | |
} | |
} | |
$sql = implode(' UNION ALL ', $sql).';'; | |
$proc = new Process(['mysql', '--table', '-e', $sql]); | |
$proc->mustRun(); | |
echo $proc->getOutput(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment