#!/usr/bin/env perl
use warnings;
use strict;
use 5.014;
our $VERSION = '2.407';

use Term::Choose::Screen qw( hide_cursor show_cursor clear_to_end_of_screen );

use App::DBBrowser;

use Encode::Locale;

binmode STDIN,  ':encoding(console_in)';
binmode STDOUT, ':encoding(console_out)';
binmode STDERR, ':encoding(console_out)';

BEGIN {
    print hide_cursor();
    $ENV{TC_RESET_AUTO_UP} = 0;
    if ( $^O eq "MSWin32" ) {
        require Win32::Console::ANSI;
        print "\e(U";
    }
}

END {
    delete $ENV{TC_RESET_AUTO_UP};
    print clear_to_end_of_screen();
    print show_cursor();
}


my $db_browser = App::DBBrowser->new();
$db_browser->run();


__END__

=pod

=encoding UTF-8

=head1 NAME

C<db-browser> - Browse SQL databases and their tables interactively.

=head1 VERSION

Version 2.407

=head1 SYNOPSIS

    db-browser -h|--help

    db-browser

    db-browser data source, ...

When the C<db-browser> is called with the argument C<-h|--help>, it displays a menu. The menu entry I<Help> shows this
documentation - see L</OPTIONS>.

If C<db-browser> is called without arguments, the user can choose from the databases offered by the database plugin.

If C<db-browser> is called with arguments, those arguments are used as the available data sources.

=head2 SQLite/Firebird

    db-browser -s|--search

Calling C<db-browser> with C<-s|--search> initiates a new search for databases instead of using cached data.

=head1 DESCRIPTION

Before using C<db-browser>, ensure you have backed up your databases.

Search and read in SQL databases: one can interactively browse databases and their tables.

C<App::DBBrowser> provides and supports plugins for the DBI drivers C<DBD::SQLite>, C<DBD::mysql>, C<DBD::MariaDB>,
C<DBD::Pg>, C<DBD::Firebird>, C<DBD::DB2>, C<DBD::Informix>, C<DBD::Oracle> and C<DBD::ODBC>. Refer to
L<App::DBBrowser::DB> for guidance on writing a database plugin.

=head1 NAVIGATION

=head2 Menus

=over

=item *

Use the C<Arrow> keys (or C<h,j,k,l>) to move up and down and to move right or left.

=item *

Press the C<PageUp> key (or C<Ctrl-P>) to go to the previous page and the C<PageDown> key (or C<Ctrl-N>) to go to the
next page.

=item *

Press the C<Home> key (or C<Ctrl-A>) to jump to the beginning of the menu and the C<End> key (or C<Ctrl-E>) to jump to
the end of the menu.

=back

When the I<mouse> option is enabled, you can use the left mouse key to navigate through the menus.

To confirm a chosen menu item, use the C<Return> key.

In some submenus, it is possible to select more than one item before pressing C<Return> (e.g., the input filters
I<Choose Rows> and I<Choose Cols>); in such submenus, the list of items marked with the C<SpaceBar> is added to the
chosen items when C<Return> is pressed. If the mouse mode is enabled, you can use the right mouse key instead of the
C<SpaceBar>. Pressing C<Ctrl-SpaceBar> inverts the made choices - for example, to select all but one, select the one
with the C<SpaceBar> and then press C<Ctrl-SpaceBar>.

=head2 Read-line

=over

=item *

Use C<BackSpace> or C<Strg-H> to delete the character behind the cursor and C<Delete> to delete the character at the
cursor.

=item *

Press C<Strg-U> to delete the text backward from the cursor to the beginning of the line and C<Strg-K> to delete the
text from the cursor to the end of the line.

=item *

Use C<Right-Arrow> to move forward a character and C<Left-Arrow> to move back a character.

=item *

Press C<Page-Up> to move back 10 characters and C<Page-Down> to move forward 10 characters.

=item *

Use C<Home> or C<Strg-A> to move to the start of the line and C<End> or C<Strg-E> to move to the end of the line.

=back

Some C<read-line>s have predefined values. You can access these values with the C<Up-Arrow> and C<Down-Arrow> keys.

