Professional Documents
Culture Documents
Oimanual Database
Oimanual Database
11 Database Components
IMPORTANT: OI-15 with Hard Drive option is required for local persistent data storage.
For OI-15 without a Hard Drive or when a Hard Drive malfunctions, data will be stored
temporarily in the system running memory and will be lost if the machine loses power.
Alternatively, OI-15 has the capability to read/write data from/to a remote database.
However, the use of this particular function is rare and application specific. Its use is
therefore restricted within OIB and we will only cover this topic briefly in the pertinent
sections.
DB Connection property is common to all Database Components. It defines the connection
parameters OI will use to communicate with a particular database server. The default
database server supported by OI-15 is PostgreSQL. By default, it communicate with database
oi on local host 127.0.0.1, with user name user and no password. OIB restricts
database server access to local and therefore the editing of hostName setting is disabled. It
can be changed however in a text editor.
To make another database write button of the same type, move the crosshair to a different
area of a screen and click again. If you wish to make a duplicate of a recently created button,
click on the chosen component and select 'copy' in the edit menu. Then select 'paste' in the
edit menu.
triggerTag: This refers to the tag that will cause data to be written to a row in the
specified database table. Auto-complete feature is enabled for this field for tags that are
already defined in the tag editor. A drop down list is also provided for tag selection.
findRecordTag:
statusTag:
tagList: Here we enter a list of tags seperated by semicolon. Each tag may only appear
once. If multiple occurances are detected, the later occurances will be ignored. At the time of
a triggering event, the values of these tags will be read and written to the specified database
table. The database table will be created when the application starts if it does not exist. The
order and names of the columns in the table will be determined by the order and names of the
tags listed. The data type of the column is determined by the data type of the tag.
If at the time of loading the application, the structure of the list has changed, the structure of
the table will be changed accordingly. In the event of this, OI system will try to modify the
previous data types to best match the new data types. If the conversion is not possible, the
previous data may be lost.
In addition to columns created by database write component based on the user provided tag
list, the following columns are implicitly created and managed by the OI system:
__id__ : internal id column used as the primary key of the table
__oi_store_time__: time at which the OI initiated the writing of the data
__db_store_time__: time at which the database system stores the data
tableName: The name of the database table into which the database write component
would insert data.
tableRowsLimit: The purpose of this property is to prevent the size of the database
tables from exceeding the limits of the storage media. This value determines the maximum
number of the records in the table. When the amount of records exceeds this limit and a new
record is written, the oldest record in the table will be erased. When this number is set to 0,
the amount of records for this table will be limited by tableSizeLimit if specified, or set
automatically based on the actual room in the storage media.
tableSizeLimitMB: Determines the maximum size of the tabel in MB. When the size of
the table exceeds this limit, the oldest record in the table will be erased. Testing available
space is performed every 10 minutes. When the test determines that the table is over-sized,
the oldest 5% of the records are removed. When this number is set to 0, the size of the
table will be limited either by tableRowLimit if specified, or automatically by the actual
room available in the storage media.
To determine when the oldest record will be erased, the lower limit of both tableRowsLimit
and tableSizeLimit is considered. In addition, the oldest records are removed automatically
whenever the storage media is running out of capacity. This can happen when one or more
tables do not have set size limits. When this occurs, the OI system automatically changes the
settings in the tableRowsLimit for all tables which are being written. It detects the actual
number of rows in each table and decreases the amount by 5%. The resulting values is then
used as the new tableRowsLimit. These settings can be edited by the user in the
tableRowsLimit field in the property editor of a database write component. Since these
automatic limits are created internally, these limits must be read from the OI before opening
the application in OIB. The limits do not save themselves to the application automatically.
The actual settings are displayed in the config screen of the OI.
Additionally, due to development in storage technology, the capacity of the hard drive is
getting so large that the amount of the data generated would not come close to the physical
limit of the hard drive within a reasonable time frame. However, because of the performance
concerns for exceptionally large databases, the OI system does impose an internal limit on
the size of database tables. This actual limit will be displayed in the config screen of the OI.
printToPrinterOnPort: This selection enables the printing via physical interfaces, in
ASCII format, of each record when it is written. The individual components are delimited by
the printColumnSeparator (see next section). The following ports are available: LPT1-3,
COM1-4, USB1-4, USBToSerial1-4. Note that all these ports may not be physically present
in every OI system type. If the Disabled option is selected, the record will not be printed.
printColumnSeparator: This specifies the delimiter used for separating the data sent to
the print port. By default, the system uses comma.
printHeader: When this option is enabled, the column names will also be printed on its
own line before the data.
Database Addressing
Before any data can be extracted from the database to tags, a user needs to understand the
database addressing sheme. In the same way that a PLC has its internal registers (a typical
integer register for AB can be N7:0, or for GE %R001) which store the actual data, the OI
database also has its own internal addressing. A new tab Database (Database_Read) is
created in the Tag Editor every time a new database read component is added to the
application. In this tab, a database address can be added and associated with a tag. The name
between the parenthesis matches the name of the corresponding database read component.
The format of the database addressing is as follows:
DB:order_of_record.name_of_the_column.
When the order_of_record is the offset from the current record;
Value 0 displays the current record.
Value 1 displays the record recorded previously to the current one, etc.
The name_of_the_column is the name of a column of the specified database table or
view. In database write component's term, it is one of the tags listed in the tagList property
and whose values was written to the database. In case the dataSource is not a table but a
result of a SQL query instead, the name_of_the_column should match the corresponding
name of the field returned by such SQL query. DataSource settings will be covered in later
sections.
Examples
if the value of the FindRecord pointer equals 1:
DB:0.xxx references the newest record of the operator name.
DB:1.xxx references the record of the recorded before the newest.
if the value of the FindRecord pointer equals 2:
DB:0.xxx references the record of the recorded before the newest record.
DB:1.xxx references the record 3 steps before the newest record.
The rest of the DB:xx tags are offset in the same way:
If the value of FindRecord pointer is changed to 10:
DB:0.xxx references the record 10 steps before the newest record.
DB:1.xxx references the record 11 steps before the newest record.
DB:2.xxx references the record 12 steps before the newest record.
Note that the number of the record is counted from the newest record. This may be
confusing. If Find Record pointer equals 10, the displayed value comes from the first
(oldest) record recorded in a table with 10 records.
findRecordTag is a read tag used to control what record to select for actual display. See
control and status tag section earlier for details.
currentRecordTag is a write tag which reports the index of current valid record. See
control and status tag section earlier for details.
totalRecordsTag is a write tag which reports to the total number of records in the data
source. See control and status tag section earlier for details.
dataSource: Data source can be either a table, a view or a query. If we need to just read
data from one table/view only, we can fill in just the name of that table/view. The query can
read data from multiple tables and perform certain operations such as addition, minimum,
maximum etc. The query is written in PostgreSQL syntax. Check PostgreSQL documentation
(http://www.postgresql.org/) for details. Note that the SQL query should NOT be terminated
with ';'.
In addition to standard SQL query syntax, OI system also support tag substitution within
SQL query. The tag is marked by the '$' character. For example, assume we have a UInt tag
defined in the OI application as 'age_filter' and this tag can be manipulated via on screen
component such as a numerical input, or via PLC. Also, assume we have a database table
named 'employees' with some basic information. It is possible to enter the following as the
dataSource:
Select count(*) as subtotal From employees Where age > $age_filter
At runtime, the OI system would automatically substitute the value of the 'age_filter' tag
before running the query against the database system. Since there is only one record returned
by this query, the result in this case can be accessed by a database tag with address
'DB:0.subtotal'.
refreshTag: A change in the value of this tag will cause the data to be refreshed by re-
reading it from the database. This is similar to the trigger tag in the Database Write
component. This feature is needed when a data source other than the local OI is writing to
the database, or when values in older records are being modified. Same effect as
refreshTime but can be user triggered.
findRecordTag is a read tag used to control what record to select for actual display. See control and
status tag section earlier under database read component for details.
currentRecordTag is a write tag which reports the index of current valid record. See control and status
tag section earlier under database read component for details.
totalRecordsTag is a write tag which reports to the total number of records in the data source. See
control and status tag section earlier under database read component for details.
refreshTag: A change in the value of this tag will cause the data to be refreshed by rereading it from the database. This is similar to the trigger tag in the Database Write
component. This feature is needed when a data source other than the local OI is writing to
the database, or when values in older records are being modified. Same effect as refreshTime
but can be user triggered.
refreshTime: sets the time in seconds when the data is refreshed by re-reading from the
database. This is practical only in the case that another data source is writing to the same
database, or when values in database records are overwritten. It is not recommended to
enable this feature for computationally intensive queries or queries against large tables since
it may render OI system unresponsive while the query is in process. For this type of queries,
trigger based refreshTag should be used instead for on-demand update. To disable automatic
refresh, set refreshTime property to value 0.
Property refreshTag and refreshTime work independently and can both be used at the same
time.
allows browsing over records using horizontal and vertical scroll bars
allows editing individual field values when user clicks on particular field cell.
The column has to be set as read/write.
It is necessary to have an unique primary key index column in the
underlaying table for this function. If values in the index column are not
unique multiple rows will be updated.
allows inserting of new records when user clicks on left vertical header and
selects Insert from the pop up dialog.
It will call INSERT INTO table (indexColumn_name) VALUES (default). As
a result of this action an empty record with values defined in the table
definition will be inserted to the table. Then a user can edit individual fields of
inserted record.
The display position of inserted record in the table is according to orderBy
property. It also depends on default values defined in table. The new record is
not made visible automatically because its position is unknown.
In order to set the value of the index filed in the inserted record a function
(ex. sequence) must be defined in SQL database for this filed.
allows deleting existing records when user clicks on left vertical header and
selects Delete in the pop up dialog. As a result the selected record will be
deleted from the table.
This function uses index column of the table. If values in this column are
not unique multiple rows will be deleted.
indexColumn: the name of one index column of the table which is defined as
primary key. The value of a field in this column determines a record in the table. If
this column is displayed it is always read only it means values in this column
cannot be modified.
filter: a filter string is an SQL WHERE clause without the WHERE keyword. It
allows select only specified records from the table based on given condition.
orderBy: it affects the order in which data records are displayed. It is defined as a
list with each item having the form column_name order separated by ; (e.g., id
ASC;surname DESC)
numOfColumns: in case the value of this property is 0 the component will display
all columns as they are defined in the table or by SELECT query. Names of
displayed columns will be the same as names of table columns or SELECT query
columns. Each displayed column will have width 100 pixels. All columns except
index column will be editable.
If the value is nonzero it specifies number of displayed columns. The following set
of properties are available for each displayed column:
Column properties:
colHeading: specifies the heading of displayed column
dbColName: specifies the matching name of the column in table or SELECT
query
width: width of displayed column
readOnly: specifies if the user can edit contents of the column. If the column
is index column setting this property to false does not have any effect.