System Database

System Database


System database is created together with a server project. You can read data of the base, send requests to the base, but you can't edit the base (delete tables/lines, update data manually)


Database Contents

System database contains several tables:
  • FLOAT_TAG_HISTORY (it contains the following fields ID, TAG_ID, DATETIME, QUALITY, VALUE)
  • INTEGER_TAG_HISTORY (it contains the following fields ID, TAG_ID, DATETIME, QUALITY, VALUE)
  • QUALITY_LIST (it contains the following field ID, NAME)
  • STRING_TAG_HISTORY (it contains the following fields ID, TAG_ID, DATETIME, QUALITY, VALUE)
  • TAGS_PASSPORT (it contains the following fields TAG_ID, TAG_TYPE, NAME, STATUS)
  • TAG_STATUSES (it contains the following fields ID, NAME)
  • TAG_TYPES_LIST (it contains the following fields ID, NAME, TABLE_NAME)

Database Location

You can find the database file via Web - server. Open Web-server page in a browser. Enter My Account with your login and password. You'll see the main page with tabs to work with the server. Enter Database tab. The first line in this tab shows database location.
Image 9334

Work with Database via JavaScript

In iRidium Script Editor you can call data of the database, if it's convenient. You can write requests that log data under certain condidtions.
To work with requests, study SQL language . This article reviews most frequently used scenarios used to work with the database.
var sql = IR.GetDatabase(); // assign sql variable properties of the system database.

To create a request to the database, do the following:
var examp = sql.Request('SELECT ...'); // assign examp variable Base Request sql property. Request body is written in brackets and inverted commas.
Log the request.
IR.Log(examp.Columns); // the number of fields (columns) of the request is logged
IR.Log(examp.Rows); // the number of rows of the request is logged 
IR.Log(examp.GetRowValue(0,0)); // cell value of row 1 and column 2 is logged
IR.Log(examp.GetColumnName(0)); //field name, whose index agrees with teh number in the brackets is logged.

If you want to get from the data base informatuib about tags whose value is <1500, do the following;
Read here how to create a database.
var i;
var j;
IR.AddListener(IR.EVENT_START,0,function()
{
var sql = IR.GetDatabase(); // ssign sql variable properties of the system database.
var examp = sql.Request('SELECT DISTINCT(ID), VALUE, TAG_ID FROM FLOAT_TAG_HISTORY WHERE VALUE<1500'); // assign examp variable Base Request sql property. Request body is written in brackets and inverted commas.
for (i=0;i<examp.Columns;i++) //make a cycle to output value
   for (j=0;j<examp.Rows;j++)
   {
      IR.Log(examp.GetRowValue(i,j); //field values are logged выводим в лог значения полей
   };  
});

This article was helpful for 6 people. Is this article helpful for you?