To exit a C<read-line> without returning anything, press C<Ctrl-X>. When the input buffer is empty and C<Enter> is
pressed, C<read-line> returns an empty string.

=head1 OUTPUT

The elements are right-justified if they look like a number; otherwise, they are left-justified.

If the option I<squash_spaces> is enabled, leading and trailing spaces are removed from the elements, and spaces are
squashed to a single white space.

Tab characters (C<\t>) are replaced with a space.

Vertical spaces (C<\v>) are squashed to two spaces.

Control characters, code points of the surrogate ranges and non-characters are removed.

See also the option group L</Output>.

C<Ctrl-F> opens a prompt. A regular expression is expected as input. This enables one to display only rows where at
least one column matches the entered pattern. See option L</Search>.

=head1 MENUS

=head2 Plugins Menu

Choosing a plugin leads to the I<Databases Menu>.

(If there is only one plugin, the plugins menu is not shown, but the plugin is chosen automatically.)

=head2 Databases Menu

Choosing a database leads to the I<Schemas Menu>.

(If there is only one database, the databases menu is not shown, but the database is chosen automatically.)

=head2 Schemas Menu

Choosing a schema leads to the I<Tables Menu>.

(If there is not more than one schema, the schemas menu is not shown, but the schema is chosen automatically.)

=head2 Tables Menu

The menu entries of the tables menu:

=head3 Prompt Line

Selecting the prompt line (the database name) opens a menu with these entries:

=over

=item

Create Table

=item

Drop Table

=item

Create View

=item

Drop View

=item

Attach DB

=item

Detach DB

=item

DB Settings

=back

For I<Create Table>, I<Drop Table>, I<Create View> and I<Drop View>, see L</WRITE ACCESS>.

These entries are available if enabled in L</Extensions>.

I<Attach DB> is available for C<SQLite> databases. I<Attach DB> can be used to attach databases to the current database.

For DB Settings, see L</DB Settings>.

=head3 Tables Entries

Choosing one of the tables leads to the I<SQL Menu>.

=head3 Derived

I<Derived> is available if enabled in L</Extensions>.

=head3 Cte

Common table expression, available if enabled in L</Extensions>.

=head3 Join

Join tables.

This entry is available if enabled in L</Extensions>.

=head3 Union

Combine the result from multiple C<SELECT> statements with C<Union>, C<Intersect> and C<Except> (C<Firebird>: Union).

This entry is available if enabled in L</Extensions>.

=head2 SQL Menu

SQL statements are created in this menu.

The SQL Menu has the following menu entries:

=head3 Prompt Line

Selecting this prompt line (I<Customize:>) opens a menu with these entries:

=over

=item

Insert

=item

Update

=item

Delete

=back

See L</WRITE ACCESS>. These entries are available if enabled in L</Extensions>.

=head3 BACK

If the user has set substatements, selecting C<BACK> will reset all changes made.

If no changes have been made or if the changes have been reset, selecting C<BACK> will exit the SQL menu.

=head3 Print TABLE

Select I<Print TABLE> to show the result of the formed statement on the screen.

=head3 The Sub-Statements Entries

In a SQL submenu (e.g., C<WHERE>), the back arrow resets the subquery step by step. With no items left, the SQL submenu
is left when the back arrow is chosen.

Adding AGGREGATE functions or GROUP BY columns enables the I<aggregate mode>. In I<aggregate mode>, the available
columns in the SELECT substatement are the added aggregate functions and the group-by columns, not the table columns.

See also L</Extensions> and L</Operators>

=head4 SELECT

Choose the required columns for the C<SELECT> substatement.

It is possible to add many columns at once by marking them with the C<SpaceBar> key. If columns are marked with the
C<SpaceBar>, the highlighted column is not added to the chosen when C<Return> is pressed.

=head4 AGGREGATE

C<AVG>, C<COUNT>, C<COUNT(*)>, C<GROUP_CONCAT>, C<MAX>, C<MIN>, C<SUM>

If the user has selected columns in the SELECT submenu: While in this submenu, the available columns are displayed in
the SELECT substatement instead of the selected columns.

=head4 DISTINCT

=head4 WHERE

=head4 GROUP BY

