Fixing issue #5817 - making sure that date strings are correctly parsed into the bindings.
This commit is contained in:
parent
db768fa6f6
commit
39182cfbc0
|
@ -14,6 +14,7 @@ CREATE TABLE Tasks (
|
|||
TaskID int NOT NULL AUTO_INCREMENT,
|
||||
PersonID INT,
|
||||
TaskName varchar(255),
|
||||
CreatedAt DATE,
|
||||
PRIMARY KEY (TaskID),
|
||||
CONSTRAINT fkPersons
|
||||
FOREIGN KEY(PersonID)
|
||||
|
@ -25,6 +26,6 @@ CREATE TABLE Products (
|
|||
updated time
|
||||
);
|
||||
INSERT INTO Persons (FirstName, LastName, Age, Address, City, CreatedAt) VALUES ('Mike', 'Hughes', 28.2, '123 Fake Street', 'Belfast', '2021-01-19 03:14:07');
|
||||
INSERT INTO Tasks (PersonID, TaskName) VALUES (1, 'assembling');
|
||||
INSERT INTO Tasks (PersonID, TaskName) VALUES (1, 'processing');
|
||||
INSERT INTO Tasks (PersonID, TaskName, CreatedAt) VALUES (1, 'assembling', '2020-01-01');
|
||||
INSERT INTO Tasks (PersonID, TaskName, CreatedAt) VALUES (2, 'processing', '2019-12-31');
|
||||
INSERT INTO Products (name, updated) VALUES ('Meat', '11:00:22'), ('Fruit', '10:00:00');
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
finaliseExternalTables,
|
||||
} from "./utils"
|
||||
import { DatasourcePlus } from "./base/datasourcePlus"
|
||||
import dayjs from "dayjs"
|
||||
|
||||
module MySQLModule {
|
||||
const mysql = require("mysql2/promise")
|
||||
|
@ -86,10 +87,16 @@ module MySQLModule {
|
|||
if (typeof binding !== "string") {
|
||||
continue
|
||||
}
|
||||
const matches = binding.match(/^\d*/g)
|
||||
const matches = binding.match(/^\d*$/g)
|
||||
// check if number first
|
||||
if (matches && matches[0] !== "" && !isNaN(Number(matches[0]))) {
|
||||
bindings[i] = parseFloat(binding)
|
||||
}
|
||||
// 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
|
||||
else if (dayjs(binding).isValid()) {
|
||||
bindings[i] = dayjs(binding).toDate()
|
||||
}
|
||||
}
|
||||
return bindings
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue