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

Updated 2006-06-06 01:53:58

Robert Abitbol 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 a comma-delimited 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.

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 and a database. Another amazing feature: the snapshots: you could enter a database and decide to write 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.

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 an ambitious Tcler who wants to build, to program a great app to show to employers who want to see an example of his/her work.

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.


Robert Abitbol Indeed! Thanks RS! The concept is very well explained on that page.

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!


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

Category Database