| 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 OR 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 be overwritten
- Additional members may be added
- Additional arrays and/or structures may be added
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.
- If the destination has more members than the source, then the excess destination members remain unaffected.
- If the destination has fewer members than the source, then the array will be extended in order to transfer all members.

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: .., 1 ];
  see( animal1[] );
  see( animal2[] );
animal1[]               animals                    (quoted string,full access)
Leg count               2  "2"                     (numeral,full access)
Name                    Owl                        (quoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         Night vision               (quoted string,full access)

animal2[]               A kind of big mouse        (quoted string,full access)
Array [   0]            Owl                        (quoted string,full access)
Array [   1]            2  "2"                     (numeral,full access)
Array [   2]            Night vision               (quoted string,full access)
Array [   3]            not a favorable pet        (softquoted string,full access)

Try it yourself: Open LAN_Features_OR_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 ]; // Owl, with skin wings like a bat
  animal2[] |<<= [ animals: .., 1 ]; // Dog, but not a favorable pet
  see( animal1[] );
  see( animal2[] );
  table list( animals ); // Ape left over
animal1[]               animals                    (quoted string,full access)
Leg count               2  "2"                     (numeral,full access)
Name                    Owl                        (quoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         Night vision               (quoted string,full access)

animal2[]               animals                    (quoted string,full access)
Array [   0]            Dog                        (quoted string,full access)
Array [   1]            4  "4"                     (numeral,full access)
Array [   2]            Sensitive nose             (quoted string,full access)
Array [   3]            not a favorable pet        (softquoted string,full access)

    0 : Name | Leg count | Special ability
    1 : Ape  | 2 or 4    | Relatively smart

Try it yourself: Open LAN_Features_OR_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 and crab and ape with some info
animal1[]               animals                    (quoted string,full access)
Leg count               2  "2"                     (numeral,full access)
Name                    Owl                        (quoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         Night vision               (quoted string,full access)
Strange habit           hangs while sleeping       (softquoted string,full access)

animal2[]               [Void]                     (void,full access)
Array [   0]            Dog                        (quoted string,full access)
Array [   1]            4  "4"                     (numeral,full access)
Array [   2]            Sensitive nose             (quoted string,full access)

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

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