0% found this document useful (0 votes)
189 views4 pages

D Bread Write

The document provides instructions for connecting Simio to a MySQL database to read and write data. It describes using the DbConnect element to define the connection, and using the DbRead and DbWrite steps to read from and write to the database within a process. An alternative approach using DbQuery and DbExecute steps is also outlined. Details are provided on setting up states, processes, and status labels to display the data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views4 pages

D Bread Write

The document provides instructions for connecting Simio to a MySQL database to read and write data. It describes using the DbConnect element to define the connection, and using the DbRead and DbWrite steps to read from and write to the database within a process. An alternative approach using DbQuery and DbExecute steps is also outlined. Details are provided on setting up states, processes, and status labels to display the data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Problem:

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.

Approach Using DbRead and DbWrite


Technical Approach:
DbConnect Element is used to connect with the MySQL database. The OnRunInitialized process is used to delete
existing data from the database table. An Add-On process is used within an object where data is read using DbRead
step. The position is defined where data has to be written in the database using Assign step. Then using DbWrite
step, data is written into database.
Details for Building the Model:
Simple System Setup

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.

Defining the States for the Model

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.

Defining the DbConnect Element

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.

Using the Database Steps in a Process

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")

Adding Status Labels to the Facility Window

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).

Approach Using SQL Query (DBQuery and DBExecute)


All the states and process information remains the same as above, but in the Processes window, use the DbQuery
and DbExecute steps instead of DbRead and DbWrite steps.

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

Go to the link below to install MySQL

http://dev.mysql.com/downloads/installer/

Download mysql-installer-community-5.6.11.0.msi version or higher and run the install.

On MySQL Installer window, select Install MySQL Products

On Find latest products tab, click Execute and then click Next.

On Setup Type tab, select Developer Default and click Next.

On Check Requirements tab, click Execute and then Next.

On Installation tab, click Execute and then Next.

On Configuration tab, click Next. When prompted for MySQL Root Password, enter root and click Next till
you get out of Configuration tab.

On Complete tab, click Finish.

Now go to the link below to install MySQL connector.

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.

On Setup window, click Next.

Click Change, then click Next and again click Change

Click Finish.

Instructions to Create table in MySQL

Open MySQL Workbench.

Click on Local instance MySQL56 and enter password root.

Enter the code below to create a table TestReadWrite


USE world;
CREATE TABLE `testreadwrite` (
`Id` int(11) NOT NULL,

`String1` varchar(45) DEFAULT NULL,


`DateTime1` datetime DEFAULT NULL,
`Integer1` int(11) DEFAULT NULL,
`Real1` double DEFAULT NULL,
`DateTime2` datetime DEFAULT NULL,
PRIMARY KEY (`Id`)
)

Click Execute to create the table.

You might also like