Merge pull request #5179 from Budibase/fix/5153
Fix for MySQL Limits and offsets (numbers in bindings)
This commit is contained in:
commit
5bc426bb33
|
@ -181,11 +181,7 @@ export interface QueryJson {
|
|||
|
||||
export interface SqlQuery {
|
||||
sql: string
|
||||
bindings?:
|
||||
| string[]
|
||||
| {
|
||||
[key: string]: any
|
||||
}
|
||||
bindings?: string[]
|
||||
}
|
||||
|
||||
export interface QueryOptions {
|
||||
|
|
|
@ -80,6 +80,20 @@ module MySQLModule {
|
|||
},
|
||||
}
|
||||
|
||||
function bindingTypeCoerce(bindings: any[]) {
|
||||
for (let i = 0; i < bindings.length; i++) {
|
||||
const binding = bindings[i]
|
||||
if (typeof binding !== "string") {
|
||||
continue
|
||||
}
|
||||
const matches = binding.match(/^\d*/g)
|
||||
if (matches && matches[0] !== "" && !isNaN(Number(matches[0]))) {
|
||||
bindings[i] = parseFloat(binding)
|
||||
}
|
||||
}
|
||||
return bindings
|
||||
}
|
||||
|
||||
class MySQLIntegration extends Sql implements DatasourcePlus {
|
||||
private config: MySQLConfig
|
||||
private client: any
|
||||
|
@ -122,7 +136,7 @@ module MySQLModule {
|
|||
// Node MySQL is callback based, so we must wrap our call in a promise
|
||||
const response = await this.client.query(
|
||||
query.sql,
|
||||
query.bindings || []
|
||||
bindingTypeCoerce(query.bindings || [])
|
||||
)
|
||||
return response[0]
|
||||
} finally {
|
||||
|
|
|
@ -3,6 +3,9 @@ const { EmailTemplatePurpose } = require("../../../constants")
|
|||
const nodemailer = require("nodemailer")
|
||||
const fetch = require("node-fetch")
|
||||
|
||||
// for the real email tests give them a long time to try complete/fail
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/api/global/email", () => {
|
||||
let request = setup.getRequest()
|
||||
let config = setup.getConfig()
|
||||
|
@ -27,6 +30,7 @@ describe("/api/global/email", () => {
|
|||
userId: user._id,
|
||||
})
|
||||
.set(config.defaultHeaders())
|
||||
.timeout(20000)
|
||||
// ethereal hiccup, can't test right now
|
||||
if (res.status >= 300) {
|
||||
return
|
||||
|
@ -39,7 +43,7 @@ describe("/api/global/email", () => {
|
|||
text = await response.text()
|
||||
} catch (err) {
|
||||
// ethereal hiccup, can't test right now
|
||||
if (parseInt(err.status) >= 300) {
|
||||
if (parseInt(err.status) >= 300 || (err && err.errno === "ETIME")) {
|
||||
return
|
||||
} else {
|
||||
throw err
|
||||
|
|
Loading…
Reference in New Issue