## Connections management

The console tool is able to handle several connections at the same time, they can dynamically be opened and closed during a session. The current connection in use is indicated by the prompt. Use the .c command to open a connection with the connection name (the name by which the connection is identified within the tool) and a connection string; for example:

    gda> .c cnc1 SalesTest
    cnc1>

The list of connection can be listed using the same .c command without any argument, for example:

    ia32> .c
              List of opened connections
    Name | Provider | DSN or connection string | Username
    -----+----------+--------------------------+---------
    cnc1 | SQLite   | SalesTest                |
    ia32 | SQLite   | IA32Instructions         |
    (2 rows)
    ia32>

To switch from one connection to the other, use the .c command with the connection name to use as single argument, for example to switch from using the "ia32" to the "cnc1" connection:

    ia32> .c cnc1
    cnc1>

## Virtual connections

Multiple connections can be bound together into a single connection in which it is possible to runs SQL statements. This effectively allows one to run SQL statements across multiple databases.

Binding connections together is done using the .bind CNC_NAME CNC_NAME1 CNC_NAME2 [CNC_NAME ...] command which creates new connection named "CNC_NAME" which binds the connections names "CNC_NAME1" and "CNC_NAME2" together (more connections can be bound); each connection to be bound into a virtual connection must of course already have been opened. The tables of each bound connection will appear into the new virtual connection as named "<cnc name>.<table name>".

In the following example, there are the "cnc1" and "cnc2" connections opened, and the "cnc3" connection is a virtual connection binding "cnc1" and "cnc2":

    cnc2> .bind cnc3 cnc1 cnc2
    Bound connections are as:
       cnc1 in the 'cnc1' namespace
       cnc2 in the 'cnc2' namespace
    cnc3> .c
              List of opened connections
    Name | Provider | DSN or connection string | Username
    -----+----------+--------------------------+---------
    cnc1 | SQLite   | DB_DIR=.;DB_NAME=pmodel  |
    cnc2 | SQLite   | SalesTest                |
    cnc3 |          | namespace cnc1           |
                      namespace cnc2
    (3 rows)
    cnc3>

The contents of each "customers" table in each of the bound connection is accessible:

    cnc3> select * from cnc1.customers;
    id | name            | last_update           | default_served_by | country | city
    ---+-----------------+-----------------------+-------------------+---------+-----
     2 | Ed Lamton       | 2008-08-12 00:00:00+0 |                 4 | SP      | MDR
     3 | Lew Bonito      | 2008-08-13 00:00:00+0 |                 1 | FR      | TLS
     4 | Mark Lawrencep  | 2007-12-25 00:00:00+0 |                   | SP      | MDR
     9 | Greg Popoff     | 2007-12-25 00:00:00+0 |                 2 | SP      | MDR
    10 | Vladimir Zirkov | 2001-01-31 00:00:00+0 |                 4 |         |
    (5 rows)
    cnc3>  select * from cnc2.customers;
    id | name            | default_served_by | country | city
    ---+-----------------+-------------------+---------+-----
     2 | Ed Lamton       |                 4 | SP      | MDR
     3 | Lew Bonito      |                 1 | FR      | TLS
     4 | Mark Lawrencep  |                   | SP      | MDR
     9 | Greg Popoff     |                 2 | SP      | MDR
    10 | Vladimir Zirkov |                 4 |         |
    (5 rows)
    cnc3>

The list of customers present in both tables are available as:

    cnc3> SELECT * FROM cnc1.customers WHERE name IN (SELECT name FROM cnc2.customers);
    id | name            | last_update           | default_served_by | country | city
    ---+-----------------+-----------------------+-------------------+---------+-----
     2 | Ed Lamton       | 2008-08-12 00:00:00+0 |                 4 | SP      | MDR
     3 | Lew Bonito      | 2008-08-13 00:00:00+0 |                 1 | FR      | TLS
     4 | Mark Lawrencep  | 2007-12-25 00:00:00+0 |                   | SP      | MDR
     9 | Greg Popoff     | 2007-12-25 00:00:00+0 |                 2 | SP      | MDR
    10 | Vladimir Zirkov | 2001-01-31 00:00:00+0 |                 4 |         |
    (5 rows)
    cnc3>