.TH gda-sql 1 "" "Version 5.2.8" "LIBGDA Manual Pages" .SH NAME gda-sql - an SQL console based on Libgda .SH SYNOPSIS .B gda-sql [\-\-help] [\-v] [\-\-version] [\-o] [\-\-output\-file \fI\fP] [\-C] [\-\-command] [\-f] [\-\-commands\-file \fI\fP] [\-i] [\-\-interactive] [\-l] [\-\-list\-dsn] [\-L] [\-\-list\-providers] [\-s] [\-\-http\-port \fI\fP] [\-t] [\-\-http\-token \fI\fP] [\-\-data\-files\-list] [\-\-data\-files\-purge \fI\fP] [connection's spec] [connection's spec...] .SH DESCRIPTION .PP gda-sql is an SQL console based on the \fILibgda\fP library. .PP It enables you to type in queries interactively, issue them to be executed by a connection, and see the query results. .PP Several connections can be opened at the same time, allowing you to switch the active connection to any opened connection. When starting, gda-sql opens a connection for each connection specified on the command line (plus optionally one corresponding to the \fBGDA_SQL_CNC\fP environment variable). The prompt indicates the current connection used when executing commands. See the \fB.c\fP internal command for an explanation about the syntax to specify a connection on the command line. .PP Alternatively, input can be from a file. In addition, it provides a number of meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks. .PP It is also possible to run the tool as a script using the classic '#!' string at the start of a script file, with the limitation that behaviour of arguments passed on the line after the '#!' command is undefined. Example: \fB#!/bin/path/to/gda-sql\fP \fB#!/usr/bin/env gda-sql\fP .SH OPTIONS gda-sql accepts the following options: .PP .TP 8 .B \-\-help Show command\-line options. .TP 8 .B \-o, \-\-output\-file \fI\fP Specifies a file to which outputs are redirected. .TP 8 .B \-C, \-\-command Run only single command (SQL or internal) and exit. .TP 8 .B \-f, \-\-commands\-file \fI\fP Execute commands from \fI\fP, then exit (except if \-i specified). .TP 8 .B \-i, \-\-interactive Keep the console opened after executing a file (used with the \-f option). .TP 8 .B \-l, \-\-list\-dsn List configured data sources and exit. .TP 8 .B \-L, \-\-list\-providers List installed database providers and exit .TP 8 .B \-s, \-\-http\-port \fI\fP Starts the embedded HTTP server on port \fI\fP .TP 8 .B \-t, \-\-http\-token \fI\fP Requires HTTP clients to authenticate by providing the \fI\fP (empty phrase by default) .TP 8 .B \-\-data\-files\-list Lists all the files used to hold information related to each connection (ie. information gathered by the tool about the connection such as meta data, defined statements,...) .TP 8 .B \-\-data\-files\-purge \fI\fP Removes file used to hold information related to each connection for the criteria passed as argument (note that adding \fB"list-only"\fP to the criteria, either before or after it using a comma, will not actually remove the file): \fB"non-dsn"\fP: remove all the files which do not correspond to a DSN (data source name). These are the files created when a connection is specified using connection parameters instead of using a DSN \fB"non-exist-dsn"\fP: same as \fB"non-dsn"\fP except it also removes the files which were for DSN which don't exist anymore \fB"all"\fP: remove all the files, for a complete cleanup For example: \fB\-\-data\-files\-purge all,list-only\fP lists all the files (which would be removed if the command was \fB\-\-data\-files\-purge all\fP). .SH ENVIRONMENT gda-sql can be configured through some environment variables: .PP .TP 8 .B GDA_SQL_CNC to define a connection to systematically be opened when the program starts. .TP 8 .B PAGER to define a text pager program to use (by default determined by the system). .TP 8 .B GDA_NO_PAGER to specify that no text pager should be used. .TP 8 .B GDA_SQL_EDITOR EDITOR VISUAL to define a text editor to be used (variables are examined in this order). .TP 8 .B GDA_SQL_VIEWER_PNG to define a PNG viewer. .TP 8 .B GDA_SQL_VIEWER_PDF to define a PDF viewer. .TP 8 .B GDA_SQL_HISTFILE to define the history file name to use (by default .gdasql_history), set to NO_HISTORY to disable history logging. .TP 8 .B GDA_DATA_MODEL_DUMP_ROW_NUMBERS if set, the first column of the output will contain row numbers .TP 8 .B GDA_DATA_MODEL_DUMP_ATTRIBUTES if set, also dump the data model's columns' types and value's attributes .TP 8 .B GDA_DATA_MODEL_DUMP_TITLE if set, also dump the data model's title .TP 8 .B GDA_DATA_MODEL_NULL_AS_EMPTY if set, replace the 'NULL' string with an empty string for NULL values .TP 8 .B GDA_DATA_MODEL_DUMP_TRUNCATE if set to a numeric value, truncates the output to the width specified by the value. If the value is -1 then the actual terminal size (if it can be determined) is used .TP 0 gda-sql can be compiled with support for binary relocatibility. This will cause data, plug-ins and configuration files to be searched relative to the location of the gda-sql executable file. .SH FILES gda-sql stores data source definitions (DSN) in Libgda defined files ($HOME/.local/share/libgda and /etc/libgda-5.0/config where ${prefix} is typically /usr). For each connection defined by a DSN, all the information regarding the connection (such as the meta data) is stored in a $HOME/.local/share/libgda/gda-sql-.db file. .SH SQL commands You can run any SQL understood by the database engine of the current connection. Additionally SQL statement can contain variables expressed as \fI##::\fP where \fI\fP is the variable's name and \fI\fP is its declared type (which can be "int", "string", "boolean", "time", "date", "timestamp" (and other types defined by GLib's syntax). Use the \fI.set\fP internal command to set variable's values. .SH Internal commands In addition to SQL commands, gda-sql supports internal commands which differ from SQL commands because they start with the "." or "\\" character. These commands are: .IP \fB.?\fP Lists all internal commands .IP \fB.bind\fP Bind two or more connections into a single new one (allowing SQL commands to be executed across multiple connections). \fB.bind [ ...]\fP creates a new connection named \fI\fP which binds the tables of the \fI\fP, \fI\fP and any other connection specified. .IP \fB.c\fP Opens a connection or sets the current connection. Username and password can pe specified using the \fB[:]@\fP or \fB[:]@\fP syntax, and if a username or a password is required but not specified, it will ba asked interactively. \fB.c \fP opens a connection internally known as \fI\fP, using the specified DSN. \fB.c \fP opens a connection internally known as \fI\fP, using a connection specified by \fI\fP which is similar to the \fI\fP parameter of the \fB.lc\fP command. \fB.c \fP sets the current connection to the connection known as \fI\fP. \fB.c ~\fP or \fB.c ~\fP set the current connection to the meta data corresponding to the current connection (for the first notation) or to the meta data corresponding to the \fI\fP connection. .IP \fB.close\fP Closes a connection. Full syntax is: \fB.close \fP. .IP \fB.cd\fP Changes the current working directory. Full syntax is: \fB.cd \fP. .IP \fB.copyright\fP Displays copyright information. .IP \fB.d\fP Lists all database objects if no argument is provided. \fB.d \fP gives details about the specified object and \fB.d .*\fP lists all objects in specified schema. .IP \fB.dn\fP Lists all schemas if no argument is provided. \fB.d \fP lists specified schema. .IP \fB.dt\fP Lists all tables if no argument is provided. \fB.d \fP lists specified table. .IP \fB.dv\fP Lists all views if no argument is provided. \fB.d \fP lists specified view. .IP \fB.fkdeclare\fP Declares a new foreign key (no constraint is added to the database). The meta data is modified to take into account a foreign key constraint. The foreign key specification is \fB (,...) (,...)\fP where \fB\fP is the name given to the foreign key constraint and \fB\fP references \fB\fP using the columns mentionned between the parenthesis. Note that the (\fB\fP, \fB\fP, \fB\fP) triplet uniquely identifies a declared foreign key (declaring a new foreign key with the same triplet will remove any previously declared one). \fINote:\fP any actual foreign key constraint will always have precedence over any declared foreign key. .IP \fB.fkundeclare\fP Un-declares a foreign key (does the opposite of \fB.fkdeclare\fP). .IP \fB.e\fP Edits the query buffer with external editor, if no argument is provided. \fB.e \fP edits the specified file name. The external editor can be specified using environment variables. .IP \fB.echo\fP Sends output to stdout, full command is: \fB.echo []\fP. .IP \fB.export\fP Exports internal parameter or table's value to the FILE file. Internal parameters are named values used when SQL statement containing variables are executed. \fB.export \fP exports the contents of the \fI\fP parameter to the specified file. \fB.export \fP exports the value of the \fI
\fP table, column \fI\fP for the row selected by \fI\fP to the specified file. This is most useful to export BLOBs. .IP \fB.g\fP Executes the contents of the query buffer, if no parameter is provided. \fB.g \fP Executes the contents of the specified query buffer. A named query buffer is created using the \fB.qs\fP command. .IP \fB.graph\fP Creates a graph of tables showing their relations (based on foreign key constraints). If no argument is provided, the graph lists all tables. \fB.graph [...]\fP creates a graph listing the specified tables. The generated graph is created as the "gdaph.dot" file. If the \fBGDA_SQL_VIEWER_PNG\fP or \fBGDA_SQL_VIEWER_PDF\fP environment variables are set and if the "dot" program (from GraphViz) is found, then the graph is displayed (if a display is available). .IP \fB.H\fP Set output format. Full syntax is: \fB.H [HTML|XML|CSV|DEFAULT]\fP. .IP \fB.http\fP Starts/stops the embedded HTTP server. Full syntax is \fB.http [ []]\fP, where \fI\fP is an optional token phrase which HTTP clients are required to send to authenticate. .IP \fB.i\fP Executes commands from file the specified file: \fB.i \fP. .IP \fB.l\fP Lists all data sources if no argument is provided. \fB.l \fP lists information about the specified DSN. .IP \fB.lp\fP Lists all available database providers if no argument is provided. \fB.lp \fP lists information about the specified provider. .IP \fB.lc\fP Declares a DSN. Full syntax is: \fB.lc []\fP. The \fI\fP format is: \fI://[[:]@]\fP where \fI\fP is a semi-colon (";") separated list of = pairs where \fI\fP is defined when using \fB.lp \fP (if \fI\fP contains non alphanumeric characters, they should be represented as specified by the RFC 1738). If a DSN with a similar name already exists, it is first removed. For example: ".lc mydsn PostgreSQL://HOST=moon;DB_NAME=mydb". .IP \fBldap_attributes\fP This option (see the \fB.option\fP command) defines or list the attributes handled by LDAP commands; it is only useful if the current connection is an LDAP connection. Its values must have the following format: \fB[,...]\fP. For multi valued attributes (such as "objectClass"), it is possible to specify how multiple values are handled by appending \fB::csv\fP (values are listed in a CVS syntax), \fB::*\fP (each row is duplicated with each value of the attribute), \fB::1\fP (only the 1st value of the attribute is shown), \fB::concat\fP (all the values are made into a string, separated by newlines) or \fB::null\fP (a NULL value is used). The default is an error value. .IP \fB.ldap_descr\fP Describes an LDAP entry; this command only works if the current connection is an LDAP connection. Full syntax is: \fB.ldap_descr ["all"|"set"|"unset"]\fP. If the \fBset\fP option is passed, then all the set attributes are shown, if the \fBall\fP option is passed, then all attributes are shown, and if the \fBunset\fP option is passed, then only attributes which don't have a value are shown. The default is to show only the set attributes specified by the \fBldap_attributes\fP option. .IP \fBldap_dn\fP This option (see the \fB.option\fP command) defines how the DN column is handled for LDAP searched entries; it is useful only if the current connection is an LDAP connection. Its values must be among: \fBdn\fP (use the full DN), \fBrdn\fP (use only the RDN), or \fBnone\fP (don't use the DN at all). .IP \fB.ldap_mod\fP Modifies an LDAP entry's attributes; this command only works if the current connection is an LDAP connection. Full syntax is: \fB.ldap_mod [[=]] [= ...]\fP. The \fB.\fP argument specifies which operation must be performed, among \fBDELETE\fP, \fBREPLACE\fP and \fBADD\fP. .IP \fB.ldap_mv\fP Renames an LDAP entry; this command only works if the current connection is an LDAP connection. Full syntax is: \fB.ldap_mv \fP. .IP \fB.ldap_search\fP Searches the LDAP directory for entries; this command only works if the current connection is an LDAP connection. Full syntax is: \fB.ldap_search ["base"|"onelevel"|"subtree" []]\fP. Filter must be a valid LDAP filter expression (outer most parenthesis are optional though), "base", "onelevel" or "subtree" can optionally specify the search scope (default is subtree), and \fB.\fP can be used to specify a different DN to search from (the default is to use the base DN specified when opening the connection). .IP \fB.lr\fP Removes a DSN declaration. Full syntax is: \fB.lc \fP. .IP \fB.meta\fP Updates the current connection's meta data (use this command after having modified the database's schema). .IP \fB.o\fP Sends output to a file or |pipe. Full syntax is: \fB.o \fP or \fB.o |\fP. .IP \fB.option\fP Defines options shared among all the connections. Full syntax is: \fB.option [
\fP (re)defines the the internal parameter named \fI\fP with the value of the \fI
\fP table, column \fI\fP for the row selected by \fI\fP.This is most useful to export BLOBs. .IP \fB.unset\fP Unset (delete) internal parameter. \fB.unset\fP unsets all the internal parameters. \fB.unset \fP unsets the internal parameter named \fI\fP. .SH SUGGESTIONS AND BUG REPORTS Any bugs found should be reported to the online bug-tracking system available on the web at http://bugzilla.gnome.org/. Before reporting bugs, please check to see if the bug has already been reported. When reporting bugs, it is important to include a reliable way to reproduce the bug, version number of gda-sql, OS name and version, and any relevant hardware specs. If a bug is causing a crash, it is very useful if a stack trace can be provided. And of course, patches to rectify the bug are even better. .SH OTHER INFO Consult the Libgda's home page at http://www.gnome-db.org/. .SH AUTHORS Vivien Malerba (for Libgda's authors, please consult the AUTORS file within the Libgda's sources) .SH "SEE ALSO" .BR psql (1), .BR mysql (1), .BR sqlite3 (1)