Browse Source

Fix for #3928 - error invalid use of FETCH was based on a lack of sorting on MS-SQL platforms, this enforces a sort of some type no matter what.

pull/4328/head
mike12345567 4 years ago
parent
commit
b9de2c1897
  1. 2
      packages/server/scripts/integrations/mssql/data/Dockerfile
  2. 21
      packages/server/scripts/integrations/mssql/data/setup.sql
  3. 14
      packages/server/src/integrations/base/sql.ts

2
packages/server/scripts/integrations/mssql/data/Dockerfile

@ -1,4 +1,4 @@
FROM mcr.microsoft.com/mssql/server
FROM mcr.microsoft.com/mssql/server:2017-latest
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Passw0rd

21
packages/server/scripts/integrations/mssql/data/setup.sql

@ -48,7 +48,20 @@ INSERT tasks
VALUES
('Processing', 1);
INSERT people
(name, age)
VALUES
('Bob', '30');
INSERT INTO people (name, age)
VALUES ('Bob', '30'),
('Bert', '10'),
('Jack', '12'),
('Mike', '31'),
('Dave', '44'),
('Jim', '43'),
('Kerry', '32'),
('Julie', '12'),
('Kim', '55'),
('Andy', '33'),
('John', '22'),
('Ruth', '66'),
('Robert', '88'),
('Bobert', '99'),
('Jan', '22'),
('Megan', '11');

14
packages/server/src/integrations/base/sql.ts

@ -166,15 +166,13 @@ class InternalBuilder {
addSorting(query: KnexQuery, json: QueryJson): KnexQuery {
let { sort, paginate } = json
if (!sort) {
return query
}
const table = json.meta?.table
for (let [key, value] of Object.entries(sort)) {
const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
query = query.orderBy(`${table?.name}.${key}`, direction)
}
if (this.client === SqlClients.MS_SQL && !sort && paginate?.limit) {
if (sort) {
for (let [key, value] of Object.entries(sort)) {
const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
query = query.orderBy(`${table?.name}.${key}`, direction)
}
} else if (this.client === SqlClients.MS_SQL && paginate?.limit) {
// @ts-ignore
query = query.orderBy(`${table?.name}.${table?.primary[0]}`)
}

Loading…
Cancel
Save