SOLVED] Sqlite with LUA

Hello,

My problem is when i make the connection and try to access the table.
I'm using the sqlite manager to create database and tables.
My database is in teh same folder of main.lua

The Error:

1
2
3
[C]: in function 'nrows'
in main chunk
Runtime error: no such table: myTable

NOTE: When providing a file path to open(), make sure to use system.pathForFile(). Providing just a plain file name such as "my.db" will not work consistently across the simulator and devices, especially on Android (see system.ResourceDirectory).

http://developer.anscamobile.com/reference/index/sqlite3

Hello Danny,

I make how you said, but the same error happens.

The Error

1
2
3
4
Runtime error: no such table: myTable
stack traceback:
        [C]: ?
        [C]: in function 'nrows'

Your first line is wrong (i presume the sql db is in the root directory)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
local path = system.pathForFile("myApp.db", system.ResourceDirectory)
db = sqlite3.open( path ) 
 
 
local function onSystemEvent(event)
        if(event.type == "applicationExit") then
                db:close();
        end
end
 
local sql = "select * from myTable"
 
for row in db:nrows(sql) do
        print(row.nome)
end
 
Runtime:addEventListener("system", onSystemEvent)

when you use system.DocumentsDirectory you have to put your database in the same path as your corona sdk installation.
I made it and now works correctly.

Thanks.

views:2169 update:2012/2/9 11:37:26
corona forums © 2003-2011