On Tue, 9 Aug 2016 17:09:39 -0300
Paulo Roberto <betobran...@gmail.com> wrote:

> I would like something like this:
> 
> "BEGIN EXCLUSIVE TRANSACTION;"
>  "SELECT counter FROM mytable WHERE counterid = ?;"
>  "UPDATE mytable SET counter=? WHERE counterid = ?;"
>   "COMMIT TRANSACTION;"

        begin transaction;

        UPDATE mytable SET counter = (
                        select 1 + max(counter)
                        from mytable where counterid = ? )
        WHERE counterid = ?;

        select counter - 1 as counter 
        from mytable where counterid = ?;

        commit transaction;

Standard SQL.  Doesn't rely on BEGIN EXCLUSIVE.  Should be just as
fast.  

--jkl

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to