14.01.2013 Views

IBM Informix Developer's Handbook - IBM Redbooks

IBM Informix Developer's Handbook - IBM Redbooks

IBM Informix Developer's Handbook - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

13.1 Concurrency and locking<br />

13.1.1 Types of locks<br />

Concurrency involves two or more independent uses of the same data at the<br />

same time. In a database system with many users, each user needs to be able to<br />

access and modify data. Unless the developer and database system impose<br />

controls, there can be negative consequences. Programs might access old data<br />

that is in the process of being changed by another user, and changes might<br />

seem to disappear even though it seems like the change was performed<br />

successfully.<br />

To take advantage of database server controls, tables in a multiple user<br />

environment should be logging tables. At a minimum, if you must use a<br />

nonlogging table within a transaction, either set Repeatable Read isolation level<br />

or lock the table in exclusive mode.<br />

To avoid concurrency problems, the database server imposes a system of locks.<br />

A lock is a claim, or reservation, that a program can place on a piece of data. The<br />

database server assures that no other program can modify it, as long as the lock<br />

is in place. When another application requests the data, the database server<br />

either makes the program wait or turns it back with an error.<br />

The application developer can control the effect of lock access using a<br />

combination of SQL statements and with the buffering mode selected for the<br />

database. The most used SQL statements are SET LOCK MODE, SET<br />

ISOLATION, and SET TRANSACTION. We discuss these in more detail later.<br />

For now, we need a better understanding of the types of locks that we can<br />

encounter.<br />

<strong>IBM</strong> <strong>Informix</strong> offers several server edition. <strong>IBM</strong> <strong>Informix</strong> Extended Parallel Server,<br />

<strong>Informix</strong> Online, and Standard Engine will have different syntax for concurrency<br />

related commands. You can find more information about the command syntax for<br />

the discussion in this chapter in <strong>IBM</strong> <strong>Informix</strong> Guide to SQL: Syntax, v11.50,<br />

SC27-3611.<br />

A lock is implemented as a variable associated with a data item. It can be<br />

explicitly placed by an application or, more frequently, is implicitly handled by the<br />

database management system. The lock is used to mark a data item as<br />

reserved; the type of lock designation determines what actions are permitted by<br />

users in regard to the data item.<br />

438 <strong>IBM</strong> <strong>Informix</strong> Developer’s <strong>Handbook</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!