/**
  * Delete the log with the specified name.
  * 
  * @param string $logName
  * 
  * @throws object LoggingException An exception with one of the
  *		   following messages defined in org.osid.logging.LoggingException
  *		   may be thrown:  {@link
  *		   org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  *		   {@link org.osid.logging.LoggingException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.logging.LoggingException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.logging.LoggingException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.logging.LoggingException#UNKNOWN_NAME UNKNOWN_NAME}
  * 
  * @access public
  */
 function deleteLog($logName)
 {
     $log = $this->getLogForWriting($logName);
     $log = null;
     $dbc = Services::getService("DatabaseManager");
     // get the entry Ids
     $query = new SelectQuery();
     $query->addColumn("id");
     $query->addTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $result = $dbc->query($query, $this->_dbIndex);
     $entryIds = array();
     while ($result->hasMoreRows()) {
         $entryIds[] = "'" . addslashes($result->field("id")) . "'";
         $result->advanceRow();
     }
     $result->free();
     // delete the agent keys
     $query = new DeleteQuery();
     $query->setTable("log_agent");
     $query->addWhere("fk_entry IN (" . implode(", ", $entryIds) . ")");
     $dbc->query($query, $this->_dbIndex);
     // delete the node keys
     $query->setTable("log_node");
     $dbc->query($query, $this->_dbIndex);
     // delete the entries
     $query = new DeleteQuery();
     $query->setTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $dbc->query($query, $this->_dbIndex);
 }
 /**
  * Remove a student from the roster.
  * 
  * @param object Id $agentId
  * 
  * @throws object CourseManagementException An exception
  *		   with one of the following messages defined in
  *		   org.osid.coursemanagement.CourseManagementException may be
  *		   thrown:	{@link
  *		   org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  *		   UNKNOWN_ID}
  * 
  * @access public
  */
 function removeStudent(Id $agentId)
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('cm_enroll');
     $query->addWhere("fk_cm_section='" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("fk_student_id='" . addslashes($agentId->getIdString()) . "'");
     $dbManager->query($query);
 }
 /**
  * Delete the specified CourseGradeRecord by Id. courseGradeRecordId
  *
  * @param object Id $courseGradeRecordId
  *
  * @throws object CourseManagementException An exception
  *		   with one of the following messages defined in
  *		   org.osid.coursemanagement.CourseManagementException may be
  *		   thrown:	{@link
  *		   org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  *		   UNKNOWN_ID}
  *
  * @access public
  */
 function deleteCourseGradeRecord(Id $courseGradeRecordId)
 {
     ArgumentValidator::validate($courseGradeRecordId, ExtendsValidatorRule::getRule("Id"), true);
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('cm_grade_rec');
     $query->addWhere("id=" . addslashes($courseGradeRecordId->getIdString()));
     $dbManager->query($query);
 }
 /**
  * Remove the mapping between AuthNTokens and an Agent
  * 
  * @param object AgentTokenMapping $mapping
  * @return void
  * @access public
  * @since 3/9/05
  */
 function deleteMapping(AgentTokenMapping $mapping)
 {
     $this->_checkConfig();
     $dbc = Services::getService("DatabaseManager");
     $dbc->beginTransaction($this->_dbId);
     $agentId = $mapping->getAgentId();
     $authNTokens = $mapping->getTokens();
     $typeKey = $this->_getTypeKey($mapping->getAuthenticationType());
     // Delete the mapping.
     $query = new DeleteQuery();
     $query->setTable($this->_mappingTable);
     $query->addWhere("agent_id='" . addslashes($agentId->getIdString()) . "'");
     $query->addWhere("token_identifier='" . addslashes($authNTokens->getIdentifier()) . "'", _AND);
     $query->addWhere("fk_type='" . addslashes($typeKey) . "'", _AND);
     $result = $dbc->query($query, $this->_dbId);
     // Delete the type if nothing is referencing it.
     $query = new SelectQuery();
     $query->addTable($this->_mappingTable);
     $query->addColumn("COUNT(*)", "count");
     $query->addWhere("fk_type='" . addslashes($typeKey) . "'");
     $result = $dbc->query($query, $this->_dbId);
     if ($result->getNumberOfRows() == 0) {
         $query = new DeleteQuery();
         $query->addTable($this->_typeTable);
         $query->addWhere("id='" . addslashes($typeKey) . "'");
         $result = $dbc->query($query, $this->_dbId);
     }
     $result->free();
     $dbc->commitTransaction($this->_dbId);
 }
 /**
  * Remove a Topic for this CanonicalCourse.
  * 
  * @param string $topic
  * 
  * @throws object CourseManagementException An exception
  *		   with one of the following messages defined in
  *		   org.osid.coursemanagement.CourseManagementException may be
  *		   thrown:	{@link
  *		   org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}
  * 
  * @access public
  */
 function removeTopic($topic)
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('cm_topics');
     $query->addWhere("fk_cm_can='" . $this->_id->getIdString() . "'");
     $query->addWhere("topic='" . addslashes($topic) . "'");
     $dbManager->query($query);
 }
 /**
  * Delete a Record.  If the specified Record has content that is inherited
  * by other Records, those other Records will not be deleted, but they
  * will no longer have a source from which to inherit value changes.
  * 
  * @param object Id $recordId
  * 
  * @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_ID UNKNOWN_ID}
  * 
  * @access public
  */
 function deleteRecord(Id $recordId)
 {
     $record = $this->getRecord($recordId);
     $structure = $record->getRecordStructure();
     $structureId = $structure->getId();
     // If this is a schema that is hard coded into our implementation, create
     // a record for that schema.
     if (in_array($structureId->getIdString(), array_keys($this->_repository->_builtInTypes))) {
         // Delete all of the Parts for the record
         $parts = $record->getParts();
         while ($parts->hasNext()) {
             $part = $parts->next();
             $record->deletePart($part->getId());
         }
         // Delete the relation for the record.
         $dbHandler = Services::getService("DatabaseManager");
         $query = new DeleteQuery();
         $query->setTable("dr_asset_record");
         $myId = $this->getId();
         $query->addWhere("fk_asset = '" . $myId->getIdString() . "'");
         $query->addWhere("fk_record = '" . $recordId->getIdString() . "'");
         $result = $dbHandler->query($query, $this->_dbIndex);
     } else {
         $recordMgr = Services::getService("RecordManager");
         $record = $recordMgr->fetchRecord($recordId->getIdString(), RECORD_FULL);
         // Check if the record is part of other record sets (assets via inheretance)
         $myId = $this->getId();
         $setsContaining = $recordMgr->getRecordSetIDsContaining($record);
         $myRecordSet = $recordMgr->fetchRecordSet($myId->getIdString());
         // If this is the last asset referencing this record, delete it.
         $idManager = Services::getService('Id');
         if (count($setsContaining) == 1 && $myId->isEqual($idManager->getId($setsContaining[0]))) {
             $myRecordSet->removeRecord($record);
             $myRecordSet->commit(TRUE);
             $record->delete();
             $record->commit(TRUE);
         } else {
             $myRecordSet = $recordMgr->fetchRecordSet($myId->getIdString());
             $myRecordSet->removeRecord($record);
             $myRecordSet->commit(TRUE);
         }
     }
     $this->updateModificationDate();
 }
 /**
  * Delete the DMRecord Set and any records that are referenced only by this record
  * set and not shared with other record sets.
  * 
  * @param int $id The Id of the set to delete.
  * @param optional boolean $prune If TRUE will make sure that the Records are removed
  * from the database.
  * @return void
  * @access public
  * @since 10/6/04
  */
 function deleteRecordSet($id, $prune = false)
 {
     ArgumentValidator::validate($id, StringValidatorRule::getRule());
     $recordSet = $this->fetchRecordSet($id);
     $recordSet->loadRecords($prune ? RECORD_FULL : RECORD_NODATA);
     // Delete the records in the set.
     $records = $recordSet->getRecords();
     foreach (array_keys($records) as $key) {
         $record = $records[$key];
         // Only delete records if they are not shared with other sets.
         $setsContaining = $this->getRecordSetIDsContaining($record);
         if (count($setsContaining) == 1 && $setsContaing[0] == $id) {
             $this->deleteRecord($record->getID(), $prune);
         }
     }
     // Delete the set from the database
     $query = new DeleteQuery();
     $query->setTable("dm_record_set");
     $query->addWhere("id = '" . addslashes($id) . "'");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, DATAMANAGER_DBID);
     $this->_recordSetCache[$id] = NULL;
     unset($this->_recordSetCache[$id]);
 }
 /**
  * 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();
 }
 /**
  * 
  * Remove a previously added Agent commitment for this ScheduleItem.
  *
  * WARNING: NOT IN OSID -- Will likely be added in v3
  * 
  * @param object Id $agentId
  * 
  * @throws object SchedulingException An exception with one of
  *         the following messages defined in
  *         org.osid.scheduling.SchedulingException may be thrown:   {@link
  *         org.osid.scheduling.SchedulingException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.scheduling.SchedulingException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.scheduling.SchedulingException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.scheduling.SchedulingException#UNIMPLEMENTED
  *         UNIMPLEMENTED}, {@link
  *         org.osid.scheduling.SchedulingException#UNKNOWN_ID UNKNOWN_ID},
  *         {@link org.osid.scheduling.SchedulingException#UNKNOWN_TYPE
  *         UNKNOWN_TYPE}
  * 
  * @access public
  */
 function removeAgentCommitment(Id $agentId)
 {
     $dbHandler = Services::getService("DBHandler");
     $query = new DeleteQuery();
     $query->setTable('sc_commit');
     $query->addWhere("fk_sc_item='" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("fk_agent_id='" . addslashes($agentId->getIdString()) . "'");
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         print "<b>Warning!</b> Agent with Id [" . $agentId->getIdString() . "] is not added to ScheduleItem " . $this->getdisplayName() . " [" . $this->_id->getIdString() . "] yet.  Do not delete agents that are not added.";
     }
 }
 /**
  * Delete a ScheduleItem by unique Id.
  *
  * @param object Id $scheduleItemId
  *
  * @throws object SchedulingException An exception with one of
  *         the following messages defined in
  *         org.osid.scheduling.SchedulingException may be thrown:   {@link
  *         org.osid.scheduling.SchedulingException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.scheduling.SchedulingException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.scheduling.SchedulingException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.scheduling.SchedulingException#UNIMPLEMENTED
  *         UNIMPLEMENTED}, {@link
  *         org.osid.scheduling.SchedulingException#NULL_ARGUMENT
  *         NULL_ARGUMENT}, {@link
  *         org.osid.scheduling.SchedulingException#UNKNOWN_ID UNKNOWN_ID}
  *
  * @access public
  */
 function deleteScheduleItem(Id $scheduleItemId)
 {
     $dbHandler = Services::getService("DBHandler");
     $query = new DeleteQuery();
     $query->setTable('sc_item');
     $query->addWhere("id=" . addslashes($scheduleItemId->getIdString()));
     $dbHandler->query($query);
     $query2 = new DeleteQuery();
     $query2->setTable('sc_commit');
     $query2->addWhere("fk_sc_item=" . addslashes($scheduleItemId->getIdString()));
     $dbHandler->query($query);
 }
 /**
  * Add a PartStructureId for which Tags should be auto-generated, in the
  * given repository
  * 
  * @param object Id $repositoryId
  * @return void
  * @access public
  * @since 11/21/06
  */
 function removePartStructureIdForTagGeneration($repositoryId, $partStructureId)
 {
     // Delete it into the database
     $query = new DeleteQuery();
     $query->setTable('tag_part_map');
     $query->addWhere("fk_repository='" . addslashes($repositoryId->getIdString()) . "'");
     $query->addWhere("fk_partstruct='" . addslashes($partStructureId->getIdString()) . "'");
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     // Remove it from the cache
     if (isset($this->_cache) && isset($this->_cache[$repositoryId->getIdString()])) {
         for ($i = 0; $i < count($this->_cache[$repositoryId->getIdString()]); $i++) {
             if ($partStructureId->isEqual($this->_cache[$repositoryId->getIdString()][$i])) {
                 unset($this->_cache[$repositoryId->getIdString()][$i]);
             }
         }
     }
 }
 /**
  * Remove an authoritative value.
  *
  * WARNING: NOT in OSID
  * 
  * @param object $value
  * @return void
  * @access public
  * @since 4/25/06
  */
 function removeAuthoritativeValue($value)
 {
     if ($this->isAuthoritativeValue($value)) {
         // remove the object from our objects array
         if (isset($this->_authoritativeValueObjects[$value->asString()])) {
             unset($this->_authoritativeValueObjects[$value->asString()]);
         }
         // Remove the string from our strings array
         unset($this->_authoritativeValueStrings[array_search($value->asString(), $this->_authoritativeValueStrings)]);
         // Remove the value from our database
         $query = new DeleteQuery();
         $query->setTable('dr_authoritative_values');
         $id = $this->getId();
         $query->addWhere("fk_partstructure = '" . addslashes($id->getIdString()) . "'");
         $query->addWhere("fk_repository = '" . addslashes($this->_repositoryId->getIdString()) . "'");
         $query->addWhere("value = '" . addslashes($value->asString()) . "'");
         $dbc = Services::getService("DBHandler");
         $configuration = $this->manager->_configuration;
         $dbc->query($query, $configuration->getProperty('database_index'));
     }
 }
 /**
  * Remove an Asset for this CourseOffering.
  *
  * @param object Id $assetId
  *
  * @throws object CourseManagementException An exception
  *		   with one of the following messages defined in
  *		   org.osid.coursemanagement.CourseManagementException may be
  *		   thrown:	{@link
  *		   org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNKNOWN_ID
  *		   UNKNOWN_ID}
  *
  * @access public
  */
 function removeAsset(Id $assetId)
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('cm_assets');
     $query->addWhere("fk_course_id='" . $this->_id->getIdString() . "'");
     $query->addWhere("fk_asset_id='" . addslashes($assetId->getIdString()) . "'");
     $dbManager->query($query);
 }
 /**
  * Remove all Items from the set.
  * @access public
  * @return void
  */
 function removeAllItems()
 {
     parent::removeAllItems();
     // Remove the item from the database
     $query = new DeleteQuery();
     $query->setTable("sets");
     $query->addWhere("id='" . addslashes($this->_setId->getIdString()) . "'");
     $dbHandler = Services::getService("DatabaseManager");
     $dbHandler->query($query, $this->_dbIndex);
 }
 /**
  * Delete all properties associated with an object
  * This is here partially to preserve the option of using non-editable agents
  * If that ceases to be an issue, this more properly belongs in
  * HarmoniEditableAgent.class
  *
  * @param string $object_id_string
  * @return boolean
  * @access public
  */
 function deleteAllProperties($object_id_string)
 {
     $dbHandler = Services::getService("DBHandler");
     //create a query to remove all properties associated with $object_id_string
     $query = new DeleteQuery();
     $query->setTable("agent_properties");
     $query->addWhere("fk_object_id='{$object_id_string}'");
     $result = $dbHandler->query($query, $this->_dbIndex);
     return $result ? true : false;
 }
