## Locking queries

Normally in JReport Designer, queries are free to be shared among reports, which could increase the potential risk of being changed unexpectedly. When a query is shared by more than one report, it can be changed by any of those reports, which means you must be very careful to avoid causing impacts to other reports when you modify the shared query for one report. However, JReport provides you with the flexibility to lock a query to prevent it from being changed by unauthorized person.

### Creating a user to a query

Before you can lock or share a query, you need to claim the query by creating a user to it.

To creating a user to a query:

1. Right-click the query you want to claim and select Create User from the shortcut menu.
2. In the Create Query's Username and Password dialog, type in the user name and password.
3. Click OK to confirm the information.

When a user has been created for a query, you can modify the user information or remove the user as required.

- To modify the user information, right-click the query and select Modify User from the shortcut menu. In the Modify User Information dialog, provide the old user name and password and click OK. Then, in the Modify Query's Username and Password dialog, type in the new user name and password as required and click OK.
- To remove a user, right-click the query and click Delete User on the shortcut menu. In the Remove User dialog, provide the user and password information and click OK. The query is then free to be shared.

Note: A query can be claimed by only one user, that is to say, you can create only one user to a query.

### Locking or sharing a query

Using the Share property of a query, you can lock or unlock it according to your requirements. By default, the Share property of a query is true, which means that all queries in a catalog can be shared among multiple reports, until you lock them.

To lock or unlock a query:

1. Select the query that you want to lock or unlock.
2. Click the Expand button on the Catalog Browser toolbar to show the Properties sheet.
3. Locate the Share property and set its property to true or false according to your requirements. If it is true, the query can be shared among reports and can be modified. Otherwise, the query is locked and can be neither used in new reports nor modified by unauthorized person.

   Make sure that you have enabled the editable mode for the Properties sheet before editing the property values, that is to say, you have unchecked the option Forbid editing data object properties in the Options dialog.

You can also lock or unlock a query in the following way:

1. Right-click the query that has already been claimed by a user and select Set Share Property from the shortcut menu.
2. In the Set Query's Share Property dialog, provide the user information and check or clear the Share option as required.
3. Click OK to confirm the change.

Notes:

- If a query has not yet been claimed by any user, when you set its Share property in the Properties sheet, you will be prompted to claim the query by creating a user to it.
- If a query is locked, it is password protected. Unless you provide valid user information, you will neither be able to create a report directly using that query nor make changes to the query, including setting its Share property.