Text/Data not visible on SQLite table.

I’m having an issue with the SQLite table. I’m sure its something in my code. When I create the table the only things that show are the rows themselves. The actual data is missing. Its just blank rows (which do correspond to how many I have in the SQLite database file). What is wrong in my code?

require ("sqlite3") local path = system.pathForFile("test.db", systemDocumentsDirectory) local db = sqlite3.open( path ) local table\_options = { top = 50, onRowRender = onRowRender, } local tableView = widget.newTableView( table\_options ) for row in db:nrows("SELECT \* FROM project") do local rowParams = { id = row.id, name = row.name, description = row.description, number = row.number, } tableView:insertRow( { rowHeight = 30, rowColor = { default={0.8,0.8,0.8,0.8} } lineColor = { 1, 0, 0 } params = rowParams, } ) end local function onRowRender( event ) local row = event.row local font = native.systemFont local fontsize = 25 local rowHeight = row.height / 2 local options\_id = { parent = row, text = row.params.id, x = 50, y = rowHeight, font = font, fontSize = fontSize, } row.id = display.newText( options\_id ) row.id.anchorX = 0 row.id:setFillColor( 155, 152, 253 ) local options\_name = { parent = row, text = row.params.name, x = 100, y = rowHeight, font = font, fontSize = fontSize, } row.name = display.newText( options\_name ) row.name.anchorX = 0 row.name:setFillColor( 1, 12, 23 ) local options\_description = { parent = row, text = row.params.description, x = 150, y = rowHeight, font = font, fontSize = fontSize, } row.description = display.newText( options\_description ) row.description.anchorX = 0 row.description:setFillColor( 1, 12, 23 ) local options\_number = { parent = row, text = row.params.number, x = 200, y = rowHeight, font = font, fontSize = fontSize, } row.number = display.newText( options\_number ) row.number.anchorX = 0 row.number:setFillColor( 1, 12, 23 ) sceneGroup:insert(row.id) sceneGroup:insert(row.name) sceneGroup:insert(row.description) sceneGroup:insert(row.number) end -------------------------------------------------------------------------- end

This could be a very “Doh!” problem. Is your background by any chance white?

row.id:setFillColor( 155, 152, 253 )

Corona colors are in the 0…1 range, not 0…255. So the above line of code is creating white text.  I see  you’re setting the row color to 80% gray, but it’s something to look at. You can also put in some print statements to print the values you’re retrieving from the database. Then look in the console log and see what you’re getting.

Rob

I’ve fixed the colors but still nothing. I changed them once I saw white in the first place but did not realize I did not add a decimal. this is what I get.

https://www.dropbox.com/s/k40u78oo7mdiutc/Untitled.jpg?dl=0

Did you add some print statements in your onRowRender() to print out the text you’re expecting to make sure it’s really there?

Yup, and nothing prints. So what does this mean?

Maybe print the value of the row’s returned by the query?

 for row in db:nrows("SELECT \* FROM project") do print( json.prettify( row ) ) --\<------ add this, you will need to require the json library local rowParams = { id = row.id, name = row.name, description = row.description, number = row.number, }

If that’s not showing anything  you will need to look at how your data got into the database to begin with and make sure the database is actually populated.

Rob

They are printing now.

https://www.dropbox.com/s/9g9mqik2oqrtbzp/Untitled2.jpg?dl=0

So would this be still a color issue? I’ve changed the color multiple times.

Copy/Paste works much better than screen shots :wink:

If you’re prints in onRowRender are not printing any values, then colors are likely not a problem. Can you repost your current code?

Thanks

Rob

Sorry about that. Here is the code for the entire page.

