<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';$f=json_decode(file_get_contents($runtime.'/fixture-journal.json'),true);$id=$f['owned']['store'];$out=['lane'=>$lane,'business_dml'=>0,'scope'=>'same-tenant synthetic rows and readonly numeric literals','metadata'=>[],'cases'=>[]];$s=$db->prepare('SELECT SUM(total_pay_price) money_sum,SUM(total_num) num_sum FROM yoshop_order_goods WHERE store_id=2147001111 AND order_id=? AND goods_id=?');$s->execute([$id['stat_order'],$id['goods']]);foreach([0,1] as $i){$warnings=[];set_error_handler(static function($n,$m)use(&$warnings){$warnings[]=$m;return true;});try{$out['metadata'][$i]=['column'=>$s->getColumnMeta($i),'warnings'=>$warnings];}catch(Throwable $e){$out['metadata'][$i]=['unavailable'=>get_class($e),'warnings'=>$warnings];}finally{restore_error_handler();}}$out['actual_aggregate']=$s->fetchAll(PDO::FETCH_ASSOC);
$format='FM'.str_repeat('9',37).'0.00';$out['DM_money_format']=$format;$values=['0.00','-0.00','0.01','-0.01','2.00','10.00','12.34','-12.34','9007199254740993.01','-9007199254740993.01','999999999999999999999999999999999999.99','-999999999999999999999999999999999999.99'];
if($dm){foreach($values as $v){$r=$read("SELECT TO_CHAR(CAST('".$v."' AS DECIMAL(38,2)),'".$format."') money_text,CAST(CAST('9007199254740993' AS DECIMAL(38,0)) AS VARCHAR(40)) count_text FROM DUAL");$expected=$v==='-0.00'?'0.00':$v;$check($r[0]['money_text']===$expected,'Exact TO_CHAR all precision '.$v);$check($r[0]['count_text']==='9007199254740993','Count >2^53 exact string');$out['cases'][]=['literal'=>$v,'expected'=>$expected,'actual'=>$r[0],'passed'=>true];}$out['actual_own_text_aggregate']=$read("SELECT TO_CHAR(SUM(total_pay_price),'".$format."') money_text,CAST(SUM(total_num) AS VARCHAR(40)) count_text FROM yoshop_order_goods WHERE store_id=2147001111 AND order_id=? AND goods_id=?",[$id['stat_order'],$id['goods']]);$check($out['actual_own_text_aggregate'][0]===['count_text'=>'1','money_text'=>'0.00'],'Own output exact MySQL strings');$out['numeric_sort_proof']=$read("SELECT val FROM (SELECT CAST('2.00' AS DECIMAL(38,2)) val FROM DUAL UNION ALL SELECT CAST('10.00' AS DECIMAL(38,2)) val FROM DUAL) ORDER BY val DESC");$check((float)$out['numeric_sort_proof'][0]['val']===10.0,'Numeric10-before2');}
$check($own()===$f['after'],'All23 source rows unchanged');file_put_contents(__DIR__.'/aggregate-text-diagnostic-'.$lane.'.json',json_encode($out,JSON_PRETTY_PRINT|JSON_PRESERVE_ZERO_FRACTION|JSON_UNESCAPED_SLASHES));echo json_encode($out,JSON_PRESERVE_ZERO_FRACTION),"\n";
