问题描述
在 pgAdmin 中创建此触发器时出错
$capital_idr = urlencode ($_GET["capital_idr"]);
$buyBot = urlencode ($_GET["buyBot"]);
$botUse = urlencode ($_GET["botUse"]);
$botPrice = urlencode ($_GET["botPrice"]);
$botProfit = urlencode ($_GET["botProfit"]);
$capital = urlencode ($_GET["capital"]);
$avg = urlencode ($_GET["avg"]);
$startdate = urlencode ($_GET["startdate"]);
$month = urlencode ($_GET["month"]);
$wdOption = urlencode ($_GET["wdOption"]);
$fields = array(
'capital_idr' => $capital_idr,'buyBot' => $buyBot,'botUse' => $botUse,'botPrice' => $botPrice,'botProfit' => $botProfit,'capital' => $capital,'avg' => $avg,'startdate' => $startdate,'month' => $month,'wdOption' => $wdOption,);
//url-ify the data for the POST
$fields_string = '';
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
$url = 'https://www.xxxx.com/index.PHP/Trading/simulation';
$referer = 'https://www.xxxx.com/';
$agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML,like Gecko)
// Create a new cURL resource
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_VERBOSE,1);
curl_setopt($ch,CURLOPT_REFERER,$referer );
curl_setopt($ch,CURLOPT_USERAGENT,$agent);
// Execute the POST request
$result = curl_exec($ch);
// Close cURL resource
curl_close($ch);
echo $result;
当我按下保存按钮时,此消息出现
解决方法
除了前面提到的缺少语句终止符 (;) 之外,您的脚本有一个致命错误,插入语句将失败。为什么?由于您没有列出要插入的列名称,因此值必须包括每列包括 id,并且它们必须按定义的顺序排列。除非您指定要插入的列(或在适当位置使用 default 关键字),否则您不能拥有自动递增列并且不指定其值。所以你需要
insert into users(email,password) values('arsa','1234');
insert into users values(default,'abc','def');
您的函数的目的似乎不是执行名称所暗示的登录,而是验证凭据。在这种情况下,您可以将其缩减为单个 SQL 语句。没有计数,没有计数检查,只有一个选择(是的,有子选择):
create or replace
function is_valid_user(_email character varying,_password character varying
)
returns boolean
language sql
as $$
select exists (select null
from users
where email = _email
and password = _password
);
$$;
见demo。
如果您确实需要触发器,则表本身还需要一个 trigger function 和一个 trigger