Table

This method creates a new table with a structure that is defined through an array with x elements or x columns in the PLC.

Syntax

METHOD Table : BOOL
VAR_INPUT
    hDBID : UDINT;
    sTableName : T_MaxString;
    pTableCfg : POINTER TO ARRAY[0..MAX_DBCOLUMNS] OF ST_ColumnInfo;
    cbTableCfg : UDINT;
END_VAR

Table 1: Inputs

Name

Type

Description

hDBID

UDINT

Indicates the ID of the database to be used.

sTableName

MaxString

Name of the table to be created.

pTableCfg

POINTER TO ARRAY[0..MAX_DBCOLUMNS] OF ST_ColumnInfo

Indicates the pointer address of the table structure array. The individual columns are written in this array.

cbTableCfg

UDINT

Indicates the length of the array in which the columns are configured.

Table 2: Return value

Name

Type

Description

Table

BOOL

Displays the status of the method. Returns TRUE as soon as the method execution is finished, even in the event of an error.

Sample

VAR
    fbPLCDBCreate : FB_PLCDBCreateEvt(sNetID := '', tTimeout := T#5S);
    ColumnInfo    : ARRAY [0..14] OF ST_ColumnInfo;
    tcMessage     : I_TcMessage;
END_VAR
ColumnInfo[0].sName := 'colBigInt';     ColumnInfo[0].eType := E_ColumnType.BigInt;     ColumnInfo[0].nLength := 8;     ColumnInfo[0].sProperty := 'IDENTITY(1,1)';
ColumnInfo[1].sName := 'colInteger';    ColumnInfo[1].eType := E_ColumnType.Integer;    ColumnInfo[1].nLength := 4;
ColumnInfo[2].sName := 'colSmallInt';   ColumnInfo[2].eType := E_ColumnType.SmallInt;   ColumnInfo[2].nLength := 2;
ColumnInfo[3].sName := 'colTinyInt';    ColumnInfo[3].eType := E_ColumnType.TinyInt;    ColumnInfo[3].nLength := 1;
ColumnInfo[4].sName := 'colBit';        ColumnInfo[4].eType := E_ColumnType.BIT_;       ColumnInfo[4].nLength := 1;
ColumnInfo[5].sName := 'colMoney';      ColumnInfo[5].eType := E_ColumnType.Money;      ColumnInfo[5].nLength := 8;
ColumnInfo[6].sName := 'colFloat';      ColumnInfo[6].eType := E_ColumnType.Float;      ColumnInfo[6].nLength := 8;
ColumnInfo[7].sName := 'colReal';       ColumnInfo[7].eType := E_ColumnType.REAL_;      ColumnInfo[7].nLength := 4;
ColumnInfo[8].sName := 'colDateTime';   ColumnInfo[8].eType := E_ColumnType.DateTime;   ColumnInfo[8].nLength := 4;
ColumnInfo[9].sName := 'colNText';      ColumnInfo[9].eType := E_ColumnType.NText;      ColumnInfo[9].nLength := 256;
ColumnInfo[10].sName := 'colNChar';     ColumnInfo[10].eType := E_ColumnType.NChar;     ColumnInfo[10].nLength := 10;
ColumnInfo[11].sName := 'colImage';     ColumnInfo[11].eType := E_ColumnType.Image;     ColumnInfo[11].nLength := 256;
ColumnInfo[12].sName := 'colNVarChar';  ColumnInfo[12].eType := E_ColumnType.NVarChar;  ColumnInfo[12].nLength := 50;
ColumnInfo[13].sName := 'colBinary';    ColumnInfo[13].eType := E_ColumnType.Binary;    ColumnInfo[13].nLength := 30;
ColumnInfo[14].sName := 'colVarBinary'; ColumnInfo[14].eType := E_ColumnType.VarBinary; ColumnInfo[14].nLength := 20;

IF fbPLCDBCreate.Table(
    hDBID:= 1,
    sTableName:= 'myNewTable', 
    pTableCfg:= ADR(ColumnInfo), 
    cbTableCfg:= SIZEOF(ColumnInfo))
THEN
    IF fbPLCDBCreate.bError THEN
        TcMessage:= fbPLCDBCreate.ipTcResult;
        nState := 255; 
    ELSE
        nState := 0;
    END_IF
END_IF