// Map the variable MapVar_Insert to the table Production of the DB Connection MyDB1 for the INSERT operation.
// Map the variable MapVar_Update to the table Production of the DB Connection MyDB1 for the UPDATE operation.
IF (Operating_Connect=TRUE) THEN
CASE Stage OF
1 : // Establish the DB Connection
DB_Connect_instance(
Execute := TRUE,
DBConnectionName := 'MyDatabase1',
DBConnection => MyDB1
);
IF (DB_Connect_instance.Done=TRUE) THEN
Stage := INT#2; // Normal end
END_IF;
IF (DB_Connect_instance.Error=TRUE) THEN
Stage := INT#99; // Error
END_IF;
2 : // Map the DB table with the variable
DB_CreateMapping_Insert_instance(
Execute := TRUE,
DBConnection := MyDB1,
TableName := 'Production',
MapVar := MapVar_Insert,
SQLType := _DBC_SQLTYPE_INSERT
);
DB_CreateMapping_Update_instance(
Execute := TRUE,
DBConnection := MyDB1,
TableName := 'Production',
MapVar := MapVar_Update,
SQLType := _DBC_SQLTYPE_UPDATE
);
IF ( (DB_CreateMapping_Insert_instance.Done=TRUE)
AND (DB_CreateMapping_Update_instance.Done=TRUE) ) THEN
Operating_Connect:=FALSE; // Normal end
END_IF;
IF ( (DB_CreateMapping_Insert_instance.Error=TRUE)
OR (DB_CreateMapping_Update_instance.Error = TRUE) ) THEN
Stage := INT#99; // Error
END_IF;
99 :
// Execute the error handler.
// Program the error hander (FaultHandler_Connect) according to the device.
FaultHandler_Connect();