Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue May 22, 2018 10:23 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to create a *limited* in-memory SQLite database
PostPosted: Sun Mar 31, 2013 7:43 pm 
Offline

Joined: Sat Dec 04, 2010 9:14 pm
Posts: 918
Hello all,

Can anyone tell me how to create an in-memory SQLite database. I would like to limit it to only certain tables, since the whole db is not necessary. Basically tables that hold configuration data. I am a bit skittish to do this with tables that need data written to them, since there is an opportunity to loose data - for many reasons!

Thank you,
Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: How to create a *limited* in-memory SQLite database
PostPosted: Sun Mar 31, 2013 8:52 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
tseyfarth wrote:
Hello all,

Can anyone tell me how to create an in-memory SQLite database. I would like to limit it to only certain tables, since the whole db is not necessary. Basically tables that hold configuration data. I am a bit skittish to do this with tables that need data written to them, since there is an opportunity to loose data - for many reasons!

Thank you,
Tim


An in memory database would disappear every time the program was shut down
Not sure that's what you want ?

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: How to create a *limited* in-memory SQLite database
PostPosted: Sun Mar 31, 2013 9:03 pm 
Offline

Joined: Sat Dec 04, 2010 9:14 pm
Posts: 918
Hello npalardy,

The in memory would be a copy of the certain tables that are used frequently during the executiion of the application. It would serve the purpose of having the data available to many objects, but without creating individual properties or local variables for each of them. I *think* it would be faster and more convenient than having several copies of the tables open in various objects - not sure about which is better either however.

The loss of the data on app shutdown is why I would only utilize "read" data, that contains app config data. On app start, it would read and load that data into memory for use by any object that requires it within the application.

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: How to create a *limited* in-memory SQLite database
PostPosted: Sun Mar 31, 2013 10:53 pm 
Offline
User avatar

Joined: Sun Jan 25, 2009 5:11 pm
Posts: 576
Location: Guatemala, Central America
Something like this:

dim db as new REALSQLDatabase

if db.Connect = false then
MsgBox "Failed to create the database "
exit
end if

// Now you got yourself an in-memory database, create the tables
dim s as string
s = "Create table Test1(id integer primary key, field1 text, field2 text)"
db.SQLExecute(s)
if db.Error then
MsgBox "Error creating the database " + EndOfLine + _
CStr(db.ErrorCode) + " - " + db.ErrorMessage
end if

// Now fill table with some data
dim rec as DatabaseRecord
dim i as integer
for i = 1 to 10
rec = new DatabaseRecord
rec.Column("field1") = "Test " + CStr(i)
rec.Column("field2") = "Something here"
db.InsertRecord("Test1", rec)
if db.error then
MsgBox "Error inserting the record" + EndOfLine + _
CStr(db.ErrorCode) + " - " + db.ErrorMessage
exit
end if
next i

_________________
Future RS guru.
Ride the world!


Top
 Profile  
Reply with quote  
 Post subject: Re: How to create a *limited* in-memory SQLite database
PostPosted: Mon Apr 01, 2013 2:15 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
For config info, I use a Dictionary. I have a db table of name/value pairs that I read into a dictionary on app startup and write back out on app exit. It's much more convenient than an in-memory database. If your config data can be represented as name/value pairs, I would highly recommend the dictionary approach. Use method overloading on some getter/setter methods to make it really convenient - no explicit data conversions required.

dim s as string = configvalue("name")
dim i as integer = configvalue("count")
dim d as date = configvalue("lastrun")


Top
 Profile  
Reply with quote  
 Post subject: Re: How to create a *limited* in-memory SQLite database
PostPosted: Mon Apr 01, 2013 12:53 pm 
Offline

Joined: Sat Dec 04, 2010 9:14 pm
Posts: 918
Good idea Tim - Thank you!
Tim


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group