Beispiel #16
0
 /**
  * Deletes the components for the property from the db
  *
  * @param object StyleProperty $sp
  * @return void
  * @access public
  * @since 4/26/06
  */
 function deleteComponentsForProperty($sp)
 {
     $dbHandler = Services::getService("DatabaseManager");
     $id = $sp->getId();
     $idValue = $id->getIdString();
     $query = new DeleteQuery();
     $query->setTable($this->_dbName . ".tm_style_component");
     $query->addWhere("fk_property_id = {$idValue}");
     $result = $dbHandler->query($query, $this->_dbIndex);
 }
 /**
  * Tests the generateSQLQuery() without WHERE clause.
  */
 function test()
 {
     // insert one row
     $query = new InsertQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->addRowOfValues(array("'Spaceboy'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     $lastId = $result->getLastAutoIncrementValue();
     // insert it again, the id must have increased by one
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 1);
     // add several rows at the same time
     $query->addRowOfValues(array("'Astrogirl'"));
     $result = $this->db->query($query);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 3);
     // now insert in the other test table
     $query = new InsertQuery();
     $query->setTable("test");
     $query->setColumns(array("FK", "value"));
     $query->addRowOfValues(array($lastId, "'Ziggy'"));
     $query->addRowOfValues(array($lastId + 1, "'Lost in the Stars'"));
     $query->addRowOfValues(array($lastId + 2, "'Headstar'"));
     $query->addRowOfValues(array($lastId + 3, "'Stardust'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     // join the inserted rows
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addTable("test", INNER_JOIN, "test.FK = test1.id");
     $query->addColumn("id", "dm86_id", "test");
     $query->addColumn("FK", "dm86_fk", "test");
     $query->addColumn("value", "dm86_value", "test");
     $query->addColumn("id", "dm98_id", "test1");
     $query->addColumn("value", "dm98_value", "test1");
     $query->addWhere("test1.id >= " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 4);
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId);
     $this->assertIdentical($result->field("dm86_value"), "Ziggy");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 1);
     $this->assertIdentical($result->field("dm86_value"), "Lost in the Stars");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 1);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 2);
     $this->assertIdentical($result->field("dm86_value"), "Headstar");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 2);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 3);
     $this->assertIdentical($result->field("dm86_value"), "Stardust");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 3);
     $this->assertIdentical($result->field("dm98_value"), "Astrogirl");
     $result->free();
     $query = new UpdateQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->setValues(array("'I changed you MF!'"));
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->field("value"), "I changed you MF!");
     $result->free();
     $query = new DeleteQuery();
     $query->setTable("test1");
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 0);
     $result->free();
 }