local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) require ("sqlite3") local path = system.pathForFile("test.db", systemDocumentsDirectory) local db = sqlite3.open( path ) local json = require( "json" ) function scene:create( event ) local sceneGroup = self.view local background = display.newImage("carbonfiber.jpg") -- flag overrides large image downscaling background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 sceneGroup:insert(background) local roundedRect = display.newRoundedRect( 40, 10, 500, 40, 8 ) roundedRect.anchorX, roundedRect.anchorY = 0.0, 0.0 -- simulate TopLeft alignment roundedRect:setFillColor( 0/255, 0/255, 0/255, 170/255 ) sceneGroup:insert(roundedRect) local roundedRectt = display.newRoundedRect( 40, 250, 500, 40, 8 ) roundedRectt.anchorX, roundedRectt.anchorY = 0.0, 0.0 -- simulate TopLeft alignment roundedRectt:setFillColor( 0/255, 0/255, 0/255, 170/255 ) sceneGroup:insert(roundedRectt) local t = display.newText( "Stadium Pub", 0, 0, native.systemFont, 15 ) t.x, t.y = display.contentCenterX, 20 sceneGroup:insert(t) local tr = display.newText( "Image Gallery Research Station", 0, 0, native.systemFont, 15 ) tr.x, tr.y = display.contentCenterX, 40 sceneGroup:insert(tr) ----------------------------------SQLite---------------------------------- require ("sqlite3") local path = system.pathForFile("test.db", systemDocumentsDirectory) local db = sqlite3.open( path ) local table\_options = { top = 50, onRowRender = onRowRender, } local tableView = widget.newTableView( table\_options ) for row in db:nrows("SELECT \* FROM project") do print( json.prettify( row ) ) --\<------ add this, you will need to require the json library local rowParams = { id = row.id, name = row.name, description = row.description, number = row.number, } tableView:insertRow( { rowHeight = 30, rowColor = { default={0.8,0.8,0.8,0.8} }, lineColor = { 1, 0, 0 }, params = rowParams, } ) end local function onRowRender( event ) local row = event.row local font = native.systemFont local fontsize = 25 local rowHeight = row.height / 2 local options\_id = { parent = row, text = row.params.id, x = 50, y = rowHeight, font = font, fontSize = fontSize, } row.id = display.newText( options\_id ) row.id.anchorX = 0 row.id:setFillColor( .4, .4, .4 ) local options\_name = { parent = row, text = row.params.name, x = 100, y = rowHeight, font = font, fontSize = fontSize, } row.name = display.newText( options\_name ) row.name.anchorX = 0 row.name:setFillColor( .4, .4, .4 ) local options\_description = { parent = row, text = row.params.description, x = 150, y = rowHeight, font = font, fontSize = fontSize, } row.description = display.newText( options\_description ) row.description.anchorX = 0 row.description:setFillColor( .4, .4, .4 ) local options\_number = { parent = row, text = row.params.number, x = 200, y = rowHeight, font = font, fontSize = fontSize, } row.number = display.newText( options\_number ) row.number.anchorX = 0 row.number:setFillColor( .4, .4, .4 ) sceneGroup:insert(row.id) sceneGroup:insert(row.name) sceneGroup:insert(row.description) sceneGroup:insert(row.number) end -------------------------------------------------------------------------- end ------- function scene:show( event ) local sceneGroup = self.view end function scene:hide( event ) local sceneGroup = self.view end function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

Found it…

You have a basic “scope” problem.

When you create your tableView, Lua doesn’t know about the function onRowRender yet. Lua is a one-pass compiler system, which means you have to define something before it can be used.  Therefore this code:

local table\_options = { top = 50, onRowRender = onRowRender, } local tableView = widget.newTableView( table\_options )

turns into this:

local table\_options = { top = 50, onRowRender = nil, } local tableView = widget.newTableView( table\_options )

since the function onRowRender() is below this block of code. If you move that function someplace before you create the tableView you should start working.

That said, I would put it above scene:create(). I’m not fond of nested functions.

Also you open the database twice, once at the very top of the module and once inside of scene:create(). I’d take the one at the top out.

Rob

That did it!! Funny thing is I noticed this earlier but didn’t move the function out of scene:create() just above the onRowRender code (possibly also did something else) and it crashed so I put it back and wrote this post. Thanks so much for your help! Also that weather app you pointed out to me has the exact function I was looking for!

This could be a very “Doh!” problem. Is your background by any chance white?

row.id:setFillColor( 155, 152, 253 )

Corona colors are in the 0…1 range, not 0…255. So the above line of code is creating white text.  I see  you’re setting the row color to 80% gray, but it’s something to look at. You can also put in some print statements to print the values you’re retrieving from the database. Then look in the console log and see what you’re getting.

Rob

I’ve fixed the colors but still nothing. I changed them once I saw white in the first place but did not realize I did not add a decimal. this is what I get.

https://www.dropbox.com/s/k40u78oo7mdiutc/Untitled.jpg?dl=0

Did you add some print statements in your onRowRender() to print out the text you’re expecting to make sure it’s really there?

Yup, and nothing prints. So what does this mean?

Maybe print the value of the row’s returned by the query?

 for row in db:nrows("SELECT \* FROM project") do print( json.prettify( row ) ) --\<------ add this, you will need to require the json library local rowParams = { id = row.id, name = row.name, description = row.description, number = row.number, }

If that’s not showing anything  you will need to look at how your data got into the database to begin with and make sure the database is actually populated.

