| |||||||||||||||||||
Data output to text files, spreadsheets and databases, and to memory Description This example shows different ways of writing out data from a Mosel model, namely to
Accessing spreadsheets and databases Using initializations to data is written to spreadsheets or databases through the ODBC connector in a similar way as text files are accessed; all necessary SQL commands are generated automatically. With the extended filename to "mmodbc.odbc:data.mdb" the data will be written to the MS Access database data.mdb and the string "mmodbc.odbc:DSN=mysql;DB=data" could be used to access a mysql database named data. Instead of using an initializations block, we may write out data from a Mosel model directly with the corresponding SQL statements (this makes it possible, for example, to clear the data table before writing to it - this functionality is not available with spreadsheets) SQLconnect("data.sqlite") SQLexecute("delete from MyOutTable") SQLexecute( "insert into MyOutTable (Index1,Index2,AValue) values (?,?,?)", A) SQLdisconnect When working with Excel spreadsheets it is recommended to use one of the dedicated spreadsheet drivers from the mmsheet module: with the excel driver, the spreadsheet may remain open while writing to it from a Mosel model, in this case the data written out to the spreadsheet does not get saved, making it possible to re-run the application with different data sets without causing any lasting modifications to your spreadsheet. All other spreadsheet drivers require the spreadsheet file to be closed. The xls/xlsx drivers do not require an installation of Excel and are available for certain non-Windows platforms. The module mmoci (requires a separate license) defines a software-specific interface to Oracle databases that is used in a similar way as the ODBC connection provided through mmmodbc. With initializations to an extended filename will take a form like "mmoci.oci:debug;myname/mypassword@dbname" and it is equally possible to use PL/SQL statements directly. Data output in memory using I/O drivers Using initializations to it is also possible to send data from a Mosel model in memory to the calling application (C/C++, C# or Java). This is done using a combination of the I/O drivers mem (data held in memory) and raw driver (data in binary format) in C, drivers dotnet and dotnetraw in C# programs and drivers java and jraw in Java programs. Other options for data output Other possibilities of outputting data from a Mosel model include
Further explanation of this example: Whitepapers 'Using ODBC and other database interfaces with Mosel' and 'Generalized file handling in Mosel'
Source Files By clicking on a file name, a preview is opened at the bottom of this page. Data Files
datainout.mos (!****************************************************** Mosel Example Problems ====================== file datainout.mos `````````````````` Data input and output through a static module. (c) 2008 Fair Isaac Corporation author: S.Heipcke, Mar. 2006, rev. Sep. 2018 *******************************************************!) model "Data input/output (static module)" uses "datainout" ! Defines 'readdata' and 'writedata' parameters INDATA='' ! Memory location of data INSIZE=0 ! Size of the data block OUTDATA='' ! Memory location of output data OUTSIZE=0 ! Size of the data block end-parameters declarations A7: dynamic array(range,range) of real end-declarations ! Data input from calling application readdata(A7, INDATA, INSIZE) ! Print out the data we have read writeln('A7 is: ', A7) declarations A: array(-1..1,5..7) of real end-declarations A :: [ 2, 4, 6, 12, 14, 16, 22, 24, 26] ! Output to calling application writedata(A, OUTDATA, OUTSIZE) end-model | |||||||||||||||||||
© Copyright 2023 Fair Isaac Corporation. |