[CALUG] Database question

Jason Dixon jason at dixongroup.net
Mon Aug 21 10:25:57 CDT 2006


On Aug 21, 2006, at 11:07 AM, Jason C. Miller wrote:

> On second look, I don't think that the transaction is the route  
> that I'm
> looking for.  It has the commit() and rollback() functionality, but  
> still
> requires that individual records be update()d, insert()ed, and  
> delete()d (if
> I'm understanding it correctly).  I'm looking to minimize database
> accesses.  Here's some pseudocode for the mechanism that I'm  
> looking to
> employ...
>
> ---------------------------------------------------------------------- 
> -----------------------------------
> app.getUsers()   // open() database, select * from user, close(),  
> store
> results in memory
>
> app.addUser("me");                     // changes values in memory
> app.dropUser("you");                   // changes values in memory
> app.updateUser("whatever");       // changes values in memory
>
> if ( app.changes_are_good() )
>   {
>     app.commitChanges()
>     // open() database, "sync up" with values modified in memory,  
> close()
>   }
> ---------------------------------------------------------------------- 
> -----------------------------------
>
> Basically, I'm looking to somehow pass the contents of a table into  
> the
> database and have it sync between that and its stored table.  I
> know...sounds waaayyy too convenient, but ya never know.  :)  Are  
> there any
> tricks to do something like this?

I emulate transactions by disabling automatic commits (perl, DBI,  
DBD::sqlite).  If the commit returns an error, I perform a rollback.   
It's a mish-mash of home-brew and the functions available in SQLite,  
but it works reasonably well.

--
Jason Dixon
DixonGroup Consulting
http://www.dixongroup.net





More information about the lug mailing list