Rob

They are printing now.

https://www.dropbox.com/s/9g9mqik2oqrtbzp/Untitled2.jpg?dl=0

So would this be still a color issue? I’ve changed the color multiple times.

Copy/Paste works much better than screen shots :wink:

If you’re prints in onRowRender are not printing any values, then colors are likely not a problem. Can you repost your current code?

Thanks

Rob

Sorry about that. Here is the code for the entire page.

local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) require ("sqlite3") local path = system.pathForFile("test.db", systemDocumentsDirectory) local db = sqlite3.open( path ) local json = require( "json" ) function scene:create( event ) local sceneGroup = self.view local background = display.newImage("carbonfiber.jpg") -- flag overrides large image downscaling background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 sceneGroup:insert(background) local roundedRect = display.newRoundedRect( 40, 10, 500, 40, 8 ) roundedRect.anchorX, roundedRect.anchorY = 0.0, 0.0 -- simulate TopLeft alignment roundedRect:setFillColor( 0/255, 0/255, 0/255, 170/255 ) sceneGroup:insert(roundedRect) local roundedRectt = display.newRoundedRect( 40, 250, 500, 40, 8 ) roundedRectt.anchorX, roundedRectt.anchorY = 0.0, 0.0 -- simulate TopLeft alignment roundedRectt:setFillColor( 0/255, 0/255, 0/255, 170/255 ) sceneGroup:insert(roundedRectt) local t = display.newText( "Stadium Pub", 0, 0, native.systemFont, 15 ) t.x, t.y = display.contentCenterX, 20 sceneGroup:insert(t) local tr = display.newText( "Image Gallery Research Station", 0, 0, native.systemFont, 15 ) tr.x, tr.y = display.contentCenterX, 40 sceneGroup:insert(tr) ----------------------------------SQLite---------------------------------- require ("sqlite3") local path = system.pathForFile("test.db", systemDocumentsDirectory) local db = sqlite3.open( path ) local table\_options = { top = 50, onRowRender = onRowRender, } local tableView = widget.newTableView( table\_options ) for row in db:nrows("SELECT \* FROM project") do print( json.prettify( row ) ) --\<------ add this, you will need to require the json library local rowParams = { id = row.id, name = row.name, description = row.description, number = row.number, } tableView:insertRow( { rowHeight = 30, rowColor = { default={0.8,0.8,0.8,0.8} }, lineColor = { 1, 0, 0 }, params = rowParams, } ) end local function onRowRender( event ) local row = event.row local font = native.systemFont local fontsize = 25 local rowHeight = row.height / 2 local options\_id = { parent = row, text = row.params.id, x = 50, y = rowHeight, font = font, fontSize = fontSize, } row.id = display.newText( options\_id ) row.id.anchorX = 0 row.id:setFillColor( .4, .4, .4 ) local options\_name = { parent = row, text = row.params.name, x = 100, y = rowHeight, font = font, fontSize = fontSize, } row.name = display.newText( options\_name ) row.name.anchorX = 0 row.name:setFillColor( .4, .4, .4 ) local options\_description = { parent = row, text = row.params.description, x = 150, y = rowHeight, font = font, fontSize = fontSize, } row.description = display.newText( options\_description ) row.description.anchorX = 0 row.description:setFillColor( .4, .4, .4 ) local options\_number = { parent = row, text = row.params.number, x = 200, y = rowHeight, font = font, fontSize = fontSize, } row.number = display.newText( options\_number ) row.number.anchorX = 0 row.number:setFillColor( .4, .4, .4 ) sceneGroup:insert(row.id) sceneGroup:insert(row.name) sceneGroup:insert(row.description) sceneGroup:insert(row.number) end -------------------------------------------------------------------------- end ------- function scene:show( event ) local sceneGroup = self.view end function scene:hide( event ) local sceneGroup = self.view end function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

Found it…

You have a basic “scope” problem.

When you create your tableView, Lua doesn’t know about the function onRowRender yet. Lua is a one-pass compiler system, which means you have to define something before it can be used.  Therefore this code:

local table\_options = { top = 50, onRowRender = onRowRender, } local tableView = widget.newTableView( table\_options )

turns into this:

local table\_options = { top = 50, onRowRender = nil, } local tableView = widget.newTableView( table\_options )

since the function onRowRender() is below this block of code. If you move that function someplace before you create the tableView you should start working.

That said, I would put it above scene:create(). I’m not fond of nested functions.

Also you open the database twice, once at the very top of the module and once inside of scene:create(). I’d take the one at the top out.

Rob