Ejemplo n.º 1
0
 /**
  * Sets the correct id on the insert query.
  *
  * @param ezcPersistentObjectDefinition $def
  * @param ezcDbHandler $db
  * @param ezcQueryInsert $q
  * @return void
  */
 public function preSave(ezcPersistentObjectDefinition $def, ezcDbHandler $db, ezcQueryInsert $q)
 {
     // Sanity check.
     // ID must have been stored during the persistence check before inserting the object.
     if ($this->id === null) {
         throw new ezcPersistentIdentifierGenerationException($def->class, 'ezcPersistentManualGenerator expects the ID to be present before saving.');
     }
     $q->set($db->quoteIdentifier($def->idProperty->columnName), $q->bindValue($this->id, null, $def->idProperty->databaseType));
 }
Ejemplo n.º 2
0
 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());
     }
 }
Ejemplo n.º 3
0
 /**
  * Bind all non-id properties to the given query $q.
  *
  * Binds all property values contained in $state to the given query $q, as
  * defined by $def.
  * 
  * @param ezcQueryUpdate|ezcQueryInsert $q
  * @param ezcPersistentObjectDefinition $def
  * @param array $state
  * @return ezcQueryUpdate|ezcQueryInsert
  */
 private function bindNonIdPropertyValuesToQuery($q, ezcPersistentObjectDefinition $def, array $state)
 {
     foreach ($state as $name => $value) {
         if ($name !== $def->idProperty->propertyName) {
             // Set each of the properties.
             $q->set($this->database->quoteIdentifier($def->properties[$name]->columnName), $q->bindValue($value, null, $def->properties[$name]->databaseType));
         }
     }
 }
Ejemplo n.º 4
0
 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));
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
0
 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]);
 }
Ejemplo n.º 7
0
 /**
  * Inserts $field with $newFieldId or not
  *
  * @param Content $content
  * @param Field $field
  * @param StorageFieldValue $value
  * @param mixed $newFieldId
  *
  * @return int|null Maybe a new field ID
  */
 protected function setInsertFieldValues(\ezcQueryInsert $q, Content $content, Field $field, StorageFieldValue $value)
 {
     $q->insertInto($this->dbHandler->quoteTable('ezcontentobject_attribute'))->set($this->dbHandler->quoteColumn('contentobject_id'), $q->bindValue($content->versionInfo->contentInfo->id, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('contentclassattribute_id'), $q->bindValue($field->fieldDefinitionId, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('data_type_string'), $q->bindValue($field->type))->set($this->dbHandler->quoteColumn('language_code'), $q->bindValue($field->languageCode))->set($this->dbHandler->quoteColumn('version'), $q->bindValue($field->versionNo, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('data_float'), $q->bindValue($value->dataFloat))->set($this->dbHandler->quoteColumn('data_int'), $q->bindValue($value->dataInt, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('data_text'), $q->bindValue($value->dataText))->set($this->dbHandler->quoteColumn('sort_key_int'), $q->bindValue($value->sortKeyInt, null, \PDO::PARAM_INT))->set($this->dbHandler->quoteColumn('sort_key_string'), $q->bindValue($value->sortKeyString))->set($this->dbHandler->quoteColumn('language_id'), $q->bindValue($this->languageMaskGenerator->generateLanguageIndicator($field->languageCode, $content->versionInfo->contentInfo->alwaysAvailable), null, \PDO::PARAM_INT));
 }