+ Transactions from Tables to Variables

Prev Next

Introduction

This form of transaction picks up a table row and treats it as a 1-level structure with members named by the corresponding header names which will then be integrated in the destination variable using the rules of the | prefix.

Table access rules: See section on Transactions from Tables to Variables.
Destination variable rules: See section on ADD Transactions between variables.

Following actions are applied on the destination variables using this assignment operator:

Destination Source Description
Simple or zero members Table contents (1 row) Base variable: Updated with table name if no ^ suffix is specified.
Structure Table contents (1 row) Base variable: See above. The members for which corresponding member positions are already existing in the destination variable will also be transferred. - Existing members will not be overwritten
- All members in the source variable will be added as furhter members to the destination array.
- Existing members will not be overwritten
Array Table contents (1 row) Base variable: See above. The members for which corresponding member positions are already existing in the destination variable will also be transferred. The existing array members will be replaced by structure members from the source variable, sorted in alphabetic order by member names.
- All members in the source variable will be added as furhter members to the destination array.
- Existing members will not be overwritten

Copy Transaction Example
  table initialize( animals,
      { { Name,  Leg count, Special ability  },
        { Owl,   2,         Night vision     },
        { Dog,   4,         Sensitive nose   },
        { Ape,   2 or 4,    Relatively smart } } );


  structure( animal1[], { Name, Special ability, Skin surface }, { Bat, "On-flight acoustic radar", skin wings } );
  array( animal2[], { Rat, "Relatively intelligent", gray hair, not a favorable pet  } );
  animal1[] = "A kind of flying dog";
  animal2[] = "A kind of big mouse";

  animal1[] +<== [ animals: .., 1 ];
  animal2[] +<==^  [ animals: .., 3 ];
  see( animal1[] ); // Adds leg count, but name and special ability are maintained
  see( animal2[] ); // animal2[] gets all table entries for the ape
animal1[]               animals                    (quoted string,full access)
Leg count               2  "2"                     (numeral,full access)
Name                    Bat                        (softquoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         On-flight acoustic radar    (quoted string,full access)

animal2[]               A kind of big mouse        (quoted string,full access)
Array [   0]            Rat                        (softquoted string,full access)
Array [   1]            Relatively intelligent     (quoted string,full access)
Array [   2]            gray hair                  (softquoted string,full access)
Array [   3]            not a favorable pet        (softquoted string,full access)
Array [   4]            Ape                        (quoted string,full access)
Array [   5]            2 or 4                     (quoted string,full access)
Array [   6]            Relatively smart           (quoted string,full access)

Try it yourself: Open LAN_Features_ADD_Transactions_from_tables_to_variables.b4p in B4P_Examples.zip. Decompress before use.
Move Transaction Example
  table initialize( animals,
      { { Name,  Leg count, Special ability  },
        { Owl,   2,         Night vision     },
        { Dog,   4,         Sensitive nose   },
        { Ape,   2 or 4,    Relatively smart } } );


  structure( animal1[], { Name, Special ability, Skin surface }, { Bat, "On-flight acoustic radar", skin wings } );
  array( animal2[], { Rat, "Relatively intelligent", gray hair, not a favorable pet  } );
  animal1[] = "A kind of flying dog";
  animal2[] = "A kind of big mouse";

  animal1[] +<<= [ animals: .., 1 ];
  animal2[] +<<=^  [ animals: .., 2 ]; // Ape on row 2 (was on row 3 before the transaction on previous row)
  see( animal1[] ); // Adds leg count, but name and special ability are maintained
  see( animal2[] ); // animal2[] gets all table entries for the ape

  table list( animals ); // Dog with its nose is left over.
animal1[]               animals                    (quoted string,full access)
Leg count               2  "2"                     (numeral,full access)
Name                    Bat                        (softquoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         On-flight acoustic radar    (quoted string,full access)

animal2[]               A kind of big mouse        (quoted string,full access)
Array [   0]            Rat                        (softquoted string,full access)
Array [   1]            Relatively intelligent     (quoted string,full access)
Array [   2]            gray hair                  (softquoted string,full access)
Array [   3]            not a favorable pet        (softquoted string,full access)
Array [   4]            Ape                        (quoted string,full access)
Array [   5]            2 or 4                     (quoted string,full access)
Array [   6]            Relatively smart           (quoted string,full access)

    0 : Name | Leg count | Special ability
    1 : Dog  | 4         | Sensitive nose

Try it yourself: Open LAN_Features_ADD_Transactions_from_tables_to_variables_01.b4p in B4P_Examples.zip. Decompress before use.
Swap Transaction Example
  table initialize( animals,
      { { Name,  Leg count, Special ability  },
        { Owl,   2,         Night vision     },
        { Dog,   4,         Sensitive nose   },
        { Ape,   2 or 4,    Relatively smart } } );

  structure( animal1[], { Name, Special ability, Skin surface, Strange habit },
                        { Bat, "On-flight acoustic radar", skin wings, hangs while sleeping } );

  array( animal2[], { Crab, 10  } );

  animal1[] +<=>  [ animals: .., 1 ]; // Exchange owl with bat
  animal2[] +<=>^ [ animals: .., 2 ]; // Exchange dog with crab

  see( animal1[] );
  see( animal2[] );
  table list( animals ); // Contains bat (row 1) and crab (row 2) in addition
animal1[]               animals                    (quoted string,full access)
Leg count               2  "2"                     (numeral,full access)
Name                    Bat                        (softquoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         On-flight acoustic radar    (quoted string,full access)
Strange habit           hangs while sleeping       (softquoted string,full access)

animal2[]               [Void]                     (void,full access)
Array [   0]            Crab                       (softquoted string,full access)
Array [   1]            10  "10"                   (numeral,full access)
Array [   2]            Owl                        (quoted string,full access)
Array [   3]            2  "2"                     (numeral,full access)
Array [   4]            Night vision               (quoted string,full access)

    0 : Name | Leg count | Special ability          | Skin surface | Strange habit       
    1 : Bat  |           | On-flight acoustic radar | skin wings   | hangs while sleeping
    2 : Crab | 10        |                          |              |                     
    3 : Owl  | 2         | Night vision             |              |                     
    4 : Dog  | 4         | Sensitive nose           |              |                     
    5 : Ape  | 2 or 4    | Relatively smart         |              |                     

Try it yourself: Open LAN_Features_ADD_Transactions_from_tables_to_variables_02.b4p in B4P_Examples.zip. Decompress before use.