Install sqlite3

Hi there,

I’ve been searching and can’t find the answer. I just need to know how to install sqlite3 so that it will work with corona and lua. The instructions in the docs section is not very helpful with installing nor is the documentation that comes with sqlite3. I am familiar with installing and using MSSQL Server however I’m lost with sqlite. Can anyone help me out with advice or useful links? Thanks for any help you can provide. [import]uid: 31262 topic_id: 5914 reply_id: 305914[/import]

You actually don’t need to install sqlite3, it’s bundled with corona. You just need to include it in your lua code like this: [lua]require “sqlite3”[/lua]
Then you can load a database, create tables and rows, etc. http://developer.anscamobile.com/content/data-storage has a lot of good info for using sqlite. Hope that helps! [import]uid: 8782 topic_id: 5914 reply_id: 20297[/import]

You should be able to just run a script. It’s already a part of Corona.

[lua]require “sqlite3”
local db = sqlite3.open_memory()

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’)
]]

print( "version " … sqlite3.version() )

for row in db:nrows(“SELECT * FROM test”) do
local t = display.newText(row.content, 20, 30 * row.id, null, 16)
t:setTextColor(255,0,255)
end[/lua]

See http://developer.anscamobile.com/content/data-storage [import]uid: 8045 topic_id: 5914 reply_id: 20298[/import]

NayGames, you beat my post by 2 seconds :smiley:

lol…

[import]uid: 8045 topic_id: 5914 reply_id: 20299[/import]

Thanks for the reply guys, you’re both awesome. Another question though… Does Corona store the database file separately like when you use Xcode? I guess that is what was confusing me. What if I wanted to make changes to the database outside of the app, could I do that? [import]uid: 31262 topic_id: 5914 reply_id: 20366[/import]

Hey NayGames, I was just wondering what you would recommend as being the best way for reseting a level. I have an object, and if it falls below the screen, then it will reset the level. Kind of like brick breaker.

I can’t find any good examples of what I’m attempting to accomplish.

Ps: I’m currently working with the director class.
Thanks

[import]uid: 42126 topic_id: 5914 reply_id: 32202[/import]

Two ways to do it.

  1. Reset all the variables

  2. Restart the level, but don’t save anything.

If you’re using director class 1.2 then you will need a loading.lua
[import]uid: 12455 topic_id: 5914 reply_id: 32204[/import]

Seems like the easiest way to do it would be to remove the localGroup and call a new() function.

That way you wont need a loading.lua file and speed performance will be better [import]uid: 42126 topic_id: 5914 reply_id: 32299[/import]

Does Corona store the database file separately like when you use Xcode?

Yes. If you look at the docs they create a file called “data.db”

In the simulator the directory system.DocumentsDirectory is in the sandbox mentioned in the Terminal output. [import]uid: 12108 topic_id: 5914 reply_id: 32309[/import]