NAME
Gtk2::Ex::DbLinker::RdbDataManager - a module that get data from a database using Rose::DB::Objects
VERSION
See Version in Gtk2::Ex::DbLinker
SYNOPSIS
use Gtk2 -init;
use Gtk2::GladeXML;
use Gtk2::Ex:Linker::RdbDataManager;
my $builder = Gtk2::Builder->new();
$builder->add_from_file($path_to_glade_file);
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::Jrn::Manager->get_jrn(query => [ nofm => {ge => 0}], sort_by => 'nofm' );
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::Jrn->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} = Linker::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 = Linker::RdbDataManager->new({data => Rdb::Ed::Manager->get_ed(sort_by => 'nom' ), meta => Rdb::Ed->meta });
$self->{linker}->add_combo({
data_manager => $dman,
id => 'noed',
fields => ["id", "nom"],
});
And when all combos or datasheets are added:
$self->{linker}->update;
To change a set of rows in a subform, use and on_changed event of the primary key in the main form and call
$self->{subform_a}->on_pk_changed($new_primary_key_value);
In the subform a module:
sub on_pk_changed {
my ($self,$value) = @_;
my $data = Rdb::Coll::Manager->get_coll(query => [noti => {eq => $value}]);
$self->{subform_a}->get_data_manager->query($data);
$self->{subform_a}->update;
DESCRIPTION
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 ...Linker::Datasheet objet constructor.
METHODS
constructor
The parameters are passed in a hash reference with the keys data
and meta
. 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::Coll::Manager->get_coll(query => [noti => {eq => $self->{noti}}]);
my $dman = Linker::RdbDataManager->new({data=> $data, meta => Rdb::Coll->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.
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.
my $data = Rdb::Coll::Manager->get_coll(query => [noti => {eq => $value}]);
$self->{form_a}->get_data_manager->query($data);
$self->{form_a}->update;
The methods belows are used by the Form module and you should not have to use them directly.
new_row();
save();
delete();
set_row_pos( $new_pos );
change the current row for the row at position $new_pos
.
get_row_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.
row_count();
Return the number of rows.
get_field_names();
Return an array of the field names.
get_primarykeys()
;
Return an array of primary key(s) (auto incremented or not).
get_autoinc_primarykeys()
;
Return an array of primary key(s).
SUPPORT
Any Gk2::Ex::DbLinker questions or problems can be posted to the the mailing list. To subscribe to the list or view the archives, go here: http://groups.google.com/group/gtk2-ex-dblinker. You may also send emails to gtk2-ex-dblinker@googlegroups.com.
The current state of the source can be extract using Mercurial from http://code.google.com/p/gtk2-ex-dblinker/.
AUTHOR
François Rappaz <rappazf@gmail.com>
COPYRIGHT AND LICENSE
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.
SEE ALSO
Gtk2::Ex::DbLinker::Forms Gtk2::Ex::DbLinker::Datasheet Rose::DB::Object
CREDIT
John Siracusa and the powerfull Rose::DB::Object ORB.