If the user has selected columns in the SELECT submenu: While in this submenu, the available columns are displayed in
the SELECT substatement instead of the selected columns.

=head4 HAVING

=head4 ORDER BY

=head4 LIMIT

=head3 Export

Export the result of the chosen SQL statement to a C<CSV>-file. See options L</Export Data>.

=head1 WRITE ACCESS

=head2 Create/Drop Table/View

I<Create/Drop Table/View> can be accessed by selecting the prompt-line in the L</Tables Menu> if the respective option
is activated.

Selecting the prompt line of the I<Create/Drop Table/View> submenu allows you to set the parse settings described in
L</Import Data>.

=head3 Create Table

If the option I<Source Type> is set to I<menu>, selecting I<Create Table> opens a submenu where you can choose the type
of the data source. If I<Source Type> is set to I<plain> or I<file>, the set data source type is automatically used
without displaying a menu. For more information, see L</Data Input>.

You will be prompted:

=over

=item

for the table name

=item

if the first data row should be used as a header

Selecting the prompt line of this menu allows you to set the 'create table' options.

=item

if an auto increment column should be added (if the option is enabled in L</Create-Table>)

=item

to edit the column names

=item

to edit the column data types

=item

to confirm the creation of the table

=back

=head3 Drop Table

Dropping a table displays the entire table before confirming the deletion.

=head3 Create View

Before creating a view, print the required select statement to make it available in the subquery menu.

=head3 Drop View

Drop a view. The entire view is shown before the user confirms dropping it.

=head2 Insert/Update/Delete

I<Insert>, I<Update> and I<Delete> can be accessed by selecting the prompt-line in the L</SQL Menu> if the respective
option is activated.

I<Delete>, I<Update>, or I<Insert> may not be available with C<Join> and C<Union>/C<Intersect>/C<Except> statements.

=head3 Insert

If the option I<Source Type> is set to I<menu>, selecting I<Insert> opens a submenu where one can choose the type of
the data source. If I<Source Type> is set to I<plain> or I<file>, the set data source type is used without showing a
menu. For more information, see L</Data Input>.

If the first column of a table is an auto-increment column, the C<INSERT INTO> statement is built without this first
column. This feature is available if supported by the database plugin.

=head3 Update

Update records. The affected (and not yet updated) records are shown before the user confirms the update.

=head3 Delete

Delete records. The affected records are shown before the user confirms the deletion.

=head2 Data Input

=head3 Data Source

=over

=item plain

Insert the data cell by cell.

=item file

The data is read from a chosen file.

Supported file formats: text files and file formats supported by L<Spreadsheet::Read>. C<Spreadsheet::Read> uses
different parser modules for the different file formats - see L<Spreadsheet::Read/DESCRIPTION>. The parser modules are not
installed automatically. It is up to the user to install the required parser modules.

Selecting I<file> opens the I<Source directory> submenu where one can choose the directory which should be
searched for files.

If the L</Directory History> is set to C<1>, the I<Source directory> submenu is skipped and the directory is chosen
automatically.

After a directory has been chosen, a submenu is opened where one can choose the source file.

If the previous submenu I<Source directory> is not shown due to the settings described before, it is possible to change
the source directory in this submenu by selecting I<Change dir>.

Selecting the prompt line of the I<Files> submenu (I<Choose a File:>) allows one to set the parse settings described in
L</Import Data>.

After the data has been read, the user can apply different input filters (See L</Input Filters>).

=back

=head3 Input Filters

=over

=item Choose Cols

Use only selected columns of the imported data.

If the data has empty columns (C<-->), the non-empty columns are preselected. Columns are regarded as empty if the
values of all fields in the column - including the column header - have no length.

Columns added with the filter I<Append Col> are empty and therefore not preselected.

If a column is not empty but has no header name, the header is named temporarily C<tmp>.

=item Choose Rows

Use only selected rows of the imported data.

If the data has empty rows, the non-empty rows are preselected. Rows are regarded as empty if the values of all fields
in the row have no length.

=item Range Rows

Use only a range of rows.

=item Row Groups

If the input has rows with different numbers of columns, I<Row Groups> sorts rows with the same number of columns into a
group. The user can then choose one or more groups of rows. There is only one group if all rows have the same column
count.

