Inserting different field into different tables

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
pidobearBUSsb9q
Posts: 34
Joined: Fri Jul 13, 2012 8:40 am

Inserting different field into different tables

Post by pidobearBUSsb9q » Mon Aug 06, 2012 4:52 am

HI

THANks in Advance for helping

i am trying to insert into different tables into a database.
how to i change the SQL statement on it so that field 1 goes into column 1 for any table and when the field is empty it just leave it blank?

put "INSERT INTO VIP (Name,Age,Job) " & \
merge("VALUES ('[[Ftname]]', '[[Ftage]]', '[[Ftjob]]')") into tCmd

Cheers :D

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Inserting different field into different tables

Post by Klaus » Mon Aug 06, 2012 11:49 am

I am not an SQL expert, but I doubt that this is possible wothout 3 different SQL statements.

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Inserting different field into different tables

Post by phaworth » Sat Aug 18, 2012 12:59 am

I don't have your schema in front of me but off the top of my head, I'd say there's a problem with its design if you have multiple tables with the same data in them.

However, if you want to do this and you you are using SQLite, take a look at triggers. They allow you to define auxiliary actions when an INSERT, DELETE, or UPDATE happens on a table. In this case, you could define a trigger on the VIP table to execute when rows are inserted into it and request that the same data be inserted into the other tables you mentioned.

Pete

Adrian
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 79
Joined: Wed Jul 11, 2012 5:03 pm

Re: Inserting different field into different tables

Post by Adrian » Sat Aug 18, 2012 5:46 pm

Could you give us some more detail about ehat you are wanting to achieve? I am not sure what you are trying to do with the merge statement, where one would expect "values".

If you build up the SQL statement string along the lines of

Put "insert into table (col1, col2) values('" & the text of field1 & "','" & the text of field2 & "')" into tSQL

(noting the single quotes within the double quotes)

then if a field is blank, the SQL would have two signel quotes for the column value, which is fine. E.g.

insert into table (col1,col2) values('abc','')

But let us know some more of what you are trying to do.

Cheers,

Adrian

Post Reply