I think I may have misunderstood something in a major way with regards to
the subject.

I have an application that maintains a single application-wide connection
which is opened with SQLITE_OPEN_FULLMUTEX flag. So if I have a method that
inserts multiple rows into a db, does that method need an application-level
lock when hit by multiple threads or does sqlite ensure serialized access
on that connection because of that flag?

This method goes something like this:

void Insert()
{
    db_conn = get_one_and_only_db_conn();
    db_conn.BeginTransaction();

    for (int i = 0; i < 33; ++i) {
        db_conn.InsertARow();
    }

    db_conn.EndTransaction();
}

Which brings me to the second question. The above code throws an exception
when Thread1 had already started a transaction via this method and Thread2
decides to enter this method and calls BeginTransaction again (cannot start
a transaction within a transaction).

Currently I wrap everything except get_one_and_only_db_conn() inside a
do/while loop, catch the exception thrown in the case of that nested
transaction error, sleep for half a second or so and try again. I try maybe
10 times or so. This doesn't look very reliable to me because under heavy
loads I keep hitting whatever retry attempt account I have set for myself.

What is the correct way to do this?
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to