我有一个帮助程序,它通过将...
axios.post('http://localhost:5000/users/register', body , config )
.then(res => dispatch({
type : ActionType.REGISTER_SUCCESS,
payload : res.data
}))
...
替换为文字参数来返回分页的SQL查询:
{}
因此最终的SQL可能如下所示:
WITH CTE AS
(
SELECT {InnerFields}, ROW_NUMBER() OVER (ORDER BY {OrderBy}) AS _RowNumber_
FROM {SourceTable}
WHERE {Filter}
)
SELECT {OuterFields}, (SELECT COUNT(*) FROM CTE) AS ID
FROM CTE
WHERE _RowNumber_ BETWEEN {From} AND {To}
然后将查询传递给Dapper,并包装其参数
WITH CTE AS
(
SELECT OrderId, Date, Amount, ROW_NUMBER() OVER (ORDER BY OrderId) AS _RowNumber_
FROM Orders
WHERE VID=@VID AND Date BETWEEN @From AND @To
)
SELECT OrderId, Date, Amount, (SELECT COUNT(*) FROM CTE) AS ID
FROM CTE
WHERE _RowNumber_ BETWEEN 1 AND 20
:
Dictionary<string, object>
这在本地和生产服务器上都可以正常工作。但是在生产中,当数据窗口是new Dictionary<string, object>
{
["VID"] = 123,
["From"] = "2019-01-01T00:00:00",
["To"] = "2019-07-01T00:00:00"
}
而不是_RowNumber_ BETWEEN 101 AND 120
或121 AND 140
时,我遇到了一个奇怪的错误101 AND 110
。谁能指出我为什么对范围如此挑剔?
更新:
SQL Server Profiler指示成功的查询会触发包含Must declare the scalar variable "@VID"
和所有参数的RPC:Completed
事件,而错误的查询会导致sp_executesql
和SQL:BatchStarting
事件,而没有参数。除了范围值,查询本身是相同的。