=item Remove Cell

Remove a cell from a chosen row.

=item Insert Cell

Insert a cell in a chosen row. The new cell is inserted in front of a chosen cell.

=item Append Col

Append an empty column. Appends a header element to the header row and adjusts the remaining rows to the length of the
header row. If the input has rows with different numbers of cells, use the I<Row Group> filter first to select the right
row-group.

=item Split Column

     Item | length/width/height             Item | length | width | height
    ------|---------------------            -----|--------|-------|------
      423 |            40/30/25              423 |     40 |    30 |    25
    ------|---------------------            -----|--------|-------|------
       64 |            80/60/30               64 |     80 |    60 |    30
    ------|---------------------            -----|--------|-------|------
      705 |            50/50/40              705 |     50 |    50 |    40

=item Search & Replace

I<s/Pattern/Replacement/Modifiers>

Remove all commas: C<s/,//g>

    id | num                       id | num
    ---|-------------              ---|-----------
     1 |    78,975.17               1 |   78975.17
    ---|-------------              ---|-----------
     2 | 1,040,745.87               2 | 1040745.87
    ---|-------------              ---|-----------
     3 | 3,129,818.21               3 | 3129818.21

Supported L<modifiers|https://perldoc.perl.org/perlre#Modifiers>: C<imnsxage>.

In the replacement, the variable C<$c> can be used as a counter. C<$c> is set to C<0> before each C<s///>.

By selecting the prompt line (I<Your choice:>), one can save I<search & replace> instructions for later use.

If a I<search & replace> has altered the first row of the input data, a menu entry named C<RESTORE header row> is
offered.

=item Split Table

     y  | factor | y  | factor              y  | factor
    ----|--------|----|--------             ---|-------
     62 | 8975.1 | 64 | 9986.5              62 | 8975.1
    ----|--------|----|--------             ---|-------
     63 | 9745.8 | 65 | 9782.7              63 | 9745.8
                                            ---|-------
                                            y  | factor
                                            ---|-------
                                            64 | 9818.2
                                            ---|-------
                                            65 | 9986.5

=item Merge Rows

     Month | Average | Average              Month | Average MinTemp | Average MaxTemp
    -------|---------|---------             ------|-----------------|----------------
           | MinTemp | MaxTemp              Jan   |               9 |              22
    -------|---------|---------             ------|-----------------|----------------
     Jan   |       9 |      22              Feb   |              10 |              23
    -------|---------|---------
     Feb   |      10 |      23

I<Merge Rows> can be used to edit a row by selecting only one row.

=item Join Columns

     Item | length | width | height          Item | length/width/height
    ------|--------|-------|--------         -----|-------------------
      423 |     40 |    30 |     25           423 | 40/30/25
    ------|--------|-------|--------         -----|-------------------
       64 |     80 |    60 |     30            64 | 80/60/30
    ------|--------|-------|--------         -----|-------------------
      705 |     50 |    50 |     40           705 | 50/50/40

I<Join Columns> can be used to edit a column by selecting only one column.

=item Fill up Rows

If the input table rows have different numbers of cells, this filter appends empty cells to the rows until the cell
count of each row is equal to the cell count of the row with the highest cell count.

You can enter the I<Row Group> filter to check if the table has rows with different lengths. If I<Row Group> shows only
one group, all rows have the same length.

=item Cols to Rows

Transpose columns to rows.

     Year | 2000 | 2001 | 2002              Year | Max | Min
    ------|------|------|------             -----|-----|----
     Max  |   14 |   22 |   17              2000 |  14 |  11
    ------|------|------|------             -----|-----|----
     Min  |   11 |   10 |    9              2001 |  22 |  10
                                            -----|-----|----
                                            2002 |  17 |   9

=item Empty to NULL

Convert fields containing an empty string to NULL (undefined).

The default values for this filter can be set using the option L</Empty to Null>.

=item Reset

Reset the filters.

=item Reparse

Change the parse settings and reparse the data with the new settings.

=back

=head1 OPTIONS

The options menu is accessed with C<db-browser -h>.

=head2 Plugins

Choose the required database plugins.

=head2 DB Settings

These driver-specific I<DB Settings> are used as the default database settings.

