Wednesday December 13, 2006
08:58 AM
making DBI writes no-ops
one of our databases consists of mysql myisam tables, which don't have transactions so you can't rollback. this makes debugging and 'dry-run' modes very difficult. one of my coworkers suggested DBD::NullP but that doesn't quite fit the bill - I want to pull data, inspect it, but no commit changes...
what I really need is some DBD driver that intercepts write statements (UPDATE, REPLACE, etc) and turns them in to no-ops. DBD::Proxy and/or DBD::ProxyServer seems to almost get me there, but I don't feel like I should have to go through a complex acl-style process for all my code - I should be able to swap out the driver and it should all just work.
so, has anyone done anything like this? I'm contemplating writing something like DBD::NullWrites, which should be relatively simple once I get my head around the DBD API. and after figuring out whether I can make it generic to apply to any read-front-end (DBD::Oracle for reads, DBD::NullWrites for writes, etc). pointers from folks who have ventured into DBD:: space appreciated :)
What about Mocking? (Score:1)
Re: (Score:2)
Two not-so-good solutions (Score:1)
1) Once per day, replicate the database to a dev copy. Run all tests on the dev database, destructively
2) Copy-on-write. I wrote a DBI facade which intercepted SQL prepares and, upon seeing an insert or update, copied the table to a new table and thereafter altered all SQL to replace the name of the old table with the new o
UID (Score:1)
Re: (Score:2)
--dry-runoption to all our scripts across the board, which works fine except for the databases that don't support transactions...Perhaps a DBI subclass ? (Score:1)
BTW: If you're using some DBI wrapper (DBIXC, CDBI, etc), you'll likely need to specify the subclass via the RootClass connect() attribute.