Beispiel #18
0
 /**
  * removes the style collection from the theme, and the DB is called for
  * 
  * @param boolean $removeFromDatabase whether to remove the data from the database
  * @param ref object StyleCollection $style the style
  * @return void
  * @access public
  * @since 5/16/06
  */
 function removeStyleCollection($style, $removeFromDatabase = false)
 {
     $guiManager = Services::getService("GUI");
     $dbHandler = Services::getService('DBHandler');
     $guiManager->deletePropertiesForCollection($style);
     if (is_object($style->_id)) {
         $id = $style->getId();
         $idValue = $id->getIdString();
         $query = new DeleteQuery();
         $query->setTable($guiManager->_dbName . ".tm_style_collection");
         $query->addWhere("fk_theme_id = {$idValue}");
         $result = $dbHandler->query($query, $guiManager->_dbIndex);
     }
     unset($this->_styles[$style->getSelector()]);
 }
Beispiel #19
0
 /**
  * Remove the tag everywhere where the current user has added it.
  * 
  * @return void
  * @access public
  * @since 11/2/06
  */
 function removeAllMine()
 {
     $query = new DeleteQuery();
     $query->setTable('tag');
     $query->addWhere("tag.value='" . addslashes($this->getValue()) . "'");
     $query->addWhere("tag.user_id='" . addslashes($this->getCurrentUserIdString()) . "'");
     $dbc = Services::getService("DatabaseManager");
     $dbc->query($query, $this->getDatabaseIndex());
 }
 /**
  * Delete a GradeRecord.  The first two parameters are required, but the
  * third may be left null to dignify any Type
  * 
  * @param object Id $gradableObjectId
  * @param object Id $agentId
  * @param object Type $GradeRecordType
  * 
  * @throws object GradingException An exception with one of the
  *         following messages defined in org.osid.grading.GradingException
  *         may be thrown:  {@link
  *         org.osid.grading.GradingException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.grading.GradingException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.grading.GradingException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  *         {@link org.osid.grading.GradingException#NULL_ARGUMENT
  *         NULL_ARGUMENT}, {@link
  *         org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID}
  * 
  * @access public
  */
 function deleteGradeRecord(Id $gradableObjectId, Id $agentId, Type $GradeRecordType)
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('gr_record');
     $query->addWhere("fk_gr_gradable='" . addslashes($gradableObjectId->getIdString()) . "'");
     $query->addWhere("fk_agent_id='" . addslashes($agentId->getIdString()) . "'");
     if (!is_null($GradeRecordType)) {
         $query->addWhere("fk_gr_record_type='" . addslashes($this->_typeToIndex('record', $GradeRecordType)) . "'");
     }
     $dbManager->query($query);
 }