In the prompt line menu of the L</Tables Menu>, the entry I<DB Settings> (if enabled in L</Extensions>) allows users to
make database-specific settings. If no database-specific settings are set, these global settings (for the database
plugin) I<DB Settings> are used.

User-defined database plugins: The options offered to be set in each option and whether the user's selections are
considered depend on the plugin.

=over

=item Fields

Set which fields are required to connect to a database.

=item Login Data

The entered login data is saved in a configuration file and used to connect to the database (the password cannot be
saved).

=item ENV Variables

The user can choose environment variables from a list of environment variables that should be used - if set - to connect
to the database.

=item Attributes

For the meaning of these driver-specific attributes, refer to the appropriate driver documentation.

=item Reset DB

Reset database-specific parameters to the global I<DB Settings>.

=back

=head2 Extensions

Add menu entries to menus:

=head3 Tables Menu

=over

=item Derived Table

Enter a subquery and use it as a table.

By selecting the I<Read-Line> menu entry, the user is asked for the query.

If stored statements are available, it is also possible to select one of those statements instead of entering a query.

Previously entered queries and the last statements printed with I<Print TABLE> are stored temporarily.

Statements can be saved permanently in the submenu, which opens by selecting the prompt line in the I<Subquery> menu
(I<Choose:>).

=item Cte

The user is asked for the CTE query and the CTE name. The syntax of the CTE name is:

    [RECURSIVE] cte_name [(col_name [, col_name] ...)]

Some database types build recursive CTEs without the C<RECURSIVE> keyword.

By selecting the I<Read-Line> menu entry, the user can enter the query.

If stored statements are available, it is also possible to select one of those statements instead of entering a query.

Previously entered queries and the last statements printed with I<Print TABLE> are stored temporarily.

Statements can be saved permanently in the submenu, which opens by selecting the prompt line in the I<CTE> menu
(I<Choose:>).

Certain uses of CTEs are not supported.

=item Join

=item Union

=item DB settings

=back

=head3 Join Menu

=over

=item Derived Table

=item Cte

=back

=head3 Union Menu

=over

=item Derived Table

=item Cte

=item Where

=item Parentheses

=back

Note: Parentheses are not available in C<SQLite> and C<Firebird>.

These settings are also valid when C<Intersect> or C<Except> is used.

=head3 Columns and Values

=over

=item

Extended Columns

If enabled, C<%%> is shown as an additional menu entry in the column menus. Selecting C<%%> lets one choose between the
available extensions.

=item

Extended Values

If enabled, then - in addition to constants - subqueries, functions and more (see the following list) are available for
the right side of operators. Places where extended values are available: C<WHERE>, C<HAVING>, C<SET> in update, and
C<WHEN>, C<THEN> and C<ELSE> in case expressions.

=item

Extended Arguments

If enabled, subqueries, functions and more (see the following list) are available for entering arguments in addition to
constants in the scalar and window functions.

This option can also be enabled later in the functions menu by selecting the prompt line.

=back

=head4 Column/Value/Argument Extensions

Not all of these extensions are available everywhere.

=over

=item Subqueries

Selecting C<SQ> opens the subqueries menu.

By selecting the I<Read-Line> menu entry, one can enter a subquery or an expression.

If stored subqueries are available, it is also possible to select one of those subqueries instead of entering a
subquery.

The last subqueries entered in the subquery menu and the last statements printed with I<Print TABLE> are stored
temporarily.

A subquery can be saved permanently in the submenu, which opens by selecting the prompt line of a subquery menu
(I<Choose SQ:>).

Entries matching C</^\s*(?:SELECT|WITH)\s/i> are automatically enclosed in parentheses.

=item Scalar Functions

Selecting C<func()> opens the menu, where the user can choose from a list of scalar functions.

Extended arguments for scalar functions can be temporarily enabled by selecting the prompt line (I<Scalar functions:>)
of the scalar function menu.

Function C<DATEADD> and C<EXTRACT>: use the keys C<Up-Arrow> and C<Down-Arrow> to choose one of the predefined fields
(in C<Value> if the extended arguments are enabled).

To subtract from a date, use C<DATEADD> with a negative amount.

