Updating Values in a Database Record

When a property list that corresponds to a row in the database is fetched, it is known as a record. In addition to its visible properties, a record also contains hidden information about the database table from which it was fetched.

To update any value within a database table, simply change the value in the record corresponding to that row in the table, and that value in the database gets updated automatically.


set member to the record of memberTable where memberNumber is 3152134

add 30 days to member's expirationDate //This will update the database

Note: This feature of automatically updating the database when values in a record are changed is turned on by default, and can be disabled if manual updates are preferred. See Manual Database Updates for more information.

The following example shows a more detailed example focused on making database table changes for colors and brightness.


set palette to table "colorpalette" of myDB //Sets the variable 'palette' to a table object representing database table 'colorpalette'

set myColor to the record of palette where ID is 3 // Sets the variable 'myColor' a record object for the corresponding record from the database

put "black" into myColor's color //Updates the database record, changing the color value to "black"

log MyColor // Logs (brightness:"9", color:"black", ID:"3")

set myColor to the record of palette where Color is "green" and brightness is "14"

add 10 to myColor's brightness //Updates the database record, adding 10 to the current brightness value

log myColor //Logs (brightness:"24", color:"green", ID:"4")

The following example shows another more detailed example focused on making database table changes for member expirations.


set memberExpirations to table "memberInfo" of myDB

put (4,10,16) into expirationstoUpdate

repeat with each Num in expirationstoUpdate

set member to the record of memberExpirations where memberNumber is Num

add 1 year to member's expirationDate

end repeat


This topic was last updated on June 21, 2019, at 02:49:49 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2019 Eggplant