Beispiel #21
0
 /**
  * Delete the item and all tags for it. This should be done when deleting
  * the thing the item represents
  * 
  * @param mixed $items This can be a single Item object, an TaggedItemIterator, 
  * 		or an array of Item objects.
  * @return void
  * @access public
  * @since 11/2/06
  */
 function deleteItems($items)
 {
     $itemDbIds = array();
     // array
     if (is_array($items)) {
         foreach (array_keys($items) as $key) {
             $itemDbIds[] = "'" . addslashes($items[$key]->getDatabaseId()) . "'";
         }
     } else {
         if (method_exists($items, 'next')) {
             while ($items->hasNext()) {
                 $item = $items->next();
                 $itemDbIds[] = "'" . addslashes($item->getDatabaseId()) . "'";
             }
         } else {
             if (method_exists($items, 'getDatabaseId')) {
                 $itemDbIds[] = "'" . addslashes($items->getDatabaseId()) . "'";
             } else {
                 throwError(new Error("Invalid parameter, {$items}, for \$items", "Tagging"));
             }
         }
     }
     if (!count($itemDbIds)) {
         return;
     }
     $dbc = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('tag');
     $query->addWhere("tag.fk_item IN (" . implode(", ", $itemDbIds) . ")");
     $dbc->query($query, $this->getDatabaseIndex());
     $query = new DeleteQuery();
     $query->setTable('tag_item');
     $query->addWhere("id IN (" . implode(", ", $itemDbIds) . ")");
     $dbc->query($query, $this->getDatabaseIndex());
 }
