Version 26 of Anyone interested in doing a comma delimited database?

Updated 2012-07-08 22:21:27 by RLE

unperson Many years ago, in the glorious days of the pioneer DOS (we thought then Dos was the end of the world but by jolly! there was much more to come afterwards!), ['We thought' ? CMcC never thought of DOS as pioneering, or the endpoint of anything, merely a second-rate knockoff of a better system] there was an amazing database software called Rapid File programmed in Forth (another amazing programming language!).

I suspect it was in fact what we called then a comma-delimited database (what we call now a comma separated value database) therefore it was occupying close to nothing in terms of space. It was small, fast, elegant, innovative.

It was the kind of stuff RS would write; one module per week-end.

See more here: http://c2.com/cgi/wiki?RapidFile (I wrote most of the text on that page).

I think Tcl/Tk would lend itself very well to such a database.

The beauty with Rapid File was that it had an incorporated editor; it was a word processor, a database and a spreadheet! It was MS Office before its time. The spreadsheet part was in fact fields called calculated fields where one could enter formulas to calculate. Amazing!

Another amazing feature: the snapshots: you could enter a database and decide to define a snapshot; a snapshot was simply a feature enabling a user to save a few selected fields, to sort them in a particular way at entry etc.

A lot of people claim Rapid File had the best macro editor of all programs during the Dos period. I do agree with this statement. In fact, macros could be done in a file level (alt a, alt b) and in the program level (ctrl f1, ctrl f2 etc.) You could operate the whole program strictly with homemade macros (enter file, save file, search for etc.)

I spoke to Mr Miller a few years ago. He is the one who owns the Rapid File copyright and he is the one who sold it to Ashton Tate. He told me the whole app has been written in Forth by one single programmer who latter passed away many years ago. God bless his soul!

If anyone is interested in writing something similar in Tcl/Tk, let me know. My e-mail address is on my homepage.

This is a good project for one or many young, ambitious Tclers who want to build, to program a great app to show to employers who want to see an example of his/her work and who have all the time in the world to do so. The work would be split up. A programmer would program the database, the other the editor and so on so forth (no pun intended! :-)).

These days, more often than not, programmers can show bits and pieces of work but not complete apps; but when they can show slick, elegant and complete, excellent apps, employers are impressed and they hire them right away. Therefore whoever will work on this project will invest in his/her future.

This program could also be offered for download or sold.

Please note that I don't have the time to supervise or get involved in this project. I can offer some guidance and advice from time to time but that is about it.


See CSV for code to deal with comma-separated-values data files.

LV Actually, csv allows the user to specify the character used for separation, with the default being a comma if one doesn't specify. That takes care of the request about the semi-colon, below. Also, see tcllib's matrix module for a way to manipulate the data as if it were rows and columns. And finally, check out tcllib's report module, which can take matrix objects and generate output from them. Thus, one uses csv to read the data, matrix to store the data, report to print the data, and if you want to change the data, you have either matrix or csv objects that you can work against...

Also, if I can suggest, take a look in tcllib's examples/csv directory - Andreas wrote some neat programs that does things like takes csv data and creates HTML tables for output, sorts csv files, cuts csv columns, compares csv files by columns, etc.

unperson Thanks Larry! Where can we get Andreas's code and the tcllib's examples?


unperson Indeed! Thanks RS and LV! The concept is very well explained on that page. Andreas has written very interesting and very useful code! I'll try it! There is certainly an amazing wealth of information on this wiki!

Now, the first step (and the most important one!) in this project would be to simply present the CSV file into a sort of file with columns (alt 179) instead of commas.

The algorithm must take into consideration the longest entry in each field and must set the width of that field accordingly.

Note that the program will do that upon entry everytime. After the user has entered data, he will click on Save and Save will represent the file into a CSV file and will save it that way.

Therefore the file is always CSV but the user sees it always with columns.

The user will be able to modify a field by hitting F2 or by clicking on the field with the mouse.

Since the comma is commonly used for text, we'll use the semi-column, to delimit. We'll then have a semi-column delimited file if you will!

Let's try:

This is the file. Name: My library.txt

  Shakespeare, William; Romeo and Juliet; 1767; Theatre
  Puzo, Mario; The Godfather; 1965; Drama
  Verne, Jules; Around the world in 80 days; 1862; Adventure
  Sheldon, Sydney; The other side of midnight; 1967; Mystery
  Mc Cullough, Colleen; Thornbirds; 1967; Saga

jmn *surely* you mean 'semicolon' not 'semi-column'. Sorry to be a wet-blanket - but I think you should leave the data-structure/file-structure design to someone who understands these things. Using semicolons only shifts the problems from text containing commas, to text containing semicolons. You need some other escaping or quoting mechanism. Perhaps you'd be better off just specifying your expected application behaviour rather than making crude attempts to get into the technical details. Unless of course this is an educational exercise for you.. which of course is a valid aim - and what most of this wiki is all about!

unperson Semi-colon! Mm! Well like for many English words this is the first time I ever write this word. Thanks for the correction! Hadn't you told me, I would have made the mistake over and over.

Well, I am trying to be as precise as possible. I believe the best would be to put some Rapid File screenshots but I don't seem to have the technology for it!


slebetman: Hmm. Originally you insisted on a comma delimited database so I thought you had a specific, non-technical, reason for using commas. Now you're saying that since you use commas a lot in your data you want to change the delimiter to a semicolon. So it seems like you don't really care what the delimiter is right? As long as the data is stored in a human readable, flat data file?

If so, this is Tcl we're talking about here, why would you want to use an alien data structure? Store your data file as a tcl list! Your code will be simpler since you don't really need to do any parsing of the data whatsoever - let the Tcl interpreter do it for you.

The sample database you've given above, written as a flat Tcl list can be written as follows:

My library.txt:

  {{Shakespeare, William} {Romeo and Juliet} 1767 Theatre}
  {{Puzo, Mario} {The Godfather} 1965 Drama}
  {{Verne, Jules} {Around the world in 80 days} 1862 Adventure}
  {{Sheldon, Sydney} {The other side of midnight} 1967 Mystery}
  {{Mc Cullough, Colleen} Thornbirds 1967 Saga}

The big advantage of this is that "parsing" the database is simply done with:

  set database [read $f]

and saving the database is also simply:

  puts $f $database

unperson Very interesting! Your point is very valid: the character used as delimeter is not relevant since the user actually never sees it (unless he looks in the file)!

Next step: I'll try to get a screenshot of how a database could be created in Rapid File. From memory I can say that the user simply did F10 to get to the menu, then (s)he would hit New and then there was a screen to enter the fields types and their names.

In fact, no. To create a database, we had to click on F10/File/Create. We'd enter the name of the field on the bottom of the screen; then the field would be drawn on the screen like a column. It was pretty neat!

CMcC thinks that a database UI in which you pressed F11 to get a menu would be better, because it would go up to 11.

unperson F12 would even be better! :-)


See solid, excellent work by Dr Csaba Nemethi in tablelist.

I wonder if the DGMK Metakit Viewer does not have a capacity to view a CSV file as a table (See: dgmkviewer).