简体   繁体   English

由于 SQL Server 2019 Linux 中的错误,需要 node-mssql GET 请求中的解决方法两语句查询(DECLARE;SELECT)

[英]Workaround two-statement query (DECLARE; SELECT) in node-mssql GET request required due to bug in SQL Server 2019 Linux

Due to a bug in SQL Server 2019 Linux, a node-mssql GET query that should be one single statement:由于 SQL Server 2019 Linux 中的一个错误,一个 node-mssql GET 查询应该是一个单一的语句:

router.get('/getresult/:srid/:x/:y', function (req, res) {
    sql.connect(config, error => {
        new sql.Request()
            .input('srid', sql.Int, req.params.srid)
            .input('x', sql.Float, req.params.x)
            .input('y', sql.Float, req.params.y)
            .query('SELECT * from dbo.bTest(geometry::Point(@x,@y,@srid))', (error, result) => {
                         res.send(result.recordset);
                    })
            if (error) {
                console.error(`error: ${error.message}`);
            }
    })
});

Now needs to be two statements.现在需要两个语句。 The query that crashes SQL Server 2019 Linux is使 SQL Server 2019 Linux 崩溃的查询是

SELECT * from dbo.bTest(geometry::Point(@x,@y,@srid))

The test table-valued function is this:测试表值 function 是这样的:

create function dbo.bTest ( @p_geom geometry )
Returns @geometries TABLE
(
  id integer,
  geom geometry
)
as
begin
  declare @g geometry;
  set @g = @p_geom.STBuffer(0.5);      
  insert into @geometries values (1, @g);
return;
end;

Until there's a fix, the workaround I've found is to use two statements in the query:在修复之前,我发现的解决方法是在查询中使用两个语句:

DECLARE @wkt geometry = geometry::Point(@x,@y,@srid);
SELECT * FROM dbo.bTest(@wkt);

As you can see in the following dbfiddle, the two statement query does not crash SQL Server 2019 Linux when it is executed the second time, whereas the single statement query crashes SQL Server 2019 Linux on the second execution: As you can see in the following dbfiddle, the two statement query does not crash SQL Server 2019 Linux when it is executed the second time, whereas the single statement query crashes SQL Server 2019 Linux on the second execution:

https://dbfiddle.uk?rdbms=sqlserver_2019l&fiddle=4a7759a742f361fc075f35ae6fbdc186 https://dbfiddle.uk?rdbms=sqlserver_2019l&fiddle=4a7759a742f361fc075f35ae6fbdc186

So, is it possible in the node-mssql GET request to use two statements (DECLARE and SELECT) or will I need to put the query in a stored procedure?那么,是否可以在 node-mssql GET 请求中使用两个语句(DECLARE 和 SELECT),或者我需要将查询放在存储过程中吗? And if I put it in a stored procedure, can I use a node-mssql GET request to execute a stored procedure and get values back?如果我把它放在一个存储过程中,我可以使用 node-mssql GET 请求来执行一个存储过程并取回值吗? I'm getting back a result.recordset that can consist of one or more results.我正在返回一个 result.recordset,它可以包含一个或多个结果。

Should work fine.应该可以正常工作。 Clients don't really know if a batch contains multiple statements.客户并不真正知道批处理是否包含多个语句。 In the general case you may need to add SET NOCOUNT ON at the top of the batch to suppress sending row counts to the client for each statement.在一般情况下,您可能需要在批处理顶部添加SET NOCOUNT ON以禁止将每个语句的行数发送到客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM