App-MysqlUtils
view release on metacpan or search on metacpan
lib/App/MysqlUtils.pm view on Meta::CPAN
Special arguments:
=over 4
=item * B<-dry_run> => I<bool>
Pass -dry_run=E<gt>1 to enable simulation mode.
=back
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code
(200 means OK, 4xx caller error, 5xx function error). Second element
($reason) is a string containing error message, or something like "OK" if status is
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth
element (%result_meta) is called result metadata and is optional, a hash
that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
=head2 mysql_fill_csv_columns_from_query
Usage:
mysql_fill_csv_columns_from_query(%args) -> [$status_code, $reason, $payload, \%result_meta]
Fill CSV columns with data from a query.
This utility is handy if you have a partially filled table (in CSV format, which
you can convert from spreadsheet or Google Sheet or whatever), where you have
some unique key already specified in the table (e.g. customer_id) and you want
to fill up other columns (e.g. customer_name, customer_email, last_order_date) from a
query:
% mysql-fill-csv-columns-from-query DBNAME TABLE.csv 'SELECT c.NAME customer_name, c.email customer_email, (SELECT date FROM tblorders WHERE client_id=$customer_id ORDER BY date DESC LIMIT 1) last_order_time FROM tblclients WHERE id=$customer_id'
The C<$NAME> in the query will be replaced by actual CSV column value. SELECT
fields must correspond to the CSV column names. For each row, a new query will
be executed and the first result row is used.
This function is not exported.
This function supports dry-run operation.
Arguments ('*' denotes required arguments):
=over 4
=item * B<count> => I<bool>
Instead of returning the CSV rows, just return the count of rows that get filled.
=item * B<database>* => I<str>
(No description)
=item * B<escape_char> => I<str>
Specify character to escape value in field in input CSV, will be passed to Text::CSV_XS.
Defaults to C<\\> (backslash). Overrides C<--tsv> option.
=item * B<filename>* => I<filename>
Input CSV file.
=item * B<header> => I<bool> (default: 1)
Whether input CSV has a header row.
By default (C<--header>), the first row of the CSV will be assumed to contain
field names (and the second row contains the first data row). When you declare
that CSV does not have header row (C<--no-header>), the first row of the CSV is
assumed to contain the first data row. Fields will be named C<field1>, C<field2>,
and so on.
=item * B<host> => I<str> (default: "localhost")
(No description)
=item * B<password> => I<str>
Will try to get default from C<~/.my.cnf>.
=item * B<port> => I<int> (default: 3306)
(No description)
=item * B<query>* => I<str>
(No description)
=item * B<quote_char> => I<str>
Specify field quote character in input CSV, will be passed to Text::CSV_XS.
Defaults to C<"> (double quote). Overrides C<--tsv> option.
=item * B<sep_char> => I<str>
Specify field separator character in input CSV, will be passed to Text::CSV_XS.
Defaults to C<,> (comma). Overrides C<--tsv> option.
=item * B<tsv> => I<bool>
Inform that input file is in TSV (tab-separated) format instead of CSV.
Overriden by C<--sep-char>, C<--quote-char>, C<--escape-char> options. If one of
those options is specified, then C<--tsv> will be ignored.
=item * B<username> => I<str>
Will try to get default from C<~/.my.cnf>.
=back
Special arguments:
=over 4
=item * B<-dry_run> => I<bool>
Pass -dry_run=E<gt>1 to enable simulation mode.
=back
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code
(200 means OK, 4xx caller error, 5xx function error). Second element
($reason) is a string containing error message, or something like "OK" if status is
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth
element (%result_meta) is called result metadata and is optional, a hash
that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
=head2 mysql_find_identical_rows
Usage:
mysql_find_identical_rows(%args) -> [$status_code, $reason, $payload, \%result_meta]
List rows on one table that are identical on another table.
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<database>* => I<str>
(No description)
=item * B<exclude_columns> => I<array[str]>
What column(s) to exclude from comparison.
=item * B<host> => I<str> (default: "localhost")
(No description)
=item * B<password> => I<str>
( run in 1.695 second using v1.01-cache-2.11-cpan-39bf76dae61 )