<?php
require __DIR__.'/NativeGate.php';$GLOBALS['NF_PLAN']=json_decode(file_get_contents(__DIR__.'/plan.json'),true);$n=0;$bad=0;
$ctx=static function(){NFGate::$case=['label'=>'p-update'];NFGate::$phase='original';NFGate::$own=['product_uuid'=>'AAAAAAAA-1111-2222-3333-444444444444','template_uuid'=>'BBBBBBBB-1111-2222-3333-444444444444'];NFGate::$dml=0;};
$bind=static function($v){return ['value'=>$v,'type'=>PDO::PARAM_STR,'php_type'=>gettype($v)];};
$test=static function($f,$reject=false)use(&$n,&$bad,$ctx){$ctx();$thrown=false;try{$f();}catch(Throwable $e){$thrown=true;}++$n;if($thrown!==$reject){++$bad;echo 'failed '.$n."\n";}};
$test(static function()use($bind){NFGate::binds('UPDATE `ydy_nutrition` SET `power`=:p WHERE `uuid` = :u',['p'=>$bind('12.345'),'u'=>$bind(NFGate::$own['product_uuid'])]);});
$test(static function()use($bind){NFGate::binds('UPDATE "ydy_nutrition_template" SET "power"=CAST(12.340000152587891 AS REAL) WHERE "uuid" = :u',['u'=>$bind(NFGate::$own['template_uuid'])]);});
$test(static function()use($bind){NFGate::binds('DELETE FROM ydy_nutrition_template_ext WHERE template_uuid = :u',['u'=>$bind(NFGate::$own['template_uuid'])]);});
$test(static function()use($bind){NFGate::binds('UPDATE ydy_nutrition SET power=:p WHERE uuid = :u',['p'=>$bind('12.345'),'u'=>$bind('natural')]);},true);
$test(static function()use($bind){NFGate::binds('UPDATE ydy_nutrition SET power=:p WHERE uuid = :u OR 1=1',['p'=>$bind('12.345'),'u'=>$bind(NFGate::$own['product_uuid'])]);},true);
$test(static function()use($bind){NFGate::$case=['label'=>'p-update-info'];NFGate::binds('UPDATE ydy_nutrition SET power=:p WHERE uuid = :u',['p'=>$bind('12.345'),'u'=>$bind(NFGate::$own['product_uuid'])]);},true);
$test(static function(){NFGate::sql('DELETE FROM ydy_user WHERE id = :u');},true);
$test(static function(){NFGate::sql('UPDATE ydy_nutrition_time SET name = :n WHERE uuid = :u');},true);
$test(static function(){NFGate::sql('ALTER TABLE ydy_nutrition MODIFY power REAL');},true);
$test(static function(){NFGate::sql('SELECT * FROM natural_other');},true);
$test(static function(){NFGate::sql('SELECT * FROM ydy_nutrition; DROP TABLE ydy_nutrition');},true);
$test(static function()use($bind){NFGate::binds('INSERT INTO ydy_nutrition (uuid,name) VALUES (:u,:n)',['u'=>$bind('AAAAAAAA-1111-2222-3333-444444444444'),'n'=>$bind('natural product')]);},true);
$test(static function()use($bind){NFGate::binds('INSERT INTO ydy_nutrition (uuid,name) VALUES (:u,:n)',['u'=>$bind('AAAAAAAA-1111-2222-3333-444444444444'),'n'=>$bind('CDXNF11F5-original-product')]);});
$test(static function()use($bind){NFGate::binds('UPDATE ydy_nutrition_category SET number=:n WHERE uuid = :u',['n'=>$bind(2),'u'=>$bind('CF11F500-0004-4000-8000-202610110004')]);});
echo json_encode(['tests'=>$n,'failures'=>$bad,'SQL'=>0,'HTTP'=>0]),"\n";exit($bad?2:0);
