index
My Database Browser (MDB version 2)
This article outlines the issues solved in the process of implementing a graphical browser for postgresql database.
code is in the Sourceforge project Gauche-mdb
(see how to install)
Let me state my aims, desired features:
- editing the sql query, with the comfort comparable with emacs's sql mode.
- images: the query result should be presented in tabular form, possibly enhanced with images.
The reason is that one can interpret an image better than some identification string/number.
- context menus should be prepared, also a keymap!, with "links" to start related queries, deriverd from the data on the
current row.
- editing: the tabular data should be editable, as much as possible (and modifications saved to the database, of course).
Implementation
Years ago, I implemented a similar browser in emacs (lisp).
This time, I opted for gtk+, and scheme programming language implementation called gauche.
The reason was (a couple years ago) the availability of gauche-gtk, binding between the scheme
interpreter and Gtk+, which was constructed with a set of interesting sets (toolset).
Also, this mixture of C and a high level language seems educating.
Query editing
Gnome project provides a widget to edit Sql text in the gtksourceview code. So, I simply use that.
It's not yet comparable to emacs, but there is TAB-completion (copied from psql), font-locking...
Presenting the data
In this section let's assume we can interpret the values (strings, numbers, etc) in the result's columns
in some way, that means we can choose a suitable functions, out of a set of pre-registered set, which
embelishes the data in that column. How this is done is explained in the section contex.
So, at some point we want to have a column full of images, that is we want a GtkCellRendererPixbuf.
The problem with this is, that the gtk-tree-view widget wants to render immediately all the images,
not only those visible. The reason is to get the dimensions. If we can get those dimensions more cheaply,
we would like to load the image pixel data lazily (just when the image is needed-exposed)! So I had to
(prepare a patch for gtk+ which) implements "lazy-pixbuf" .... for details see gtk-patches
Defining Actions on "domains".
What is an action?
it's a:
recipe on how to construct the GtkModel, GtkViewTree, and how to contribute to the context menu, and to the keymap.
Propagation of action to derived (db) relations
Let's imagine we have a table, which represents people, and we identify each one by a number, stored in the ID
attribute, but want to see the personal photo each time we have the ID attribute in the result.
So, yes, we register a personal-photo action to that ID attribute of the table. But, we use the ID as foreign-key
in other tables too, and want that handler used for those, referencing attributes too.
Yes, that is implemented. Views can also be regarded, in a way, as tables referencing values in other tables,
and the action is applied for attributes derived in this way too!
Editing
Related projects