UpdateData - Maple Help

Result

 UpdateData
 set the value to which an element will be changed

 Calling Sequence result:-UpdateData( index, data )

Parameters

 result - Result module index - string or integer; the column to be updated data - the new value

Description

 • UpdateData sets the value that the element stored in the row (indicated by the row cursor) and the column (indicated by index) will be changed to on a call to UpdateRow. The value the element will be changed to is data.
 • To update a row, set the new values by by calling UpdateData and then submit these updates by calling UpdateRow.  Changing the current row discards any values set with UpdateData.
 • Maple can automatically determine the type of the column and convert data; however, this requires querying the type of the column.  To avoid this overhead the type can be specified using an explicit cast. For more information, see conversions.
 • An element can be set to SQL NULL by passing 'SQLNULL' for data.
 • Not all Result modules can be updated.  Only Result modules representing tables containing data from a single table (no joins) and a column of primary keys are guaranteed to be updatable.  Particular JDBC Drivers and databases may allow a wider range of updatable tables and thus Result modules.

Examples

Create a Result to be updated.

 > $\mathrm{driver}≔\mathrm{Database}\left[\mathrm{LoadDriver}\right]\left(\right):$
 > $\mathrm{conn}≔\mathrm{driver}:-\mathrm{OpenConnection}\left(\mathrm{url},\mathrm{name},\mathrm{pass}\right):$$\mathrm{res}≔\mathrm{conn}:-\mathrm{ExecuteQuery}\left("SELECT id,name,number,mass FROM animals"\right):$$\mathrm{res}:-\mathrm{Next}\left(\right)$
 ${\mathrm{true}}$ (1)

Get the current values.

 > $\mathrm{res}:-\mathrm{GetData}\left(2\right)$
 ${"fish"}$ (2)
 > $\mathrm{res}:-\mathrm{GetData}\left(3\right)$
 ${100}$ (3)
 > $\mathrm{res}:-\mathrm{GetData}\left(4\right)$
 ${0.0100000000000000002}$ (4)

Set the update values.

 > $\mathrm{res}:-\mathrm{UpdateData}\left(2,"chicken"\right);$$\mathrm{res}:-\mathrm{UpdateData}\left(3,6\right);$$\mathrm{res}:-\mathrm{UpdateData}\left(4,2.5\right)$

The new values are not sent to the database yet.

 > $\mathrm{res}:-\mathrm{GetData}\left(2\right)$
 ${"fish"}$ (5)
 > $\mathrm{res}:-\mathrm{GetData}\left(3\right)$
 ${100}$ (6)
 > $\mathrm{res}:-\mathrm{GetData}\left(4\right)$
 ${0.0100000000000000002}$ (7)

Update the row.

 > $\mathrm{res}:-\mathrm{UpdateRow}\left(\right)$

Check the values.

 > $\mathrm{res}:-\mathrm{GetData}\left(2\right)$
 ${"chicken"}$ (8)
 > $\mathrm{res}:-\mathrm{GetData}\left(3\right)$
 ${6}$ (9)
 > $\mathrm{res}:-\mathrm{GetData}\left(4\right)$
 ${2.50000000000000000}$ (10)