& 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 AND 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
- No additional member names will be added.
Array Table contents (1 row) Base variable: See above. Existing array members will be overwritten. - 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 remaining members in the source variable will not be copied.

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 ]; // Owl with skin wings and night vision
       animal2[] &<== [ animals: .., 1 ]; // Owl
       see( animal1[] );
       see( animal2[] );
animal1[]               animals                    (quoted string,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]            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_AND_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
       animal2[] &<<= [ animals: .., 1 ]; // Dog
       see( animal1[] );
       see( animal2[] );
       table list( animals ); // Ape left over
animal1[]               animals                    (quoted string,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_AND_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 ]; // Animal1: Owl with night vision, no info on legs, keeps bat wings and hangs while sleeping
       animal2[] &<=>^ [ animals: .., 2 ]; // Animal2: Dog with 4 legs.  Circumflex symbol: Do not transfer table name.

       see( animal1[] );
       see( animal2[] );
       table list( animals ); // Contains bat and crab and ape with some info
animal1[]               animals                    (quoted string,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)

    0 : Name | Leg count | Special ability         
    1 : Bat  | 2         | On-flight acoustic radar
    2 : Crab | 10        | Sensitive nose          
    3 : Ape  | 2 or 4    | Relatively smart        

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