one of the interesting things is the script seems to slow down overtime. i am trying to convert each line to a sql insert command so i can bulk import them to a sqlite database.
Here is my code
Code: Select all
function prepareSQL pText, pColumns
delete the first line of pText
local sqlText, sqlLineTemplate, theLines
put 1 into theLines
put "INSERT INTO 'TheTable'" && "(" & theDatabaseColumns & ")" && "VALUES" into sqlLineTemplate
repeat for each line tLine in pText
local tempLine
put tLine into tempLine
if item 1 of tempLine is not empty then
put quote before item 1 of tempLine
put quote after item 1 of tempLine
end if
local x = 1
repeat for each item tItem in tempLIne
if theLines is 1947 then
if theSchemaArray[x] is "INTEGER" and item x of tempLine is " " then
put "NULL" into item x of tempLine
end if
end if
if tItem is empty then
put "NULL" into item x of the last line of tempLine
else
if Not(tItem contains quote) and not (item x of tempLine is a number) then
if theSchemaArray[x] is "INTEGER" then
repeat with y = number of chars in tItem down to 1
if char y of tItem is not a number then
delete char y of tItem
end if
end repeat
if tItem is empty then put "NULL" into item x of tempLine
end if
end if
end if
add 1 to x
end repeat
put sqlLineTemplate && "(" & tempLine & ");" into line theLines of sqlText
add 1 to theLines
wait 0 millisec with messages
updateProgressBar theLines
end repeat
return sqlText
end prepareSQL