## Virtual connections

### Introduction to virtual connections

Libgda implements so called virtual connections which are used like normal GdaConnection objects (open, close, execute SQL commands, etc) but which in fact don't access any real DBMS.

Virtual connections allow one to use SQL to work on data when it is normally not available, such as sorting data physically stored in CSV or XML files.

A virtual connection is not created in the same way as for a normal connection:

- A specific GdaServerProvider object is required

- No data source (DSN) or connection string can be used

- One must use the gda_virtual_connection_open() method which creates and "opens" a virtual connection.

Here is an example of code on how to create a virtual connection using the GdaVproviderDataModel virtual provider:

    GdaConnection *cnc;
    GdaVirtualProvider *provider;

    provider = gda_vprovider_data_model_new ();
    cnc = gda_virtual_connection_open (provider, NULL);

Some examples of virtual connections usage can be found in the source distribtion of Libgda in:

- `samples/Virtual`

- `samples/DirDataModel`

- `samples/F-Spot`

Note that virtual connections have some inherent limitations [1]due to the implementation.

[1] As virtual connections are implemented using SQLite's virtual table features, the SQL dialect which can be used is the SQLite one (see the SQL as Understood By SQLite page), and there are a few limitations inherent to this implementation (see link for more information).

Also note that it is possible to create temporary tables in virtual connections using "CREATE TEMP TABLE..." statements, but the contents of such tables will be lost once the connection is closed.