来自Codeigniter

时间:2018-05-07 11:53:24

标签: sql-server codeigniter codeigniter-2 codeigniter-3

如何防止单个请求多次执行存储过程?

$from_statecode = 'TN'; 
$this->db->query("Declare @CurrentInvoiceNo int 
                             Execute spSetInvoiceNoStatewise '$from_statecode', @CurrentInvoiceNo output
                             select @CurrentInvoiceNo");

存储过程:spSetInvoiceNoStatewise,如下: -

CREATE Procedure [dbo].[spSetInvoiceNoStatewise]
@StateCode nvarchar(20),
@InvoiceNo int = 0 output
AS
Begin
select @InvoiceNo=invoice_no from statewise_invoice_no where invoice_state_code=@StateCode

if(@InvoiceNo is not NULL) 
        UPDATE statewise_invoice_no set invoice_no = @InvoiceNo + 1 where invoice_state_code = @StateCode

if(@InvoiceNo is NULL) 
        insert into statewise_invoice_no (invoice_state_code,invoice_no) values (@StateCode, 1);

select @InvoiceNo=invoice_no from statewise_invoice_no where invoice_state_code=@StateCode

End

存储过程有什么问题吗? 或者可以做些什么来阻止单个请求的多次执行?

我已经阅读了一些建议" 锁定资源或交易的文章"

0 个答案:

没有答案