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 = sqlite3.open( path )
local function onSystemEvent( event )
if event.type == ‘applicationExit’ then
db:close()
end
end
function _M.init()
local info = settings.DATABASE.STRUCTURE_DATABASE
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 )
end
end
I did some test using the sample code from the documentation….
The first problem is that sqlite3.open() 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 = sqlite3.open( path )
db:exec[[
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')
]]
db:close()
end
local function checkDBFile()
local file = io.open(path, "rb")
if not file then
fileInfo.text = "data.db Not found."
return false
end
local size = file:seek("end") -- get file size
fileInfo.text = "data.db found with size of size: " .. size
return true
end
if not checkDBFile() then
createDB()
fileInfo.text = "Created new data.db."
end
-- read db content
local db = sqlite3.open( path )
for row in db:nrows("SELECT * FROM test") do
local t = display.newText( row.content, 20, 50*row.id, nil, 16 )
t:setFillColor( 1, 0, 1 )
end
thanks
i did an update to the solar2d in my computer and some changes and it worked, but now it work in some devices, like mine and my boss’s device, anyone else’s it doesn’t upload
A little of a few things
i’d need a new access token in laravel, i was using an already used one
this
local path = system.pathForFile( settings.DATABASE.DATABASE_NAME … ‘.db’ or ‘data.db’, system.DocumentsDirectory )
but the thing that annoys me is the thing that i can upload in my device but other people no
can be the “developers mode” in android? or im just crazy?
Not really sure what you mean by uploading, but either way, you’ll definitely need to be able to replicate the issue on your side or get some logs from the other devices with meaningful output, otherwise you’ll just be guessing what the issue could be.