I am in the initial stages of an apps development. At the moment my code is only writing to the console to check proper access to and retrieval of data from the SQLite3 database.
The problem is: I am trying to find the date of today in the database.
I have created a variable using:
local todaysdate = ( os.date("%d.%m.%Y") )
The data in the database is formated the same, where todays date would be 14.02.2013 as TEXT.
I have tried several variations to search for that string but each time either no data is found or an error of “attempt to call local ‘todaysdate’ (a string value)” is returned.
When I search for the specific string of “14.02.2013” all works fine. I assume there must be non-similarities in the created os.date() string but fail to see how to remedy this, hopefully, simple syntax problem.
[code]
local localGroup = display.newGroup();
local Main = {}
-------------------------- Begin database access --------------------------
–include sqlite
require “sqlite3”
–open database and set path to the same folder as our main.lua file
local path = system.pathForFile(“20132015.sqlite”, system.ResourceDirectory)
local db = sqlite3.open( path )
–handle the applicationExit event to close the db
local function onSystemEvent( event )
if( event.type == “applicationExit”) then
db:close()
end
end
print ("Sqlite 3 Version is : "…sqlite3.version())
print (“Database Path is: “…path)
local todaysdate = ( os.date(”%d.%m.%Y”) )
print ("Today is: " …todaysdate)
–
– local tablesetup = [[CREATE TABLE IF NOT EXISTS test02 (id INTEGER PRIMARY KEY, UTCDate TEXT, Time TEXT, Type TEXT, Units TEXT, Sunrise TEXT, Sunset TEXT, DaylightTime INTEGER );]]
– print(tablesetup)
– db:exec( tablesetup )
local count = 0
local output
local sql="SELECT * FROM test02 WHERE UTCDate LIKE ‘%“todaysdate”%’ "
– local sql="SELECT * FROM test02 WHERE UTCDate LIKE ‘“todaysdate”’ "
– local sql="SELECT * FROM test02 WHERE UTCDate LIKE ‘todaysdate’ "
– for row in db:nrows("SELECT * FROM test where UTCDate = ‘todaysdate’ ") do
for row in db:nrows(sql) do
print("UTCDate = " …row.UTCDate)
count = count + 1
print(count)
print(“Todays Sunrise and Sunset are at: " …row.Sunrise…”, " …row.Sunset)
end
--------------------------- End database access ---------------------------
– Main Function
– system listener for applicationExit
Runtime:addEventListener(“system”, onSystemEvent)
Main()
[/code] [import]uid: 101897 topic_id: 35913 reply_id: 335913[/import]