# Bredth first listing of all nodes under given root (incl. root). # my $get_children = sub { my $parents = \@_; # Hackery. We should really only accept one id. my @children; my $dbh = $DB->getDatabaseHandle; local $" = ','; while ( @$parents > 0 ) { push @children, @$parents; $parents = $dbh->selectcol_arrayref(qq{ SELECT note_id FROM note WHERE parent_node IN ( @$parents ) }); } return @children; # Returns root at head of list (easier later ;) } # Runs a search and replace on the title of selected nodes. Returns # number of records updated (0 still true). # my $retitle = sub { my $new_title = shift; my $old_title = shift; my @nodes = @_; my $dbh = $DB->getDatabaseHandle; local $" = ','; $dbh->do(qq{ UPDATE note SET title = REPLACE(title, ? , ?) WHERE note_id IN( @nodes ) }, undef, ($old_title, $new_title) ); } my $id = getId($NODE); $retitle_nodes->( 'new_title_var_goes_here', getNodeById($id)->{title}, $get_children->($id) );