Error on insert into

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Error on insert into

Post by AlessioForconi » Fri Nov 30, 2018 8:43 pm

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?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Error on insert into

Post by Klaus » Fri Nov 30, 2018 8:54 pm

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

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Error on insert into

Post by bangkok » Sat Dec 01, 2018 1:56 am

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

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: Error on insert into

Post by AlessioForconi » Sat Dec 01, 2018 8:42 am

@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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Error on insert into

Post by Klaus » Sat Dec 01, 2018 11:03 am

I have my example from the dictionary! :D

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: Error on insert into

Post by AlessioForconi » Sat Dec 01, 2018 11:41 am

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”