Using Dataport Functions : Using Functions in C Language Programs : Initializing the Retrieval Process : Self Transaction Mode

Self Transaction Mode

Use self_transaction mode when working with applications that are sensitive to database changes performed by a process that runs in parallel with your program. When you operate using the self_transaction mode, you must explicitly perform a start_transaction before you call Dataport retrieval library functions. This is done by including the following statement in your program:

stm_start_transaction();

For each start_transaction, you must perform an explicit commit_transaction to conclude the database retrievals by including the following statement in your program:

stm_commit_transaction();

You can start and commit transactions at any stage of your program. However, before retrieving additional data following a commit_transaction, you must first perform another start_transaction. Perform a new start_transaction whenever you want to refresh the image of the database so subsequent retrievals accurately reflect the database information.

The following is the structure of the self_transaction mode:

main()
{
int status, success;
stm_list st_list;
stm_id el;
success = stm_init_uad ("PROJ", "/local/proj",
self_transaction, &status);
if (!success)
{
printf ("cause of failure is: %d", status);
return;
}
/* */
/* once initialization is done, */
/* a start_transaction statement is */
/* needed in this mode. */
/* */
stm_start_transaction ();
st_list = stm_r_st_name_of_st ("*", &status);
for (el = (stm_id)
stm_list_first_element (st_list, 0);el!=NIL;
el = (stm_id)stm_list_next_element(st_list, 0))
{
printf ("\n%s", stm_r_st_name (el, 0));
}
/* */
/* retrievals are done for now, so a */
/* commit_transaction is performed. */
/* */
/* stm_commit_transaction(); */
/* The resulting output is: */
/* state_a */
/* state_b */
/* state_c */
/* state_d */
/* */
/* During the course of this output */
/* another process has updated the */
/* database, drawing a new state since */
/* this last transaction took place. */
/* */
/* If the same retrieval is done again, */
/* different results should be found! */
/* To insure that the program "sees" */
/* the changes, start_transaction is */
/* performed again. */
/* */
stm_start_transaction ();
st_list = stm_r_st_name_of_st ("*", &status);
for (el = (stm_id)
stm_list_first_element (st_list, 0);el!=NIL;
el =(stm_id)stm_list_next_element (st_list, 0))
{
printf ("\n%s", stm_r_st_name (el, 0));
}
/* */
/* The resulting output is: */
/* state_a */
/* state_b */
/* state_c */
/* state_d */
/* state_e */
/* */
/* The last state, e, is new to the list */
/* */
stm_commit_transaction ();
stm_finish_uad ();
}