creapage.net

HOWTO - Sashipa development

 Field: How to define selected values.

You wish to display a computed value in an unsaved field of your cardForm. This value doesn't match to a database column.

Look at the example database, there are Boxes contain Products. Here is the SQL script for creating tables (with HSQL syntax):

  CREATE TABLE Box (
    Id_Box integer not null primary key,
    Box_Name varchar(100) not null
  );
  CREATE TABLE Product (
    Id_Personne integer not null primary key,
    Ref_Box integer not null,
    Product_Label varchar(100) not null,
    Price integer,
    FOREIGN KEY (Ref_Box) REFERENCES Box (Id_Box)
  );

In the Box card, we wish to display the sum of product prices. For doing this, we replace the schemaColumnRef element by a selectedValue, which contains a selectQueryBuilder. Example:

  <cardForm db='dbExample'>
    <title>Box card</title>
    <location x='10' y='10' />
    <cardSchemaTableRef schemaTable='tblBox' updateAfterInsert='no'
                        multipleInsert='yes' queries='sudi' />
    <fieldContainer>
      <textField>
        <schemaColumnRef schemaColumn='tblBox_BoxName' />
      </textField>

      <!-- Computed field -->
      <textField readOnly='yes' save='no'>
        <label>Sum of prices</label>
        <selectedValue>
          <selectQueryBuilder>
            <castFilterSet stuckWhenNoFilter='yes' />
            <selectStatementBuilder>
              <instanceColumnList>
                <agregatInstanceColumn type='sum' schemaColumn='tblProduct_Price' />
              </instanceColumnList>
            </selectStatementBuilder>
            <fromStatementBuilder>
              <mainInstanceTable schemaTable='tblProduct' />
            </fromStatementBuilder>
          </selectQueryBuilder>
        </selectedValue>
      </textField>

    </fieldContainer>
  </cardForm>

Remarks:

For details on selectQueryBuilder, please see the SelectQueryBuilder HOWTO.

© Copyright 2003 Sashipa-Melba Team. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License as much as this note clearly appears.