logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: transactions in SQlite: msg#00004

Subject: Re: transactions in SQlite
Hi,

RCS Computers wrote:
> Can someone give me an example of transactions in SQlite?  Thank you.
>

These would be the same as transactions for any db; there are a couple of approaches, but the simplest is like this:

try {
  $con->begin();
  $con->executeUpdate(...);
  $con->executeUpdate(...);
  $con->executeUpdate(...);
  $con->executeUpdate(...);
  $con->executeUpdate(...);
  $con->commit();
} catch (Exception $e) {
  $con->rollback();
  throw $e;
}

As you can see this works quite well with exception try/catch model.

You can also use exceptions in the traditional JDBC way, by calling $con->setAutoCommit(false) instead of $con->begin(). I think the $con->begin() is conceptually easier to understand. Also you can nest transactions in some databases; not SQLite, though, AFAIR.

Cheers,
Hans


<Prev in Thread] Current Thread [Next in Thread>