Exemplo n.º 1
0
 public function load($sql)
 {
     $this->dbh->exec('PRAGMA writable_schema = 1;');
     $this->dbh->exec('PRAGMA ignore_check_constraints = 1;');
     parent::load($sql);
     $this->dbh->exec('PRAGMA ignore_check_constraints = 0;');
     $this->dbh->exec('PRAGMA writable_schema = 0;');
 }
Exemplo n.º 2
0
 public function setUp()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $this->sql = explode("\n", $sql);
     $this->sqlite = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     $this->sqlite->cleanup();
 }
Exemplo n.º 3
0
 protected function loadDump()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $sql = explode("\n", $sql);
     $sqlite = \Codeception\Lib\Driver\Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     $sqlite->load($sql);
 }
Exemplo n.º 4
0
 public function setUp()
 {
     try {
         $this->postgres = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
     }
     $this->postgres->load(self::$sql);
 }
Exemplo n.º 5
0
 public static function setUpBeforeClass()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     self::$sql = explode("\n", $sql);
     try {
         self::$sqlite = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
         self::$sqlite->cleanup();
     } catch (\Exception $e) {
     }
 }
Exemplo n.º 6
0
 public function setUp()
 {
     $this->testCase = Stub::make('\\Codeception\\TestCase');
     $module = new \Codeception\Module\Dbh(make_container());
     try {
         $driver = Driver::create($this->config['dsn'], $this->config['user'], $this->config['password']);
         $module::$dbh = $driver->getDbh();
     } catch (\PDOException $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
         return;
     }
     $this->module = $module;
 }
Exemplo n.º 7
0
 public function setUp()
 {
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/mysql.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $this->sql = explode("\n", $sql);
     try {
         $this->mysql = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
         return;
     }
     $this->mysql->cleanup();
 }
Exemplo n.º 8
0
 public function load($sql)
 {
     if ($this->hasSnapshot) {
         $this->dbh = null;
         file_put_contents($this->filename, file_get_contents($this->filename . '_snapshot'));
         $this->dbh = new \PDO($this->dsn, $this->user, $this->password);
     } else {
         if (file_exists($this->filename . '_snapshot')) {
             unlink($this->filename . '_snapshot');
         }
         parent::load($sql);
         copy($this->filename, $this->filename . '_snapshot');
         $this->hasSnapshot = true;
     }
 }
Exemplo n.º 9
0
 public function sqlLine($sql)
 {
     if (!$this->putline) {
         return parent::sqlLine($sql);
     }
     if ($sql == '\\.') {
         $this->putline = false;
         pg_put_line($this->connection, $sql . "\n");
         pg_end_copy($this->connection);
         pg_close($this->connection);
     } else {
         pg_put_line($this->connection, $sql . "\n");
     }
     return true;
 }
Exemplo n.º 10
0
 public function setUp()
 {
     if (!function_exists('pg_connect')) {
         return $this->markTestSkipped("Postgres extensions not loaded");
     }
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/postgres.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     $this->sql = explode("\n", $sql);
     try {
         $this->postgres = Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
         return;
     }
     $this->postgres->cleanup();
 }
Exemplo n.º 11
0
 public static function setUpBeforeClass()
 {
     if (!function_exists('pg_connect')) {
         return;
     }
     if (getenv('APPVEYOR')) {
         self::$config['password'] = '******';
     }
     $sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/postgres.sql');
     $sql = preg_replace('%/\\*(?:(?!\\*/).)*\\*/%s', "", $sql);
     self::$sql = explode("\n", $sql);
     try {
         self::$postgres = Db::create(self::$config['dsn'], self::$config['user'], self::$config['password']);
         self::$postgres->cleanup();
     } catch (\Exception $e) {
     }
 }
Exemplo n.º 12
0
 protected function proceedSeeInDatabase($table, $column, $criteria)
 {
     $query = $this->driver->select($column, $table, $criteria);
     $this->debugSection('Query', $query, json_encode($criteria));
     $sth = $this->driver->getDbh()->prepare($query);
     if (!$sth) {
         $this->fail("Query '{$query}' can't be executed.");
     }
     $sth->execute(array_values($criteria));
     return $sth->fetchColumn();
 }
Exemplo n.º 13
0
 /**
  * Prepares a fragment of SQL to be used within a query.
  * This supports both [field] = [value]|[placeholder] or just [value]|[placeholder]
  *
  * @param string $field        The field name to be used, set to null if it's not needed
  * @param string $placeholder  The placeholder name to be used, set to null if a value is specified instead
  * @param string $value        The value to be used, set to null if a placeholder is specified instead
  * @param Driver $driver       Database driver, used to quote field names
  * @param bool   $is_for_nulls if true, we treat NULL different, otherwise use '=' only ( for UPDATE )
  *
  * @return string
  */
 private static function prepareClause($field, $placeholder, $value, Driver $driver, $is_for_nulls = true)
 {
     $rhs = $placeholder === null ? $value : $placeholder;
     if ($field === null) {
         return $rhs;
     }
     // If the value is NULL, we need to use IS NULL, rather than =.
     $operator = $is_for_nulls && $value === null ? 'IS' : '=';
     return "{$driver->getQuotedName($field)} {$operator} {$rhs}";
 }
Exemplo n.º 14
0
 protected function proceedSeeInDatabase($table, $column, $criteria)
 {
     $query = $this->driver->select($column, $table, $criteria);
     $this->debugSection('Query', $query, json_encode($criteria));
     $sth = $this->driver->executeQuery($query, array_values($criteria));
     return $sth->fetchColumn();
 }
Exemplo n.º 15
0
 protected function proceedSeeInDatabase($table, $column, $criteria)
 {
     $query = $this->driver->select($column, $table, $criteria);
     $parameters = array_values($criteria);
     $this->debugSection('Query', $query);
     if (!empty($parameters)) {
         $this->debugSection('Parameters', $parameters);
     }
     $sth = $this->driver->executeQuery($query, $parameters);
     return $sth->fetchColumn();
 }
Exemplo n.º 16
0
 public function testThrowsExceptionIfInMemoryDatabaseIsUsed()
 {
     $this->setExpectedException('\\Codeception\\Exception\\ModuleException', ':memory: database is not supported');
     Db::create('sqlite::memory:', '', '');
 }