## MySQL Plugin

### Description

Import values from a MySQL database.

Using this plugin you can synchronise your qtstalker charts with quote data you keep in a MySQL database. The plugin does not depend on specific table or field names. Instead, you configure it by specifying the SQL query it should execute.

This plugin requires the mysql client libraries on the machine it is running on. Check if you have `/usr/lib/libmysqlclient.so` (or something similar).

If you want to compile this plugin yourself, you'll need the mysql client development package. This provides the C header files for the MySQL API.

### Plugin Parameters

- Database - Name of the MySQL database to connect to.
- Host - Name of the machine hosting the MySQL database
- Incremental - If checked then only quotes newer than the latest quote found in qtstalker for each symbol will be imported. (See discussion of SQL Query below.) If not checked, then all quotes for each symbol will be imported.
- Password - The password for connecting to the MySQL database. Note: this password will be stored in plaintext on your machine. For the security-aware, the best thing to do is to define a 'qtstalker' user on the database, whose rights are restricted to doing SELECTs on the quote tables. This user could do without a password.
- SQL Query - The query string to use (see below for explanation)
- Symbols - The list of the symbols to update, separated by spaces.
- Username - The username for connecting to the MySQL database. See discussion of password above. This MySQL user must have SELECT rights on the appropriate table(s).

Note that you need to specify all these settings only once. They are remembered between uses of the plugin.

#### The SQL Query

In order to keep this plugin maximally flexible, you must provide the SQL query to extract quotes for a specific symbol from the database.

The query you specify can be arbitrarily complex, as long as it is a single SQL SELECT statement which meets the following requirements:

- The names of the fields returned do not matter, but their order does. The order must be date, open, high, low, close, volume, open interest. (Open interest is optional.)
- The statement must return quotes for one single symbol. Use the placeholder $SYMBOL$ whereever the actual symbol name must be substituted in the statement.
- Use the placeholder $LASTDAY$ in a WHERE clause if you want to use the 'Incremental' feature (see examples below). The substring $LASTDAY$ will be replaced with the date of the last quote present in the qtstalker datafile for the symbol being updated. (If the 'Incremental' checkbox is not checked, it will be replaced with a prehistoric date.)

Here is an example for someone using one table per symbol, table name corresponding to symbol name.

       SELECT day,open,high,low,close,volume
       FROM $SYMBOL$
       WHERE day > '$LASTDAY$'
       ORDER BY day

Here is another example, for someone using a single table for all quotes for all symbols.

       SELECT day,open,high,low,close,volume
       FROM Quotes
       WHERE symbol = '$SYMBOL$' AND day > '$LASTDAY$'
       ORDER BY day

One more example, which looks like my set-up. I have a Quotes table and a Symbols table, which both have a foreign key (stockId) referring to a shared primary key in a Stocks table.

       SELECT day,open,high,low,close,volume
       FROM Symbols JOIN Quotes USING (stockId)
       WHERE symbol = '$SYMBOL$' AND day > '$LASTDAY$'
       ORDER BY day

If any of the above is incorrect or unclear, please let me know. I'll be happy to explain, and improve these docs. Please contact the maintainers via the qtstalker forums on SourceForge.