|
Re: Exporting Object Memory: msg#00076lang.smalltalk.squeak.beginners
Chris Cunnington wrote: If I had data in object memory, because I've saved answers from a user intoThe end-user data is presumable stored in your application's object model. Normally for me that is some kind of "database" class. Let's call it "Database" and assume it understands #default (which returns the only Database instance). There are lots of ways to answer your question so let me mention a couple in increasing order of work involved: You could export your data as XML using SIXX (load from SqueakMap). You could export your data in binary format using ImageSegments You could write your data to CSV Using SIXX you would just do this: s := SixxWriteStream newFileNamed: 'myData.sixx'. s nextPut: Database default. s close. That's it. You can read your data back in using a SixxReadStream. Now, while SIXX is the easiest that I can think of you mentioned CSV so I'll assume you want it in that format for some reason. In any case, if XML is good enough just write your data to a file with: Let's further suppose that the database instance understands #data which answers a collection of data items that all understand #printCSVOn:. Then I'd write that database to a file with: fileStream := FileDirectory current newFileNamed: 'someFile.csv'. [Database default data do: [:dataItem | dataItem printCSVOn: fileStream. fileStream cr]] ensure: [fileStream close]. Notice that I make sure that the fileStream get's closed even if there is an error during the writing. Now, of course, the real work is in printCSVOn: which obviously depends on your data. Suppose you have an Account class which has i-vars for accountNumber, ownerName, ownerPhoneNumber. You could write them out with: Account>>printCSVOn: aStream aStream nextPutAll: '"' , accountNumber , '",'. aStream nextPutAll: '"' , ownerName ,'",'. aStream nextPutAll: '"' , ownerPhoneNumber ,'"'. Of course CSV will probably be useless if your database has more than one type of thing in it (each line will have different columns). You could modify this example so that each different kind of thing stored in your database is written to a different file. HTH, David
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Exporting Object Memory, Herbert König |
|---|---|
| Next by Date: | Re: Exporting Object Memory, Chris Cunnington |
| Previous by Thread: | Re: Exporting Object Memory, Herbert König |
| Next by Thread: | Re: Exporting Object Memory, Chris Cunnington |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |