12.07.2015 Views

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Reading from a databaseIn <strong>OPL</strong>, database relations can be read into sets or arrays. For instance, these instructionsfrom the model file:tuple gasType {string name;float demand;float price;float octane;float lead;}tuple oilType {string name;float capacity;float price;float octane;float lead;}And these instructions from the data file:GasData from DBRead(db,"SELECT * FROM GasData");OilData from DBRead(db,"SELECT * FROM OilData");Together illustrate how to initialize a set of tuples from the relation OilData in the databasedb. In this example, the DBRead instruction inserts an element into the set for each tuple ofthe relations.Important conventions adopted by <strong>OPL</strong>:1. If read into a set, the resulting set must be a set of integers, floats, or strings, or a set oftuples whose elements are integers, floats, or strings.2. If read into an array, the resulting array must be an array of integers, floats, or strings, oran array of tuples whose elements are integers, floats, or strings.3. In the case of tuples, the columns of the SQL query result are mapped by position to thefield of the <strong>OPL</strong> tuples. For instance, in the above query, the column name has beenmapped to the field name and so on.4. When initializing an array with a DBRead statement, the indexing set and array cells areinitialized at the same time.Note: <strong>OPL</strong> does not parse the query; it simply sends the string to the database system thathas full responsibility for handling it. As a consequence, the syntax and the semanticsI L O G O P L D E V E L O P M E N T S T U D I O L A N G U A G ER E F E R E N C E M A N U A L59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!