François Rappaz
and 1 contributors


Gtk2::Ex::DbLinker::RdbDataManager - a module that get data from a database using Rose::DB::Objects


See Version in Gtk2::Ex::DbLinker::DbTools


        use Gtk2 -init;
        use Gtk2::GladeXML;
        use Gtk2::Ex:Linker::RdbDataManager; 
        my $builder = Gtk2::Builder->new();

Instanciation of a RdbManager object is a two step process:

  • use a Rose::DB::Object::Manager derived object to get a array of Rose::DB::Object derived rows.

             my $data = Rdb::Mytable::Manager->get_mytable(query => [ pk_field => {ge => 0}], sort_by => 'field2' );
  • Pass this object to the RdbDataManager constructor with a Rose::DB::Object::Metatdata derived object

            my $rdbm = Gtk2::Ex::DbLinker::RdbDataManager->new(data => $data,
                    meta => Rdb::Mytable->meta,

To link the data with a Gtk window, the Gtk entries id in the glade file have to be set to the names of the database fields

          $self->{linker} = Gtk2::Ex::DbLinker::Form->new( 
                    data_manager => $rdbm,
                    builder =>  $builder,
                    rec_spinner => $self->{dnav}->get_object('RecordSpinner'),
                    status_label=>  $self->{dnav}->get_object('lbl_RecordStatus'),
                    rec_count_label => $self->{dnav}->get_object("lbl_recordCount"),

To add a combo box in the form, the first field given in fields array will be used as the return value of the combo. noed is the Gtk2combo id in the glade file and the field's name in the table that received the combo values.

        my $dman = Gtk2::Ex::DbLinker::RdbDataManager->new(data => Rdb::Combodata::Manager->get_combodata(sort_by => 'name' ), meta => Rdb::Combodata->meta );

        data_manager => $dman,
        id => 'comboid',
        fields => ["id", "name"],

And when all combos or datasheets are added:


To change a set of rows in a subform, use and on_changed event of the primary key in the main form and call


In the subform a module:

        sub on_pk_changed {
                 my ($self,$value) = @_;
                my $data =  Rdb::Mytable::Manager->get_mytable(query => [pk_field => {eq => $value}]);


This module fetch data from a dabase using Rose::DB::Object derived objects.

A new instance is created using an array of objects issue by a Rose::DB::Object::Manager child and this instance is passed to a Gtk2::Ex::DbLinker::Form object or by Gtk2::Ex::DbLinker::Datasheet objet constructor.



The parameters are passed as a list of parameters name => value, or as a hash reference with the parameters name as keys.

Parameters are data, meta, columns or '+columns', alias.

The value for data is a reference to an array of Rose::SB::Object::Manager derived objects. The value for meta is the corresponding metadata object.

                my $data = Rdb::Mytable::Manager->get_mytable(query => [pk_field => {eq => $value }]);
                my $dman = Gtk2::Ex::DbLinker::RdbDataManager->new(data=> $data, meta => Rdb::Mytable->meta );

Array references of primary key names and auto incremented primary keys may also be passed using primary_keys, ai_primary_keys as hash keys. If not given the RdbDataManager uses the metadata to have these.

You may pass a columns or '+columns' parameters. The value is as a hash ref where the keys are the names of the relationship and the values are an array ref holding the fields names accessed by this relationship. Use +columns if you are using fields from the main table and from joined table(s). Use columns if you are interested only in fields from tables bounded by join clauses. Use neither of them if you want to access fields from the main table only, the relationship being used to restrict the rows. The fields selected with '+columns' or with 'columns' are readonly: a call to set_field($field_id, $field_value) will not change any value.

alias is a hash ref of field (key) and array ref (alias list). For example if my module define __PACKAGE__->meta->setup( table => 'speaks',

            columns => [
                speaksid  => { type => 'serial' },
                countryid => { type => 'integer', not_null => 1 },
                langid    => { type => 'integer', not_null => 1 },

                primary_key_columns => [ 'speaksid' ],

Giving alias = {langid => [qw(langid1 langid2)]},> in the constructor will enable the RdbDataManager to return the langid value when called with $dman-get_field('langid1')>. It is possible to add alias directly with using Rose::DB::Object::Metadata but I confess I have not found out how...

query( $data );

To display an other set of rows in a form, call the query method on the datamanager instance for this form with a new array of Rose::DB::Object derived objects. Return 0 if there is no row or 1 if there are any.

        my $data =  Rdb::Mytable::Manager->get_mytable(query => [pk_field => {eq => $value}]);

The methods belows are used by the Form module and you should not have to use them directly.




set_row_pos( $new_pos );

change the current row for the row at position $new_pos.


Return the position of the current row, first one is 0.

set_field ( $field_id, $value);

Sets $value in $field_id. undef as a value will set the field to null.

get_field ( $field_id );

Return the value of a field or undef if null.

get_field_type ( $field_id );

Return one of varchar, char, integer, date, serial, boolean.


Return the number of rows.


Return an array of the field names.


Return an array of primary key(s) (auto incremented or not).


Return an array of autoincremented primary key(s) defined by the the 'serial' column's type or undef.


Any Gk2::Ex::DbLinker questions or problems can be posted to me (rappazf) on my gmail account.

The current state of the source can be extract using Mercurial from


François Rappaz <>


Copyright (c) 2014 by F. Rappaz. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.






John Siracusa and the powerfull Rose::DB::Object ORB.