question

Fu P avatar image
0 Likes"
Fu P asked Felix Möhlmann answered

Update global table from MySQL every second

I wrote a program to import data into a MySQL table every second.

How can I write some custom code to read from MySQL and update the global table every second.

FlexSim 19.2.4
update global table
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered

First, set up a connection to your database in the "Database Connector" (found under "Connectivity" in the toolbox).

1647330661753.png

Then you can use the "Database" class and it's methods to read or write values from/to the database.

https://docs.flexsim.com/en/20.1/Reference/CodingInFlexSim/FlexScriptAPIReference/Database/Database.Connection.html

The attached model contains an example we build for a client some time ago (v18.2) that contains some code which adds a new row to the database. To read from it you would use the standard "SELECT ... FROM ... " sql query structure.

The code can be part of a custom code activity in process flow, so a token can loop through a delay activity and run the code periodically.

database_test_182.fsm


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Iago MF avatar image
1 Like"
Iago MF answered Iago MF edited

Hi!

After creating and a DatabaseConnector, you can use this command inside a loop in Process Flow:

function_s(model().find("Tools/DatabaseConnectors/DBConnector1"), "importAll");


1647330706425.png



1647330706425.png (106.7 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.