forked from gs1/GS1_DigitalLink_Resolver_CE
-
Notifications
You must be signed in to change notification settings - Fork 0
Lock and unlock writing data way
Nam Hoang edited this page Apr 1, 2024
·
2 revisions
When the data is set up successfully on the server, we do not want to lose it by accident or by mistake of the someone who updates the data by testing the code. So, we need to lock the data to prevent the data from being updated by mistake. In this notebook, I will show you how to lock and unlock the data using the SQL command.
The credential is in https://github.com/gs-gs/fa-ag-trace/wiki/DLR's-variables
To lock or unlock the data, first, you need to connect to the database. Then you can use the SQL command to lock or unlock the data.
- Lock the data
BEGIN TRANSACTION
UPDATE
GL
SET
GL.LOCKED = 1,
GL.DATE_LAST_UPDATED = CURRENT_TIMESTAMP
FROM
[farm-dlr-db].DBO.GLOBAL_LOCKS AS GL
WHERE
GL.NAME = 'WRITE';
UPDATE
GL
SET
GL.LOCKED = 1,
GL.DATE_LAST_UPDATED = CURRENT_TIMESTAMP
FROM
[feedlot-dlr-db].DBO.GLOBAL_LOCKS AS GL
WHERE
GL.NAME = 'WRITE';
UPDATE
GL
SET
GL.LOCKED = 1,
GL.DATE_LAST_UPDATED = CURRENT_TIMESTAMP
FROM
[processor-dlr-db].DBO.GLOBAL_LOCKS AS GL
WHERE
GL.NAME = 'WRITE';
COMMIT;
- Unlock the data
BEGIN TRANSACTION
UPDATE
GL
SET
GL.LOCKED = 0,
GL.DATE_LAST_UPDATED = CURRENT_TIMESTAMP
FROM
[farm-dlr-db].DBO.GLOBAL_LOCKS AS GL
WHERE
GL.NAME = 'WRITE';
UPDATE
GL
SET
GL.LOCKED = 0,
GL.DATE_LAST_UPDATED = CURRENT_TIMESTAMP
FROM
[feedlot-dlr-db].DBO.GLOBAL_LOCKS AS GL
WHERE
GL.NAME = 'WRITE';
UPDATE
GL
SET
GL.LOCKED = 0,
GL.DATE_LAST_UPDATED = CURRENT_TIMESTAMP
FROM
[processor-dlr-db].DBO.GLOBAL_LOCKS AS GL
WHERE
GL.NAME = 'WRITE';
COMMIT;