Issue
I am trying to insert a time value from Input1 on Appsmith into a time column on my database. However, I am getting an error message stating that the query preparation failed. The solution is to use moment to convert the DateTime field since the database only accepts the DateTime field in string format. Additionally, I need to update the default text in Input2 to reflect this solution and turn off prepared statements.
Resolution
The issue with the provided query is that the database expects the time value in the DateTime format rather than the time format. To solve this, the moment library can be used to convert the time format to the DateTime format.
The following code demonstrates how to use moment to convert the time value before inserting it into the database:
// import moment library
const moment = require('moment');
// get input from Appsmith
const input1 = moment(input1.text, 'HH:mm').format('YYYY-MM-DD HH:mm:ss');
// insert data into the database
INSERT INTO public."TTKHACHHANG" ("sdt", "gio_gian_so")
VALUES ({{input1.value}},'{{input2.text}}');
It is also suggested to turn off prepared statements to avoid any other query preparation issues.