Пример #1
0
 static function __static()
 {
     if (extension_loaded('mssql')) {
         \rdbms\DriverManager::register('mssql+std', new \lang\XPClass(__CLASS__));
         \rdbms\DriverManager::register('sybase+ms', new \lang\XPClass(__CLASS__));
     }
 }
Пример #2
0
 static function __static()
 {
     if (extension_loaded('sybase_ct')) {
         ini_set('sybct.deadlock_retry_count', 0);
         \rdbms\DriverManager::register('sybase+ct', new \lang\XPClass(__CLASS__));
     }
 }
 /**
  * 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([]);
     $this->assertEquals($conn1, $cm->register($conn1));
     $this->assertEquals($conn2, $cm->register($conn2));
     $this->assertEquals($conn2, $cm->getByHost('host', 0));
 }
Пример #5
0
 /**
  * Setup method
  */
 public function setUp()
 {
     with($conn = \rdbms\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((new Criteria(Job::column('job_id')->equal(5)))->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(Job::column('job_id'))->add(Job::column('title'))));
     $this->qb = new SelectQuery();
     $this->qb->setPeer(Person::getPeer());
     $this->qb->setCriteria((new Criteria())->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(Person::column('job_id'))->add(Person::column('name'))));
 }
 static function __static()
 {
     if (strncasecmp(PHP_OS, 'Win', 3) === 0) {
         self::$lookup = XPClass::forName('rdbms.tds.SqlIniLookup')->newInstance();
     } else {
         if (getenv('SYBASE')) {
             self::$lookup = XPClass::forName('rdbms.tds.InterfacesLookup')->newInstance();
         } else {
             self::$lookup = XPClass::forName('rdbms.tds.FreeTdsLookup')->newInstance();
         }
     }
     DriverManager::register('sybase+x', new XPClass(__CLASS__));
 }
Пример #7
0
 /**
  * Entry point
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $db = DriverManager::getConnection($args[0]);
     try {
         $db->connect();
         $tran = $db->begin(new \rdbms\Transaction('process'));
         Console::$out->writeLine('! Started');
         while ($sql = Console::$in->readLine()) {
             $db->query($sql);
             Console::$out->writeLine('+ OK');
         }
         $tran->commit();
     } catch (\rdbms\SQLException $e) {
         Console::$out->writeLine('- ', nameof($e));
     }
 }
Пример #8
0
 /**
  * Constructor
  *
  * @param   util.cmd.ParamString args
  */
 public function __construct(\util\cmd\ParamString $args)
 {
     $dsn = new DSN($args->value(0));
     $this->adapter = self::$adapters[$dsn->getDriver()]->newInstance(DriverManager::getInstance()->getConnection($dsn->dsn));
     $this->package = $args->value('package', 'p', 'db');
     $this->host = $args->value('host', 'h', $dsn->getHost());
     $this->naming = $args->value('nstrategy', 'n', '');
     if ('' != $this->naming) {
         DBXMLNamingContext::setStrategy(XPClass::forName($this->naming)->newInstance());
     }
     $this->prefix = $args->value('prefix', 'pv', '');
     $this->ptargets = explode('|', $args->value('ptargets', 'pt', ''));
     $this->pexclude = $args->value('pexclude', 'pe', false);
     // Setup generator
     $this->processor = new DomXSLProcessor();
     $this->processor->setXSLBuf($this->getClass()->getPackage()->getResource($args->value('lang', 'l', 'xp5.php') . '.xsl'));
     $this->processor->setParam('package', $this->package);
     if ($this->prefix) {
         $this->processor->setParam('prefix', $this->prefix);
         $this->processor->setParam($this->pexclude ? 'exprefix' : 'incprefix', implode(',', $this->ptargets));
     }
 }
 public function connectFailedThrowsException()
 {
     DriverManager::getConnection(str_replace(':' . $this->db(false)->dsn->getPassword() . '@', ':hopefully-wrong-password@', $this->dsn))->connect();
 }
Пример #10
0
 /**
  * Setup function
  */
 public function setUp()
 {
     $this->conn = DriverManager::getConnection('mock://mock/MOCKDB?autoconnect=0');
     $this->assertEquals(0, $this->conn->flags & DB_AUTOCONNECT);
 }
Пример #11
0
 /**
  * Setup method
  */
 public function setUp()
 {
     $this->fixture = new JobFinder();
     $this->fixture->getPeer()->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
Пример #12
0
 /**
  * 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];
     }
     throw new DriverNotSupportedException('Neither a connection string nor a rdbms.DBConnection given.');
 }
 public static function registerMockConnection()
 {
     \rdbms\DriverManager::register('mock', \lang\XPClass::forName('net.xp_framework.unittest.rdbms.mock.MockConnection'));
     Job::getPeer()->setConnection(\rdbms\DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
Пример #14
0
 static function __static()
 {
     if (extension_loaded('mysqli')) {
         \rdbms\DriverManager::register('mysql+i', new \lang\XPClass(__CLASS__));
     }
 }
 public function connectFailedThrowsException()
 {
     $dsn = new DSN($this->dsn);
     $dsn->url->setUser('wrong-user');
     $dsn->url->setPassword('wrong-password');
     DriverManager::getConnection($dsn)->connect();
 }
Пример #16
0
 function regressionIteratorDatasetType()
 {
     $conn = DriverManager::getConnection('mock://mock/JOBS?autoconnect=1');
     $conn->setResultSet(new MockResultSet([['count' => 5]]));
     $crit = (new Criteria())->withProjection(Projections::count('*'));
     $this->peer->setConnection($conn);
     $this->assertInstanceOf(Record::class, $this->peer->iteratorFor($crit)->next());
 }
Пример #17
0
 /**
  * Setup method
  */
 public function setUp()
 {
     Job::getPeer()->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
 public function searchImplementation()
 {
     // Should not be found
     $this->register('tests', \lang\XPClass::forName('net.xp_framework.unittest.rdbms.mock.MockConnection'));
     // Should choose the "a" implementation
     $this->register('test+a', \lang\ClassLoader::defineClass('net.xp_framework.unittest.rdbms.mock.AMockConnection', 'net.xp_framework.unittest.rdbms.mock.MockConnection', array(), '{}'));
     $this->register('test+b', \lang\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'));
 }
 /**
  * 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'));
 }
Пример #20
0
 static function __static()
 {
     \rdbms\DriverManager::register('mysql+std', new \lang\XPClass(__CLASS__));
 }
 /**
  * This method gets invoked after all test methods of a given class have
  * executed, and after any methods annotated with afterTest
  *
  * @param  lang.XPClass $c
  * @return void
  */
 public function afterTestClass(\lang\XPClass $c)
 {
     \rdbms\DriverManager::remove('mock');
 }
Пример #22
0
 static function __static()
 {
     DriverManager::register('mysql+x', new XPClass(__CLASS__));
 }
 static function __static()
 {
     if (extension_loaded('interbase')) {
         \rdbms\DriverManager::register('ibase+std', new \lang\XPClass(__CLASS__));
     }
 }
 public static function registerMockConnection()
 {
     DriverManager::register('mock', XPClass::forName('rdbms.unittest.mock.MockConnection'));
     Job::getPeer()->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }