New topic: 

Exporing database from project to file

<http://forums.realsoftware.com/viewtopic.php?t=34181>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        rebrandsoftware          Post subject: Exporing database from 
project to filePosted: Tue Jun 08, 2010 4:34 pm                                 
Joined: Wed Mar 25, 2009 4:30 pm
Posts: 86
Location: Alexandria, VA, USA                Hi Everyone,

I'm trying to avoid having an installer for my application but I need to 
provide some initial data in a database that is stored on the hard drive.  This 
is what I want to do:

-Check to see if the database exists on the user's hard drive
-If it does not exist, copy an internal copy of the database to the hard drive

So I dragged the copy of the database that I want to include into the IDE 
thinking I could then access it as text, or as a folderitem.  However, RB 
immediately identifies it as a database so I can't use a TextOutputStream to 
write it to the drive.

Any help would be greatly appreciated.

Thanks!

-Mike

An alternate but more difficult solution would be to create a blank database on 
file with the same table structure, and then copy all the data from my internal 
database to the external database.  I think I have this working now but it's 
very tedious because of the large number of columns in my database.

Code:  Dim testDb As New REALSQLDatabase
  dim dbr as new DatabaseRecord
  dim sql as string

  If testDb.CreateDatabaseFile Then
  // Database is now available for use
  testDb.SQLExecute("CREATE TABLE tblChannels (channel_id INTEGER, channel_name 
TEXT);")
   // Creates a duplicate empty database on the hard drive
  testDB.Commit
  
   
    // Connect to the database in my project, named "TV"
    sql = "select * from tblChannels"
    dim rs as RecordSet = TV.SQLSelect(sql)
    while not (rs.eof or rs.bof)
    dbr.IntegerColumn("channel_id") = rs.Field("channel_id").IntegerValue
    dbr.Column("channel_name") = rs.Field("channel_name").StringValue
    testdb.insertRecord "tblChannels", dbr
    rs.MoveNext
    wend
    testdb.commit
    testdb.close
  end if
  end if
   
                             Top                 timhare          Post subject: 
Re: Exporing database from project to filePosted: Tue Jun 08, 2010 5:00 pm      
                   
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 7873
Location: Portland, OR  USA                Change the extension of the file 
(eg., to .txt) before you drag it into the project.  If RB doesn't recognize 
the file, it becomes a string contsant.  Later, you simply create a file of the 
appropriate name/type and write that string to it.   
                             Top                rebrandsoftware          Post 
subject: Re: Exporing database from project to filePosted: Tue Jun 08, 2010 
7:02 pm                                 
Joined: Wed Mar 25, 2009 4:30 pm
Posts: 86
Location: Alexandria, VA, USA                Thanks for the reply.  I tried 
that at the suggestion of some forum posts but no matter what I changed it to 
(.txt, .xyz, .dat) it always recognized it as a database.   
                             Top                 timhare          Post subject: 
Re: Exporing database from project to filePosted: Tue Jun 08, 2010 7:22 pm      
                   
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 7873
Location: Portland, OR  USA                Must be on Mac.  Change the creator 
codes, etc.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 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]

Reply via email to