Code for Updating SQLite database table

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
montymay
Posts: 145
Joined: Thu Jul 18, 2013 5:23 am

Code for Updating SQLite database table

Post by montymay » Wed Jan 25, 2017 12:10 pm

Hello fellow LiveCoders

I have a SQLite database table. I have written code that successfully updates existing records but I can't find code that will create new records. I searched this forum and found the following code--abridged for display here--that I amended to reflect my application, but it doesn't work. No new record is created.

Code: Select all

put fld "pcfnum" into tPCFnum
put fld "agency" into tDept
put fld "subject" into tSubject
put "INSERT INTO OpsDetails (pcfum,dept,subject) VALUES (" & merge ((" '[[tPCFnum]]' ,  '[[tDept]]', '[[tSubject]] ")) & ")" into tSQL
revExecuteSQL gDatabaseID, tSQL
I know I need to continue my studies of SQL, but in the meantime is the error in this code obvious? is there a better method? Thanks for any suggestions.

Monty May

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Code for Updating SQLite database table

Post by AxWald » Wed Jan 25, 2017 1:52 pm

Hi,

set a breakpoint & examine tSQL. It should look like this:

Code: Select all

INSERT INTO myTable (Field_1, Field_2) VALUES 
(0, 'Something'), 
(2, 'WhatOther'), 
[...]
(723, 'Anything');
(Returns not mandatory, spaces at line end often required, single quotes for anything but integers)
Besides it you can try your tSQL manually in a db manager; for SQLite I use "SQLite Manager" (the Firefox plugin accessible via the Add-ons-pane). This saves a lot of time & nerves ;-)

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply