public function testOnDuplicate() { $q = new InsertQuery(array('test'), true); $q->setValues(array('id' => '35', 'field1' => 'value1', 'field2' => 'value2')); $this->assertEquals('INSERT INTO `test` (`id`, `field1`, `field2`) VALUES (:p1, :p2, :p3) ON DUPLICATE KEY UPDATE `id` = LAST_INSERT_ID(`id`), `field1` = VALUES(`field1`), `field2` = VALUES(`field2`)', $q->sql()); $params = $q->parameters(); $this->assertEquals('35', $params[':p1']); $this->assertEquals('value1', $params[':p2']); $this->assertEquals('value2', $params[':p3']); $this->assertEquals(3, count($params)); }
/** * Add a new Id to the set. * @param object Id $id The Id to add. * @access public * @return void */ function addItem($id) { parent::addItem($id); $position = $this->getPosition($id); // Add the item to the database $query = new InsertQuery(); $query->setTable("sets"); $columns = array("id", "item_id", "item_order"); $values = array("'" . addslashes($this->_setId->getIdString()) . "'", "'" . addslashes($id->getIdString()) . "'", "'" . $position . "'"); $query->setColumns($columns); $query->setValues($values); $dbHandler = Services::getService("DatabaseManager"); $dbHandler->query($query, $this->_dbIndex); }
/** * Add this tag to an Item * * @param object TaggedItem $item * @return object The item * @access public * @since 11/6/06 */ function tagItem($item) { // Make sure the item is not already tagged if ($this->isItemTagged($item)) { return $item; } // Make sure the tag has a non-zero length if (!$this->getValue()) { return $item; } $query = new InsertQuery(); $query->setTable('tag'); $query->setColumns(array('value', 'user_id', 'fk_item')); $query->setValues(array("'" . addslashes($this->getValue()) . "'", "'" . addslashes($this->getCurrentUserIdString()) . "'", "'" . addslashes($item->getDatabaseId()) . "'")); $dbc = Services::getService("DatabaseManager"); $result = $dbc->query($query, $this->getDatabaseIndex()); return $item; }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { ArgumentValidator::validate($value, StringValidatorRule::getRule()); // Store the size in the object in case its asked for again. try { $size = ByteSize::fromString($value); } catch (InvalidArgumentException $e) { $size = ByteSize::withValue(0); } $this->_size = $size->value(); // then write it to the database. $dbHandler = Services::getService("DatabaseManager"); // Check to see if the name is in the database $query = new SelectQuery(); $query->addTable("dr_file"); $query->addColumn("COUNT(*) as count"); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file"); $query->setColumns(array("size")); $query->setValues(array("'" . addslashes($this->_size) . "'")); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file"); $query->setColumns(array("id", "size")); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($this->_size) . "'")); } $result->free(); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * A public function for getting a type id (and ensuring that it exists * in the database). One might consider implementing a Type manager for * stuff like this that has no proper home. * * @param object Type $type * * @return integer * * @access public * * @since 11/18/04 */ function getTypeId($type) { $dbc = Services::getService("DBHandler"); // Check to see if the type already exists in the DB $query = new SelectQuery(); $query->addColumn("type_id"); $query->addTable("type"); $query->addWhere("type_domain='" . addslashes($type->getDomain()) . "'"); $query->addWhere("type_authority='" . addslashes($type->getAuthority()) . "'", _AND); $query->addWhere("type_keyword='" . addslashes($type->getKeyword()) . "'", _AND); $result = $dbc->query($query, $this->_dbIndex); // If we have a type id already, use that if ($result->getNumberOfRows()) { $typeId = $result->field("type_id"); $result->free(); } else { $result->free(); $query = new InsertQuery(); $query->setTable("type"); $query->setAutoIncrementColumn("type_id", "type_type_id_seq"); $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description")); $query->setValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'")); $result = $dbc->query($query, $this->_dbIndex); $typeId = $result->getLastAutoIncrementValue(); } return $typeId; }
function save() { Assert::isFalse($this->isReadonly(), 'cannot save readonly collections'); // delete relations if (sizeof($this->getLostTracked())) { EntityQuery::create($this->mtm->getProxy())->where(Expression::in($this->mtm->getEncapsulantProxyProperty(), $this->getLostTracked()))->delete(); } // create new relations $containerSetter = $this->mtm->getContainerProxyProperty()->getSetter(); $encapsulantSetter = $this->mtm->getEncapsulantProxyProperty()->getSetter(); foreach ($this->getUntracked() as $object) { $proxy = $this->mtm->getProxy()->getLogicalSchema()->getNewEntity(); $proxy->{$containerSetter}($this->getParentObject()); $proxy->{$encapsulantSetter}($object); $insertQuery = new InsertQuery($this->mtm->getProxy()->getPhysicalSchema()->getTable()); $insertQuery->setValues($this->mtm->getProxy()->getMap()->disassemble($proxy)); try { $this->mtm->getProxy()->getDao()->executeQuery($insertQuery); } catch (UniqueViolationException $e) { } } }
/** * Answer the mime type key * * @param string $mimeType * @return integer * @access public * @since 2/13/06 */ function getMimeKey() { // If we have a key, make sure it exists. if ($this->_mimeType && $this->_mimeType != "NULL") { $dbc = Services::getService('DatabaseManager'); // Check to see if the type is in the database $query = new SelectQuery(); $query->addTable("dr_mime_type"); $query->addColumn("id"); $query->addWhere("type = '" . $this->_mimeType . "'"); $result = $dbc->query($query, $this->getDBIndex()); // If it doesn't exist, insert it. if (!$result->getNumberOfRows()) { $query = new InsertQuery(); $query->setTable("dr_mime_type"); $query->setAutoIncrementColumn("id", "dr_mime_type_id_seq"); $query->setColumns(array("type")); $query->setValues(array("'" . addslashes($this->_mimeType) . "'")); $result2 = $dbc->query($query, $this->getDBIndex()); $mimeId = "'" . $result2->getLastAutoIncrementValue() . "'"; } else { $mimeId = "'" . $result->field("id") . "'"; } $result->free(); } else { $mimeId = "NULL"; } return $mimeId; }
/** * Insert [if needed] into the item table and return the database id of this * item * * @return integer * @access public * @since 11/6/06 */ function getDatabaseId() { if (!isset($this->_dbId)) { $dbc = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addColumn('db_id'); $query->addTable('tag_item'); $query->addWhere("id='" . addslashes($this->getIdString()) . "'"); $query->addWhere("system='" . addslashes($this->getSystem()) . "'"); $result = $dbc->query($query, $this->getDatabaseIndex()); if ($result->getNumberOfRows() && $result->field('db_id')) { $this->_dbId = intval($result->field('db_id')); } else { $query = new InsertQuery(); $query->setTable('tag_item'); $query->setAutoIncrementColumn("db_id", "tag_item_db_id_seq"); $query->setColumns(array('id', 'system')); $query->setValues(array("'" . addslashes($this->getIdString()) . "'", "'" . addslashes($this->getSystem()) . "'")); $result = $dbc->query($query, $this->getDatabaseIndex()); $this->_dbId = intval($result->getLastAutoIncrementValue()); } } return $this->_dbId; }
/** * Saves the style components of a style property * * @param object StyleCollection $property * @return void * @access public * @since 4/26/06 */ function saveStyleComponentsForProperty($property) { // get the style components for the property $dbHandler = Services::getService("DatabaseManager"); $styleComponents = $property->getSCs(); foreach ($styleComponents as $styleComponent) { $id = $styleComponent->getId(); $idValue = $id->getIdString(); $query = new SelectQuery(); $query->addTable($this->_dbName . ".tm_style_component"); $query->addWhere('component_id = ' . $idValue); $query->addColumn("component_id"); $queryResult = $dbHandler->query($query, $this->_dbIndex); if ($queryResult->getNumberOfRows() > 1) { throwError(new Error("GUIManager", "component id multiplicity")); } else { if ($queryResult->getNumberOfRows() == 1) { $queryResult->free(); $query = new UpdateQuery(); $query->setWhere("component_id = {$idValue}"); } else { $queryResult->free(); $query = new InsertQuery(); } } $query->setTable($this->_dbName . ".tm_style_component"); $query->setColumns(array('component_id', 'component_class_name', 'component_value')); $query->setValues(array("'" . addslashes($idValue) . "'", "'" . addslashes(get_class($styleComponent)) . "'", "'" . addslashes($styleComponent->getValue()) . "'")); $dbHandler->query($query, $this->_dbIndex); // save the style properties for this theme } }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { $file = $this->_getFilePath(); if (!($handle = fopen($file, 'w'))) { throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be opened for writing.", "FileSystemFileDataPart", true)); } if (fwrite($handle, $value) === FALSE) { fclose($handle); throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be written to.", "FileSystemFileDataPart", true)); } fclose($handle); // Check to see if the size is in the database $dbHandler = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable("dr_file"); $query->addColumn("COUNT(*) as count"); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file"); $query->setColumns(array("size")); $query->setValues(array("'" . strlen($value) . "'")); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file"); $query->setColumns(array("id", "size")); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . strlen($value) . "'")); } $result->free(); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { if (is_array($value)) { $this->_dimensions = $value; $dbHandler = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable($this->_table); $query->addColumn("COUNT(*)", "count"); $query->addWhere($this->_idColumn . " = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable($this->_table); $query->setColumns(array($this->_widthColumn, $this->_heightColumn)); $query->setValues(array("'" . $this->_dimensions[0] . "'", "'" . $this->_dimensions[1] . "'")); $query->addWhere($this->_idColumn . " = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable($this->_table); $query->setColumns(array($this->_idColumn, $this->_widthColumn, $this->_heightColumn)); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . $this->_dimensions[0] . "'", "'" . $this->_dimensions[1] . "'")); } $result->free(); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // This gets done during thumbnail generation, so don't change our // asset's modification date. // $this->_asset->updateModificationDate(); } }
/** * Create a new Repository of the specified Type. The implementation of * this method sets the Id for the new object. * * @param string $displayName * @param string $description * @param object Type $repositoryType * * @return object Repository * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_TYPE * UNKNOWN_TYPE} * * @access public */ function createRepository($displayName, $description, Type $repositoryType, Id $id = NULL) { // Argument Validation ArgumentValidator::validate($displayName, StringValidatorRule::getRule()); ArgumentValidator::validate($description, StringValidatorRule::getRule()); ArgumentValidator::validate($repositoryType, ExtendsValidatorRule::getRule("Type")); // Create an Id for the digital Repository Node if (!is_object($id)) { $IDManager = Services::getService("Id"); $id = $IDManager->createId(); } // Store the type passed in our own table as we will be using // a special type, "repositoryKeyType", as definition of which // Nodes in the Hierarchy are Repositories. $dbc = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addColumn("type_id"); $query->addTable("dr_type"); $query->addWhere("type_domain = '" . addslashes($repositoryType->getDomain()) . "'"); $query->addWhere("type_authority = '" . addslashes($repositoryType->getAuthority()) . "'", _AND); $query->addWhere("type_keyword = '" . addslashes($repositoryType->getKeyword()) . "'", _AND); $result = $dbc->query($query, $this->_dbIndex); if ($result->getNumberOfRows()) { $typeId = $result->field("type_id"); $result->free(); } else { $result->free(); $query = new InsertQuery(); $query->setTable("dr_type"); $query->setAutoIncrementColumn("type_id", "dr_type_type_id_seq"); $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description")); $query->setValues(array("'" . addslashes($repositoryType->getDomain()) . "'", "'" . addslashes($repositoryType->getAuthority()) . "'", "'" . addslashes($repositoryType->getKeyword()) . "'", "'" . addslashes($repositoryType->getDescription()) . "'")); $result = $dbc->query($query, $this->_dbIndex); $typeId = $result->getLastAutoIncrementValue(); } $query = new InsertQuery(); $query->setTable("dr_repository_type"); $query->setColumns(array("repository_id", "fk_dr_type")); $query->setValues(array("'" . addslashes($id->getIdString()) . "'", "'" . addslashes($typeId) . "'")); $result = $dbc->query($query, $this->_dbIndex); // Add this DR's node to the hierarchy. // If we don't have a default parent specified, create // it as a root node if ($this->_defaultParentId == NULL) { $node = $this->_hierarchy->createRootNode($id, $this->repositoryKeyType, $displayName, $description); } else { $node = $this->_hierarchy->createNode($id, $this->_defaultParentId, $this->repositoryKeyType, $displayName, $description); } $this->_createdRepositories[$id->getIdString()] = new HarmoniRepository($this, $this->_hierarchy, $id, $this->_configuration); return $this->_createdRepositories[$id->getIdString()]; }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { if (!is_null($value)) { ArgumentValidator::validate($value, StringValidatorRule::getRule()); } // Store the name in the object in case its asked for again. $this->_value = $value; // then write it to the database. $dbHandler = Services::getService("DatabaseManager"); // Delete the row if we are setting the value to null if (is_null($value)) { $query = new DeleteQuery(); $query->setTable("dr_file_data"); $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); return; } // Check to see if the name is in the database // Check to see if the data is in the database $query = new SelectQuery(); $query->addTable("dr_file_url"); $query->addColumn("COUNT(*) as count"); $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file_url"); $query->setColumns(array("url")); $query->setValues(array("'" . addslashes($value) . "'")); $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file_url"); $query->setColumns(array("fk_file", "url")); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($value) . "'")); } $result->free(); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Creates a new Authorization object, caches it, and inserts it into the database. * @access public * @param ref object agentId who is authorized to perform this Function for this Qualifer and its descendants * @param ref object functionId the Id of the Function for this Authorization * @param ref object qualifierId the Id of the Qualifier for this Authorization * @param object DateAndTime effectiveDate when the Authorization becomes effective * @param object DateAndTime expirationDate when the Authorization stops being effective * @return ref object Authorization **/ function createAuthorization(Id $agentId, Id $functionId, Id $qualifierId, $effectiveDate = NULL, $expirationDate = NULL) { // ** parameter validation ArgumentValidator::validate($effectiveDate, OptionalRule::getRule(IntegerValidatorRule::getRule()), true); ArgumentValidator::validate($expirationDate, OptionalRule::getRule(IntegerValidatorRule::getRule()), true); // ** end of parameter validation // create the authorization object $idManager = Services::getService("Id"); $id = $idManager->createId(); $idValue = $id->getIdString(); // figure out whether it's dated or not $dated = isset($effectiveDate) && isset($expirationDate); if ($dated) { $authorization = new HarmoniAuthorization($idValue, $agentId, $functionId, $qualifierId, true, $this, $effectiveDate, $expirationDate); } else { $authorization = new HarmoniAuthorization($idValue, $agentId, $functionId, $qualifierId, true, $this); } $dbHandler = Services::getService("DatabaseManager"); if (isset($this->harmoni_db)) { if (!isset($this->createAZ_stmt)) { $query = $this->harmoni_db->insert(); $query->setTable("az_authorization"); $query->addRawValue("authorization_id", "?"); $query->addRawValue("fk_agent", "?"); $query->addRawValue("fk_function", "?"); $query->addRawValue("fk_qualifier", "?"); $query->addRawValue("authorization_effective_date", "?"); $query->addRawValue("authorization_expiration_date", "?"); $this->createAZ_stmt = $query->prepare(); } $this->createAZ_stmt->bindValue(1, $idValue); $this->createAZ_stmt->bindValue(2, $agentId->getIdString()); $this->createAZ_stmt->bindValue(3, $functionId->getIdString()); $this->createAZ_stmt->bindValue(4, $qualifierId->getIdString()); if (is_object($effectiveDate)) { $this->createAZ_stmt->bindValue(5, $dbHandler->toDBDate($effectiveDate, $this->_dbIndex)); } else { $this->createAZ_stmt->bindValue(5, null); } if (is_object($expirationDate)) { $this->createAZ_stmt->bindValue(6, $dbHandler->toDBDate($expirationDate, $this->_dbIndex)); } else { $this->createAZ_stmt->bindValue(6, null); } // try { $this->createAZ_stmt->execute(); // } catch (Zend_Db_Statement_Exception $e) { // throw new OperationFailedException("An Explicit Authorization already exists for '$agentId' to '$functionId' at '$qualifierId'"); // } } else { // now insert into database $dbHandler = Services::getService("DatabaseManager"); $query = new InsertQuery(); $query->setTable("az_authorization"); $columns = array(); $columns[] = "authorization_id"; $columns[] = "fk_agent"; $columns[] = "fk_function"; $columns[] = "fk_qualifier"; if ($dated) { $columns[] = "authorization_effective_date"; $columns[] = "authorization_expiration_date"; } $query->setColumns($columns); $values = array(); $values[] = "'" . addslashes($idValue) . "'"; $values[] = "'" . addslashes($agentId->getIdString()) . "'"; $values[] = "'" . addslashes($functionId->getIdString()) . "'"; $values[] = "'" . addslashes($qualifierId->getIdString()) . "'"; if ($dated) { if (is_object($effectiveDate)) { $values[] = $dbHandler->toDBDate($effectiveDate, $this->_dbIndex); } else { $values[] = "NULL"; } if (is_object($expirationDate)) { $values[] = $dbHandler->toDBDate($expirationDate, $this->_dbIndex); } else { $values[] = "NULL"; } } $query->setValues($values); try { $dbHandler->query($query, $this->_dbIndex); } catch (DuplicateKeyDatabaseException $e) { throw new OperationFailedException("An Explicit Authorization already exists for '{$agentId}' to '{$functionId}' at '{$qualifierId}'"); } } $this->_authorizations[$idValue] = $authorization; return $authorization; }
/** * Get the key of the type. * * @param object Type $type * @return integer * @access private * @since 3/9/05 */ function _getTypeKey(Type $type) { $dbc = Services::getService("DatabaseManager"); // Check if the type exists and return its key if found. $query = new SelectQuery(); $query->addTable($this->_typeTable); $query->addColumn('id'); $query->addWhere("domain='" . addslashes($type->getDomain()) . "'"); $query->addWhere("authority='" . addslashes($type->getAuthority()) . "'", _AND); $query->addWhere("keyword='" . addslashes($type->getKeyword()) . "'", _AND); $result = $dbc->query($query, $this->_dbId); if ($result->getNumberOfRows() == 1) { return $result->field('id'); } else { $result->free(); $query = new InsertQuery(); $query->setTable($this->_typeTable); $query->setAutoIncrementColumn("id", $this->_typeTable . "_id_seq"); $query->setColumns(array('domain', 'authority', 'keyword', 'description')); $query->setValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'")); $result = $dbc->query($query, $this->_dbId); return $result->getLastAutoIncrementValue(); } }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { if (!is_null($value)) { ArgumentValidator::validate($value, NonzeroLengthStringValidatorRule::getRule()); } // Store the name in the object in case its asked for again. $this->_type = $value; // then write it to the database. $dbHandler = Services::getService("DatabaseManager"); // If we have a key, make sure it exists. if ($this->_type && $this->_type != "NULL") { // Check to see if the type is in the database $query = new SelectQuery(); $query->addTable("dr_mime_type"); $query->addColumn("id"); $query->addWhere("type = '" . $this->_type . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it doesn't exist, insert it. if (!$result->getNumberOfRows()) { $query = new InsertQuery(); $query->setTable("dr_mime_type"); $query->setAutoIncrementColumn("id", "dr_mime_type_id_seq"); $query->setColumns(array("type")); $query->setValues(array("'" . addslashes($this->_type) . "'")); $result2 = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $mimeId = "'" . $result2->getLastAutoIncrementValue() . "'"; } else { $mimeId = "'" . $result->field("id") . "'"; } $result->free(); } else { $mimeId = "NULL"; } // add its id to the file. $query = new UpdateQuery(); $query->setTable("dr_file"); $query->setColumns(array("fk_mime_type")); $query->setValues(array($mimeId)); $query->addWhere("id = '" . $this->_recordId->getIdString() . "'"); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Update the value for this Part. * * @param object mixed $value (original type: java.io.Serializable) * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT} * * @access public */ function updateValue($value) { // ArgumentValidator::validate($value, StringValidatorRule::getRule()); $dbHandler = Services::getService("DatabaseManager"); // Delete the row if we are setting the value to null if (is_null($value)) { $query = new DeleteQuery(); $query->setTable("dr_file_data"); $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'"); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); return; } // Store the data in the object in case its asked for again. // $this->_data = $value; // Make sure that the dr_file row is inserted. $query = new InsertQuery(); $query->setTable("dr_file"); $query->addValue("id", $this->_recordId->getIdString()); try { $dbHandler->query($query, $this->_configuration->getProperty("database_index")); } catch (QueryDatabaseException $e) { // If an error is thrown inserting (because the file already exists) // ignore it. } $dbHandler->beginTransaction($this->_configuration->getProperty("database_index")); // Base64 encode the data to preserve it, // then write it to the database. // Check to see if the data is in the database $query = new SelectQuery(); $query->addTable("dr_file_data"); $query->addColumn("COUNT(*) as count"); $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'"); $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // If it already exists, use an update query. if ($result->field("count") > 0) { $query = new UpdateQuery(); $query->setTable("dr_file_data"); $query->setColumns(array("data")); $query->setValues(array("'" . base64_encode($value) . "'")); $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'"); } else { $query = new InsertQuery(); $query->setTable("dr_file_data"); $query->setColumns(array("fk_file", "data")); $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . base64_encode($value) . "'")); } $result->free(); // printpre($query); // printpre(MySQL_SQLGenerator::generateSQLQuery($query)); // run the query $dbHandler->query($query, $this->_configuration->getProperty("database_index")); // Update the size row. $query = new UpdateQuery(); $query->setTable("dr_file"); $query->addValue("size", strval(strlen($value))); $query->addWhereEqual("id", $this->_recordId->getIdString()); $dbHandler->query($query, $this->_configuration->getProperty("database_index")); $dbHandler->commitTransaction($this->_configuration->getProperty("database_index")); $this->_asset->updateModificationDate(); }
/** * Creates a new Authorization object, caches it, and inserts it into the database. * @access public * @param ref object agentId who is authorized to perform this Function for this Qualifer and its descendants * @param ref object functionId the Id of the Function for this Authorization * @param ref object qualifierId the Id of the Qualifier for this Authorization * @param object DateAndTime effectiveDate when the Authorization becomes effective * @param object DateAndTime expirationDate when the Authorization stops being effective * @return ref object Authorization **/ function createAuthorization(Id $agentId, Id $functionId, Id $qualifierId, $effectiveDate = NULL, $expirationDate = NULL) { // ** parameter validation ArgumentValidator::validate($effectiveDate, OptionalRule::getRule(IntegerValidatorRule::getRule()), true); ArgumentValidator::validate($expirationDate, OptionalRule::getRule(IntegerValidatorRule::getRule()), true); // ** end of parameter validation // create the authorization object $idManager = Services::getService("Id"); $id = $idManager->createId(); $idValue = $id->getIdString(); // figure out whether it's dated or not $dated = isset($effectiveDate) && isset($expirationDate); if ($dated) { $authorization = new AuthZ2_Authorization($idValue, $agentId, $functionId, $qualifierId, true, $this, $effectiveDate, $expirationDate); } else { $authorization = new AuthZ2_Authorization($idValue, $agentId, $functionId, $qualifierId, true, $this); } $dbHandler = Services::getService("DatabaseManager"); if (isset($this->harmoni_db)) { if (!isset($this->createAZ_stmt)) { $query = $this->harmoni_db->insert(); $query->setTable("az2_explicit_az"); $query->addRawValue("id", "?"); $query->addRawValue("fk_agent", "?"); $query->addRawValue("fk_function", "?"); $query->addRawValue("fk_qualifier", "?"); $query->addRawValue("effective_date", "?"); $query->addRawValue("expiration_date", "?"); $this->createAZ_stmt = $query->prepare(); } $this->createAZ_stmt->bindValue(1, $idValue); $this->createAZ_stmt->bindValue(2, $agentId->getIdString()); $this->createAZ_stmt->bindValue(3, $functionId->getIdString()); $this->createAZ_stmt->bindValue(4, $qualifierId->getIdString()); if (is_object($effectiveDate)) { $this->createAZ_stmt->bindValue(5, $dbHandler->toDBDate($effectiveDate, $this->_dbIndex)); } else { $this->createAZ_stmt->bindValue(5, null); } if (is_object($expirationDate)) { $this->createAZ_stmt->bindValue(6, $dbHandler->toDBDate($expirationDate, $this->_dbIndex)); } else { $this->createAZ_stmt->bindValue(6, null); } $this->createAZ_stmt->execute(); } else { // now insert into database $dbHandler = Services::getService("DatabaseManager"); $query = new InsertQuery(); $query->setTable("az2_explicit_az"); $columns = array(); $columns[] = "id"; $columns[] = "fk_agent"; $columns[] = "fk_function"; $columns[] = "fk_qualifier"; if ($dated) { $columns[] = "effective_date"; $columns[] = "expiration_date"; } $query->setColumns($columns); $values = array(); $values[] = "'" . addslashes($idValue) . "'"; $values[] = "'" . addslashes($agentId->getIdString()) . "'"; $values[] = "'" . addslashes($functionId->getIdString()) . "'"; $values[] = "'" . addslashes($qualifierId->getIdString()) . "'"; if ($dated) { if (is_object($effectiveDate)) { $values[] = $dbHandler->toDBDate($effectiveDate, $this->_dbIndex); } else { $values[] = "NULL"; } if (is_object($expirationDate)) { $values[] = $dbHandler->toDBDate($expirationDate, $this->_dbIndex); } else { $values[] = "NULL"; } } $query->setValues($values); $dbHandler->query($query, $this->_dbIndex); } $this->_authorizations[$idValue] = $authorization; $this->createImplicitAZsForAZ($authorization); return $authorization; }