Log in

View Full Version : Unit Testing & Transactions


VBCoder
06-28-2005, 09:18 PM
I'd like to use transactions to add unit testing to my vB mods & code. That is, I'd like to tell vB "Start a transaction. Now, use the DM API to do things. Now roll that transaction back" So the tests haven't disturbed anything.

Is there anyway to do this? How? (PHP4/MySQL4, but could switch to PHP5 if necessary)

merk
06-28-2005, 11:24 PM
From memory, the transactional things are dealt with by mysql, not php.

But MyISAM doesnt support transactional queries.

Marco van Herwaarden
06-29-2005, 06:13 AM
Have a look at the following URL's:
http://dev.mysql.com/books/mysqlpress/mysql-tutorial/ch10.html
http://dev.mysql.com/doc/mysql/en/ansi-diff-transactions.htmlhttp://dev.mysql.com/doc/mysql/en/innodb-transactions-with-different-apis.html

Like Merk already say, you can not use this with MyISAM tables. For InnoDB it is basically:

Start transaction:
BEGIN TRANSACTION;

Then end the transaction with one of the following:
COMMIT;
or:
ROLLBACK;

VBCoder
06-30-2005, 02:40 AM
Sorry for not being more clear. I know how to do transactions in SQL. My question is, could I somehow wrap vB's actions in transactions. Something like:

mysql_query('BEGIN TRANSACTION');
build_new_post();
mysql_query('ROLLBACK');

or, even better:

$vbulletin->database->begin_transaction();
$dm = init_datamanager(...)
$dm->...
$vbulletin->database->rollback_transaction();


Note: I'm working from memory, so my syntax isn't exact