Skip to content

Commit 361a8b3

Browse files
fix issue with bigger array query returning zero results
#343
1 parent 27c20a9 commit 361a8b3

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

Diff for: src/worker/executors/select/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,23 @@ export class Select extends BaseFetch {
150150
else {
151151
this.results = output;
152152
}
153+
return promiseResolve();
153154
};
154-
const executeWhere = (whereQuery) => {
155+
const executeWhere = (whereQuery): Promise<any> => {
155156
const select = new Select({
156157
from: this.query.from,
157158
where: whereQuery as any
158159
}, this.util);
159160
return select.execute().then(results => {
160161
this.results = results;
161-
onSuccess();
162+
return onSuccess();
162163
});
163164
};
164-
const processFirstQry = () => {
165+
const processFirstQry = (): Promise<any> => {
165166
let whereQueryToProcess = whereQuery.shift();
166167
const whereQueryOr = whereQueryToProcess[QUERY_OPTION.Or];
167168
if (whereQueryOr) {
168-
if (Array.isArray(whereQueryOr)) {
169+
if (isArray(whereQueryOr)) {
169170
operation = QUERY_OPTION.Or;
170171
return executeWhere(whereQueryOr);
171172
}

Diff for: src/worker/executors/select/join.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ class Join {
126126
whereQueryModified: whereQryParam
127127
}
128128
}
129-
const result = removeJoinColumn(whereQuery);
130-
const whereQryAfterJoin = result.whereQryAfterJoin;
131-
query.where = result.whereQueryModified;
132-
if (result.isWhereEmpty) {
129+
const removeJoinColumnResult = removeJoinColumn(whereQuery);
130+
const whereQryAfterJoin = removeJoinColumnResult.whereQryAfterJoin;
131+
query.where = removeJoinColumnResult.whereQueryModified;
132+
if (removeJoinColumnResult.isWhereEmpty) {
133133
delete query.where;
134134
}
135135
const joinQuery = this.joinQueryStack_[0];

Diff for: test/cases/select/select_complex.js

+71
Original file line numberDiff line numberDiff line change
@@ -530,4 +530,75 @@ describe('Test select complex case', function () {
530530
done(err);
531531
})
532532
});
533+
534+
it(`SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
535+
FROM Orders
536+
where orderId<1000000 && shipperId=2 and ((employeeId=4 and customerId=34) or (employeeId=4 and customerId=76)) order by orderid asc
537+
`, function (done) {
538+
con.select({
539+
from: "Orders",
540+
order: {
541+
by: 'customerId',
542+
type: 'asc' //supprted sort type is - asc,desc
543+
},
544+
where: [{
545+
orderId: {
546+
'<': 1000000
547+
}
548+
}, {
549+
shipperId: 2,
550+
},
551+
[{
552+
employeeId: 4,
553+
customerId: 34,
554+
}, {
555+
or: {
556+
employeeId: 4,
557+
customerId: 76
558+
}
559+
}],
560+
]
561+
}).then(function (results) {
562+
expect(results).to.be.an('array').length(3);
563+
const expectedIds = results.map(result => result.orderId);
564+
expect(expectedIds).eql([10250, 10252, 10302])
565+
done();
566+
}).catch(done)
567+
});
568+
569+
it(`SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
570+
FROM Orders
571+
where shipperId=2 and ((employeeId=4 and customerId=34) or (employeeId=4 and customerId=76)) and orderId<1000000 order by orderid asc
572+
`, function (done) {
573+
con.select({
574+
from: "Orders",
575+
order: {
576+
by: 'customerId',
577+
type: 'asc' //supprted sort type is - asc,desc
578+
},
579+
where: [{
580+
shipperId: 2,
581+
},
582+
[{
583+
employeeId: 4,
584+
customerId: 34,
585+
}, {
586+
or: {
587+
employeeId: 4,
588+
customerId: 76
589+
}
590+
}],
591+
{
592+
orderId: {
593+
'<': 1000000
594+
}
595+
},
596+
]
597+
}).then(function (results) {
598+
expect(results).to.be.an('array').length(3);
599+
const expectedIds = results.map(result => result.orderId);
600+
expect(expectedIds).eql([10250, 10252, 10302])
601+
done();
602+
}).catch(done)
603+
});
533604
});

0 commit comments

Comments
 (0)