SQLite newbie question

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jeffInt
Posts: 23
Joined: Tue Jun 17, 2008 8:29 pm

SQLite newbie question

Post by jeffInt » Sun Oct 12, 2008 9:53 pm

Am I correct in thinking that using SQLite within RR creates a memory resident database?

If so is there a way to save the database off to disk? If we can do this there must also be a way to reload it?

Regards

Jeff

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Sun Oct 12, 2008 10:54 pm

Your assumption is wrong. sqlite in rev always uses a file, that has to be saved somewhere, it can't do it's thing only in memory.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

jeffInt
Posts: 23
Joined: Tue Jun 17, 2008 8:29 pm

assumption not totally incorrect?

Post by jeffInt » Mon Oct 13, 2008 8:19 pm

I can't be totally off the mark in my assumption that RR creates a sqlite database in memory or the following should not work;

on mouseUp
global gConID
local tConID

put revOpenDatabase("sqlite",,,,,) into tConID
/* Note no database name given */
if tConID is"" then
answer warning "Problem creating or accesing database!"
else
answer information "Memo connected, your connection ID is: " &tConID
put tConID into gConID
end if

end mouseUp


When this code runs I get an integer returned which I can use to create a table

on mouseUp
global gConID
if gConID is "" then
answer information "No database is connected"
exit mouseUp
end if

local tSQL, tResult
put"CREATE TABLE apps(appID integer primary key, appName text, appRegCode text, appUserID)" into tSQL
revExecuteSQL gConID, tSQL
put the result into tResult
/*handleRevDBerror tResult*/
if the result is not empty then
answer warning the result
exit mouseUp
end if
answer information "Number of tables added: "& tResult
end mouseUp


If I look in the directory where my stack resides I see no sqlite db file.

I imagine that I need to do one of the following;

Save the database - using what commands?

Export the database (as SQL?) - using what commands?

Cheers

Jeff

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm
Location: Blenheim, New Zealand

Post by paul_gr » Mon Oct 13, 2008 8:46 pm

this will create a db file in the same folder as the stack.
You have to provide a path (just a filename will do) to get a file written to disk.

on mouseUp
global gConID
put revOpenDatabase("sqlite","lite_DB.db",,,,,,) into gConID
end mouseUp

Paul

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Mon Oct 13, 2008 9:20 pm

put revOpenDatabase("sqlite",,,,,) into tConID /* Note no database name given */
interesting i didn't know that was possible, i need to remember that, possible that i could need it some when.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

jeffInt
Posts: 23
Joined: Tue Jun 17, 2008 8:29 pm

Not getting what your getting

Post by jeffInt » Mon Oct 13, 2008 9:28 pm

Hmm. If I use my code I can connect, add a table and disconnect. If I reconnect then the table must be added again. This tells me that this database resides in memory. There is no file in the stack directory.

If I attempt to open a database with a filename (as you suggest) my code reports the following error "Unable to open the database file". Perhaps there is something wrong with my setup. Or do I need to create the db file with another app?

I am using RR studio 3.0 if this has a bearing.

Cheers

Jeff

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm
Location: Blenheim, New Zealand

Post by paul_gr » Mon Oct 13, 2008 9:38 pm

Have you had a look at the sample sqlite stack in your rev installation folder?
it's called SQLite Sampler.rev, and it's in the resources/examples folder.

Paul

PS, couple of sentences from "The definitive guide to sqlite"

"SQLite can also create in-memory databases. In most extensions, if you use :memory: or an empty string as the name for the database, it will create the database in RAM. The database will only be accessible to the connection that created it (it cannot be shared with other connections).
Furthermore, the database will only last for the duration of the connection. It is deleted from memory when the connection closes.
When you connect to a database on disk, SQLite opens a file, if it exists. If you try to open a file that doesn’t exist, SQLite will assume that you want to create a new database. In this case, SQLite doesn’t immediately create a new operating system file. It will only create a new file if you put something into the new database—create a table or view or other database object. If you just open a new database, do nothing, and close it, SQLite does not bother with creating a database file—it would just be an empty file anyway."
Last edited by paul_gr on Mon Oct 13, 2008 10:06 pm, edited 1 time in total.

jeffInt
Posts: 23
Joined: Tue Jun 17, 2008 8:29 pm

sqlite example

Post by jeffInt » Mon Oct 13, 2008 10:03 pm

Yes I have tried to run the sqlite example stack. This gives me an error when I try the first "connect" button "Database error: Unable to open the database file.

Jeff
Chat with other RunRev developers, pop over to www.bjoernke.com/runrev/chatrev.php

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm
Location: Blenheim, New Zealand

Post by paul_gr » Mon Oct 13, 2008 10:09 pm

That's strange; I just tried the sample stack again using Rev Studio 3.0 and it works ok for me.

Paul

jeffInt
Posts: 23
Joined: Tue Jun 17, 2008 8:29 pm

There is something amiss!

Post by jeffInt » Mon Oct 13, 2008 10:17 pm

Hmm, perhaps something was not correctly installed. The RR app I am using is a downloaded version. I will perhaps re-install when I receive the CD copy.

Jeff
Chat with other RunRev developers, pop over to www.bjoernke.com/runrev/chatrev.php

jeffInt
Posts: 23
Joined: Tue Jun 17, 2008 8:29 pm

Called the cavalry

Post by jeffInt » Mon Oct 13, 2008 10:35 pm

I have posted a request for help with RunRev, perhaps they can help clear the problem. I will post any further results as they arrive.

Jeff
Chat with other RunRev developers, pop over to www.bjoernke.com/runrev/chatrev.php

jeffInt
Posts: 23
Joined: Tue Jun 17, 2008 8:29 pm

Post by jeffInt » Tue Oct 14, 2008 6:51 pm

OK more news.

When I originally installed RunRev I did so from a user account. I actually ran the exe file as administrator on this user account. Now when I attempt run the SQLite example stack on this user account I get the errors we have talked about.

If I log on as administrator the SQLite example works fine.... almost. When I run the example I do not see the db file created, even if I add tables. However, if I alter the code within the example to qualify the file path i.e. C:\Appreg.db everything is sublime.

I hope we have all learned from this!

Regards

Jeff
Chat with other RunRev developers, pop over to www.bjoernke.com/runrev/chatrev.php

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Tue Oct 14, 2008 10:36 pm

Yes, not having writing rights to a hard disk or specific folder will prevent you from creating files there :)
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply

Return to “Databases”