Not really I think my problem is how to get the tableView to update with my new sql query (In this game I like to first list every entry in the db and then I like to filter out and narrow the search so to say)
I use composer and everything but the updatefunction works nice! Heres a stripped version of the playGame file:
[LUA]
– THE PLAYGAME FILE:
– LOCALS FWD
local composer = require “composer”
local scene = composer.newScene()
local path = system.pathForFile( “Birds.sqlite”, system.ResourceDirectory ) – IM NOT WRITING TO THE DB FILE
local imagePath = “Images/Birds/”
local bgImage = imagePath … “bgTheme.jpg”
local text, themeText, bg, t, count, bgItem, bg, colorConverter, tableView, leftRib, woodPanel, butNext, butBack
local leftIndent = 50
local dbTable = {}
local rowBg = {}
local rowName = {}
local rowLatin = {}
local playButton = {}
local onRowRender = {}
local onRowTouch = {}
local funtionSqlView = {}
local db = sqlite3.open( path )
local _W, _H = display.contentWidth, display.contentHeight
local group = {}
local containerGroup = display.newGroup( )
local dashboardGroup = display.newGroup( )
–GLOBALS FWD
mySqlView = {} – I CHOOSE TO HAVE THIS GLOBAL FOR NOW
_G.specPool = {}
_G.catText = “Push one of the buttons”
updateSql = {}
– FUNCTIONS
function functionSqlView() – THIS IS THE SQL STATEMENT BUILDER (YOU CAN SEE IN THE TERMINAL)… LAME NAME, I KNOW HAHA
local counter = 1
local res = {}
local sep = ‘"’ – FOR LAZYNESS
table.insert(res, "SELECT * FROM birds WHERE ")
for _,v in ipairs(mySqlView) do
if counter < #mySqlView then
table.insert( res, (v … " AND ")) – I WILL DEAL WITH ‘OR’ LATER ;D
else
table.insert( res, v )
end
counter = counter + 1
end
sql = sep … table.concat( res ) … sep – CONCATENATES THE WHOLE STATEMEMT STRING
updateSql(sql)
– HERE IS WHERE I START TO GET LOST, I HAVE THE STATEMENT AND I WANT TO UPDATE AND REMOVE
– THE ROWS THAT DOESN´T MEET THEESE CRITERIAS… FOLLOW DOWN TO UPDATESQL FUNCTION
end
local function onSystemEvent( event )
if ( event.type == “applicationExit” ) then
db:close()
end
end
local function colorConverter(r, g, b, a) – JUST SO I CAN USE RGB VALUES DIRECT FROM PHOTOSHOP OR ILLUSTRATOR
local colorR, colorG, colorB, alphA
colorR = r/256; colorG = g/256; colorB = b/256
alphA = a or nil
return colorR, colorG, colorB, alphA
end
function updateCatText() – FOR UPDATING THE GLOBAL CATEGORY TEXT OVER THE BUTTONS
if themeText then display.remove( themeText) end
themeText = display.newText( tostring(_G.catText), 0, 0, _G.msgFont , 34 )
themeText.anchorX, themeText.anchorY = 0, 0
themeText.x, themeText.y = leftIndent, (woodPanel.y - woodPanel.height) + 20
themeText:setFillColor( colorConverter(236, 210, 135, 1) )
return true
end
–[[
SCENARIO:
I start the app with the sql query showing all rows in db without any limit, like this:
“SELECT * FROM birds”
The function over called functionSqlView() produces sql queries based on what buttons i decide to click on.
Let´s say I hit two buttons, then my sql query could look like this:
“SELECT * FROM birds WHERE WINGS = ‘Long’ AND TAIL = ‘Short’”
WHAT COMES HERE IS WHAT I REALLY DONT KNOW!!
- I GOT TO TRAVERSE THE RIGHT ROWS FROM THE DB
- THE LIST OF BIRDS IN THE TABLEVIEW WILL SHOW LESSER AND LESSER ENTRIES
THE MORE I NARROW THE SEARCH.
–]]
function updateSql(event)
tableView:deleteAllRows() – FIRST I LIKE TO REMOVE THE ROWS AND THAT WORKS OF COURSE
for i = 1, #dbTable do
local isCategory = false
local rowHeight = 70
local rowColor = {
default = { colorConverter(114, 72, 30, 0) },
}
local lineColor = { colorConverter(20, 20, 0, 0) }
– Insert the row into the tableView
tableView:insertRow
{
– isCategory = isCategory,
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
}
end
end
– THIS ONE WORKS NICE AND IT TAKES YOU OVER TO A SPEC PAGE AND SO ON…
local function birdSpec(self, event)
if event.phase == “began” then
if _G.debug == 1 then print("** birdSpec: \n\n") end – DEBUG
_G.specPool.name = self.specName
_G.specPool.latin = self.specLatin
_G.specPool.info = self.specInfo
composer.gotoScene( “playSpecScene” )
elseif event.phase == “cancelled” or event.phase == “ended” then
end
return true
end
function onRowRender( event )
local phase = event.phase
local row = event.row
row.bg = display.newRoundedRect( 0, 0, display.contentWidth -48, 50, 12 )
row.bg.strokeWidth = 0
row.bg:setFillColor( colorConverter(236, 210, 135, 1) )
row.bg.alpha = 1
row.bg.anchorX = 1
row.bg.anchorY = 0
row.bg.x = display.contentWidth
row.bg.y = 10
row:insert( row.bg )
row.title = display.newText( row, dbTable[row.index].NAME, 0, 0, _G.msgFont , 24 )
row.title.x = leftIndent + 10
row.title.anchorX = 0
row.title.y = row.contentHeight * 0.15+ row.bg.y
row.title:setFillColor( colorConverter(114, 72, 30, 1) )
row.ingress = display.newText( row, dbTable[row.index].LATIN, 0, 0, _G.msgFont , 14 )
row.ingress.x = leftIndent + 10
row.ingress.anchorX = 0
row.ingress.y = row.title.y +20
row.ingress:setFillColor( colorConverter(114, 72, 30, 1) )
row.image = display.newImageRect(row, tostring(imagePath … dbTable[row.index].NAME) … “.jpg”, 45,45 )
row.image:addEventListener( “touch”, row.image)
row.image.touch = birdSpec
row.image.anchorX = 1
row.image.anchorY = 0.25
row.image.x = display.viewableContentWidth - row.image.width/2
row.image.y = row.title.y
– PARSE VARIABLE TO THE GLOBAL SPECPOOL TABLE
row.image.specName = dbTable[row.index].NAME
row.image.specLatin = dbTable[row.index].LATIN
row.image.specInfo = dbTable[row.index].INFO
end
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
--Bird.group = Bird.group
bg = display.newImageRect( bgImage, _W, _H, 375, 667, true )
bg.anchorX, bg.anchorY = 0, 0
bg.alpha = 1
sceneGroup:insert(bg)
leftRib = display.newImageRect( “leftRib.png”, 48, 793, true )
leftRib.anchorX, leftRib.anchorY = 0, 0
leftRib.alpha = 1
sceneGroup:insert(leftRib)
woodPanel = display.newImageRect( “woodPanel.png”, 375, 131, true )
woodPanel.x, woodPanel.y = display.contentWidth/2, display.contentHeight
woodPanel.anchorX, woodPanel.anchorY = 0.5, 1
woodPanel.alpha = 1
sceneGroup:insert(woodPanel)
themeText = display.newText( tostring(_G.catText), 0, 0, _G.msgFont , 18 )
themeText.anchorX, themeText.anchorY = 0, 0
themeText.x, themeText.y = leftIndent, (woodPanel.y - woodPanel.height) + 30
themeText:setFillColor( colorConverter(236, 210, 135, 1) )
sceneGroup:insert(themeText)
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
composer.removeHidden( )
elseif ( phase == “did” ) then
– load the data into a table array
– WHEN I FIRE IT UP THE FIRST TIME IT WILL SHOW ALL ENTRIES
if sql == nil then sql = “SELECT * FROM birds” print(“Initiated SQL *”) end
count = 0
for row in db:nrows(sql) do
count = count +1
dbTable[count]={}
dbTable[count].NAME = row.NAME
dbTable[count].LATIN = row.LATIN
dbTable[count].INFO = row.INFO
end
tableView = widget.newTableView
{
top = 0,
width = _W+1,
height = display.contentHeight,
hideBackground = true,
isBounceEnabled = true,
listener = tableViewListener,
onRowRender = onRowRender,
}
for i = 1, #dbTable do
local isCategory = false
local rowHeight = 70
local rowColor = {
default = { colorConverter(114, 72, 30, 0) },
}
local lineColor = { colorConverter(20, 20, 0, 0) }
– Insert the row into the tableView
tableView:insertRow
{
– isCategory = isCategory,
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
}
end
sceneGroup:insert(tableView)
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
if tableView and tableView:getNumRows()>1 then tableView:deleteAllRows()
print(“TableView iterated and deleted from scene hide in playGame”)
end
_G.catText = “”
updateCatText()
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/LUA]
Hope anyone can help me