public function setUp() { try { $this->db = ezcDbInstance::get(); if ($this->db === false) { $this->markTestSkipped("You must provide a database to runtests.php."); } $tables = array(self::$table => new ezcDbSchemaTable(array(self::$fieldId => new ezcDbSchemaField('integer', false, true, null, true), self::$fieldUser => new ezcDbSchemaField('text', 32, true), self::$fieldPassword => new ezcDbSchemaField('text', 64, true), self::$fieldName => new ezcDbSchemaField('text', 64, true), self::$fieldCountry => new ezcDbSchemaField('text', 32, true)), array(self::$fieldUser => new ezcDbSchemaIndex(array(self::$fieldUser => new ezcDbSchemaIndexField()), false, false)))); $schema = new ezcDbSchema($tables); $schema->writeToDb($this->db); } catch (Exception $e) { // Oracle seems to skip every other test if the next line is enabled // $this->markTestSkipped( "Cannot create test table '" . self::$table . "'. " . $e->getMessage() ); } if (!isset($this->db)) { $this->markTestSkipped("You must provide a database to runtests.php. Run runtests.php --help to see how to specify a database."); } try { $query = new ezcQueryInsert($this->db); $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('1'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('jan.modaal'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(sha1('qwerty')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Jan Modaal'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('NL')); $stmt = $query->prepare(); $stmt->execute(); $query = new ezcQueryInsert($this->db); $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('2'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('john.doe'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(crypt('foobar', 'jo')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('John Doe'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('US')); $stmt = $query->prepare(); $stmt->execute(); $query = new ezcQueryInsert($this->db); $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('3'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('zhang.san'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(md5('asdfgh')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Zhang San'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('CN')); $stmt = $query->prepare(); $stmt->execute(); $query = new ezcQueryInsert($this->db); $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('4'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('hans.mustermann'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue('abcdef'))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Hans Mustermann'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('DE')); $stmt = $query->prepare(); $stmt->execute(); } catch (Exception $e) { $this->markTestSkipped("Cannot insert test values into table '" . self::$table . "'. " . $e->getMessage()); } }
public function testOnDatabaseWithWhere() { // fill database with some dummy data $q = new ezcQueryInsert(ezcDbInstance::get()); // insert some data we can update $company = 'eZ systems'; $section = 'Norway'; $q->insertInto('query_test')->set('id', 1)->set('company', $q->bindParam($company))->set('section', $q->bindParam($section))->set('employees', 20); $stmt = $q->prepare(); $stmt->execute(); $q->insertInto('query_test'); $q->set('id', 2); $q->set('employees', 70); $company = 'trolltech'; $section = 'Norway'; $stmt = $q->prepare(); $stmt->execute(); // delete one $this->q->deleteFrom('query_test')->where($this->q->expr->eq('id', 1)); $stmt = $this->q->prepare(); $stmt->execute(); // test that table has one row $db = ezcDbInstance::get(); $q = $db->createSelectQuery(); // get select query $q->select('*')->from('query_test'); $stmt = $q->prepare(); $stmt->execute(); $result = $stmt->fetchAll(); $this->assertEquals(1, count($result)); }
/** * Stores an association in the store linked to the OpenID provider URL. * * Returns true always. * * @param string $url The URL of the OpenID provider * @param ezcAuthenticationOpenidAssociation $association The association value to store * @return bool */ public function storeAssociation($url, $association) { $table = $this->options->tableAssociations; $data = serialize($association); $query = new ezcQueryInsert($this->instance); $query->insertInto($this->instance->quoteIdentifier($table['name']))->set($this->instance->quoteIdentifier($table['fields']['url']), $query->bindValue($url))->set($this->instance->quoteIdentifier($table['fields']['association']), $query->bindValue($data)); $stmt = $query->prepare(); $stmt->execute(); return true; }
public function testOnDatabaseWithWhere() { $q = new ezcQueryInsert(ezcDbInstance::get()); $company = 'eZ systems'; $section = 'Norway'; // insert some data we can update $q->insertInto('query_test')->set('id', 1)->set('company', $q->bindParam($company))->set('section', $q->bindParam($section))->set('employees', 20); $stmt = $q->prepare(); $stmt->execute(); $q->insertInto('query_test'); $q->set('id', 2); $q->set('employees', 70); $company = 'trolltech'; $section = 'Norway'; $stmt = $q->prepare(); $stmt->execute(); $this->q->update('query_test')->set('employees', 50)->where($this->q->expr->eq('id', 1)); $stmt = $this->q->prepare(); $stmt->execute(); // check that entry 1 was updated correctly // but not two $db = ezcDbInstance::get(); $q = $db->createSelectQuery(); // get select query $q->select('*')->from('query_test')->orderBy('company'); $stmt = $q->prepare(); $stmt->execute(); $result = $stmt->fetchAll(); $this->assertEquals(50, (int) $result[0][3]); $this->assertEquals(70, (int) $result[1][3]); }