Once features have been inserted into a database, you may need to update the
data as values change. Updating a feature involves the following steps:
- Identify which features to update by formulating a query. The query can
involve an attribute, a spatial constraint, or both. The SE_stream_update_table
function is used to define the query.
- Set which values to update by setting or binding individual values. Values
are set by data type (SE_stream_set_string, SE_stream_set_integer, etc.) or
bound to memory locations with SE_stream_bind_input_column.
- Execute the query with SE_stream_execute.
You can execute updates against a single feature or a collection of features.
For example, individual parcels can be identified by using a unique identifier
in the query:
strcpy (where, "Parcel_ID = 12345");
/*When executed, a single parcel with Parcel_ID = 12345 will have the
* specified
columns updated. You can update groups of features by formulating
* a query that
selects multiple features:*/
num_cols = 3;
attrs = malloc (num_cols * sizeof (CHAR *));
attrs[0] = "area";
attrs[1] = "population";
attrs[2] = "boundary";
/* Formulate the where clause to update the correct city */
strcpy (where, "city_name = 'Aylmer'");
/* Initialize the stream with the update operation */
rc = SE_stream_update_table (stream, "cities", num_cols, (const char **)attrs,
where);
/* See Error handling section for check_error function code. */
check_error(NULL, Stream, rc, "SE_stream_update_table");
/* Bind the address of our input variables and indicators */
rc = SE_stream_bind_input_column (stream, 1, &area, &area_indicator);
check_error(NULL, Stream, rc, "SE_stream_bind_input_column");
rc = SE_stream_bind_input_column (stream, 2, &population, &pop_indicator);
check_error(NULL, Stream, rc, "SE_stream_bind_input_column");
rc = SE_stream_bind_input_column (stream, 3, shape, &shape_indicator);
check_error(NULL, Stream, rc, "SE_stream_bind_input_column");
/* Set the indicators for non NULL input data */
area_indicator = SE_IS_NOT_NULL_VALUE; pop_indicator = SE_IS_NOT_NULL_VALUE;
shape_indicator = SE_IS_NOT_NULL_VALUE;
/* Execute the update statement */
rc = SE_stream_execute (stream);
check_error(NULL, Stream, rc, "SE_stream_execute");
free (attrs);
|