Non-ANSI SQL scalar functions may not work with the C<ODBC> plugin.

=item Window Functions

Selecting C<win()> opens the menu, where the user can choose from a list of window functions.

=item Case Expression

Selecting C<case> opens the menu, where the user can build a C<CASE> expression.

=item Maths

Selecting C<math()> opens the menu, where the user can combine expressions with arithmetic operators.

=item Columns

Selecting C<col> opens the menu, where the user can choose a column.

=item Set to C<NULL>

Available after the C<SET> in an C<UPDATE> statement.

=item Parentheses

C<WHERE>, C<WHEN> and C<HAVING>: in the C<%%> menu are also available parentheses.

=item Column Aliases

Selecting C<as> allows one to set aliases for the selected columns.

=back

=head3 Write Access

Enable write access - use with care.

=over

=item

Insert Records

=item

Update Records

=item

Delete Records

=item

Create Table

=item

Drop Table

=item

Create View

=item

Drop View

=back

=head2 SQL Settings

=head3 System Data

If I<System data> is enabled, system tables/schemas/databases are appended to their respective lists.

=head3 Operators

Choose the required operators.

There are two regexp entries: C<REGEXP> matches case-sensitive, while C<REGEXP_i> matches case-insensitive.

With C<MySQL>, the sensitive match is achieved by enabling the C<BINARY> operator.

With C<Firebird>, C<SIMILAR TO> is used instead of C<REGEXP>.

=head3 Aliases

Alias settings for:

=over

=item

Functions/Subqueries in SELECT

=item

Tables in JOIN

=item

Non-unique columns in JOIN

=item

Derived table

C<Postgres>, C<MySQL> and C<MariaDB>: ensure that aliases for derived tables are enabled.

=item

Ordinary table

=back

Possible settings:

=over

=item

NO

no alias

=item

AUTO

a default alias is used

=item

ASK

the user is asked for the alias; if nothing is entered, no alias is added

=item

ASK/AUTO

the user is asked for the alias; if nothing is entered, a default alias is added

=back

Not all of these settings are available for any alias type.

=head3 Identifiers

=over

=item

Qualified Table Names

=item

Quote Table Names

=item

Quote Column Names

=item

Quote Aliases

=back

C<SQLite>: if the current database has attached databases, the use of qualified table names is enabled automatically.

C<SQLite>: database names in SQL statements (C<ATTACH DATABASE>) are always quoted.

C<Informix>: set the C<DELIMIDENT> environment variable to allow quoted identifiers.

=head3 View Prefix

Enter a string that should be automatically placed in front of all view names.

=head2 Create-Table

=head3 Enable Options

=over

=item

Auto Increment

Enabling I<Auto Increment> makes the 'auto-increment primary key' option available when creating a table.

=item

Data Type Guessing

When this option is enabled and a table is created, C<SQL::Type::Guess> is used to guess the data types. These data types
are then used as defaults when the user is prompted for data types.

=back

=head3 Add Form Fields

=over

=item

Table Constraint Fields

Specify the number of fields available for entering table constraints (0-9).

=item

Table Option Fields

Specify the number of fields available for entering table options (0-9).

=back

=head3 Auto Increment Column Name

Set the default value for the auto-increment primary key column name.

=head2 Output

=head3 Binary Filter

Set I<Binary filter> to C<NO>, C<BNRY>, or C<Hexadecimal>.

C<NO> - print the binary data as it is

C<BNRY> - "BNRY" is printed instead of the binary data

C<Hexadecimal> - the binary data is printed in hexadecimal format

If the first 100 characters of the data match the regexp C</[\x00-\x08\x0B-\x0C\x0E-\x1F]/>, the data is considered
arbitrary binary data.

Printing unfiltered arbitrary binary data could break the output.

=head3 Squash Spaces

If I<squash_spaces> is enabled, consecutive spaces are squashed to one space, and leading and trailing spaces are
removed.

=head3 Indentation

Set the indentation width for the SQL substatements.

=head3 Undef String

Set the string that will be shown on the screen instead of an undefined field.

On C<MSWin32>, only single-byte character sets are supported when entering the setting I<Undef string>, I<user>,
I<host>, or I<port> with the C<db-browser>'s readline. However, it is possible to edit the entry in configuration files
directly after the entry was created with this options menu.

