I really need help guys. I keep getting the error that there is no such table: birthclass…
I can’t get it to work and I don’t know why. Here is my code where I am trig to create the table and the database:
Thank you…
– herdData.lua
– Hold the herds Data
local widget = require (“widget”)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()
local localGroup = display.newGroup()
– include sqlite
require “sqlite3”
– called if the scene hasnt been seen
function scene:createScene(event)
– open database
local path = system.pathForFile(“herd.sqlite”, system.DocumentsDirectory)
local db = sqlite3.open(path)
print(path)
– print all the table contents
local sql = “SELECT * FROM birthclass”
for row in db:nrows(sql) do
local text = row.CowID…", “…row.Age…”, “…row.CalfID…”, “…row.Sex…”, “…row.Date…”, “…row.Weight…”, “…row.Sire…”, "…row.Notes
local t = display.newText(text, 200, 30 *row.id, native.systemFont, 24)
t:setTextColor(255,255,255)
localGroup:insert(t)
end
– setup function for button to load student data
local herdData_function = function(event)
– return to menu screen
storyboard.gotoScene(“menu”, “slideRight”, 400)
end
local herdData_button = widget.newButton
{
defaultFile = “Button2.png”,
overFile = “Button2.png”,
label “Return to Menu”,
fontSize = 50,
labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},
emboss = true,
onRelease = herdData_function,
id = “herdData”,
}
herdData_button.x = display.contentWidth/2 + 200
herdData_button.x = display.contentHeight/2 - 400
– add to local group
localGroup:insert(addHerd_button)
– handle the applicationexit event to close db
local function onSystemEvent(event)
if(event.type == “applicationExit”) then
db:close()
end
end
– system listener for applicationExit to handle closing database
Runtime:addEventListener (“system”, onSystemEvent)
end
function scene:enterScene(event)
storyboard.purgeScene(“menu”)
localGroup.alpha = 1
end
function scene:exitScene(event)
localGroup.alpha=0
end
– “createScene” is called whenever the scene is FIRST called
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
return scene
– addBirth.lua
– Add Data
local widget = require(“widget”)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()
local localGroup = display.newGroup()
– require sqlite3
local sqlite3 = require “sqlite3”
local db = sqlite3.open_memory()
– called if the cene has not been previously seen
function scene:createScene(event)
– Add text boxes to enter the data
local title = display.newText(localGroup, “*Congratulation on the new Birth!!*”, display.contentWidth/2, 100, native.systemFont, 30)
title:setFillColor(1,0,2)
local cowIDLabel = display.newText(localGroup, “Cow ID:”, 155, 200, native.systemFont, 30)
cowIDLabel:setFillColor(255,223,0)
local ageLabel = display.newText(localGroup, “Age:”, 425, 200, native.systemFont, 30)
ageLabel:setFillColor(255,223,0)
local calfIDLabel = display.newText(localGroup, “Calf ID:”, 155, 300, native.systemFont, 30)
calfIDLabel:setFillColor(255,223,0)
local sexLabel = display.newText(localGroup, “Sex:”, 425, 300, native.systemFont, 30)
sexLabel:setFillColor(255,223,0)
local dateLabel = display.newText(localGroup, “Date:”, 140, 400, native.systemFont, 30)
dateLabel:setFillColor(255,223,0)
local weightLabel = display.newText(localGroup, “Weight:”, 155, 500, native.systemFont, 30)
weightLabel:setFillColor(255,223,0)
local sireLabel = display.newText(localGroup, “Sire:”, 425, 500, native.systemFont, 30)
sireLabel:setFillColor(255,223,0)
– NOTES NEED TO BE SCROLLABLE!!
local notesLabel = display.newText(localGroup, “Notes”, display.contentWidth/2, 600, native.systemFont, 30)
notesLabel:setFillColor(255,223,0)
local line = display.newLine(340, 615, 425, 615)
line:setStrokeColor(255,233,0)
line.strokeWidth = 3
local cowID = native.newTextField(290, 200, 150, 45)
cowID.inputType = “default”
localGroup:insert(cowID)
local age = native.newTextField(550, 200, 150, 45)
age.inputType = “default”
localGroup:insert(age)
local calfID = native.newTextField(290, 300, 150, 45)
calfID.inputType = “default”
localGroup:insert(calfID)
local sex = native.newTextField(550, 300, 150, 45)
sex.inputType = “default”
localGroup:insert(sex)
– MAKE A PICKER WHEEL FOR THE DAT AND SET IT TO DEFAULT TO THE CURRENT DAY THAT DAY
local date = native.newTextField(420, 400, 410, 50)
date.inputType = “default”
localGroup:insert(date)
local weight = native.newTextField(290, 500, 150, 45)
weight.inputType = “default”
localGroup:insert(weight)
local sire = native.newTextField(550, 500, 150, 45)
sire.inputType = “default”
localGroup:insert(sire)
– NOTES NEED TO BE SCROLLABLE WHEN ENTERED
local notes = native.newTextField(display.contentWidth/2, 710, 400, 100)
notes.inputType = “default”
localGroup:insert(notes)
local addBirth_function = function(event)
– open sqlite database if it does not exist
local path = system.pathForFile(“herd.sqlite”, system.DocumentsDirectory)
local db = sqlite3.open(path)
– check that the path was made
print(path)
– setup the table if it does not exist
local tablesetup = “CREATE TABLE IF NOT EXISTS birthclass (id INTEGERS PRIMARY KEY AUTOINCREMENT, CowId INTEGER, Age INTEGER, CalfId INTEGER, Sex text, Date INTEGER, Weight INTEGER, Sire INTEGER, Notes text);”
db:exec(tablesetup)
– check that it created the table
print(tablesetup)
local tablefill = “INSERT INTO birthclass VALUES(NULL, '” …cowID.text… “’,’”…age.text…"’,’"…calfID.text…"’,’"…sex.text…"’,’"…date.text…"’,’"…weight.text…"’,’"…sire.text…"’,’"…notes.text…"’);"
– check that it filled the table
print(tablefill)
db:exec(tablefill)
– close database
db:close()
– check that it closed
print(“db closed”)
– clear textFields and return to menu screen
cowID:removeSelf()
age:removeSelf()
calfID:removeSelf()
sex:removeSelf()
date:removeSelf()
weight:removeSelf()
sire:removeSelf()
notes:removeSelf()
line:removeSelf()
storyboard.gotoScene(“menu”, “slideLeft”, 400)
end – submitBirth_function
local saveBirth_button = widget.newButton
{
defaultFile = “Save.png”,
overFile = “Save.png”,
label = “Save”,
fontSize = 65,
labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},
emboss = true,
onRelease = addBirth_function,
id = “addBirth”
}
saveBirth_button.x = display.contentWidth/2
saveBirth_button.y = display.contentHeight/2 +350
– add all display items to the group
localGroup:insert(saveBirth_button)
– handle the applicationExit scene to close db
local function onSystemEvent(event)
if(event.type == “applicationExit”) then
db:close()
end
end
– system listener for applicationExit to handle closing db
Runtime:addEventListener (“system”, onSystemEvent)
end
function scene:enterScene(event)
storyboard.purgeScene(“menu”)
localGroup.alpha=1
end
function scene:exitScene(event)
localGroup.alpha = 0
end
– “createScene” is called whenever the scene is FIRST called
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
return scene