11.2 SQL Programming Interface
This programming interface is used to created customized database readers for importing parameters into the SME from SQL databases. The current implementation of the SME is set up to interoperate with the Postgres database, other databases will probably require some reconfiguration.
A new database reader is created by defining a DBaseFunction object in the SQLFunctions.SMML file in the project's UserCode directory. This object is invoked by the m4 config-cmd described in Section 7.1.6. As an example we will look at the default reader sme_default which is pre-definedin SQLFunctions.SMML:
DBaseFunction sme_default {
Arg tableName = NULL;
Arg sectorName = NULL;
Arg parmName = NULL;
Code = !{
SELECT HabIndex, ParmValue FROM tableName WHERE
SectorName = 'sectorName' and ParmName = 'parmName';
}!;
}
This block of SMML code defines a DBaseFunction object called sme_default which has three arguments: tableName, sectorName, parmName. The Code attribute declaration declares the SQL code that is used to implement the reader. When this funcion is invoked by the m4 config-cmd, the arguments supplied in the config-cmd are substituted for the declared arguments in the SQL code block, which is then used to define the reader. Substitutions are case-sensitive, and arguments are matched by order of declaration. For example, an m4 command which looks like:
m4(CME_Maxwell,HAB,sme_default,PLM_HDP,Forest,Canopy_Height)
will result in an SQL reader the executes the code:
SELECT HabIndex, ParmValue FROM PLM_HDP WHERE
SectorName = 'Forest' and ParmName = 'Canopy_Height';
to read a set of parameters form the table PLM_HDP in the database CME_Maxwell. The reader should return a set of tuples with two fields, the first giving the map index value (in this case, HabIndex for the map HAB) and the second giving the parameter value (in this case, ParmValue) for that index. This example assumes that a table called PLM_HDP exists in the dataBase CME_Maxwell and has the columns HabIndex, ParmValue, SectorName, and ParmValue. This table may be created using the SME datbase interface, see section 5.1.5 for a brief introduction.