<!--
* 
*
*  ProLinga-Doc
*
*  Copyright (C) 2002-2008 Xobas Software.
*  All rights reserved.
*  
*  This file is part of ProLinga-Doc.
*
*  ProLinga-Doc is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  ProLinga-Doc is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with ProLinga-Doc.  If not, see <http://www.gnu.org/licenses/>.
*
*  More information is available at the following addresses:
*
*  Website     : http://www.prolinga.org
*
*  Email       : prolinga-list@prolinga.org
*
*
-->
<refentry id="cmd_datamodel">
  <refmeta>
    <refentrytitle>DATAMODEL Command</refentrytitle>
    <manvolnum>1</manvolnum>
  </refmeta>

  <refnamediv>
    <refname>DATAMODEL</refname>
    <refpurpose>Modify datamodel and matching database table.</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <cmdsynopsis>
      <command>DATAMODEL</command>
      <arg choice='plain'><option>APPEND</option></arg>
      <arg choice='plain'><replaceable>data_model_name</replaceable></arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>DATAMODEL</command>
      <arg choice='plain'><option>SELECT</option></arg>
      <arg choice='plain'><replaceable>data_model_name</replaceable></arg>
      <arg choice='plain'><option>TABLE</option></arg>
      <arg choice='plain'><replaceable>table_name</replaceable></arg>
      <arg choice='opt'>
        <arg choice='plain'><option>CONDITION</option></arg>
        <arg choice='plain'><replaceable>condition</replaceable></arg>
        <arg rep='repeat' choice='opt'><replaceable>condition</replaceable></arg>
      </arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>DATAMODEL</command>
      <arg choice='plain'><option>REMOVE</option></arg>
      <arg choice='plain'><replaceable>data_model_name</replaceable></arg>
    </cmdsynopsis>
    <cmdsynopsis>
      <command>DATAMODEL</command>
      <arg choice='plain'><option>UPDATE</option></arg>
      <arg choice='plain'><replaceable>data_model_name</replaceable></arg>
    </cmdsynopsis>
  </refsynopsisdiv>

  <refsect1 id="cmd_datamodel_introduction">
    <title>Introduction</title>
    <para>
      The <link linkend="cmd_datamodel">DATAMODEL</link> command loads, appends a row to, 
      removes a row from or updates a row in a datamodel. The database table linked
      to this datamodel will updated accordingly. 
      All DATAMODEL commands will return a status. As soon as something goes wrong, 
      the status will have a value other than 0. The status can be retrieved 
      by calling 
      the built-in function DATAMODELSTATUS().
    </para>
  </refsect1>
  <refsect1 id="cmd_datamodel_arguments">
    <title>Arguments</title>
    <variablelist>
      <varlistentry>
	<term><replaceable>data_model_name</replaceable></term>
	<listitem>
	  <simpara>
            The name of the data model as defined in the development environment.
	  </simpara>
	</listitem>
      </varlistentry>
      <varlistentry>
	<term><replaceable>table_name</replaceable></term>
	<listitem>
	  <simpara>
            The name of the table where data needs to be changed.
	  </simpara>
	</listitem>
      </varlistentry>
      <varlistentry>
	<term><replaceable>condition</replaceable></term>
	<listitem>
	  <simpara>
            Additional SQL conditions can be placed here to limit the numbers of
            entries in the Data Model.
	  </simpara>
	</listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

  <refsect1 id="cmd_datamodel_example">
    <title>Example</title>
<programlisting>
. . .
. . .
CLEAR DATAMODEL Cust
DATAMODEL SELECT Cust TABLE Cust
FOREACH Cust
	M-status.Cust = "Active"
	DATAMODEL UPDATE Cust
ENDFOR
. . .
. . .
CLEAR DATAMODEL Devices
DATAMODEL SELECT dmDevices TABLE Devices CONDITION "where device_id = '" L-deviceID "'"
FOREACH dmDevices
	M-installDate.dmDevices = DATE()
	DATAMODEL UPDATE Cust
	BREAK
ENDFOR
. . .
. . .
</programlisting>
  </refsect1>

  <refsect1 id="cmd_datamodel_related">
    <title>Related Commands</title>
    <para>
      <link linkend="cmd_foreach">FOREACH</link>
      <link linkend="cmd_sql">SQL</link>
    </para>
  </refsect1>

</refentry>

