NAME
pmsql - interactive shell with readline for msql
SYNOPSIS
pmsql [-h host] [database]
DESCRIPTION
pmsql lets you talk to a running msql daemon sending either SQL queries or relshow commands. The output is formatted much in the same way as by the msql monitor (see below) and the relshow program, which are both coming with msql. The additional capability is a connection to a readline interface (if available) and a pipe to your favorite pager. Additionally you may switch between hosts and databases within one session and you don't have to type the nasty \g
(a trailing \g
, \q
, and \p
will be ignored).
If a command starts with one of the following reserved words, it's treated specially, otherwise it is passed on verbatim to the mSQL daemon. Output from the daemon is piped to your pager specified by either the PMSQL_PAGER or the PAGER environment variable. If both are undefined, the PATH is searched for either "less" or "more" and the first program found is taken. If no pager can be determined, the program writes to unfiltered STDOUT.
?
-
print usage summary and current host and database
ho[st] host
-
Set default host to "host"
da[tabase] database
-
Set default database to "database"
re[lshow] [-h host] [database] [table]
-
Describe databases or tables in the same way as done by the relshow program. If host or database are specified, the defaults are set to these values.
! EXPR
-
Eval the EXPR in perl
q[uit]
-
Leave pmsql
Global Variable
The global variable $Q
is used for the statement handle of the current query. You can use this variable in eval statements.
There's no global variable for the database connection, because we connect to the database for each command separately.
Completion
pmsql comes with some basic completion definitions that are far from being perfect. Completion means, you can use the TAB character to run some lookup routines on the current host or database and use the results to save a few keystrokes.
The completion mechanism is very basic, and I'm not intending to refine it in the near future. Feel free to implement your own refinements and let me know, if you have something better than what we have here.
Msql::Statement::as_string
The output of select commands is formatted by an Msql::Statement::as_string method. This works similar to the msql monitor with a few exceptions:
- the width of a column
-
is calculated by examining the width of all entries in that column
- control characters
-
are mapped into their backslashed octal representation
- backslashes
-
are doubled (
\\ instead of \
) - numeric values
-
are adjusted right (both integer and floating point values)
The differences are illustrated by the following table:
Input to msql (a real carriage return here replaced with ^M):
CREATE TABLE demo (
first_field CHAR(10),
second_field INT
) \g
INSERT INTO demo VALUES ('new
line',2)\g
INSERT INTO demo VALUES ('back\\slash',1)\g
INSERT INTO demo VALUES ('cr^Mcrnl
nl',3)\g
Output of msql:
+-------------+--------------+
| first_field | second_field |
+-------------+--------------+
| new
line | 2 |
| back\slash | 1 |
crnlr
nl | 3 |
+-------------+--------------+
Output of pmsql:
+----------------+------------+
|first_field |second_field|
+----------------+------------+
|new\010line | 2|
|back\\slash | 1|
|cr\013crnl\010nl| 3|
+----------------+------------+
BUGS
pmsql is not an msql clone. If you use it as such for bulk uploads into the database, you will notice an enourmous disadvantage in performance. The reason is that pmsql intentionally disconnects from the database after every query.
SEE ALSO
You need a readline package installed to get the advantage of a readline interface. If you don't have it, you won't be able to use the arrow keys in a meaningful manner. Term::ReadKey and Term::ReadLine do not come with the perl distribution but are available from CPAN (the Comprehensive Perl Archive Network).
See Msql, Term::ReadKey, Term::ReadLine.