<?php
declare(strict_types=1);require __DIR__.'/native.php';require $root.'/vendor/autoload.php';spl_autoload_register(static function($class)use($root){if(strpos($class,'app\\')===0){$f=$root.'/app/'.str_replace('\\','/',substr($class,4)).'.php';if(is_file($f))require $f;}},true,true);require __DIR__.'/NativePdo.php';
$fixture=json_decode(file_get_contents($runtime.'/exact-SQL-bind-plan.json'),true);CoreGate::$ids=$fixture['ids'];CoreGate::$scenario='DIRECT_002';CoreGate::$started=time();$checks=0;$negative=0;$plans=$fixture['entries'];
foreach($plans as $i=>&$p){foreach($p['bind_plan'] as &$b){if(is_string($b[0])&&preg_match('/^2026-10-11 \d{2}:\d{2}:\d{2}(\.\d{6})?$/D',$b[0]))$b[0]=strpos($b[0],'.')!==false?(new DateTimeImmutable())->format('Y-m-d H:i:s.u'):date('Y-m-d H:i:s');elseif(is_int($b[0])&&$b[0]>1700000000&&$b[0]<2000000000)$b[0]=time();}unset($b);}
unset($p);$generated=[];foreach($plans as $p){$s=preg_replace('/[`"]([a-zA-Z_][a-zA-Z0-9_]*)[`"]/','$1',$p['queryString']);if(preg_match('/UPDATE ydy_meal_order/',$s)){preg_match('/account_settlement_id\s*=\s*:(\w+)/',$s,$m);$generated['yoshop_account_settlement']=$p['bind_plan'][$m[1]][0];preg_match('/WHERE\s+id\s*=\s*:(\w+)/',$s,$m);$generated['ydy_meal_order']=$p['bind_plan'][$m[1]][0];}}CoreGate::$generated=$generated;
$reject=static function($db,$sql,$bind)use(&$checks,&$negative){try{CoreGate::plan($db,$sql,$bind);throw new LogicException('Corrupt DML accepted');}catch(RuntimeException $e){$checks++;$negative++;}};
foreach($plans as $p){CoreGate::plan($p['connection'],$p['queryString'],$p['bind_plan']);$checks++;foreach($p['bind_plan'] as $key=>$pair){$b=$p['bind_plan'];$b[$key][0]=is_int($pair[0])?987654321:is_float($pair[0])?9.98:'WRONG';$reject($p['connection'],$p['queryString'],$b);$b=$p['bind_plan'];$b[$key][1]=$pair[1]===1?2:1;$reject($p['connection'],$p['queryString'],$b);}
 $reject($p['connection'],$p['queryString'].' AND 1=1',$p['bind_plan']);$reject($p['connection'],$p['queryString'].'; DELETE FROM yoshop_user',$p['bind_plan']);}
foreach(['DELETE FROM ydy_meal_order WHERE id=1','CREATE TABLE x(id int)','SELECT * FROM ydy_equipment','CALL SP_TABLEDEF(?, ?)'] as $s)$reject('ZHCT',$s,[]);
CoreGate::$scenario='GUARD_002';$reject($plans[0]['connection'],$plans[0]['queryString'],$plans[0]['bind_plan']);
echo json_encode(['checks'=>$checks,'counterexamples'=>$negative,'SQL'=>0,'HTTP'=>0,'original_SQL_whitespace_preserved'=>true,'qualified_tenant_PDO2_PHPint'=>true,'FLOAT21_native2_conversion_kept'=>true]),"\n";
