swright3

Unable to Insert output of a data file into a DB using NAS Lua script.

Discussion created by swright3 on Dec 11, 2013
Latest reply on Dec 13, 2013 by jonhcw

I have a tab delimited file that I'm trying to insert into a custom DB using a lua script.  The file opens and files are correctly parsed into three fields.  The problem is when I attempt to insert the values into the newly created DB/table. 

 

My Script:

 

 

--Load the Store Location File into a database

buf =file.read("strloc.txt")

ul =split(buf, "\n")

rc=database.open("STORE_INFO")

print(rc)

database.query("DROP TABLE IF EXISTS STORE_TBL")

database.query("CREATE TABLE STORE_TBL (rec integer, store_number text, concept text, country text)")

for

i=1, #ul do

f =split(ul[i],"\t")

 

strno = f[1]

strcon = f[2]

strcool = f[3]

printf("Output: %d %s %s %s", i,strno,strcon,strcool)

 

rc,y=database.query("INSERT INTO STORE_TBL VALUES (i, strno, strcon, strcool)")

 

print(y)

 

end

database.close("STORE_INFO")

 

The output:

 

Output: 3 0008 WS USA

1

Output: 4 0011 WS USA

1

Output: 5 0013 WS USA

1

Output: 6 0019 WS USA

1

Output: 7 0020 WS USA

1

Output: 8 0021 WS USA

1

 

 

 

Any Ideas what is going wrong?

Outcomes