Hi,
Not a lot of thought wrote:Would that look like:
loop
BEGIN TRANSACTION;
INSERT;
END TRANSACTION;
end loop
or
BEGIN TRANSACTION;
loop
INSERT;
end loop
END TRANSACTION;
The second should be much faster. Read
this.
I'd do it in another way, without any looping. Provided I have data like this:
Code: Select all
ANum: AChar: AStr:
321; "A"; "A.A"
654; "B"; "B.B"
987; "C"; "C.C"
On we go:
Code: Select all
replace ";" with "," in MyCSVData -- or whatever needed
replace quote with "'" in MyCSVData -- again, depends of your format
replace return with ")," & return & "(" in MyCSVData -- voodoo!
-- now our data are like #1, below.
put "INSERT INTO 't_Table' ('r_Rec1', 'r_Rec2', 'r_Rec3') Values " & return & "(" into StrSQL
put MyCSVData & ");" after StrSQL
-- see the SQL string in #2, below
get revdatafromquery( , , MyDBID, StrSQL)
--Ahem, see #3 ...
Explanation:
#1: This is "sanitized" data, I usually have a function to do this *1)
Code: Select all
321,'A','A.A'),
(654,'B','B.B'),
(987,'C','C.C'
#2: Look, a nice, working SQL string :)
Code: Select all
INSERT INTO 't_book' ('bk_Num', 'bk_1', 'bk_2') Values
(321,'A','A.A'),
(654,'B','B.B'),
(987,'C','C.C');
#3:
Yes, it's "revDataFromQuery" for an action query - while looking for code to post here I found this in a production software of me, and it really works! LiveCode is full of miracles and wonders!
Well, the transaction - you could always start your insert with a "begin":
Code: Select all
put "BEGIN;" & return & "INSERT INTO 't_book' ('bk_Num', 'bk_1', 'bk_2') Values " & return & "(" into StrSQL
and after checking the result, dropping a "COMMIT;" or a "ROLLBACK;" ...
I know this is not the canonical way the LC books show you, but I'm used to do it this way, and it works great, usually ;-) And I hate the "insert into mytable values(:1,:2,:1)" notation ...
Besides, it's much more entertaining this way once you're accustomed to do some chunk juggling & SQL rhyming!
Have fun, hope I could help.
*1) There's a nice CSV converter above, I know - just I have given up trying to use "kill 'em all" approaches. "Character Separated Values" files can come in such many flavors, you'll always bite the carpet sooner or later. But usually they come repeatedly, so it's (for me) no problem to analyze once & quickly hack me a customized converter. After all, most often it's not more than a few "replace"s ...