Fix for #5612 - stop some formats of string being in-correctly parsed as dates by MySQL - disable type coercion for data source plus mysql tables (knex converts).
This commit is contained in:
parent
a7fe15244b
commit
be4b930c8a
|
@ -101,7 +101,7 @@ module MySQLModule {
|
||||||
}
|
}
|
||||||
// if not a number, see if it is a date - important to do in this order as any
|
// if not a number, see if it is a date - important to do in this order as any
|
||||||
// integer will be considered a valid date
|
// integer will be considered a valid date
|
||||||
else if (dayjs(binding).isValid()) {
|
else if (/^\d/.test(binding) && dayjs(binding).isValid()) {
|
||||||
bindings[i] = dayjs(binding).toDate()
|
bindings[i] = dayjs(binding).toDate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,20 +151,24 @@ module MySQLModule {
|
||||||
|
|
||||||
async internalQuery(
|
async internalQuery(
|
||||||
query: SqlQuery,
|
query: SqlQuery,
|
||||||
connect: boolean = true
|
opts: { connect?: boolean; disableCoercion?: boolean } = {
|
||||||
|
connect: true,
|
||||||
|
disableCoercion: false,
|
||||||
|
}
|
||||||
): Promise<any[] | any> {
|
): Promise<any[] | any> {
|
||||||
try {
|
try {
|
||||||
if (connect) {
|
if (opts?.connect) {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
}
|
}
|
||||||
|
const baseBindings = query.bindings || []
|
||||||
|
const bindings = opts?.disableCoercion
|
||||||
|
? baseBindings
|
||||||
|
: bindingTypeCoerce(baseBindings)
|
||||||
// Node MySQL is callback based, so we must wrap our call in a promise
|
// Node MySQL is callback based, so we must wrap our call in a promise
|
||||||
const response = await this.client.query(
|
const response = await this.client.query(query.sql, bindings)
|
||||||
query.sql,
|
|
||||||
bindingTypeCoerce(query.bindings || [])
|
|
||||||
)
|
|
||||||
return response[0]
|
return response[0]
|
||||||
} finally {
|
} finally {
|
||||||
if (connect) {
|
if (opts?.connect) {
|
||||||
await this.disconnect()
|
await this.disconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +183,7 @@ module MySQLModule {
|
||||||
// get the tables first
|
// get the tables first
|
||||||
const tablesResp = await this.internalQuery(
|
const tablesResp = await this.internalQuery(
|
||||||
{ sql: "SHOW TABLES;" },
|
{ sql: "SHOW TABLES;" },
|
||||||
false
|
{ connect: false }
|
||||||
)
|
)
|
||||||
const tableNames = tablesResp.map(
|
const tableNames = tablesResp.map(
|
||||||
(obj: any) =>
|
(obj: any) =>
|
||||||
|
@ -191,7 +195,7 @@ module MySQLModule {
|
||||||
const schema: TableSchema = {}
|
const schema: TableSchema = {}
|
||||||
const descResp = await this.internalQuery(
|
const descResp = await this.internalQuery(
|
||||||
{ sql: `DESCRIBE \`${tableName}\`;` },
|
{ sql: `DESCRIBE \`${tableName}\`;` },
|
||||||
false
|
{ connect: false }
|
||||||
)
|
)
|
||||||
for (let column of descResp) {
|
for (let column of descResp) {
|
||||||
const columnName = column.Field
|
const columnName = column.Field
|
||||||
|
@ -254,7 +258,8 @@ module MySQLModule {
|
||||||
async query(json: QueryJson) {
|
async query(json: QueryJson) {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
try {
|
try {
|
||||||
const queryFn = (query: any) => this.internalQuery(query, false)
|
const queryFn = (query: any) =>
|
||||||
|
this.internalQuery(query, { connect: false, disableCoercion: true })
|
||||||
return await this.queryWithReturning(json, queryFn)
|
return await this.queryWithReturning(json, queryFn)
|
||||||
} finally {
|
} finally {
|
||||||
await this.disconnect()
|
await this.disconnect()
|
||||||
|
|
Loading…
Reference in New Issue