No such table: Error

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

your trying to select from the table before your create table sql

Move below code to right below your local db = sqlite3.open(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)

Thanks for replying. I thought that was how I have it already? In the addBirth.lua correct? I create the local db with the sqlite3.open(path) then I print agh to show that it was made in the terminal. Then I populate the table with tablesetup and tablefill. That not right?

Unless you are calling addBirth.lua before loading herdData.lua then nope. 

I see what you are trying to do just wondering at want point you call herdData?

I’m sorry. I understand what you are saying now. So i have a menu.lua also. Sorry for not posting that too. It is there where I call the addBirth.lua on a button release and in addBirth.lua sends the user back to the menu.lua after the saveButton is released and then the user taps the herd data button and that calls the herdData.lua and should display the content in the table. Here is my menu.lua:


– menu.lua


– Store the menu and all the buttons

local widget = require (“widget”)

local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

local localGroup = display.newGroup()

function scene:createScene(event)

local background = display.newImage(“barn.jpg”, display.contentCenterX, display.contentCenterY ) – WORK ON!! **

local display_stage = display.getCurrentStage()

display_stage:insert(background)

display_stage:insert(storyboard.stage)

background:toBack() 

local herdData_function = function (event)

storyboard.gotoScene(“herdData”, “fade”, 400)

end

local  herdData_button = widget.newButton

{

defaultFile = “Button.png”,

label = “Herd Data”,

size = 30,

fontSize = 60,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = herdData_function,

id = “herdData”,

}

local addBirth_function = function(event)

storyboard.gotoScene(“addBirth”, “fade”, 400)

end

local addBirth_button = widget.newButton

{

defaultFile = “Button.png”,

label = “Add Birth”,

size = 30,

fontSize = 60,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = addBirth_function,

id = “addBirth”,

}

local doctorVisit_function = function (event)

storyboard.gotoScene(“doctorVisit”, “fade”, 400)

end

local doctorVisit_button = widget.newButton

{

defaultFile = “Button2.png”,

label = “Doctor Visit”,

labelsize = 24,

fontSize = 40,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = doctorVisit_function,

id = “doctorVisit”,

}

local doctorRecords_function = function (event)

storyboard.gotoscene(“doctorRecords”, “fade”, 400)

end

local doctorRecords_button = widget.newButton

{

defaultFile = “Button2.png”,

label = “Doctor Records”,

size = 24,

fontSize = 40,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = doctorRecords_function,

id = “doctorRecords”,

}

addBirth_button.x = display.contentWidth/2

addBirth_button.y = display.contentHeight/2 -350

doctorVisit_button.x = display.contentWidth/2

doctorVisit_button.y = display.contentHeight/2 +10

doctorRecords_button.x = display.contentWidth/2

doctorRecords_button.y = display.contentHeight/2-150

herdData_button.x = display.contentWidth/2

herdData_button.y = display.contentWidth/2 + 500

localGroup:insert(addBirth_button)

addBirth_button:toFront()

localGroup:insert(doctorVisit_button)

localGroup:insert(doctorRecords_button)

localGroup:insert(herdData_button)

end

function scene:enterScene(event)

localGroup.alpha = 1

storyboard.purgeAll()

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

your trying to select from the table before your create table sql

Move below code to right below your local db = sqlite3.open(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)

Thanks for replying. I thought that was how I have it already? In the addBirth.lua correct? I create the local db with the sqlite3.open(path) then I print agh to show that it was made in the terminal. Then I populate the table with tablesetup and tablefill. That not right?

Unless you are calling addBirth.lua before loading herdData.lua then nope. 

I see what you are trying to do just wondering at want point you call herdData?

I’m sorry. I understand what you are saying now. So i have a menu.lua also. Sorry for not posting that too. It is there where I call the addBirth.lua on a button release and in addBirth.lua sends the user back to the menu.lua after the saveButton is released and then the user taps the herd data button and that calls the herdData.lua and should display the content in the table. Here is my menu.lua:


– menu.lua


– Store the menu and all the buttons

local widget = require (“widget”)

local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

local localGroup = display.newGroup()

function scene:createScene(event)

local background = display.newImage(“barn.jpg”, display.contentCenterX, display.contentCenterY ) – WORK ON!! **

local display_stage = display.getCurrentStage()

display_stage:insert(background)

display_stage:insert(storyboard.stage)

background:toBack() 

local herdData_function = function (event)

storyboard.gotoScene(“herdData”, “fade”, 400)

end

local  herdData_button = widget.newButton

{

defaultFile = “Button.png”,

label = “Herd Data”,

size = 30,

fontSize = 60,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = herdData_function,

id = “herdData”,

}

local addBirth_function = function(event)

storyboard.gotoScene(“addBirth”, “fade”, 400)

end

local addBirth_button = widget.newButton

{

defaultFile = “Button.png”,

label = “Add Birth”,

size = 30,

fontSize = 60,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = addBirth_function,

id = “addBirth”,

}

local doctorVisit_function = function (event)

storyboard.gotoScene(“doctorVisit”, “fade”, 400)

end

local doctorVisit_button = widget.newButton

{

defaultFile = “Button2.png”,

label = “Doctor Visit”,

labelsize = 24,

fontSize = 40,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = doctorVisit_function,

id = “doctorVisit”,

}

local doctorRecords_function = function (event)

storyboard.gotoscene(“doctorRecords”, “fade”, 400)

end

local doctorRecords_button = widget.newButton

{

defaultFile = “Button2.png”,

label = “Doctor Records”,

size = 24,

fontSize = 40,

labelColor = { default = {1,1,1}, over = {0,0,0,0.5}},

emboss = true,

onRelease = doctorRecords_function,

id = “doctorRecords”,

}

addBirth_button.x = display.contentWidth/2

addBirth_button.y = display.contentHeight/2 -350

doctorVisit_button.x = display.contentWidth/2

doctorVisit_button.y = display.contentHeight/2 +10

doctorRecords_button.x = display.contentWidth/2

doctorRecords_button.y = display.contentHeight/2-150

herdData_button.x = display.contentWidth/2

herdData_button.y = display.contentWidth/2 + 500

localGroup:insert(addBirth_button)

addBirth_button:toFront()

localGroup:insert(doctorVisit_button)

localGroup:insert(doctorRecords_button)

localGroup:insert(herdData_button)

end

function scene:enterScene(event)

localGroup.alpha = 1

storyboard.purgeAll()

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