Re: grid with database access



Gabor Szabo wrote:

I am looking for a grid with capabilities similar to that of MS Access.
OK, I know this seems to be a long shot and to tell the truth I am not sure
what exactly I am looking for.
In general I should be able to connect the grid to an extarnal database table, 
page over the entries, add new entry, edit entries. 
I should also be able to define specific select statements and then
see the results
in the grid.

Where should I look for such thing in GTK ?

 

I currently achieve this functionality with a Gtk2::SimpleList and a lot
of code handling changes. If you just want to display the data, that's
*easy* ... just open a DBI recordset and throw it at the SimpleList. But
editing and adding new data isn't quite so nice. I've considered doing
something generic, but basically haven't really had any pressing need
for it. Most of our DB front-end stuff is done in Glade with widgets for
each field - in most cases I only use a 'datasheet' object for
displaying information - possibly stuff that users can select or
double-click on.

There are a number of issues with what you want to do. For starters, the
cell renderers you have available aren't as nice as standard Gtk2
widgets. You can make custom cell renderers ( for example I use a
spinbutton cell renderer in some cases ), but this slows things down
*incredibly*. I think Gtk2 just added a combobox renderer, but I'm not
sure if it's supported yet by Gtk2-Perl. If not, see previous point re:
custom cell renderers - there are ways around it, but the solution is
overly complex and feels very much like a hack instead of a cool widget.

I would like to see a DB-aware datasheet-type widget though:) I suppose
it wouldn't be *that* hard. As you said, you'd need to be able to pass a
query to it and have it query the database and then fill the datasheet.
You'd have to know what the primary key is, for updates. Then you'd have
to detect changes and decide what to do with them - usually update the
database with the changes. You'd need a delete and an insert method. For
inserts, I find that adding a special character as the primary key ( I
use a '!' character ) is a nice way of tagging a record as being 'new',
so when you go to apply the updates, you know you're doing an insert
instead of an update. You'd need to be able to handle things like combo
boxes, so I'd have a think about this before getting too exited...

I have a module that does all the above for Glade-generated forms ( ie
with separate widgets per field ), Gtk2::Ex::DBI at
http://entropy.homelinux.org/Gtk2-Ex-DBI/ ... I was considering making a
datasheet extension to it "one day". Feel free to add to it or grab the
bits you want for your own project. However, note that a couple of
people have recommended that I port it to use Class::DBI, and I'll most
likely do that when I get some time, so maybe it would be a better idea
for you to do that from the start? It ( apparently ) makes things more
DB-neutral - I'll believe it when I see it.

Oh yeah - one more thing - I think Gtk2::SimpleList has been superseded
by Gtk2::Ex::Simple - so you should probably use that instead of
Gtk2::SimpleList. I did all my datasheet-type stuff before
Gtk2::Ex::Simple and haven't bothered updating. I can post some example
code if you like, but I haven't bothered for the above reason ( I'm
using the outdated Gtk2::SimpleList ).

Enjoy :)

-- 
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]