I’ll explain the basic steps to access SQLite database and loop through records in a table using Corona sdk.

Create sqlite database. (here I created country_capital.sqlite.)
Create table tbl_country_capital with the columns country and capital.

Copy the code below, paste it in main.lua file and execute it.. You’ll be able to see your table contents

-- inlcude sqlite db

require "sqlite3"


-- set the database path, here its the same folder where main.lua file resides.

local path = system.pathForFile("country_capital.sqlite", system.ResourceDirectory)

-- open db
db = sqlite3.open( path )
-- a variable to dynamically change the Y coordinate

local count = 1
-- sql query
local sql = "SELECT * FROM tbl_country_capital"
-- looping through result set and printing the output.

for row in db:nrows(sql) do

local text = row.country..", "..row.capital.." "
local t = display.newText(text, 50, 50 +(40 * count), native.systemFont, 30)
t:setTextColor(255,255,255)
count = count + 1
end


 

Incoming search terms:

  • print sql data on corona
  • corona sdk search sqllite
  • corona sdk sqlite tutorial
  • corona sql database
  • database corona sdk
  • putting data from sql database into tables corona
  • sqlite module corona

Tagged with:

Filed under: AndroidiPhone

Like this post? Subscribe to my RSS feed and get loads more!