Kevin Ryde > chart-248 > App::Chart::Gtk2::Ex::ListStoreDBISeq

Download:
chart-248.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  15
Open  3
View/Report Bugs
Source  

NAME ^

App::Chart::Gtk2::Ex::ListStoreDBISeq -- list read from DBI table with "seq"

SYNOPSIS ^

 use App::Chart::Gtk2::Ex::ListStoreDBISeq;
 my $ls = App::Chart::Gtk2::Ex::ListStoreDBISeq->new (dbh => $dbh,
                                          table => 'mytable',
                                          columns => ['c1','c2']);

 # changing the store updates the database
 $ls->set ($ls->get_iter_first, 0 => 'newval');

 # insert updates sequence numbers
 $ls->insert_with_values (3, 0=>'newrow');

OBJECT HIERARCHY ^

App::Chart::Gtk2::Ex::ListStoreDBISeq is a subclass of Gtk2::ListStore, though perhaps in the future it'll be just a Glib::Object.

    Glib::Object
      Gtk2::ListStore
        App::Chart::Gtk2::Ex::ListStoreDBISeq

DESCRIPTION ^

A ListStoreDBISeq holds data values read from a DBI table with a sequence number in it. The sequence number column must be called "seq". For example

    seq   col1  col2
    0     aaa   first
    1     bbb   another
    2     ccc   yet more
    3     ddd   blah

This is designed for use with data rows that should be kept in a given order, like a user shopping list or "to do" list.

Changes made to the ListSeq in the program are immediately applied to the database. This means the database contents can be edited by the user with a Gtk2::TreeView or similar, and any programmatic changes are then reflected in the view too.

The current implementation is a subclass of Gtk2::ListStore because it's got a fairly reasonable set of editing functions, and it's fast when put in a TreeView.

Drag and Drop

A ListSeq inherits drag-and-drop from Gtk2::ListStore but it's worth noting DnD works by inserting and deleting rows rather than a direct re-order. This means a drop will first create an empty row, so even if you normally don't want empty rows in the database you'll have to relax database constraints on that so it can be created first then filled a moment later.

FUNCTIONS ^

App::Chart::Gtk2::Ex::ListStoreDBISeq->new (key => value, ...)

PROPERTIES ^

dbh (DBI database handle)
table (string)
columns (arrayref of strings)

The DBI handle, table name, and column names to present in the ListStore.

The "seq" column can be included in the presented data if desired, though it's value will always be the same as the row position in the ListStore, which you can get from the TreePath or TreeIter anyway.

where (hashref, default undef)

A set of column values to match in "where" clauses for the data. This allows multiple sequences to be stored in a single table, with a column value keeping them separate. The property here is a hashref of column names and values. For example,

    $ls->set (where => { flavour => 'foo' });

The table could have

    flavour  seq   content
    foo      0     aaa
    foo      1     bbb
    foo      2     ccc
    foo      3     ddd
    bar      0     xxx
    bar      1     yyy

and only the "foo" rows are presented and edited by the ListSeq.

Note that this where cannot select a subset of a sequence and attempting to do so will probably corrupt the sequential numbering.

When setting a where property must be done before setting dbh etc, or (in the current implementation) the ListSeq will try to read without the where clause, which will almost certainly fail (with duplicate seq numbers).

SEE ALSO ^

Gtk2::ListStore

syntax highlighting: