New topic: export/import tables rsd
<http://forums.realsoftware.com/viewtopic.php?t=46994> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message vfran Post subject: export/import tables rsdPosted: Tue Feb 19, 2013 6:14 am Joined: Mon Dec 07, 2009 7:30 pm Posts: 114 Location: Europe/Italy I have a rsd database with a few tables that users should be able to export and import for backup purposes. I want user to be able to select which tables eg(userfoodbase, userexercises, userworkouts etc) he wants to export. And when importing the various tables again later simply replacing the existing ones. What is the best way to do this? Can anyone one point me in the right direction? Thanks. Top Stuart J Sykes Post subject: Re: export/import tables rsdPosted: Tue Feb 19, 2013 8:04 am Joined: Fri Oct 26, 2012 6:24 am Posts: 67 Hi vfran Ok, one way is to EXPORT the data from each of the tables as a CSV file, then IMPORT the data back into the database when required? This has the added advantage of being able to be Imported into any spreadsheet program. Im assuming you are displaying your data in a listbox? if so... You need 2 buttons (Export Data & Import Data) for each of the listbox's (each table) - Here's how to export Listbox 1 (Table1) EXPORTING: dim f as FolderItem dim s as String dim i,j as Integer 'Show the file selector f=GetSaveFolderItem("text/plain","Table1.csv") if f=nil then exit sub dim tos as TextOutputStream = TextOutputStream.Create(f) if tos = Nil then MsgBox("The file could not be created!") exit sub end if if Listbox1.ListCount>0 then for i = 0 to Listbox1.ListCount-1 s="" for j=1 to Listbox1.ColumnCount-1 s=s+Listbox1.Cell(i,j)+ "," next tos.WriteLine s.left(s.len-1) next end if tos.Close (Of course using a comma separated values file means that your data should be free from commas (or whatever delimiter used)) IMPORTING the CSV file back into the Table is a little bit more complex and I would need a bit more info as to table and field names, but heres the Method for parsing the CSV file.. Create a Method called ImportList with the parameters: FileName As String, FilePath As String, List As ListBox Dim f as FolderItem Dim TextIn As TextInputStream Dim count,i,r, x As Integer Dim line,c,s As String count = List.ColumnCount List.DeleteAllRows f = GetFolderItem(FilePath) If f <> Nil then // check to make sure the file exists //TextIn = f.OpenAsTextFile TextIn = TextInputStream.Open(f) If TextIn <> NIL Then Do // read a line line = TextIn.ReadLine // add a row in the listbox List.AddRow "" For i = 1 To count // read the data c = NthField(line,Chr(44),i) r = List.LastIndex x = Len(c) s = Mid(c,1,(x)) //To strip off any enclosing quotes use this instead //s = Mid(c,2,(x-2)) // put the data in the cell List.Cell(r,(i)) = s Next Loop Until TextIn.EOF = True End If Else // error message MsgBox "Error Reading input file: " + FileName End If To call the Method use: ImportList(fName,pName,ListBox1) //where fName if the Filename - pName is the Path name _________________ Stuart J Sykes - www.real-soft.co.uk Mountain Lion 10.8.2 (Real Studio 2012 2.1) Top vfran Post subject: Re: export/import tables rsdPosted: Tue Feb 19, 2013 10:13 am Joined: Mon Dec 07, 2009 7:30 pm Posts: 114 Location: Europe/Italy Hey Stuart, thanks I will be looking into the CSV idea Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 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]
