<?php
require __DIR__.'/common.php';if(is_file(__DIR__.'/private/before.json'))throw new RuntimeException('No lease replay');$s=$source();$old=json_decode(file_get_contents(__DIR__.'/expected-plain-final-'.$lane.'.json'),true)['source'];foreach(['nutrition','nutrition_template','nutrition_set','nutrition_category','nutrition_time','nutrition_template_ext','actor']as $k)if($s[$k]!==$old[$k])throw new RuntimeException('Full11/actor drift '.$k);if($s['config_hash']!==['count'=>count($old['config']),'sha256'=>hash('sha256',json_encode($old['config'],JSON_PRESERVE_ZERO_FRACTION))])throw new RuntimeException('Exact clock hash drift');
$p=null;$t=null;foreach($s['nutrition']as $r)if($r['uuid']===$productUuid)$p=$r;foreach($s['nutrition_template']as $r)if($r['uuid']===$templateUuid)$t=$r;if(!$p||!$t||count($s['nutrition'])!==2||count($s['nutrition_template'])!==2||count($s['nutrition_template_ext'])!==2)throw new RuntimeException('Exact11 fixture');foreach(['img_path','source_img_path','app_img']as $f)if($p[$f]!=='')throw new RuntimeException('Nonempty media prohibited');$ownbits=null;foreach($s['nutrition_native']as $n)if($n['uuid']===$productUuid)$ownbits=$n['fields'];if($ownbits['use_weight_computed']['bits64']!=='000000403cdd5e40')throw new RuntimeException('Must use finalized123.4568 physical bits');
$dict=$q('SELECT COUNT(*) AS n FROM ydy_nutrition_time WHERE del_flag=?',[0]);if($dict[0]['n']>200)throw new RuntimeException('Time dictionary cap');
$tables=['ydy_config','ydy_user','ydy_nutrition','ydy_nutrition_set','ydy_nutrition_category','ydy_nutrition_time','ydy_nutrition_template','ydy_nutrition_template_ext'];$names=$lane==='B'?$tables:array_map('strtoupper',$tables);$marks=implode(',',array_fill(0,8,'?'));
$columns=$lane==='B'?$q('SELECT TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,EXTRA FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('.$marks.') ORDER BY TABLE_NAME,ORDINAL_POSITION',$names):$q('SELECT TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH,DATA_PRECISION,DATA_SCALE,NULLABLE,DATA_DEFAULT FROM USER_TAB_COLUMNS WHERE TABLE_NAME IN ('.$marks.') ORDER BY TABLE_NAME,COLUMN_ID',$names);
$constraints=$lane==='B'?$q('SELECT TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('.$marks.') ORDER BY TABLE_NAME,CONSTRAINT_NAME',$names):$q('SELECT TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,SEARCH_CONDITION FROM USER_CONSTRAINTS WHERE TABLE_NAME IN ('.$marks.') ORDER BY TABLE_NAME,CONSTRAINT_NAME',$names);
$triggers=$lane==='B'?$q('SELECT EVENT_OBJECT_TABLE,TRIGGER_NAME,ACTION_TIMING,EVENT_MANIPULATION,ACTION_STATEMENT FROM information_schema.TRIGGERS WHERE EVENT_OBJECT_SCHEMA=DATABASE() AND EVENT_OBJECT_TABLE IN ('.$marks.') ORDER BY EVENT_OBJECT_TABLE,TRIGGER_NAME',$names):$q('SELECT * FROM USER_TRIGGERS WHERE TABLE_NAME IN ('.$marks.') ORDER BY TABLE_NAME,TRIGGER_NAME',$names);
$join=$q('SELECT COUNT(*) AS n FROM ydy_nutrition a JOIN ydy_nutrition_set b ON a.set_uuid=b.uuid JOIN ydy_nutrition_category c ON a.nutrition_category_uuid=c.uuid WHERE a.uuid=?',[$productUuid]);if($join[0]['n']!==1)throw new RuntimeException('Unique own join');$identity=$lane==='B'?$q('SELECT VERSION() AS version,DATABASE() AS db,@@character_set_connection AS charset'):$q("SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS db FROM DUAL");$events=$GLOBALS['NR_ORACLE'];if(count($events)>18)throw new RuntimeException('Preflight SELECT budget');$save('before.json',$s);$save('lease-oracle.json',$events);$save('metadata.json',['columns'=>$columns,'constraints'=>$constraints,'triggers'=>$triggers,'time_dictionary_count'=>$dict,'identity'=>$identity]);$save('lease.json',['SELECT'=>count($events),'own_rows'=>11,'HTTP'=>0,'DML'=>0,'media_empty'=>true,'final_plain_bits'=>'000000403cdd5e40']);echo json_encode(['lane'=>$lane,'SELECT'=>count($events),'own_rows'=>11,'HTTP'=>0,'DML'=>0]),"\n";
