Hi,
To lock a table for writing in H2, you can use SELECT ... FOR UPDATE.
See also http://h2database.com/html/grammar.html#select So instead of
LOCK TABLE nested_category WRITE;
you would write:
SELECT * FROM nested_category WHERE 1=0 FOR UPDATE;
Regards,
Thomas
On Tue, Mar 20, 2012 at 7:52 PM, iwbnwif <[email protected]> wrote:
> Sorry for the very newbie question, but what is the syntax used to
> lock tables for a series of actions, for example in MySql the
> following applies:
>
> LOCK TABLE nested_category WRITE;
>
> SELECT @myRight := rgt FROM nested_category
> WHERE name = 'TELEVISIONS';
>
> UPDATE nested_category SET rgt = rgt + 2 WHERE rgt > @myRight;
> UPDATE nested_category SET lft = lft + 2 WHERE lft > @myRight;
>
> INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES',
> @myRight + 1, @myRight + 2);
>
> UNLOCK TABLES;
>
> I believe this is handled by transactions in H2, but I cannot find the
> syntax for BEGIN TRANSACTION in the documentation.
>
> The following works:
>
> BEGIN TRANSACTION;
>
> SELECT @myRight := rgt FROM nested_category
> WHERE name = 'TELEVISIONS';
>
> UPDATE nested_category SET rgt = rgt + 2 WHERE rgt > @myRight;
> UPDATE nested_category SET lft = lft + 2 WHERE lft > @myRight;
>
> INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES',
> @myRight + 1, @myRight + 2);
>
> COMMIT;
>
> but I am not sure if it is correct or not?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups "H2
> Database" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.