基本步骤:
-
Connect to a database.
-
Initiate the insert statement on the stream.
-
For each row to be inserted
{
Set the data values.
Insert row by executing statement.
}
-
Disconnect from the database.
代码:
* Define the columns to be filled in on insert */
num_cols = 4;
attrs = (CHAR **) malloc (num_cols * sizeof(CHAR *));
attrs[0] = "city_name";
attrs[1] = "area";
attrs[2] = "population";
attrs[3] = "boundary";
/* 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&ldots;)
{
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);
check_error(NULL, Stream, rc, "SE_stream_set_shape");
rc = SE_stream_execute (Stream);
check_error(NULL, Stream, rc, "SE_stream_execute");
}