D Bread Write
D Bread Write
I want to use MySQL to read data into Simio and also to write data from Simio.
Categories:
File Management
Key Concepts:
DBConnect Element, DBRead Step, DBWrite Step, DBQuery Step, DBExecute Step, Database, SQL, MySQL
Assumptions:
Database connectivity must already be setup or this model will not run! See Appendix for example.
There are two approaches described below, one model using DbRead, and DbWrite, and another model using
DbQuery and DbExecute.
Within the Facility window, place a Source, a Server and a Sink and connect them using Path objects.
Within the Sinks input node, double-click on the Entered Add-On Process to create a new process named
Input_Sink1_Entered. We will add steps within that process shortly.
Within the Definitions window, click on the States panel and add a String state with the Name
StringState1. Set the Initial State Value to DefaultEntity.11.
Add a Real state with the Name RealState1. Change the Initial State Value to -1.
Add two DateTime states with the Name of DateTimeState1 and DateTimeState2. Set their Initial State
Value properties to 10/1/12 and 11/1/12, respectively.
Add two Integer states with the Name of IntegerState1 and RowID. Leave the Initial State Value of both
to the default 0.
Add a Boolean state with the Name SimpleDbSteps that has an Initial State Value of True.
Within the Definitions window, click on the Element panel and select the DbConnect element from the
User Defined button pull down.
In the property window for DbConnect1, enter the Connection String as Server=localhost; Port=3306;
Database=world; Uid=root; Pwd=root. Click on Provider Name and set it as MySQL Data Provider.
Within the Processes window, click on Select Process in the Process ribbon and select the OnRunInitialized
process. Add a DbExecute step from the User Defined panel to the process. Specify the DbConnect as
DbConnect1, the SQL Statement as Delete From TestReadWrite where Id>@1. Within the Items repeat
group, enter the Expression RowID.
Next, within the Input_Sink1_Entered process, add the Decide, DbRead, Assign and DbWrite steps.
Within the Decide step, keep Decide Type as ConditionBased and add Expression as RowID > 0.
For the DbRead properties, the DbConnect is DbConnect1, created above. Assign the Table Name to
TestReadWrite. Click on Columns repeating property editor and add 5 items as shown below
o
o
o
o
o
Column State
String1 StringState1
Integer1 IntegerState1
Real1 RealState1
DateTime1 DateTimeState1
DateTime2 DateTimeState2
Within the Where repeating property editor, add Where Column value Id and Where State value RowID.
Within the Assign step, enter the State Variable Name as RowID and New Value as RowID+1.
For the DbWrite properties, the DbConnect is DbConnect1 and the Table Name is TestReadWrite. Click
on Columns repeating property editor and add 6 items as shown below
o
o
o
o
o
o
Column Expression
Id -- RowID
String1 Entity.Name
Integer1 Entity.ID
Real1 TimeNow
DateTime1 String.FromDateTime( Entity.TimeCreated, "yyyy/MM/dd HH:mm:ss")
DateTime2 String.FromDateTime( TimeNow, "yyyy/MM/dd HH:mm:ss")
From Animation ribbon, select and place 6 Status Labels in the Facility window.
For first label, enter the Expression StringState1. Repeat the same for the other 5 states defined above
(not needed is the SimpleDbSteps Boolean state). In the case of the DateTime states, use the Expression
DateTime.ToString(DateTimeState1) and DateTime.ToString(DateTimeState2).
For the DbQuery step, the DbConnect is DbConnect1. For the SQL Statement, enter Select String1,
Integer1, Real1, DateTime1, DateTime2 from TestReadWrite where Id = @6. Within the States repeating
property editor, add 6 State values:
o
o
o
o
o
o
State
StringState1
IntegerState1
RealState1
DateTimeState1
DateTimeState2
RowID
For the DbExecute step, the DbConnect is DbConnect1. The SQL Statement value is Insert into
TestReadWrite (Id, String1, Integer1, Real1, DateTime1, DateTime2) values (@1, '@2', @3, @4, '@5',
'@6'). Within the Items repeating property editor, add 6 Expression values:
o
o
o
o
o
o
Expression
RowID
Entity.Name
Entity.ID
TimeNow
String.FromDateTime( Entity.TimeCreated, "yyyy/MM/dd HH:mm:ss")
String.FromDateTime( TimeNow, "yyyy/MM/dd HH:mm:ss")
Appendix:
Instructions to Install MySQL
http://dev.mysql.com/downloads/installer/
On Find latest products tab, click Execute and then click Next.
On Configuration tab, click Next. When prompted for MySQL Root Password, enter root and click Next till
you get out of Configuration tab.
http://dev.mysql.com/downloads/connector/net/
Download mysql-connector-net-6.6.5.msi version (you must use this version) and run the install. When
prompted, choose the Complete install.
Click Finish.