我是按照api和参考sdk自己写的token生成和发送请求函数。返回错误码 -5999,ERR_CGI_PARAM,包体错误。明明完全按照文档格式发送的请求。以简单上传为例:请求头中,设置Authorization为后端返回的token。请求体为FormData,添加了op和filecontent。控制台中设置了跨域(Access-Control-Allow-Origin: *,方法都勾选了),其他没有设置。但是每次请求都是400错误。而且是第一次发送option请求时就返回400了。不知道哪里出错了,是控制台中跨域相关的没有设置好吗?另外我用的fetch api,也该和它没什么关系吧?求助啊~~
一个很好的方法,但是如果你授予代表权,那么它应该是第一个接受它的人。唯一的问题是插入它仍然是两个IO操作。
MS Sql2008 merge从SQL:2003标准介绍:
merge tablename with(HOLDLOCK) as target
using (values ('new value', 'different value'))
as source (field1, field2)
on target.idfield = 7
when matched then
update
set field1 = source.field1,
field2 = source.field2,
...
when not matched then
insert ( idfield, field1, field2, ... )
values ( 7, source.field1, source.field2, ... )
现在它只是一个IO操作,但是可怕的代码:-(
不要忘记交易。性能是好的,但简单(IF EXISTS ..)方法是非常危险的。
当多个线程将尝试执行插入或更新时,您可以轻松地获得主键违例。
@Beau Crawford&@Esteban提供的解决方案显示了一般想法,但容易出错。
为了避免死锁和PK违规,你可以使用这样的东西:
begin tran
if exists (select * from table with (updlock,serializable) where key = @key)
begin
update table set ...
where key = @key
end
else
begin
insert into table (key, ...)
values (@key, ...)
end
commit tran
要么
begin tran
update table with (serializable) set ...
where key = @key
if @@rowcount = 0
begin
insert into table (key, ...) values (@key,..)
end
commit tran
相似问题