db-browser - Browse SQLite/MySQL/PostgreSQL databases and their tables interactively.
db-browser
Version 0.035_03
db-browser db-browser -h|--help
When the db-browser is called with the argument -h|--help, it shows a menu - see "OPTIONS".
-h|--help
db-browser [-s|--search] [directories to be searched]
If no directories are passed, the home directory is searched for SQLite databases.
db-browser called with -s|--search causes a new search of SQLite databases instead of using the cached data.
-s|--search
Search and read in SQLite/MySQL/PostgreSQL databases. With the db-browser one can browse databases and their tables interactively. The available DBI drivers are DBD::SQLite, DBD::mysql and DBD::Pg.
DBD::SQLite
DBD::mysql
DBD::Pg
To be able to browse database-, schema- and table-lists and the content of tables one needs to have the database privileges required for fetching the respective data.
The db-browser expects an existing home directory with read and write permissions for the user of the db-browser.
It is recommended to work with an UTF encoding. Non mappable characters might break the output.
It is required a terminal with a width of at least 40 print columns.
Before the output leading and trailing spaces are removed from the elements and spaces are squashed to a single white-space.
The elements in a column are right-justified if one or more elements of that column do not look like a number, else they are left-justified.
See Term::TablePrint for more details.
The best way to find out how db-browser works is calling db-browser.
To be able to use all the features of the db-browser some basic SQL knowledge is required.
The SQL menu is the menu which opens after a table was selected.
If AGGREGATE or GROUP BY is set, the SELECT statement is automatically formed; a previous user defined SELECT statement is reset. A user defined SELECT resets a previous set AGGREGATE or GROUP BY statement.
AGGREGATE
GROUP BY
SELECT
To reset a SQL "sub-statement" (e.g WHERE) re-enter into the respective menu entry and choose '- OK -'.
WHERE
'- OK -'
Changing the lock mode (Lk0,Lk1) resets the entire SQL.
Lk0
Lk1
the Arrow keys (or h,j,k,l) to move up and down and to move to the right and to the left,
Arrow
h,j,k,l
the PageUp key (or Ctrl-B) to go back one page, the PageDown key (or Ctrl-F) to go forward one page.
PageUp
Ctrl-B
PageDown
Ctrl-F
the Home key (or Ctrl-A) to jump to the beginning of the menu, the End key (or Ctrl-E) to jump to the end of the menu.
Home
Ctrl-A
End
Ctrl-E
With the option mouse enabled it can be used the mouse with the left mouse key to navigate through the menus.
To confirm a chosen menu item use the Return key.
Return
When choosing columns for the SELECT and GROUP BY statement, it is possible to select items with the SpaceBar key before Return is pressed. Then the list of items marked with the SpaceBar including the highlighted item are added to the chosen items. If a mouse mode is enabled, it can be used the right mouse key instead of the SpaceBar. Ctrl-SpaceBar (or Ctrl-@) inverts the made choices - marked items are unmarked and unmarked items are marked.
SpaceBar
Ctrl-SpaceBar
Ctrl-@
To move backwards in the menu hierarchy one can press the q key . When prompted for a string, use Ctrl-D instead of q.
q
Ctrl-D
Show this Info.
Shows the version and the path of the running db-browser and the path of the application directory.
Columns with a width below or equal Colwidth are only trimmed if it is still required to lower the row width despite all columns wider than Colwidth have been trimmed to Colwidth.
Set Database defaults.
The DB Defaults can be overwritten for each database with the database menu entry "Database settings".
If set to "YES", DBD::SQLite tries to see if the bind values are numbers or not, and does not quote if they are numbers.
See DBD::SQLite for details. This is a SQLite-only option.
If Enable utf8 is enabled, the utf8 flag will be turned on for character data coming from the database.
For a more driver specific explanation see the documentation of the respective Perl DBI driver.
With the Pg driver in use it is available - apart from the "YES/NO" choices - also an "AUTO" choice. If the DBD::Pg version is less than 3.0.0, "AUTO" is mapped to "YES". For the meaning of "AUTO" look in pg_enable_utf8 for the value -1.
Pg
-1
Print "BNRY" instead of arbitrary binary data.
If the data matches the repexp /[\x00-\x08\x0B-\x0C\x0E-\x1F]/, it is considered arbitrary binary data.
/[\x00-\x08\x0B-\x0C\x0E-\x1F]/
Printing arbitrary binary data could break the output.
Sets the default directories where db-browser searches for SQLite databases. This is a SQLite-only option.
To move around in the directory tree select a directory and press Return to enter in the selected directory or choose " .. " to move upwards. To add the current working-directory to the list of chosen directories use the " . " menu entry. To confirm the made choices select " = ". The ( " < " ) menu entry resets the list of chosen directories if any. If the list of chosen directories is empty, " < " goes back without changing anything.
..
.
=
<
This setting can not be overwritten in a single database.
RESET resets the database settings.
Choose the required database drivers.
Determine when db-browser asks for the login data:
Ask host/port per DB
If set to "YES" host and port data is asked once per database else the global settings are used if any.
Ask user/pass per DB
If set to "YES" username and password data is asked once per database else only once.
This option has no meaning if the SQLite driver is in use.
Set the behavior of different interactive menus:
- setting Menus to "Memory" means: save the selected menu position in the database/schema/table menus while entering in a sub menu.
- setting Print Table to "Expand" means: enable printing the chosen table row.
- setting Table Header to "Each page" means: print the table header on top of each page.
- use DBI_USER as username for all database logins if the environment variable exists and Ask user/pass is set to "Once".
DBI_USER
- use DBI_PASS as password for all database logins if the environment variable exists and Ask user/pass is set to "Once".
DBI_PASS
- use DBI_USER as host for all database connections if the environment variable exists and Ask host/port is set to "No".
- use DBI_PORT as port for all database connections if the environment variable exists and Ask host/port is set to "No".
DBI_PORT
This options have no meaning if the SQLite driver is in use.
Set the default lock value:
- Lk0: Reset the SQL-statement after each "PrintTable".
- Lk1: Reset the SQL-statement only when a table is selected.
Set the maximum number of fetched table rows. This can be overwritten by setting a SQL LIMIT statement.
LIMIT
The fetched table rows are kept in memory.
To disable the automatic limit set Max Rows to 0.
If Metadata is enabled, system tables/schemas/databases are appended to the respective list.
Set the mouse mode (see "mouse" in Term::Choose).
Choose the required operators.
With this menu entry it is possible to mark items with the SpaceBar key.
Enable parentheses in WHERE and/or HAVING TO clauses.
HAVING TO
- (YES: the position of "(" in the menu is before the column names.
(YES
- YES(: the position of "(" in the menu is after the column names.
YES(
Set the progress bar threshold. If the number of fields (rows x columns) is higher than the threshold, a progress bar is shown while preparing the data for the output.
If Regexp Case is enabled, REGEXP will match case sensitive.
REGEXP
With MySQL the sensitive match is achieved by enabling the BINARY operator.
BINARY
With the Sssc mode "compat" enabled back-arrows are offered in the SQL menus entries. In the "simple" mode it can be used the q key instead of the back-arrows.
Set the number of spaces between columns.
Set the string that will be shown on the screen instead of an undefined field.
There is a hidden menu entry: selecting the prompt line in the SQL menu - Customize: - makes available some scalar functions.
With SQLite the function TRUNCATE is a user-defined function which returns stringified values.
TRUNCATE
return sprintf "%.*f", $places, int( $number * 10 ** $places ) / 10 ** $places;
When comparing in WHERE or HAVING TO clauses with numbers, take the non-truncated (original) value for the comparison if sqlite_see_if_its_a_number is enabled (default).
sqlite_see_if_its_a_number
Also to get a numeric comparison in an ORDER BY clause use the non-truncated (original) values for the ordering.
ORDER BY
With SQLite the function Bit_Length is a user-defined function which uses the Perl builtin length. To make length return the number of bytes the bytes pragma is used.
Bit_Length
length
bytes
use
With SQLite the function Char_Length is a user-defined function which uses the Perl builtin length to get the number of characters.
Char_Length
To remove a chosen scalar function from a column select the column with the function a second time.
The syntax of the configuration file names is "conf_${driver_name}.json". To find out the location of the configuration files call db-browser -h and choose Path.
"conf_${driver_name}.json"
db-browser -h
The data is saved in JSON format.
The global settings are placed in the member called "*$db_driver". This settings are used if ask per DB in DB Login is not enabled. If ask per DB is enabled each database uses is own member named like the database. With the SQLite driver "database name" means the absolute path to the database file.
"*$db_driver"
SQLite
Sub-members (keys):
SQLite: sqlite_unicode (0,1) mysql: user Pg: user sqlite_see_if_its_a_number (0,1) host host binary_filter (0,1) port port dirs_sqlite_search ¹ mysql_enable_utf8 (0,1) pg_enable_utf8 (0,1,-1) binary_filter (0,1) binary_filter (0,1)
¹ only in "*SQLite": expects an array-reference as its value. db-browser searches for SQLite databases in the directories passed with dirs_sqlite_search.
"*SQLite"
dirs_sqlite_search
Examples
conf_SQLite.json: conf_mysql.json: { { "*SQLite" : { "*mysql" : { "binary_filter" : 0, "binary_filter" : 0, "dirs_sqlite_search" : [ "host" : "localhost", "/home/my/Documents", "mysql_enable_utf8" : 1, "/home/my/databases" "port" : null, ], "user" : "name" "sqlite_see_if_its_a_number" : 1, }, "sqlite_unicode" : 1 "database1" : { }, "mysql_enable_utf8" : 0, "/home/my/databases/db1.sqlite" : { "host" : "my_host", "binary_filter" : 1, "user" : "user_5" "sqlite_unicode" : 0 }, } "database2" : { } "binary_filter" : 1
See "REQUIREMENTS" in Term::TablePrint.
Requires Perl version 5.10.1 or greater.
DBI, DBD::SQLite, DBD::mysql, DBD::Pg.
Thanks to the Perl-Community.de and the people form stackoverflow for the help.
Matthäus Kiem <cuer2s@gmail.com>
Copyright 2012-2014 Matthäus Kiem.
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.
To install App::DBBrowser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::DBBrowser
CPAN shell
perl -MCPAN -e shell install App::DBBrowser
For more information on module installation, please visit the detailed CPAN module installation guide.