Lua - SQLite3 isn't inserting rows into its database

Tdhphhyodi

New Member
I'm trying to build an expense app for Android phones, and I need a way to display the expenses. The plan (for my current step) is to allow the user to view their expenses. I want to show a calendar-like screen, and if there is at least one expense for a day, then use a different color for the button.My problem is in inserting information to the \[code\]sqlite3\[/code\] table. Here is my code:\[code\]require "sqlite3"--create pathlocal path = system.pathForFile("expenses.sqlite", system.DocumentsDirectory )file = io.open( path, "r" )if( file == nil )then -- Doesn't Already Exist, So Copy it In From Resource Directory pathSource = system.pathForFile( "expenses.sqlite", system.ResourceDirectory ) fileSource = io.open( pathSource, "r" ) contentsSource = fileSource:read( "*a" ) --Write Destination File in Documents Directory pathDest = system.pathForFile( "expenses.sqlite", system.DocumentsDirectory ) fileDest = io.open( pathDest, "w" ) fileDest:write( contentsSource ) -- Done io.close( fileSource ) io.close( fileDest ) enddb = sqlite3.open( path )--setup the table if it doesn't existlocal tableSetup = [[CREATE TABLE IF NOT EXISTS expenses (id INTEGER PRIMARY KEY, amount, description, year, month, day);]]db:exec(tableSetup)local tableFill = [[INSERT INTO expenses VALUES (NULL,']] .. 15 .. [[',']] .. "Groceries" .. [[',']] .. 2013 .. [[',']] .. 4 .. [[',']] .. 8 ..[[');]]db:exec(tableFill)for row in db:nrows("SELECT * FROM expenses") do print("hi") if row.year == dateTable.year and row.month == dateTable.month and row.day == dateTable.day then flag = dateTabel.day endend\[/code\]I have looked everywhere to see if I've used the wrong sqlite3 commands wrong since I'm not very familiar to it, but I tried everything I found and nothing worked. The \[code\]print("hi")\[/code\] line doesn't execute, so that tells me that there are no rows in the table.Also, if I say \[code\]db:nrows("SELECT year, month, day FROM expenses")\[/code\], sqlite3 gives me an error saying there is no year column. My overall guess is that I'm not inserting the information into the table properly, but I've tried everything I can think of. Can anyone help?
 
Top