/**
  * Testing transaction support
  */
 function testTransactions()
 {
     if (!$this->supported('Transactions')) {
         return;
     }
     $this->db->autoCommit(0);
     $row = 0;
     $data = array();
     $data['user_name'] = "user_{$row}";
     $data['user_password'] = '******';
     $data['subscribed'] = (bool) ($row % 2);
     $data['user_id'] = $row;
     $data['quota'] = strval($row / 100);
     $data['weight'] = sqrt($row);
     $data['access_date'] = MDB_Date::mdbToday();
     $data['access_time'] = MDB_Date::mdbTime();
     $data['approved'] = MDB_Date::mdbNow();
     $prepared_query = $this->db->prepareQuery('INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->types);
     $this->insertTestValues($prepared_query, $data);
     $result = $this->db->executeQuery($prepared_query);
     $this->db->rollback();
     $result = $this->db->query('SELECT * FROM users');
     if (MDB::isError($result)) {
         $this->assertTrue(false, 'Error selecting from users' . $result->getMessage());
     }
     $this->assertTrue($this->db->endOfResult($result), 'Transaction rollback did not revert the row that was inserted');
     $this->db->freeResult($result);
     $this->insertTestValues($prepared_query, $data);
     $result = $this->db->executeQuery($prepared_query);
     $this->db->commit();
     $result = $this->db->query('SELECT * FROM users');
     if (MDB::isError($result)) {
         $this->assertTrue(false, 'Error selecting from users' . $result->getMessage());
     }
     $this->assertTrue(!$this->db->endOfResult($result), 'Transaction commit did not make permanent the row that was inserted');
     $this->db->freeResult($result);
     $result = $this->db->query('DELETE FROM users');
     if (MDB::isError($result)) {
         $this->assertTrue(false, 'Error deleting from users' . $result->getMessage());
         $this->db->rollback();
     }
     $autocommit = $this->db->autocommit(1);
     $this->assertTrue(!MDB::isError($autocommit), 'Error autocommiting transactions');
     $this->db->freePreparedQuery($prepared_query);
     $result = $this->db->query('SELECT * FROM users');
     if (MDB::isError($result)) {
         $this->assertTrue(false, 'Error selecting from users' . $result->getMessage());
     }
     $this->assertTrue($this->db->endOfResult($result), 'Transaction end with implicit commit when re-enabling auto-commit did not make permanent the rows that were deleted');
     $this->db->freeResult($result);
 }
function MetabaseNow()
{
    return MDB_Date::mdbNow();
}
示例#3
0
 /**
  * http://pear.php.net/bugs/bug.php?id=946
  */
 function testBug946()
 {
     $data = array();
     $total_rows = 5;
     $prepared_query = $this->db->prepareQuery('INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->types);
     for ($row = 0; $row < $total_rows; $row++) {
         $data[$row]['user_name'] = "user_{$row}";
         $data[$row]['user_password'] = '******';
         $data[$row]['subscribed'] = (bool) ($row % 2);
         $data[$row]['user_id'] = $row;
         $data[$row]['quota'] = sprintf("%.2f", strval(1 + ($row + 1) / 100));
         $data[$row]['weight'] = sqrt($row);
         $data[$row]['access_date'] = MDB_Date::mdbToday();
         $data[$row]['access_time'] = MDB_Date::mdbTime();
         $data[$row]['approved'] = MDB_Date::mdbNow();
         $this->insertTestValues($prepared_query, $data[$row]);
         $result = $this->db->executeQuery($prepared_query);
         if (MDB::isError($result)) {
             $this->assertTrue(false, 'Error executing prepared query' . $result->getMessage());
         }
     }
     $this->db->freePreparedQuery($prepared_query);
     $result = $this->db->limitQuery('SELECT * FROM users', null, 1, 3);
     $numrows = $this->db->numRows($result);
     while ($row = $this->db->fetchInto($result)) {
         if (MDB::isError($row)) {
             $this->assertTrue(false, 'Error fetching a row' . $row->getMessage());
         }
     }
     $this->db->freeResult($result);
     $result = $this->db->query('SELECT * FROM users');
     $numrows = $this->db->numRows($result);
     while ($row = $this->db->fetchInto($result)) {
         if (MDB::isError($row)) {
             $this->assertTrue(false, 'Error fetching a row with limit' . $row->getMessage());
         }
     }
     $this->db->freeResult($result);
 }
示例#4
0
                    if (0 == $counte)
                    {
				  		//There are no overlaps
				  		if (4 == $area)
                        {
					  		$name = $jpnames[mt_rand(1,count($jpnames)-1)];
				  		}
                        else
                        {
					  		$name = $ennames[mt_rand(1,count($ennames)-1)];
				  		}
				  		$type = $intext[mt_rand(1,2)];
                  		$id = $mdb->nextId('mrbs_entry_id');
                        $sql_4_data = array($id, $room, $REMOTE_ADDR, $starttime,
                        					$endtime, $type, $name, 'A meeting',
                                            MDB_Date::mdbNow());
                        $param_types = array('integer', 'integer', 'text', 'integer',
                        					 'integer', 'text', 'text', 'text', 'timestamp');
                        $res = $mdb->execute($prepared_query_4, NULL, $sql_4_data,
                        					 $param_types);
                        if (MDB::isError($res))
              			{
                			echo $res->getMessage() . "<BR>";
                			die($res->getUserInfo());
            			}
        			}
                    echo "$area - $room ($starthour,$length), $type<br>";
		  		}
	  		}
  		}
 	}