Discussion of article "SQLite: Native handling of SQL databases in MQL5"


New article SQLite: Native handling of SQL databases in MQL5 has been published:

The development of trading strategies is associated with handling large amounts of data. Now, you are able to work with databases using SQL queries based on SQLite directly in MQL5. An important feature of this engine is that the entire database is placed in a single file located on a user's PC.

Debugging SQL queries in MetaEditor

All functions for working with the database return the error code in case of an unsuccessful code. Working with them should not cause any issues if you follow four simple rules:

  1. all query handles should be destroyed after use by DatabaseFinalize();
  2. the database should be closed with DatabaseClose() before completion;
  3. query execution results should be checked;
  4. in case of an error, a query is destroyed first, while the database is closed afterwards.

The most difficult thing is to understand what the error is if the query has not been created. MetaEditor allows opening *.sqlite files and work with them using SQL queries. Let's see how this is done using the company.sqlite file as an example:

1. Open the company.sqlite file in the common terminal folder.

2. After opening the database, we can see the COMPANY table in the Navigator. Double-click on it.

3. The "SELECT * FROM COMPANY" query is automatically created in the status bar.

4. The query is executed automatically. It can also be executed by pressing F9 or clicking Execute.

5. See the query execution result.

6. If something is wrong, the errors are displayed in the editor’s Journal.

SQL queries allow obtaining statistics on table fields, for example, the sum and the average. Let's make the queries and check if they work.

Author: MetaQuotes

  • www.mql5.com
Trader's profile