Beispiel #22
0
 /**
  * Write the cache
  * 
  * @return void
  * @access public
  * @since 2/13/06
  */
 function writeCache()
 {
     $dbc = Services::getService('DatabaseManager');
     $query = new DeleteQuery();
     $query->setTable('dr_resized_cache');
     $query->addWhere("dr_resized_cache.fk_file = '" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("dr_resized_cache.size = '" . addslashes($this->_size) . "'");
     $query->addWhere("dr_resized_cache.websafe = " . ($this->_websafe ? '1' : '0'));
     $dbc->query($query, $this->getDBIndex());
     $query = new InsertQuery();
     $query->setTable('dr_resized_cache');
     $query->setColumns(array('fk_file', 'size', 'websafe', 'cache_time', 'fk_mime_type', 'data'));
     $values = array();
     $values[] = "'" . addslashes($this->_id->getIdString()) . "'";
     $values[] = "'" . addslashes($this->_size) . "'";
     $values[] = $this->_websafe ? '1' : '0';
     $values[] = "NOW()";
     $imgProcessor = Services::getService("ImageProcessor");
     if ($this->_websafe) {
         $this->_mimeType = $imgProcessor->getWebsafeFormat($this->_parts['MIME_TYPE']->getValue());
         $values[] = $this->getMimeKey();
         $values[] = "'" . addslashes($imgProcessor->getWebsafeData($this->_parts['MIME_TYPE']->getValue(), $this->_size, $this->_parts['FILE_DATA']->getValue())) . "'";
     } else {
         $this->_mimeType = $imgProcessor->getResizedFormat($this->_parts['MIME_TYPE']->getValue());
         $values[] = $this->getMimeKey();
         $values[] = "'" . addslashes($imgProcessor->getResizedData($this->_parts['MIME_TYPE']->getValue(), $this->_size, $this->_parts['FILE_DATA']->getValue())) . "'";
     }
     $query->addRowOfValues($values);
     $dbc->query($query, $this->getDBIndex());
 }
 /**
  * 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();
 }
 /**
  * Add tokens and associated Properties to the system.
  * 
  * @param object AuthNTokens $authNTokens
  * @return void
  * @access public
  * @since 3/1/05
  */
 function deleteTokens($authNTokens)
 {
     ArgumentValidator::validate($authNTokens, ExtendsValidatorRule::getRule("AuthNTokens"));
     if (!$this->tokensExist($authNTokens)) {
         throwError(new Error("Token Deletion Error: " . "'" . $authNTokens->getUsername() . "' does not exist.", "SQLDatabaseAuthNMethod", true));
     } else {
         $dbc = Services::getService("DatabaseManager");
         $dbId = $this->_configuration->getProperty('database_id');
         $authenticationTable = $this->_configuration->getProperty('authentication_table');
         $usernameField = $this->_configuration->getProperty('username_field');
         $passwordField = $this->_configuration->getProperty('password_field');
         $query = new DeleteQuery();
         $query->setTable($authenticationTable);
         $query->addWhere($usernameField . "='" . addslashes($authNTokens->getUsername()) . "'");
         $result = $dbc->query($query, $dbId);
     }
 }