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 ) 
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Liane
  • 111
  • 10
  • possible duplicate of [How do I create an Sqlite3 database using luasql?](http://stackoverflow.com/questions/12395072/how-do-i-create-an-sqlite3-database-using-luasql) – Oliver Feb 11 '14 at 17:18

2 Answers2

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)

K09P
  • 480
  • 4
  • 13
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 )