/**
  * Retrieve database connection object
  *
  * @param   bool connect default TRUE
  * @return  rdbms.DBConnection
  */
 protected function db($connect = TRUE)
 {
     with($db = DriverManager::getConnection($this->dsn));
     if ($connect) {
         $db->connect();
     }
     return $db;
 }
 public function registerOverwritesPreviouslyRegistered()
 {
     $conn1 = DriverManager::getConnection('mock://*****:*****@host/db1');
     $conn2 = DriverManager::getConnection('mock://*****:*****@host/db2');
     $cm = $this->instanceWith(array());
     $this->assertEquals($conn1, $cm->register($conn1));
     $this->assertEquals($conn2, $cm->register($conn2));
     $this->assertEquals($conn2, $cm->getByHost('host', 0));
 }
Esempio n. 3
0
 /**
  * Setup method
  *
  */
 public function setUp()
 {
     with($conn = DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
     Job::getPeer()->setConnection($conn);
     Person::getPeer()->setConnection($conn);
     $this->qa = new SelectQuery();
     $this->qa->setPeer(Job::getPeer());
     $this->qa->setCriteria(create(new Criteria(Job::column('job_id')->equal(5)))->setProjection(Projections::ProjectionList()->add(Job::column('job_id'))->add(Job::column('title'))));
     $this->qb = new SelectQuery();
     $this->qb->setPeer(Person::getPeer());
     $this->qb->setCriteria(create(new Criteria())->setProjection(Projections::ProjectionList()->add(Person::column('job_id'))->add(Person::column('name'))));
 }
Esempio n. 4
0
 /**
  * Entry point
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $db = DriverManager::getConnection($args[0]);
     try {
         $db->connect();
         $tran = $db->begin(new Transaction('process'));
         Console::$out->writeLine('! Started');
         while ($sql = Console::$in->readLine()) {
             $db->query($sql);
             Console::$out->writeLine('+ OK');
         }
         $tran->commit();
     } catch (SQLException $e) {
         Console::$out->writeLine('- ', $e->getClassName());
     }
 }
Esempio n. 5
0
 /**
  * Setup function
  *
  */
 public function setUp()
 {
     $this->conn = DriverManager::getConnection('mock://mock/MOCKDB');
     $this->assertEquals(0, $this->conn->flags & DB_AUTOCONNECT);
 }
Esempio n. 6
0
 /**
  * Setup method
  *
  */
 public function setUp()
 {
     $this->fixture = new JobFinder();
     $this->fixture->getPeer()->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
 /**
  * Setup method
  *
  */
 public function setUp()
 {
     $this->conn = DriverManager::getConnection('mock://mock/JOBS?autoconnect=1');
     $this->peer = Job::getPeer();
     $this->peer->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
 /**
  * Replace registered DSN with DBConnection if needed
  *
  * @param   string name name of connection
  * @param   var value either DSN or DBConnection
  * @return  rdbms.DBConnection
  */
 protected function conn($name, $value)
 {
     if ($value instanceof DBConnection) {
         return $value;
     }
     if (is_string($value)) {
         // Resolve lazy-loading DSNs
         $this->pool[$name] = DriverManager::getConnection($value);
         return $this->pool[$name];
     }
     raise('rdbms.DriverNotSupportedException', 'Neither a connection string nor a rdbms.DBConnection given.');
 }
 public function connectFailedThrowsException()
 {
     DriverManager::getConnection(str_replace(':' . $this->db(FALSE)->dsn->getPassword() . '@', ':hopefully-wrong-password@', $this->dsn))->connect();
 }
 public function searchImplementation()
 {
     // Should not be found
     $this->register('tests', XPClass::forName('net.xp_framework.unittest.rdbms.mock.MockConnection'));
     // Should choose the "a" implementation
     $this->register('test+a', ClassLoader::defineClass('net.xp_framework.unittest.rdbms.mock.AMockConnection', 'net.xp_framework.unittest.rdbms.mock.MockConnection', array(), '{}'));
     $this->register('test+b', ClassLoader::defineClass('net.xp_framework.unittest.rdbms.mock.BMockConnection', 'net.xp_framework.unittest.rdbms.mock.MockConnection', array(), '{}'));
     $this->assertInstanceOf('net.xp_framework.unittest.rdbms.mock.AMockConnection', DriverManager::getConnection('test://localhost'));
 }
 public static function registerMockConnection()
 {
     DriverManager::register('mock', XPClass::forName('net.xp_framework.unittest.rdbms.mock.MockConnection'));
     Job::getPeer()->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
Esempio n. 12
0
 /**
  * Setup method
  *
  */
 public function setUp()
 {
     Job::getPeer()->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }