|
NAMESQLite::Work - report on and update an SQLite database.VERSIONversion 0.1601SYNOPSISuse SQLite::Work; my $rep = SQLite::Work->new(%new_args); if ($rep->do_connect()) { if ($simple_report) { $rep->do_report(%report_args); } elsif ($multi_page_report) { $rep->do_multi_page_report(%report_args); } elsif ($split_report) { $rep->do_split_report(%report_args); } $rep->do_disconnect(); } DESCRIPTIONSQLite::Work is a perl module for interfacing with an SQLite database. It can be used to:
This generates HTML (and non-HTML) reports from an SQLite database, taking care of the query-building and the report formatting. This also has methods for adding and updating the database. The SQLite::Work::CGI module has extra methods which deal with CGI using the CGI module; the included "show.cgi" and "edit.cgi" are demonstration CGI scripts which use the SQLite::Work::CGI module. There is also the "show.epl" demonstration Embperl script which has the necessary alterations for using this with Embperl. The sqlreport script uses SQLite::Work to generate reports from the command-line. The sqlw_mail script uses SQLite::Work::Mail to email reports. LimitationsThis only deals with single tables and views, and simple one-field, two-table joins. More complex joins should be dealt with by making a view.This only deals with one database at a time. CLASS METHODSnewmy $rep = SQLite::Work->new( database=>$database_file, row_ids=>{ episodes=>'title_id', }, join_cols=>{ 'episodes+recordings'=>'title_id', } }, report_template=>$template, default_format=>{ 'episodes' => { 'title'=>'title', 'series_title'=>'title', } }, use_package=>[qw(File::Basename MyPackage)], );Make a new report object. This takes the following arguments:
OBJECT METHODSMethods in the SQLite::Work object interfacedo_connect$rep->do_connect();Connect to the database. do_disconnect$rep->do_disconnect();Disconnect from the database. do_report$rep->do_report( table=>$table, table2=>$table2, where=>\%where, not_where=>\%not_where, sort_by=>\@sort_by, show=>\@show, distinct=>0, headers=>\@headers, header_start=>1, groups=>\@groups, limit=>$limit, page=>$page, layout=>'table', row_template=>$row_template, outfile=>$outfile, report_style=>'full', table_border=>1, truncate_colnames=>0, title=>'', ); Select data from a table in the database, and make a HTML report. Arguments are as follows (in alphabetical order):
The same format is used for groups and row_template.
do_multi_page_report$rep->do_multi_page_report( table=>$table, table2=>$table2, where=>\%where, not_where=>\%not_where, sort_by=>\@sort_by, show=>\@show, headers=>\@headers, groups=>\@groups, limit=>$limit, page=>$page, layout=>'table', row_template=>$row_template, prev_next_template=>$prev_next_template, multi_page_template=>$multi_page_template, outfile=>$outfile, table_border=>1, table_class=>'plain', truncate_colnames=>0, report_style=>'full', link_suffix=>'.html', ); Select data from a table in the database, and make a HTML file for EVERY page in the report. If the limit is zero, or the number of rows is less than the limit, or the outfile is destined for STDOUT, then calls do_report to do a single-page report. If no rows match the criteria, does nothing and returns false. Otherwise, it uses the 'outfile' name as a base upon which to build the file-names for all pages in the report (basically appending the page-number to the name), and generates a report file for each of them, and an index-page file which is called the 'outfile' value. The 'link_suffix' argument, if given, overrides the suffix given in links to the other pages in this multi-page report; this is useful if you're post-processing the files (and thus changing their extensions) or are using something like Apache MultiViews to eliminate the need for extensions in links. See do_report for information about the rest of the arguments. do_split_report$rep->do_split_report( table=>$table, split_col=>$colname, split_alpha=>$n, command=>'Select', table2=>$table2, where=>\%where, not_where=>\%not_where, sort_by=>\@sort_by, show=>\@show, headers=>\@headers, header_start=>1, groups=>\@groups, limit=>$limit, page=>$page, layout=>'table', row_template=>$row_template, outfile=>$outfile, table_border=>1, table_class=>'plain', truncate_colnames=>0, report_style=>'full', link_suffix=>'.html', ); Build up a multi-file report, splitting it into different pages for each distinct value of the 'split_col' column. (If the outfile is destined for STDOUT, then this will call do_report intead). The filenames generated will use 'outfile' as a prefix, and the column name and values as the rest; this calls in turn do_multi_page_report to break those into multiple pages if need be. An index-page is also generated, which will be called outfile + colname + .html If 'split_alpha' is also given and is not zero, then instead of splitting on each distinct value in the 'split_col' column, the split is done by the truncated values of that column; if 'split_alpha' is 1, then the split is by the first letter, if it is 2, by the first two letters, and so on. The 'link_suffix' argument, if given, overrides the suffix given in links to the other pages in this multi-page report; this is useful if you're post-processing the files (and thus changing their extensions) or are using something like Apache MultiViews to eliminate the need for extensions in links. See do_report for information about the rest of the arguments. get_total_matching$rep->get_total_matching( table=>$table, where=>\%where, not_where=>\%not_where, ); Get the total number of rows which match the selection criteria. See do_report for the meaning of the arguments. update_one_rowif ($rep->update_one_field( table=>$table, row_id=>$row_id, field=>$field, update_values=>\%values, )) { ... } Update one row; either a single column, or the whole row. Returns 0 if failure, or the constructed update query if success (so that one can be informative). Sets $rep->{message} with a success message if successful. add_one_rowif ($rep->add_one_row( table=>$table, add_values=>\%values)) { ... } Add a row to a table. Sets $rep->{message} with a success message if successful. delete_one_rowif ($rep->delete_one_row( table=>$table, row_id=>$row_id)) { ... } Delete a single row. Sets $rep->{message} with a success message if successful. do_import_fvif ($rep->do_import_fv( table=>$table, datafile=>$filename, row_delim=>"=")) { ... } Import a field:value file into the given table. Field names are taken from the table; rows not starting with a field name "Field:" are taken to be a continuation of the previous field value. Rows are delimited by the given row_delim argument on a line by itself. Returns the number of records imported. Helper MethodsLower-level methods, generally just called from other methods, but possibly suitable for other things.print_messagePrint an (error) message to the user.$self->print_message($message); # error message $self->print_message($message, 0); # non-error message (here so that it can be overridden, say, for a CGI script) make_selectionsmy ($sth1, $sth2) = $rep->make_selections(%args); Make the selection(s) for the matching table(s). get_tablesmy @tables = $self->get_tables();my @tables = $self->get_tables(views=>0); Get the names of the tables (and views) in the database. get_colnamesmy @columns = $self->get_colnames($table);my @columns = $self->get_colnames($table, do_rowid=>0); Get the column names of the given table. get_distinct_col@vals = $rep->get_distinct_col( table=>$table, colname=>$colname, where=>\%where, not_where=>\%not_where, ); Get all the distinct values for the given column (which match the selection criteria). Private Methodsprint_selectPrint a selection result.get_templatemy $templ = $self->get_template($template);Get the given template (read if it's from a file) get_id_colname$id_colname = $self->get_id_colname($table);Get the name of the column which is used for row-identification. (Most of the time it is just 'rowid') get_join_colname$join_col = $self->get_join_colname($table1, $table2);Get the name of the column which is used to join these two tables. col_is_intmy $res = $self->col_is_int(table=>$table, column=>$column);Checks the column type of the given column in the given table; returns true if it is an integer type. format_report$my report = $self->format_report( table=>$table, command=>'Search', columns=>\@columns, force_show_cols=>\%force_show_cols, sort_by=>\@sort_by, headers=>\@headers, header_start=>1, table2=>$table2, layout=>'table', row_template=>$row_template, report_style=>'compact', table_header=>$thead, table_border=>1, table_class=>'plain', truncate_colnames=>0, );Construct a HTML result table get_row_template$row_template = $self->get_row_template( table=>$table, row_template=>$rt, layout=>'table', columns=>\@columns, show_cols=>\%show_cols, nice_cols=>\%nice_cols, ); Get or set or create the row template. set_nice_cols%nice_cols = $self->set_nice_cols( truncate_colnames=>0, columns=>\@columns); start_section$sect = $self->start_section(type=>'table', table_border=>$table_border, table_class=>$table_class);Start a new table/para/list The 'table_border' option is the border-size of the table if using table style The 'table_class' option is the class of the table if using table style end_section$sect = $self->end_section(type=>'table');End an old table/para/list build_where_conditionsTake the %where, %not_where hashes and make an array of SQL conditions.@where = $self->build_where_conditions(where=>\%where, not_where=>\%not_where); BUGSPlease report any bugs or feature requests to the author.AUTHORKathryn Andersen (RUBYKAT) perlkat AT katspace dot com http://www.katspace.com COPYRIGHT AND LICENCECopyright (c) 2005 by Kathryn AndersenThis program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |