Home    |    Concepts   |   API   |   Samples
Concepts > Schema Objects > Tables
Inserting data
The principal steps in getting data into an ArcSDE geodatabase are as follows:

1. Connect to a database.

2. Initiate the insert statement on the stream.

3. For each row to be inserted, set the data values and insert row by executing statement.

4. Disconnect from the database.

Inserting new data into a table is the opposite of fetching data from a table. Instead of executing the query, iterating over the record set, and extracting the values, you tell ArcSDE that you are inserting data, set the values, and execute the statement for each new record.

As in our previous examples, assume that you are adding new records to the cities table and adding data to the following columns: city_name, area, population, and boundary (a shape column). The following example performs this operation:

/* Define the columns to be filled in on insert */

num_cols = 5;

attrs = (CHAR **) malloc (num_cols * sizeof(CHAR *));
attrs[0] = "city_name";
attrs[1] = "area";
attrs[2] = "population";
attrs[3] = "boundary";
attrs[4] = "updated";

/* Tell the stream that you are inserting new records into the table */
rc = SE_stream_insert_table (Stream, "cities", num_cols, attrs);

/* See Error handling section for check_error function code. */
check_error(NULL, Stream, rc, "SE_stream_insert_table");

/* For each record to be inserted into the table */
while (more data exists for insert)
{
   rc = SE_stream_set_string (Stream, 1, city_name);
   check_error(NULL, Stream, rc, "SE_stream_set_string");

   rc = SE_stream_set_double (Stream, 2, area);
   check_error(NULL, Stream, rc, "SE_stream_set_double");

   rc = SE_stream_set_integer (Stream, 3, population);
   check_error(NULL, Stream, rc, "SE_stream_set_integer");

   rc = SE_stream_set_shape (Stream, 4, shape);

   rc = SE_stream_set_date (Stream, 5, updated_on);
   check_error(NULL, Stream, rc, "SE_stream_set_date");

   rc = SE_stream_execute (Stream);
   check_error(NULL, Stream, rc, "SE_stream_execute");
}

feedback | privacy | legal