Page 1 of 1

Error on insert into

Posted: Fri Nov 30, 2018 8:43 pm
by AlessioForconi
Hello everyone,

having this command sql

Code: Select all

put "INSERT INTO tb_godute ('fld_data', 'fld_ore', 'fld_causale') VALUES (:1, :2, :3)", miadata, ore, causale into sqlInsert
revExecuteSQL conn, sqlInsert 
miadata --> 2018-11-30
ore --> 3
causale --> ROL

I get this error
There was a problem saving this record: ner "2018": sintax error
but from what I understand SQlite accepts dates in YYYY-MM-DD format.
The data field in the database is of type text, even if you try the datetime or date type the error is the same

Where's the mistake?

Re: Error on insert into

Posted: Fri Nov 30, 2018 8:54 pm
by Klaus
Buonasera Alessio,

I think the variables need to be in quotes and must not be part of the roiginal SQL statement:

Code: Select all

put "INSERT INTO tb_godute ('fld_data', 'fld_ore', 'fld_causale') VALUES (:1, :2, :3)" into sqlInsert
revExecuteSQL conn, sqlInsert, "miadata", "ore", "causale" 
If in doubt ALWAYS take a look into the dictionary! 8)


Best

Klaus

Re: Error on insert into

Posted: Sat Dec 01, 2018 1:56 am
by bangkok
You should use the more straightforward syntax, instead of placeholders.

It will ease the debugging by allowing you to "see" exactly what is the query.

Code: Select all

put "INSERT INTO tb_godute (fld_data, fld_ore, fld_causale) VALUES ('"&miadata&"','"&ore&"','"&causale&"')" into sqlInsert
answer sqlInsert
revExecuteSQL conn, sqlInsert 
put the result into sqlResult
 if sqlResult is not a number then answer error sqlResult

Re: Error on insert into

Posted: Sat Dec 01, 2018 8:42 am
by AlessioForconi
@klaus @bangkok

Both solutions work, I got there close but I missed putting the "" in the right order.

I always look at the dictionary before writing, if only for not annoying you uselessly and to succeed on its own.

Thank you very much indeed

Re: Error on insert into

Posted: Sat Dec 01, 2018 11:03 am
by Klaus
I have my example from the dictionary! :D

Re: Error on insert into

Posted: Sat Dec 01, 2018 11:41 am
by AlessioForconi
Klaus wrote:
Sat Dec 01, 2018 11:03 am
I have my example from the dictionary! :D
:shock: :oops: