Not creating the .db file in cellphone

before build and install the apk in the cellphone, it doesns create the data.db file but it does in the CoronaSimulator

in the code i have the line

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

and tried with this settings in the build.settings file

android =
usesPermissions =

Hi Darco, we’ll probably need more information…

Are you getting any errors? How are you verifying the file is not being created?
What’s your code for creating the file, and for reading the file?

This is the initial block of code,
the system.pathForFile is supposed to create the file right?

local settings = require( ‘settings’ )

local sqlite3 = require( ‘sqlite3’ )
local json = require( ‘json’ )
local syncLib = require( ‘libs.sync’ )

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

local function onSystemEvent( event )
if event.type == ‘applicationExit’ then

function _M.init()
for i = 1, #info do
local columns = table.concat( info[i][‘COLUMNS’], ', ’ )
local query = [[CREATE TABLE IF NOT EXISTS ]] … info[i][‘TABLE_NAME’] … [[(]] … columns … [[);]]
db:exec( query )

I did some test using the sample code from the documentation….

The first problem is that will create a new db file if none exists, and it doesn’t tell you if it was able to open an existing file or if it created a new one.

Here’s some code you can use to test with:

local sqlite3 = require( "sqlite3" )
local lfs = require("lfs")
local path = system.pathForFile( "data.db", system.DocumentsDirectory )

local fileInfo = display.newText("File info:", 0, 20, nil, 10)
	fileInfo.anchorX = 0
	fileInfo.anchorY = 0
local function createDB()
	local db = path )
		  CREATE TABLE test (id INTEGER PRIMARY KEY, content);
		  INSERT INTO test VALUES (NULL, 'Hello World');
		  INSERT INTO test VALUES (NULL, 'Hello Lua');
		  INSERT INTO test VALUES (NULL, 'Hello Sqlite3')
local function checkDBFile()
	local file =, "rb")
	if not file then
		fileInfo.text = "data.db Not found."
		return false
    local size = file:seek("end")    -- get file size
	fileInfo.text = "data.db found with size of size: " .. size
	return true

if not checkDBFile() then
	fileInfo.text = "Created new data.db."

-- read db content
local db = path )
for row in db:nrows("SELECT * FROM test") do
  local t = display.newText( row.content, 20, 50*, nil, 16 )
  t:setFillColor( 1, 0, 1 )