Lua - SQLite3 isn't inserting rows into its database -
i'm trying build expense app android phones, , need way display expenses. plan (for current step) allow user view expenses. want show calendar-like screen, , if there @ least 1 expense day, use different color button.
my problem in inserting information sqlite3
table. here code:
require "sqlite3" --create path local path = system.pathforfile("expenses.sqlite", system.documentsdirectory ) file = io.open( path, "r" ) if( file == nil )then -- doesn't exist, copy in 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 ) end db = sqlite3.open( path ) --setup table if doesn't exist local tablesetup = [[create table if not exists expenses (id integer primary key, amount, description, year, month, day);]] db:exec(tablesetup) local tablefill = [[insert expenses values (null,']] .. 15 .. [[',']] .. "groceries" .. [[',']] .. 2013 .. [[',']] .. 4 .. [[',']] .. 8 ..[[');]] db:exec(tablefill) row in db:nrows("select * expenses") print("hi") if row.year == datetable[i].year , row.month == datetable[i].month , row.day == datetable[i].day flag = datetabel[i].day end end
i have looked everywhere see if i've used wrong sqlite3 commands wrong since i'm not familiar it, tried found , nothing worked. print("hi")
line doesn't execute, tells me there no rows in table.
also, if db:nrows("select year, month, day expenses")
, sqlite3 gives me error saying there no year column. overall guess i'm not inserting information table properly, i've tried can think of. can help?
i figured out there issue current version of sqlite3 , 1 have on computer. anyway, changed couple of lines , works flawlessly. changed select statement , loop.
--sqlite statement local check = "select distinct year, month, day expenses year = '"..datetable[i].year.."' , month = '"..datetable[i].month.."' , day = '"..datetable[i].day.."'" --check if there @ least 1 expense given day --if there isn't one, loop won't execute row in db:nrows(check) flag = row.day end
then go on create button different color if day number equal flag variable.
this inside loop creates each datetable[i]
.
Comments
Post a Comment