DESCRIPTION

dbs_update is an utility to update \s-1SQL\s0 databases from text files.

\$1

dbs_update assumes that each line of the input contains a data record and that the field within the records are separated by tabulators. You can tell dbs_update about the input format with the --format option.

The first field of the data record is used as table specification. These consists of the table name and optionally the index of starting column, separated by a dot.

Alternatively dbs_update can read the column names from the first line of input (see the -h/--headline option). These can even be aliases for the real column names (see the -m/--map option).

COMMAND LINE PARAMETERS

Required command line parameters are the \s-1DBI\s0 driver (\*(C`Pg\*(C' for Postgres or \*(C`mysql\*(C' for MySQL) and the database name. The third parameter is optionally and specifies the database user and/or the host where the database resides (\*(C`racke\*(C', \*(C`[email protected]\*(C' or \*(C`@linuxia.de\*(C').

OPTIONS

Removes all records which remain unaffected from the update process. The same result as deleting all records from the table first and then running dbs_update, but the table is not empty in the meantime. Update only the table columns given by the \s-1COLUMN\s0 parameters. To exclude columns from the update prepend \*(C`!\*(C' or \*(C`^\*(C' to the parameters. Update only the input rows given by the \s-1ROW\s0 parameters. The first row is 1 where headlines doesn't count. To exclude rows from the update prepend \*(C`!\*(C' or \*(C`^\*(C' to the parameters. Reads records from file \s-1FILE\s0 instead of from standard input. Assumes \s-1FORMAT\s0 as format for the input. Only \s-1CSV\s0 can be specified for now, default is \s-1TAB\s0. The default field separator for \s-1CSV\s0 is a comma, you may change this by appending the separator to the format. Reads the column names from the first line of the input instead of dedicting them from the database layout. Requires the -t/--table option. Specifies the keys for the table(s) either as the number of columns used as keys or by specifying them explicitly as comma separated arguments to the option. This is used for the detection of existing records. Maps the names found in the first line of input to the actual column names in the database. The alias and the column name are separated with \*(C`=\*(C' signs and the different entries are separated by \*(C`;\*(C' signs, e.g. \*(C`Art-No.=code;Short Description=shortdescr'\*(C'. Applies a filter to the column names read from the input file. Currently there is only the \*(C`lc\*(C' filter available. Updates only records where the value of the column \s-1FIELD\s0 is in the result set of the \s-1SQL\s0 statement \s-1STATEMENT\s0, e.g. \*(C`category:{select distinct name from categories}\*(C'. Updates existing database entries only, stops if it detects new ones. Applies \s-1ROUTINE\s0 to any data record. \s-1ROUTINE\s0 must be a subroutine. dbs_update passes the table name and a hash reference to this subroutine. The keys of the hash are the column names and the values are the corresponding field values. If the return value of \s-1ROUTINE\s0 is not a truth value, the data record will be skipped.

\*(C`sub {my ($table, $valref) = @_;

    unless (defined $$valref{country} && $$valref{country} !~ /\S/) {
        $$valref{country} = "Germany";
    }
    1;

}\*(C' Lines not matching the assumed format are ignored. Without this option, dbs_update simply stops. Uses \s-1TABLE\s0 as table name for all records instead of the first field name.

AUTHOR

Stefan Hornburg (Racke), [email protected]

RELATED TO dbs_update…

perl\|(1), DBIx::Easy\|(3)