本文整理汇总了PHP中SQLQuery::getDelete方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLQuery::getDelete方法的具体用法?PHP SQLQuery::getDelete怎么用?PHP SQLQuery::getDelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLQuery
的用法示例。
在下文中一共展示了SQLQuery::getDelete方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: augmentSQL
/**
* @see DataExtension::augmentSQL()
*/
public function augmentSQL(SQLQuery &$query)
{
$select = $query->getSelect();
if (empty($select) || $query->getDelete() || in_array("COUNT(*)", $select) || in_array("count(*)", $select)) {
return;
}
if (!isset(self::$sortTables[$this->owner->class])) {
$classes = array_reverse(ClassInfo::dataClassesFor($this->owner->class));
$class = null;
foreach ($classes as $cls) {
if (DataObject::has_own_table($cls) && ($fields = DataObject::database_fields($cls)) && isset($fields['SortOrder'])) {
$class = $cls;
break;
}
}
self::$sortTables[$this->owner->class] = $class;
} else {
$class = self::$sortTables[$this->owner->class];
}
if ($class) {
$query->addOrderBy("\"{$class}\".\"SortOrder\" " . self::$sort_dir);
} else {
$query->addOrderBy("\"SortOrder\" " . self::$sort_dir);
}
}
示例2: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
if (Subsite::$disable_subsite_filter) {
return;
}
if ($dataQuery->getQueryParam('Subsite.filter') === false) {
return;
}
// Don't run on delete queries, since they are always tied to
// a specific ID.
if ($query->getDelete()) {
return;
}
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
// if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) {
if (!$query->where || !preg_match('/\\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0])) {
if (Subsite::$force_subsite) {
$subsiteID = Subsite::$force_subsite;
} else {
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */
$subsiteID = (int) Subsite::currentSubsiteID();
}
// The foreach is an ugly way of getting the first key :-)
foreach ($query->getFrom() as $tableName => $info) {
// The tableName should be SiteTree or SiteTree_Live...
if (strpos($tableName, $this->owner->ClassName) === false) {
break;
}
$query->addWhere("\"{$tableName}\".\"SubsiteID\" IN ({$subsiteID})");
break;
}
}
}
示例3: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
$ctrl = null;
if (Controller::has_curr()) {
$ctrl = Controller::curr();
}
if (Subsite::$disable_subsite_filter) {
return;
}
if ($dataQuery->getQueryParam('Subsite.filter') === false) {
return;
}
if ($ctrl && get_class(Controller::curr()) == 'Security') {
return;
}
// Don't run on delete queries, since they are always tied to
// a specific ID.
if ($query->getDelete()) {
return;
}
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
// if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) {
if (!$query->filtersOnID()) {
if (Subsite::$force_subsite) {
$subsiteID = Subsite::$force_subsite;
} else {
$subsiteID = (int) Subsite::currentSubsiteID();
}
$froms = $query->getFrom();
$froms = array_keys($froms);
$tableName = array_shift($froms);
$query->addWhere("\"{$tableName}\".\"SubsiteID\" IN ({$subsiteID})");
}
}
示例4: augmentSQL
public function augmentSQL(SQLQuery &$query)
{
if (empty($query->getSelect()) || $query->getDelete() || in_array("COUNT(*)", $query->getSelect()) || in_array("count(*)", $query->getSelect())) {
return;
}
if (!$query->getWhere() || !preg_match('/\\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->getWhere()[0])) {
$c = Controller::curr();
if (!startsWith($c->class, "CMS") && !startsWith($c->class, "Model") && $c->getAction() != "update") {
$className = $this->owner->ClassName;
$query->addWhere("{$className}.Published=1");
// $query->addWhere( "DATE({$className}.PublicationDate)<=DATE(NOW())" );
$query->addWhere("({$className}.ExpirationDate IS NULL) OR ({$className}.ExpirationDate IS NOT NULL AND DATE({$className}.ExpirationDate)>=DATE(NOW()))");
}
}
}
示例5: augmentSQL
/**
* Manipulates the SQL query
*
* @param SQLQuery &$query Query to manipulate
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 04.05.2012
*/
public function augmentSQL(SQLQuery &$query)
{
if (!$query->isJoinedTo($this->getLanguageClassName()) && !$query->getDelete()) {
$silvercartDefaultLocale = SilvercartConfig::Locale();
$query->addLeftJoin($this->getLanguageClassName(), sprintf("(\"%s\".\"ID\" = \"%s\".\"%s\")", $this->getBaseClassName(), $this->getLanguageClassName(), $this->getRelationFieldName()));
$addToWhere = '';
if ($this->getBaseLanguageClassName() != $this->getLanguageClassName()) {
$query->addLeftJoin($this->getBaseLanguageClassName(), sprintf("(\"%s\".\"ID\" = \"%s\".\"ID\")", $this->getLanguageClassName(), $this->getBaseLanguageClassName()));
$addToWhere = sprintf("AND \"%s\".\"ID\" = \"%s\".\"ID\"", $this->getBaseLanguageClassName(), $this->getLanguageClassName());
}
if (SilvercartConfig::useDefaultLanguageAsFallback() && Translatable::get_current_locale() != $silvercartDefaultLocale && !empty($silvercartDefaultLocale)) {
$query->addWhere(sprintf("\"%s\".\"Locale\" = IFNULL((%s), (%s)) %s", $this->getBaseLanguageClassName(), $this->getLocaleDependantSelect(Translatable::get_current_locale()), $this->getLocaleDependantSelect($silvercartDefaultLocale), $addToWhere));
} elseif (!empty($silvercartDefaultLocale)) {
$query->addWhere(sprintf("\"%s\".\"Locale\" = '%s' %s", $this->getBaseLanguageClassName(), Translatable::get_current_locale(), $addToWhere));
}
}
}
示例6: augmentSQL
/**
* @see DataExtension::augmentSQL()
*/
public function augmentSQL(SQLQuery &$query)
{
$select = $query->getSelect();
if (empty($select) || $query->getDelete() || in_array("COUNT(*)", $select) || in_array("count(*)", $select)) {
return;
}
if (!isset(self::$sortTables[$this->owner->class])) {
// look up the table that has the SortOrder field
$class = ClassInfo::table_for_object_field($this->owner->class, 'SortOrder');
self::$sortTables[$this->owner->class] = $class;
} else {
$class = self::$sortTables[$this->owner->class];
}
if ($class) {
$query->addOrderBy("\"{$class}\".\"SortOrder\" " . self::$sort_dir);
} else {
$query->addOrderBy("\"SortOrder\" " . self::$sort_dir);
}
}
示例7: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
// Filters are disabled globally
if (self::$disable) {
return;
}
// Filters are disabled for this query
if ($dataQuery->getQueryParam('SoftDeletable.filter') === false) {
return;
}
// Don't run on delete queries, since they are always tied to a specific ID.
if ($query->getDelete()) {
return;
}
// Don't run if querying by ID
if ($query->filtersOnID()) {
return;
}
$froms = $query->getFrom();
$froms = array_keys($froms);
$tableName = array_shift($froms);
$query->addWhere("\"{$tableName}\".\"Deleted\" IS NULL");
}
示例8: sqlQueryToString
/**
* Convert a SQLQuery object into a SQL statement
* @param $query SQLQuery
*/
public function sqlQueryToString(SQLQuery $query)
{
if ($query->getDelete()) {
$text = 'DELETE ';
} else {
$text = $this->sqlSelectToString($query->getSelect(), $query->getDistinct());
}
if ($query->getFrom()) {
$text .= $this->sqlFromToString($query->getFrom());
}
if ($query->getWhere()) {
$text .= $this->sqlWhereToString($query->getWhere(), $query->getConnective());
}
// these clauses only make sense in SELECT queries, not DELETE
if (!$query->getDelete()) {
if ($query->getGroupBy()) {
$text .= $this->sqlGroupByToString($query->getGroupBy());
}
if ($query->getHaving()) {
$text .= $this->sqlHavingToString($query->getHaving());
}
if ($query->getOrderBy()) {
$text .= $this->sqlOrderByToString($query->getOrderBy());
}
if ($query->getLimit()) {
$text .= $this->sqlLimitToString($query->getLimit());
}
}
return $text;
}
示例9: augmentSQL
/**
* Update any requests to limit the results to the current site
*/
public function augmentSQL(SQLQuery &$query)
{
if (Subsite::$disable_subsite_filter) {
return;
}
// If you're querying by ID, ignore the sub-site - this is a bit ugly... (but it was WAYYYYYYYYY worse)
//@TODO I don't think excluding if SiteTree_ImageTracking is a good idea however because of the SS 3.0 api and ManyManyList::removeAll() changing the from table after this function is called there isn't much of a choice
$from = $query->getFrom();
$where = $query->getWhere();
if (!isset($from['SiteTree_ImageTracking']) && !($where && preg_match('/\\.(\'|"|`|)ID(\'|"|`|)/', $where[0]))) {
$subsiteID = (int) Subsite::currentSubsiteID();
// The foreach is an ugly way of getting the first key :-)
foreach ($query->getFrom() as $tableName => $info) {
$where = "\"{$tableName}\".\"SubsiteID\" IN (0, {$subsiteID})";
$query->addWhere($where);
break;
}
$sect = array_values($query->getSelect());
$isCounting = strpos($sect[0], 'COUNT') !== false;
// Ordering when deleting or counting doesn't apply
if (!$query->getDelete() && !$isCounting) {
$query->addOrderBy("\"SubsiteID\"");
}
}
}
示例10: sqlQueryToString
/**
* Convert a SQLQuery object into a SQL statement
* Caution: Expects correctly quoted and escaped SQL fragments.
*
* @param $query SQLQuery
*/
public function sqlQueryToString(SQLQuery $query)
{
if ($query->getDelete()) {
//Appended space at the end of string causing an issue but this might not be the best solution
//@see sqlSelectToString() sqlFromToString
$text = 'DELETE';
} else {
if ($traverse = $query->getTraverse()) {
//Build the traverse string here
$text = $this->sqlTraverseToString($traverse);
} else {
$text = $this->sqlSelectToString($query->getSelect(), $query->getDistinct());
}
}
if ($query->getFrom()) {
$text .= $this->sqlFromToString($query->getFrom());
}
if ($query->getWhere()) {
$text .= $this->sqlWhereToString($query->getWhere(), $query->getConnective());
}
// these clauses only make sense in SELECT queries, not DELETE
if (!$query->getDelete()) {
if ($query->getGroupBy()) {
$text .= $this->sqlGroupByToString($query->getGroupBy());
}
if ($query->getHaving()) {
$text .= $this->sqlHavingToString($query->getHaving());
}
if ($query->getOrderBy()) {
$text .= $this->sqlOrderByToString($query->getOrderBy());
}
if ($query->getLimit()) {
$text .= $this->sqlLimitToString($query->getLimit());
}
}
// SS_Log::log(new Exception(print_r($text, true)), SS_Log::NOTICE);
return $text;
}