2

I have problem in creating a database I find no errors but still no database in my documents folder

here is my code :

local sqlite3 = require "sqlite3"

local path = system.pathForFile( "data.db", system.DocumentsDirectory )
local db = sqlite3.open( path ) 
1

2 Answers 2

0

Try to check this out:

http://sqlite.org/cintro.html

I know it is aiming to C and C++. But maybe you can translate from one language to another. I'd do it for you, but I don't actually know Lua =/

Also, check the value of system.DocumentsDirectory to be sure you're looking in the right place (and why not, check for user rights)

Sign up to request clarification or add additional context in comments.

Comments

0

You have to add some data to create it.

local tablesetup = [[CREATE TABLE IF NOT EXISTS place (id INTEGER PRIMARY KEY, name, xcor, ycor);]]
db:exec( tablesetup )

local testvalue = {}
testvalue[1] = 'Name6'
testvalue[2] = 'x'
testvalue[3] = 'y'
local tablefill =[[INSERT INTO place VALUES (']]..x..[[',']]..testvalue[1]..[[',']]..testvalue[2]..[[',']]..testvalue[3]..[[')  ]]

also remember to use this to close it after app exits.

local function onSystemEvent( event )
        if( event.type == "applicationExit" ) then              
            db:close()
        end
end

Runtime:addEventListener( "system", onSystemEvent )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.