Skip to main content

lock_mode

1. LOCK_MODE Function

The LOCK_MODE function in H2 database is used to retrieve the lock mode of a specified table.

2. Syntax

The syntax for the LOCK_MODE function in H2 database is as follows:

LOCK_MODE(tableName)

Arguments

  • tableName: The name of the table for which you want to retrieve the lock mode. It should be a valid table name in the database.

Return

  • The LOCK_MODE function returns a string indicating the lock mode of the specified table. Possible values are "NONE", "READ", "WRITE", or "EXCLUSIVE".

3. Notes

  • The LOCK_MODE function is specific to the H2 database and may not be available in other database systems.
  • The function returns "NONE" if the table does not exist or if it is not locked.
  • It is important to note that the lock mode returned by this function represents the current lock state, and it can change over time.

4. Examples

Here are a few examples demonstrating the usage of the LOCK_MODE function in H2 database:

Example 1 - Retrieving the lock mode of a table:

CREATE TABLE my_table (
id INT PRIMARY KEY,
name VARCHAR(50)
);

-- Locking the table
LOCK TABLE my_table IN EXCLUSIVE MODE;

-- Retrieving the lock mode
SELECT LOCK_MODE('my_table') AS lock_mode;

Output:

lock_mode
-----------
EXCLUSIVE

Example 2 - Retrieving the lock mode of a non-existing table:

SELECT LOCK_MODE('non_existing_table') AS lock_mode;

Output:

lock_mode
-----------
NONE

There are no directly related functions to the LOCK_MODE function in H2 database. However, you can explore other locking-related functions and statements such as LOCK TABLE, UNLOCK TABLE, and SHOW LOCKS to manage and monitor table locks in H2 database.