当前位置: 首页>>代码示例>>PHP>>正文


PHP SQLQuery::setDelete方法代码示例

本文整理汇总了PHP中SQLQuery::setDelete方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLQuery::setDelete方法的具体用法?PHP SQLQuery::setDelete怎么用?PHP SQLQuery::setDelete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLQuery的用法示例。


在下文中一共展示了SQLQuery::setDelete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run($request)
 {
     $confirm = $request->getVar('run') ? true : false;
     $force = $request->getVar('force') ? true : false;
     $since = $request->getVar('older');
     if (!$since) {
         echo "Please specify an 'older' param with a date older than which to prune (in strtotime friendly format)<br/>\n";
         return;
     }
     $since = strtotime($since);
     if (!$since) {
         echo "Please specify an 'older' param with a date older than which to prune (in strtotime friendly format)<br/>\n";
         return;
     }
     if ($since > strtotime('-3 months') && !$force) {
         echo "To cleanup data more recent than 3 months, please supply the 'force' parameter as well as the run parameter, swapping to dry run <br/>\n";
         $confirm = false;
     }
     $since = date('Y-m-d H:i:s', $since);
     $items = DataChangeRecord::get()->filter('Created:LessThan', $since);
     $max = $items->max('ID');
     echo "Pruning records older than {$since} (ID {$max})<br/>\n";
     if ($confirm && $max) {
         $query = new SQLQuery('*', 'DataChangeRecord', '"ID" < \'' . $max . '\'');
         $query->setDelete(true);
         $query->execute();
     } else {
         echo "Dry run performed, please supply the run=1 parameter to actually execute the deletion!<br/>\n";
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-datachange-tracker,代码行数:30,代码来源:CleanupDataChangeHistoryTask.php

示例2: checkBlogEntryPermissions

 private function checkBlogEntryPermissions()
 {
     $authorsId = array();
     $sqlQuery = new SQLQuery();
     $sqlQuery->setFrom('SiteTree_versions');
     $sqlQuery->selectField('AuthorID');
     $sqlQuery->addWhere('RecordID = ' . $this->ID);
     $sqlQuery->setOrderBy('ID DESC');
     $rawSQL = $sqlQuery->sql();
     $result = $sqlQuery->execute();
     foreach ($result as $row) {
         $authorsId[] = $row['AuthorID'];
     }
     $sqlQuery->setDelete(true);
     if (in_array(Member::currentUser()->ID, $authorsId) || $this->parent->OwnerID == Member::currentUser()->ID || Permission::check('ADMIN')) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:helpfulrobot,项目名称:zirak-blog-users-permissions,代码行数:20,代码来源:UserRestrictedBlogEntry.php

示例3: delete

 /**
  * Delete this data object.
  * $this->onBeforeDelete() gets called.
  * Note that in Versioned objects, both Stage and Live will be deleted.
  *  @uses DataExtension->augmentSQL()
  */
 public function delete()
 {
     $this->brokenOnDelete = true;
     $this->onBeforeDelete();
     if ($this->brokenOnDelete) {
         user_error("{$this->class} has a broken onBeforeDelete() function.  Make sure that you call parent::onBeforeDelete().", E_USER_ERROR);
     }
     // Deleting a record without an ID shouldn't do anything
     if (!$this->ID) {
         throw new Exception("DataObject::delete() called on a DataObject without an ID");
     }
     // TODO: This is quite ugly.  To improve:
     //  - move the details of the delete code in the DataQuery system
     //  - update the code to just delete the base table, and rely on cascading deletes in the DB to do the rest
     //    obviously, that means getting requireTable() to configure cascading deletes ;-)
     $srcQuery = DataList::create($this->class, $this->model)->where("ID = {$this->ID}")->dataQuery()->query();
     foreach ($srcQuery->queriedTables() as $table) {
         $query = new SQLQuery("*", array('"' . $table . '"'));
         $query->setWhere("\"ID\" = {$this->ID}");
         $query->setDelete(true);
         $query->execute();
     }
     // Remove this item out of any caches
     $this->flushCache();
     $this->onAfterDelete();
     $this->OldID = $this->ID;
     $this->ID = 0;
 }
开发者ID:nomidi,项目名称:sapphire,代码行数:34,代码来源:DataObject.php

示例4: setupStructure

 /**
  *	Create a database table to replay the site tree creation, based on the chronological order of the site tree version table.
  */
 protected function setupStructure()
 {
     if (!DB::getConn() instanceof MySQLDatabase) {
         exit('This task currently only supports <strong>MySQL</strong>...');
     }
     $replaceArray = self::$db_columns;
     unset($replaceArray['FullURL']);
     $this->replaceColumnString = implode(',', array_keys($replaceArray));
     $tableList = DB::tableList();
     if (self::$use_temporary_table || !in_array(self::$default_table, $tableList)) {
         $options = self::$use_temporary_table ? array('temporary' => true) : null;
         $this->replayTable = DB::createTable(self::$default_table, self::$db_columns, null, $options);
     } else {
         // Delete all records from the table.
         $query = new SQLQuery('', self::$default_table);
         $query->setDelete(true);
         $query->execute();
     }
 }
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-misdirection,代码行数:22,代码来源:MisdirectionHistoricalLinkMappingTask.php

示例5: removeByID

 /**
  * Remove the given item from this list.
  * Note that for a ManyManyList, the item is never actually deleted, only the join table is affected
  * @param $itemID The item it
  */
 public function removeByID($itemID)
 {
     if (!is_numeric($itemID)) {
         throw new InvalidArgumentException("ManyManyList::removeById() expecting an ID");
     }
     $query = new SQLQuery("*", array("\"{$this->joinTable}\""));
     $query->setDelete(true);
     if ($filter = $this->foreignIDFilter()) {
         $query->setWhere($filter);
     } else {
         user_error("Can't call ManyManyList::remove() until a foreign ID is set", E_USER_WARNING);
     }
     $query->addWhere("\"{$this->localKey}\" = {$itemID}");
     $query->execute();
 }
开发者ID:normann,项目名称:sapphire,代码行数:20,代码来源:ManyManyList.php

示例6: removeAll

 /**
  * Remove all items from this many-many join.  To remove a subset of items,
  * filter it first.
  *
  * @return void
  */
 public function removeAll()
 {
     $base = ClassInfo::baseDataClass($this->dataClass());
     // Remove the join to the join table to avoid MySQL row locking issues.
     $query = $this->dataQuery();
     $query->removeFilterOn($query->getQueryParam('Foreign.Filter'));
     $query = $query->query();
     $query->setSelect("\"{$base}\".\"ID\"");
     $from = $query->getFrom();
     unset($from[$this->joinTable]);
     $query->setFrom($from);
     $query->setDistinct(false);
     // ensure any default sorting is removed, ORDER BY can break DELETE clauses
     $query->setOrderBy(null, null);
     // Use a sub-query as SQLite does not support setting delete targets in
     // joined queries.
     $delete = new SQLQuery();
     $delete->setDelete(true);
     $delete->setFrom("\"{$this->joinTable}\"");
     $delete->addWhere($this->foreignIDFilter());
     $delete->addWhere("\"{$this->joinTable}\".\"{$this->localKey}\" IN ({$query->sql()})");
     $delete->execute();
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:29,代码来源:ManyManyList.php

示例7: testDeprecatedSetDelete

    /**
     * Test deprecation of SQLQuery::setDelete/getDelete
     */
    public function testDeprecatedSetDelete()
    {
        // Temporarily disable deprecation
        Deprecation::notification_version(null);
        $query = new SQLQuery();
        $query->setSelect(array('"SQLQueryTest_DO"."Name"'));
        $query->setFrom('"SQLQueryTest_DO"');
        $query->setWhere(array('"SQLQueryTest_DO"."Name"' => 'Andrew'));
        // Check SQL for select
        $this->assertSQLEquals(<<<EOS
SELECT "SQLQueryTest_DO"."Name" FROM "SQLQueryTest_DO"
WHERE ("SQLQueryTest_DO"."Name" = ?)
EOS
, $query->sql($parameters));
        $this->assertEquals(array('Andrew'), $parameters);
        // Check setDelete works
        $query->setDelete(true);
        $this->assertSQLEquals(<<<EOS
DELETE FROM "SQLQueryTest_DO"
WHERE ("SQLQueryTest_DO"."Name" = ?)
EOS
, $query->sql($parameters));
        $this->assertEquals(array('Andrew'), $parameters);
        // Check that setDelete back to false restores the state
        $query->setDelete(false);
        $this->assertSQLEquals(<<<EOS
SELECT "SQLQueryTest_DO"."Name" FROM "SQLQueryTest_DO"
WHERE ("SQLQueryTest_DO"."Name" = ?)
EOS
, $query->sql($parameters));
        $this->assertEquals(array('Andrew'), $parameters);
    }
开发者ID:tcaiger,项目名称:mSupplyNZ,代码行数:35,代码来源:SQLQueryTest.php


注:本文中的SQLQuery::setDelete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。