On Mon, Oct 18, 2010 at 8:16 AM, Ian Hardingham <i...@omroth.com> wrote:
>  Hey guys.
>
> If I wish to log how often a user does action x, I'm assuming I would be
> best off doing something like:
>
> /SELECT whatever FROM actionPerfomedTable WHERE user = y, action = x
> LIMIT 1/
>
> If a record is returned, perform
>
> /UPDATE actionPerfomedTable SET number = incremented number WHERE user =
> y, action = x/
>
> Otherwise, perform
>
> /INSERT INTO actionPerfomedTable yada yada yada./
>

You're on the right track, but there's no need to do a SELECT first.
Do an UPDATE SET number=number+1, and check the returned number of
modified rows.  If it returns 0, do the INSERT.
-- 
Cory Nelson
http://int64.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to