New topic: How to create a *limited* in-memory SQLite database
<http://forums.realsoftware.com/viewtopic.php?t=47460> Page 1 of 1 [ 5 posts ] Previous topic | Next topic Author Message tseyfarth Post subject: How to create a *limited* in-memory SQLite databasePosted: Sun Mar 31, 2013 7:43 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 876 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 npalardy Post subject: Re: How to create a *limited* in-memory SQLite databasePosted: Sun Mar 31, 2013 8:52 pm Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7771 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) ââââââââââââââââââââââââââââââââââââââââââââââââââ Real Studio Developer Conference - April 23 - 26, 2013 http://www.realsoftware.com/community/realworld.php Top tseyfarth Post subject: Re: How to create a *limited* in-memory SQLite databasePosted: Sun Mar 31, 2013 9:03 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 876 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 HMARROQUINC Post subject: Re: How to create a *limited* in-memory SQLite databasePosted: Sun Mar 31, 2013 10:53 pm Joined: Sun Jan 25, 2009 5:11 pm Posts: 546 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 timhare Post subject: Re: How to create a *limited* in-memory SQLite databasePosted: Mon Apr 01, 2013 2:15 am Joined: Fri Jan 06, 2006 3:21 pm Posts: 12188 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 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 5 posts ]
-- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