=head3 Warnings

Enable/disable:

=over

=item

C<File::Find> warnings when searching for C<SQLite> databases.

=item

Warnings (e.g., UTF-8 warnings) when printing a table.

=back

=head3 Progress Bar

Set the progress bar threshold. If the number of fields (rows x columns) exceeds the threshold, a progress bar is shown
while preparing the data for output.

=head3 Tab Width

Set the number of spaces between columns.

=head3 Color

Enable support for color and text formatting escape sequences (SGR) by setting it to C<Enable>. Before the output, a
reset (C<\e[0m>) is added at the end of each row.

=head3 Truncate Fractions First

If the terminal width is insufficient and I<Trunc fract first> is enabled, the first step to reduce the column width is
to truncate the fraction part of numbers to 2 decimal places.

=head3 Truncate Column Threshold

Columns with a width below or equal to I<Trunc col threshold> are only trimmed if it is still necessary to reduce the
row width, even after all columns wider than I<Trunc col threshold> have been trimmed to I<Trunc col threshold>.

=head2 Import Data

=head3 Parse Tool

Set how to parse text files. Files for which C<-T $filename> returns true are considered text files. If a file isn't a
text file, C<Spreadsheet::Read> is always used to parse it, regardless of this setting.

=over

=item

Text::CSV

Advantages:

=over

=item

Allows different CSV-related options.

=item

Speed

=back

=back

=over

=item

split

Reads the entire input at once and splits it using the input record separator (IRS) to obtain the records (rows). It
then splits the records using the input field separator (IFS) to acquire the fields (columns) of each record.

To decode the files, the L</File Encoding> is used.

Advantages:

=over

=item

The values assigned to the input record separator (IRS) and the input field separator (IFS) are treated as regex
patterns.

=back

=back

=over

=item

Template

Uses C<unpack> with the C<A> character to break up input lines.

=over

=item

If the row length exceeds the screen width, take note of the number of columns and the length of each column before
using I<Template>.

=item

Choose the input record separator.

=item

Set the number of columns (I<Col count>) and the width of the column separator (I<Sep width>). I<Col count> expects an
integer of 1 or greater; I<Sep width> expects an integer of 0 or greater.

=item

Set the widths of the columns (1 or greater). For the last column, one can also enter an asterisk (C<*>). An asterisk in
the last column means: Use the remaining part of the row for the last column.

=item

Decide whether leading spaces should be removed. Trailing whitespaces are removed automatically.

=back

Advantages:

=over

=item

Ideal for fixed-length inputs containing only single-width characters.

=back

=back

=over

=item

Spreadsheet::Read

If C<Spreadsheet::Read> is chosen, the default settings from L<Spreadsheet::Read> are utilized.

C<Spreadsheet::Read> will use the first line of the file to auto-detect the separation character if the file is a CSV
file.

C<Spreadsheet::Read::rows> automatically fills up uneven rows, so the filters L</Fill up Rows> and L</Row Groups> have no
significance when C<Spreadsheet::Read> is used.

Advantages:

=over

=item

Automatically detects the separation character for CSV files.

=back

=back

=head3 CSV Options In a

Set C<sep_char>, C<quote_char>, C<escape_char>, C<eol> and C<comment_str>. If left empty, default values are used. For
details on these options, refer to L<Text::CSV_XS>.

=head3 CSV Options In b

Set C<allow_loose_escapes>, C<allow_loose_quotes>, C<allow_whitespace>, C<blank_is_undef>, C<binary>, C<decode_utf8>,
C<empty_is_undef> and C<skip_empty_rows>. For meanings of these options, refer to L<Text::CSV_XS>.

=head3 Settings 'split'

=over

=item

Record Separator

Set the input record separator (regexp).

=item

Trim Record Left

Expects a regex pattern. If set, removes leading characters matching the regexp from each record.

=item

Trim Record Right

Expects a regex pattern. If set, removes trailing characters matching the regexp from each record.

=item

Field Separator

Set the input field separator (regexp).

=item

Trim Field Left

Expects a regex pattern. If set, removes leading characters matching the regexp from each field.

=item

Trim Field Right

Expects a regex pattern. If set, removes trailing characters matching the regexp from each field.

=back

=head3 Input Filter

Enable the input filter menu.

Enabling I<input filter> will cause a second copy of the data to be kept in memory.

=head3 Empty to Null

Set the I<empty_to_null> defaults for the different data source types.

=head3 File Encoding In

How to decode text files.

=head3 Directory History

Set how many searched directories should be saved in the directory history.

A value of C<0> disables the history.

If I<Directory History> is set to C<1> and a directory has been saved, the directory is chosen automatically without
showing the history menu.

=head3 File Filter

This option expects a string as its value, used as a glob pattern.

If I<file> is selected as the data source type, only files matching this glob pattern are part of the available files.

=head3 Hidden Files

If I<file> is selected as the data source type, this setting determines if hidden files are included in the available
files or not.

=head3 Source Type

Set the data source type to C<plain>, C<file>, or C<menu> for C<Insert Into> and for C<Create Table>.

If set to C<menu>, a menu is offered where the user can choose the type of the data source. If set to C<plain> or
C<file>, the respective setting is used directly without any menu.

=head2 Export Data

=head3 Destination Folder

Set the folder where the data to be exported will be saved as a CSV file.

=head3 File Name

=over

=item File Extension CSV

If enabled, the file extension C<csv> is automatically added to the file name.

=item Default File Name

If enabled, the table name will be used as the default file name.

=back

=head3 CSV Options Out a

Set C<sep_char>, C<quote_char>, C<escape_char>, C<eol> and C<undef_str>.

If left empty, default values are used except for C<eol>, which is then set to C<$/> (input record separator).

For the meaning of the different options, see L<Text::CSV_XS>.

=head3 CSV Options Out b

Set C<always_quote>, C<binary>, C<escape_null>, C<quote_binary>, C<quote_empty> and C<quote_space>.

For the meaning of the different options, see L<Text::CSV_XS>.

=head3 File Encoding Out

The encoding of the exported CSV file.

=head2 Miscellaneous

=head3 Menu Memory

If enabled, saves the menu position while entering a submenu.

=head3 Expand Table

Expand table rows:

=over

=item C<YES>

If C<Return> is pressed, the selected table row is printed with each column in its line. The first row is not expanded
if the cursor auto-jumped to the first row.

=item C<NO>

Don't expand table rows.

=back

=head3 Search

Set the search behavior (C<Ctrl-F>).

=over

=item

disabled

=item

case-insensitive search

=item

case-sensitive search

=back

=head3 Mouse Mode

Set the I<Mouse mode> (see L<Term::Choose/mouse>).

=head3 DB2 Encoding

For C<DB2> databases only: set the application code set.

Data from a DB2 database is decoded using this encoding.

=head2 Help

Display this documentation.

=head2 Path

Displays the version and path of the running C<db-browser>, along with the application directory path.

=head1 CONFIGURATION FILES

To locate the configuration files, run C<db-browser -h> and select I<Path>. The data is saved in JSON format.

=head1 REQUIREMENTS

=head2 Perl Version

Requires Perl version 5.14.0 or later.

=head2 Decoded Strings

C<db-browser> expects decoded strings.

Non-mappable characters can disrupt the output.

=head2 Terminal

Requires a terminal with a monospaced font supporting the printed characters.

The terminal must comprehend ANSI escape sequences. For MSWin32, C<App::DBBrowser> utilizes L<Win32::Console::ANSI> to
emulate an ANSI console for the C<db-browser>.

=head2 Permissions

To browse the database, schema, table lists and table content, the user must possess the necessary database privileges
for fetching the requested data.

C<db-browser> expects an existing home directory with read and write permissions for the user of the C<db-browser>.

=head1 CREDITS

Thanks to the L<Perl-Community.de|http://www.perl-community.de> and the people form
L<stackoverflow|http://stackoverflow.com> for the help.

=head1 AUTHOR

Matthäus Kiem <cuer2s@gmail.com>

=head1 LICENSE AND COPYRIGHT

Copyright 2012-2024 Matthäus Kiem.

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For
details, see the full text of the licenses in the file LICENSE.

=cut
