예제 #1
0
//var_dump( $conn1 );
Transaction::reset();
T::ok(Transaction::start(), 'started a transaction at the global level');
$conn1 = $newconn();
$conn2 = $newconn();
T::ok($conn1->start(), 'started a transaction on conn1');
T::ok($conn2->start(), 'started a transaction on conn2');
$rs = $conn1->execute("insert into {$table} values (3)");
T::ok($rs, 'inserted a row into test table from conn1');
//if( ! $rs ) T::debug( $conn1 );
$rs = $conn2->execute("insert into {$table} values(4)");
T::ok($rs, 'inserted a row into test table from conn2');
//if( ! $rs ) T::debug( $conn2 );
T::ok($conn1->commit(), 'committed inserted row on conn1');
T::ok($conn2->commit(), 'committed inserted row on conn2');
T::ok(Transaction::rollback(), 'rolled back the transaction at the global level');
T::ok($rs = $dbmain->execute("select id from {$table}"), 'selected all rows from the table');
$ct = $rs->affected();
T::is($ct, 2, '2 rows in the table, new rows rolled back');
$rs = $conn1->execute("select id from {$table}");
T::is($rs, FALSE, 'after rolling back, new queries fail on rolled back db object');
$dbmain->execute("drop table {$table}");
$db = $newconn();
$raw = file_get_contents(__DIR__ . '/sample/i_can_eat_glass.txt');
$lines = explode("\n", $raw);
$lines = array_slice($lines, 0, 10) + array_slice($lines, 100, 10) + array_slice($lines, 200, 10) + array_slice($lines, 200, 10);
$raw = implode("\n", $lines);
$sql = "CREATE TEMPORARY TABLE t1utf8 (`i` INT UNSIGNED NOT NULL PRIMARY KEY, `line` VARCHAR(5000) ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8";
$db->execute($sql);
foreach ($lines as $i => $line) {
    //$lines[ $i ] = $line = mb_convert_encoding($line, 'UTF-8', 'auto');
예제 #2
0
파일: DB.php 프로젝트: wukka/db
 /**
  * rollback a transaction.
  * connected to the Transaction singleton to support multi-database transactions.
  */
 public function rollback()
 {
     $args = func_get_args();
     $auth = isset($args[0]) ? $args[0] : NULL;
     if ($this->core instanceof Iface) {
         return $this->core->rollback($auth);
     }
     if ($auth != Transaction::SIGNATURE) {
         return Transaction::rollback();
     }
     if (!$this->txn) {
         return FALSE;
     }
     if ($this->lock) {
         return TRUE;
     }
     $f = $this->_[__FUNCTION__];
     $res = (bool) $f($auth);
     $this->lock = TRUE;
     return $res;
 }