Previous Topic

Next Topic

Record/Row Locking

..\sdk\ctree.cpp\tutorials\ctpp_tutorial3.cpp

Now we will explore row/record locks using the c-treeACE C++ Database Framework.

The functionality for this tutorial focuses on inserting/adding rows/records, then updating a single row/record in the customer master table under locking control. The application will pause after a LOCK is placed on a row/record. Another instance of this application should then be launched, which will block, waiting on the lock held by the first instance. Pressing the <Enter> key will enable the first instance to proceed. This will result in removing the lock thereby allowing the second instance to continue execution. Launching two processes provides a visual demonstration of the effects of locking and a basis for experimentation on your own.

Like all other examples in the c-tree tutorial series, this tutorial simplifies the creation and use of a database into four simple steps: Initialize(), Define(), Manage(), and you’re Done() !

Tutorial #3: Locking

Here we demonstrate the enforcement of data integrity by introducing record/row "locking".

  • Initialize() - Connects to the c-treeACE Database Engine.
  • Define() - Defines and creates a "customer master" (custmast) table/file.
  • Manage() - Adds a few rows/records; Reads the rows/records back from the database; displays the column/field content. Then demonstrates an update operation under locking control, and a scenario that shows a locking conflict.
  • Done() - Disconnects from c-treeACE Database Engine.

Note our simple mainline:

//
// main()
//
// The main() function implements the concept of "init, define, manage
// and you're done..."
//

int main (COUNT argc, pTEXT argv[])
{
#ifdef LOCK_SUPPORT
   Initialize();

   Define();

   Manage();

   Done();
#else
   printf("\nThis tutorial demonstrates basic Record Locking. Record Locking is not");
   printf("\napplicable to c-tree's SingleUser model. In order to run this program");
   printf("\nselect a c-tree Multi-User or Client-Side type c-tree model");
#endif

   printf("\nPress <ENTER> key to exit . . .\n");
   getchar();

   return(0);
}

We suggest opening the source code with your own editor.

Continue now to review these four steps.

In This Section

Init

Define

Manage

Done

Additional Resources