private function hasReferenceByTable($proptable, $id) { $row = false; $db = $this->store->getConnection('mw.db'); if ($proptable->usesIdSubject()) { $row = $db->selectRow($proptable->getName(), array('s_id'), array('s_id' => $id), __METHOD__); } if ($row !== false) { return true; } $fields = $proptable->getFields($this->store); // Check whether an object reference exists or not if (isset($fields['o_id'])) { $row = $db->selectRow($proptable->getName(), array('o_id'), array('o_id' => $id), __METHOD__); } // If the property table is not a fixed table (== assigns a whole // table to a specific property with the p_id column being suppressed) // then check for the p_id field if ($row === false && !$proptable->isFixedPropertyTable()) { $row = $db->selectRow($proptable->getName(), array('p_id'), array('p_id' => $id), __METHOD__); } // If the query table contains a reference then we keep the object (could // be a subject, property, or printrequest) where in case the query is // removed the object will also loose its reference if ($row === false) { $row = $db->selectRow(SQLStore::QUERY_LINKS_TABLE, array('o_id'), array('o_id' => $id), __METHOD__); } return $row !== false; }
/** * Transform input parameters into a suitable string of additional SQL * conditions. The parameter $valuecol defines the string name of the * column to which value restrictions etc. are to be applied. * * @since 1.8 * * @param RequestOptions|null $requestOptions * @param string $valueCol name of SQL column to which conditions apply * @param string $labelCol name of SQL column to which string conditions apply, if any * @param boolean $addAnd indicate whether the string should begin with " AND " if non-empty * * @return string */ public function getSQLConditionsFrom(RequestOptions $requestOptions = null, $valueCol = '', $labelCol = '', $addAnd = true) { $sqlConds = ''; if ($requestOptions === null) { return $sqlConds; } $connection = $this->store->getConnection('mw.db'); // Apply value boundary if ($valueCol !== '' && $requestOptions->boundary !== null) { if ($requestOptions->ascending) { $op = $requestOptions->include_boundary ? ' >= ' : ' > '; } else { $op = $requestOptions->include_boundary ? ' <= ' : ' < '; } $sqlConds .= ($addAnd ? ' AND ' : '') . $valueCol . $op . $connection->addQuotes($requestOptions->boundary); } // Apply string conditions if ($labelCol !== '') { foreach ($requestOptions->getStringConditions() as $strcond) { $string = str_replace('_', '\\_', $strcond->string); $condition = 'LIKE'; switch ($strcond->condition) { case StringCondition::COND_PRE: $string .= '%'; break; case StringCondition::COND_POST: $string = '%' . $string; break; case StringCondition::COND_MID: $string = '%' . $string . '%'; break; case StringCondition::COND_EQ: $condition = '='; break; } $conditionOperator = $strcond->isDisjunctiveCondition ? ' OR ' : ' AND '; $sqlConds .= ($addAnd || $sqlConds !== '' ? $conditionOperator : '') . "{$labelCol} {$condition} " . $connection->addQuotes($string); } } return $sqlConds; }
private function findNextIdPosition(&$id, $emptyrange) { $nextpos = $id + $this->iterationLimit; $db = $this->store->getConnection('mw.db'); // nothing found, check if there will be more pages later on if ($emptyrange && $nextpos > \SMWSql3SmwIds::FXD_PROP_BORDER_ID) { $nextByPageId = (int) $db->selectField('page', 'page_id', "page_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "page_id ASC")); $nextBySmwId = (int) $db->selectField(\SMWSql3SmwIds::TABLE_NAME, 'smw_id', "smw_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "smw_id ASC")); // Next position is determined by the pool with the maxId $nextpos = $nextBySmwId != 0 && $nextBySmwId > $nextByPageId ? $nextBySmwId : $nextByPageId; } $id = $nextpos ? $nextpos : -1; }
private function hasReferenceInPropertyTable($proptable, $id) { $row = false; $db = $this->store->getConnection('mw.db'); if ($proptable->usesIdSubject()) { $row = $db->selectRow($proptable->getName(), array('s_id'), array('s_id' => $id), __METHOD__); } if ($row !== false) { return true; } $fields = $proptable->getFields($this->store); // Check whether an object reference exists or not if (isset($fields['o_id'])) { $row = $db->selectRow($proptable->getName(), array('o_id'), array('o_id' => $id), __METHOD__); } // If the property table is not a fixed table (== assigns a whole // table to a specific property with the p_id column being suppressed) // then check for the p_id field if ($row === false && !$proptable->isFixedPropertyTable()) { $row = $db->selectRow($proptable->getName(), array('p_id'), array('p_id' => $id), __METHOD__); } return $row !== false; }
/** * @since 2.4 * * @param SQLStore $store */ public function __construct(SQLStore $store) { $this->store = $store; $this->connection = $this->store->getConnection('mw.db'); }
/** * @since 2.5 * * @param TableBuilder $tableBuilder */ public function checkOnPostCreation(TableBuilder $tableBuilder) { $this->doCheckInternalPropertyIndices($this->store->getConnection(DB_MASTER)); $tableBuilder->checkOn(TableBuilder::POST_CREATION); }