Displaying Data in tableView from sqlite.db

As a real newbie, I copied code to show data from a string of data, which displayed in the tableView OK.  I then tried to adjust the main.lua to extract data from an sqlite database to display that in the tableView.  I know the data extract works as it prints the data in the Corona Simulator console. I am not handling the insert function correctly, but I am not sure to to do it.  Below is my main.lua (the original code is there remarked out).  Can someone put my on the right track please?  Thanks…Rob

local sqlite3 = require( “sqlite3” )

local widget = require( “widget” )

local path = system.pathForFile( “GolfCourses.db”, system.DocumentsDirectory )

local db = sqlite3.open( path )

local top = display.statusBarHeight

local listRecs ={}

local list = nil

–***********************************************

– Was namedata list but trying to get from db

–***********************************************

–local nameData = {“Smith”, “Johnson”, “Williams”, “Jones”, “Brown”, “Davis”, “Miller”, “Wilson”, “Moore”, “Taylor”, “Anderson”, “Thomas”, “Jackson”, “White”, “Harris”}

local nameData ={}

local RecNos = 0

local function setup()

    local bg = display.newRect(0,top, display.contentWidth, display.contentHeight - top)

    bg:setFillColor(0,155,73)

    

    list = widget.newTableView {top = top +10, height = 304 , onRowRender = onRowRender, onRowTouch = onRowTouch,}

    --maskFile = “mask.png”

end

z = 0

local function loadData()

for x in db:nrows(“SELECT DISTINCT Course FROM NSW”) do

listRecs[x] = {}

listRecs[x].name = x.Course

listRecs[x].showDel = false

z = (z + 1)

print(listRecs[x].name …" "… z )

    --for x =1 , #nameData do

       – listRecs[x] = {}

       – listRecs[x].name = nameData[x]

       – listRecs[x].age = math.random(18,35)

       – listRecs[x].showDel = false

       – print(listRecs[x].name…" "…listRecs[x].age)

    --end

end

–print(RecNos)

end

function onRowRender(event)

    local row = event.row

    local groupContentHeight = row.contentHeight

    local idx = row.index or 0

   – print("the index value is: "…idx)

    local textObj = display.newText( row, listRecs[idx].name, 0, 0, native.systemFontBold, 14 )

    textObj.x = 20

    textObj.anchorX = 0

    textObj.y = groupContentHeight * 0.35

    textObj:setFillColor( 0, 0, 0 )  

   – local textObj2 = display.newText( row, listRecs[idx].age, 0, 0, native.systemFontBold, 14 )

   – textObj2.x = 20

   – textObj2.anchorX = 0

   – textObj2.y = groupContentHeight * 0.65

   --textObj2:setFillColor( 0, 0, 0 )  

end 

– onRowRender

local function showRecords()

local function rowListener(event)

end – row Listener

for x = 1, #listRecs do

       list:insertRow{

    }

end

end – showRecords

local function onSystemEvent( event )

    if ( event.type == “applicationExit” ) then

        if ( db and db:isopen() ) then

            db:close()

        end

    end

end

setup()

loadData()

showRecords()