3. The subsystem "Database" (TBDS)
Subsystem «Databases» is represented by the object TBDS, which contains a modular objects of the following types of DB TTipBD. Each type of database contains objects of individual databases of that type TBD. Each database in its turn, contains the objects of their tables TTable (Fig. 3).

Fig. 3. Hierarchical structure of the database subsystem.
The subsystem provides the basic functions to access the type of database, as well as generalized functions for the manipulation of the databases and tables. For example, to hide the source of data, which may be a configuration file, the functions of an abstract access to the data source are provided. For the storage system-wide data the system table and the function of the abstract to access it are provided. Consequently, system-wide data can be stored in the configuration file and in the database table. Priority source, in this case, is the database table.
Being a modular object, the type of database (TTipBD) provides access to the implementation of the mechanism of one or another database. Access is made through a public databases of the module of a given type of database. Open/registered database is described in the table of databases to be opened or in the configuration file. There is, the so-called, the working database, which is always opens and is shown in the configuration file. DB which support the SQL-queries can grant access based on direct SQL-queries.
While working, the components of the OpenSCADA system open tables (TTable) available in the database and work with them.
3.1. Object of subsystem «Database» (TBDS)
Data:
Flags of the queries to the system table (enum – TDBS::ReqGen):
- OnlyCfg -- request only to the configuration file.
- UseTranslate -- use the translation of text variable.
Public methods:
- int subVer( ); -- Subsystem version.
- static string realDBName( const string &bdn ); -- Conversion of the full template name of the database or table (of view *.*.myTbl) in the real name. Actually the replacement of the special elements '*' by the elements of the working DB.
- void dbList( vector<string> &ls, bool checkSel = false ); -- Список доступных БД. <checkSel> указывает на необходимость проверки факта загрузки из выбранной БД и вставки в список БД только выбранной.
- AutoHD<TTable> open( const string &bdn, bool create = false ); -- Открытие таблицы <bdn> БД по её полному пути с созданием <create> в случае отсутствия.
- void close( const string &bdn, bool del = false ); -- Закрытие таблицы <bdn> БД по её полному пути с возможностью удаления после закрытия <del>.
- bool dataSeek( const string &bdn, const string &path, int lev, TConfig &cfg ); -- Общее сканирование записей источника данных. В качестве источника выступает конфигурационный файл или БД. В случае отсутствия БД используется конфигурационный файл. Если имя БД <bdn> или путь <path> конфигурационного файла не указаны, то их обработка пропускается.
- bool dataGet( const string &bdn, const string &path, TConfig &cfg ); -- Получение записи из источника данных (БД или конфигурационный файл). Если имя БД <bdn> или путь <path> конфигурационного файла не указаны, то их обработка пропускается.
- void dataSet( const string &bdn, const string &path, TConfig &cfg ); -- Установить/сохранить запись в источнике данных (БД или конфигурационный файл). Если имя БД <bdn> или путь <path> конфигурационного файла не указаны, то их обработка пропускается.
- bool dataDel( const string &bdn, const string &path, TConfig &cfg, bool useKeyAll = false ); -- Удаление записи из источника данных (БД или конфигурационный файл). Если имя БД <bdn> или путь <path> конфигурационного файла не указаны, то их обработка пропускается. <useKeyAll> используется для указания необходимости установки всех ключей для использования их при удалении с восстановлением исходного состояний выбора ключей при выходе из функции. Если этот флаг не установлен, то используются ранее выбранные ключи для выполнения операции.
- static string genDBGet( const string &path, const string &oval = "", const string &user = "root", char rFlg = 0 ); -- Получить общесистемные данные из конфигурационного файла или системной таблицы от имени пользователя <user>. Если данные отсутствуют, то возвращается значений <oval>.
- static void genDBSet( const string &path, const string &val, const string &user = "root", char rFlg = 0 ); -- Установить/сохранить обще-системные данные в конфигурационном файле или системной таблице от имени пользователя <user>.
- string fullDBSYS( ); -- Полное имя системной таблицы.
- string fullDB( ); -- Полное имя таблицы с описанием зарегистрированных БД.
- TElem &openDB_E( ) -- Структура таблицы зарегистрированных БД.
- AutoHD<TTipBD> at( const string &iid ) -- Обращение к модулю БД (типу БД).
- string optDescr( ); -- Локализованная помощь по опциям командной строки и параметрам конфигурационного файла.