本文整理汇总了PHP中DatabaseBase::addQuotes方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase::addQuotes方法的具体用法?PHP DatabaseBase::addQuotes怎么用?PHP DatabaseBase::addQuotes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseBase
的用法示例。
在下文中一共展示了DatabaseBase::addQuotes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSQLCondition
/**
* @see SMWDescription::getSQLCondition
*
* FIXME: store specific code should be in the store component
*
* @since 0.6
*
* @param string $tableName
* @param array $fieldNames
* @param DatabaseBase $dbs
*
* @return boolean
*/
public function getSQLCondition($tableName, array $fieldNames, DatabaseBase $dbs)
{
$dataItem = $this->getDataItem();
// Only execute the query when the description's type is geographical coordinates,
// the description is valid, and the near comparator is used.
if ($dataItem instanceof SMWDIGeoCoord) {
switch ($this->getComparator()) {
case SMW_CMP_EQ:
$comparator = '=';
break;
case SMW_CMP_LEQ:
$comparator = '<=';
break;
case SMW_CMP_GEQ:
$comparator = '>=';
break;
case SMW_CMP_NEQ:
$comparator = '!=';
break;
default:
return false;
}
$lat = $dbs->addQuotes($dataItem->getLatitude());
$lon = $dbs->addQuotes($dataItem->getLongitude());
$conditions = array();
$conditions[] = "{$tableName}.{$fieldNames['1']} {$comparator} {$lat}";
$conditions[] = "{$tableName}.{$fieldNames['2']} {$comparator} {$lon}";
return implode(' AND ', $conditions);
}
return false;
}
示例2: refreshBatch
public function refreshBatch(DatabaseBase $dbr, UUID $continue, $countableActions, UUID $stop)
{
$rows = $dbr->select('flow_revision', array('rev_id', 'rev_user_id'), array('rev_id > ' . $dbr->addQuotes($continue->getBinary()), 'rev_id <= ' . $dbr->addQuotes($stop->getBinary()), 'rev_user_id > 0', 'rev_user_wiki' => wfWikiID(), 'rev_change_type' => $countableActions), __METHOD__, array('ORDER BY' => 'rev_id ASC', 'LIMIT' => $this->mBatchSize));
// end of data
if (!$rows || $rows->numRows() === 0) {
return false;
}
foreach ($rows as $row) {
// User::incEditCount only allows for edit count to be increased 1
// at a time. It'd be better to immediately be able to increase the
// edit count by the exact number it should be increased with, but
// I'd rather re-use existing code, especially in a run-once script,
// where performance is not the most important thing ;)
$user = User::newFromId($row->rev_user_id);
$user->incEditCount();
// save updates so we can print them when the script is done running
if (!isset($this->updates[$user->getId()])) {
$this->updates[$user->getId()] = 0;
}
$this->updates[$user->getId()]++;
// set value for next batch to continue at
$continue = $row->rev_id;
}
return UUID::create($continue);
}
示例3: testAddQuotesStringQuote
public function testAddQuotesStringQuote()
{
$check = "'string''s cause trouble'";
if ($this->db->getType() === 'mysql') {
$check = "'string\\'s cause trouble'";
}
$this->assertEquals($check, $this->db->addQuotes("string's cause trouble"));
}
示例4: addToUsageCount
/**
* @see PropertyStatisticsStore::addToUsageCount
*
* @since 1.9
*
* @param integer $propertyId
* @param integer $value
*
* @return boolean Success indicator
* @throws MWException
*/
public function addToUsageCount($propertyId, $value)
{
if (!is_int($value)) {
throw new MWException('The value to add must be an integer');
}
if (!is_int($propertyId) || $propertyId <= 0) {
throw new MWException('The property id to add must be a positive integer');
}
if ($value == 0) {
return true;
}
return $this->dbConnection->update($this->table, array('usage_count = usage_count ' . ($value > 0 ? '+ ' : '- ') . $this->dbConnection->addQuotes(abs($value))), array('p_id' => $propertyId), __METHOD__);
}
示例5: checkLinkTable
/**
* Check and repair the destination fields in a link table
* @param string $table The link table name
* @param string $fieldPrefix The field prefix in the link table
* @param int $ns Destination namespace id
* @param string $name
* @param array $options Associative array of validated command-line options
* @param array $extraConds Extra conditions for the SQL query
*/
private function checkLinkTable($table, $fieldPrefix, $ns, $name, $options, $extraConds = array())
{
$batchConds = array();
$fromField = "{$fieldPrefix}_from";
$namespaceField = "{$fieldPrefix}_namespace";
$titleField = "{$fieldPrefix}_title";
$batchSize = 500;
while (true) {
$res = $this->db->select($table, array($fromField, $namespaceField, $titleField), array_merge($batchConds, $extraConds, array($namespaceField => 0, $titleField . $this->db->buildLike("{$name}:", $this->db->anyString()))), __METHOD__, array('ORDER BY' => array($titleField, $fromField), 'LIMIT' => $batchSize));
if ($res->numRows() == 0) {
break;
}
foreach ($res as $row) {
$logTitle = "from={$row->{$fromField}} ns={$row->{$namespaceField}} " . "dbk={$row->{$titleField}}";
$destTitle = $this->getDestinationTitle($ns, $name, $row->{$namespaceField}, $row->{$titleField}, $options);
$this->totalLinks++;
if (!$destTitle) {
$this->output("{$table} {$logTitle} *** INVALID\n");
continue;
}
$this->resolvableLinks++;
if (!$options['fix']) {
$this->output("{$table} {$logTitle} -> " . $destTitle->getPrefixedDBkey() . " DRY RUN\n");
continue;
}
$this->db->update($table, array($namespaceField => $destTitle->getNamespace(), $titleField => $destTitle->getDBkey()), array($namespaceField => 0, $titleField => $row->{$titleField}, $fromField => $row->{$fromField}), __METHOD__, array('IGNORE'));
$this->output("{$table} {$logTitle} -> " . $destTitle->getPrefixedDBkey() . "\n");
}
$encLastTitle = $this->db->addQuotes($row->{$titleField});
$encLastFrom = $this->db->addQuotes($row->{$fromField});
$batchConds = array("{$titleField} > {$encLastTitle} " . "OR ({$titleField} = {$encLastTitle} AND {$fromField} > {$encLastFrom})");
wfWaitForSlaves();
}
}
示例6: buildConditions
/**
* Uses the primary key list and the maximal result row from the
* previous iteration to build an SQL condition sufficient for
* selecting the next page of results. All except the final key use
* `=` conditions while the final key uses a `>` condition
*
* Example output:
* array( '( foo = 42 AND bar > 7 ) OR ( foo > 42 )' )
*
* @return array The SQL conditions necessary to select the next set
* of rows in the batched query
*/
protected function buildConditions()
{
if (!$this->current) {
return $this->conditions;
}
$maxRow = end($this->current);
$maximumValues = array();
foreach ($this->primaryKey as $column) {
$maximumValues[$column] = $this->db->addQuotes($maxRow->{$column});
}
$pkConditions = array();
// For example: If we have 3 primary keys
// first run through will generate
// col1 = 4 AND col2 = 7 AND col3 > 1
// second run through will generate
// col1 = 4 AND col2 > 7
// and the final run through will generate
// col1 > 4
while ($maximumValues) {
$pkConditions[] = $this->buildGreaterThanCondition($maximumValues);
array_pop($maximumValues);
}
$conditions = $this->conditions;
$conditions[] = sprintf('( %s )', implode(' ) OR ( ', $pkConditions));
return $conditions;
}
示例7: fixTemplate
/**
* fixTemplate
*
* This code ensures that the version of the Template that was in existence
* at the same time as the Memento gets loaded and displayed with the
* Memento.
*
* @fixme make this compatible with parser cache
* @param Title $title
* @param Parser $parser
* @param integer $id
*
* @return array containing the text, finalTitle, and deps
*/
public function fixTemplate(Title $title, Parser $parser, &$id)
{
// stopgap measure until we can find a better way
// to work with parser cache
$parser->disableCache();
$request = $parser->getUser()->getRequest();
if ($request->getHeader('ACCEPT-DATETIME')) {
$requestDatetime = $request->getHeader('ACCEPT-DATETIME');
$mwMementoTimestamp = $this->parseRequestDateTime($requestDatetime);
$firstRev = $title->getFirstRevision();
// if the template no longer exists, return gracefully
if ($firstRev != null) {
if ($firstRev->getTimestamp() < $mwMementoTimestamp) {
$pgID = $title->getArticleID();
$this->db->begin();
$res = $this->db->selectRow('revision', array('rev_id'), array('rev_page' => $pgID, 'rev_timestamp <=' . $this->db->addQuotes($mwMementoTimestamp)), __METHOD__, array('ORDER BY' => 'rev_id DESC', 'LIMIT' => '1'));
$id = $res->rev_id;
} else {
// if we get something prior to the first memento, just
// go with the first one
$id = $firstRev->getId();
}
}
}
}
示例8: getConflicts
/**
* Find pages in mainspace that have a prefix of the new namespace
* so we know titles that will need migrating
* @param $ns int Namespace id (id for new namespace?)
* @param $name String Prefix that is being made a namespace
*/
private function getConflicts( $ns, $name ) {
$page = 'page';
$table = $this->db->tableName( $page );
$prefix = $this->db->strencode( $name );
$encNamespace = $this->db->addQuotes( $ns );
$titleSql = "TRIM(LEADING '$prefix:' FROM {$page}_title)";
if( $ns == 0 ) {
// An interwiki; try an alternate encoding with '-' for ':'
$titleSql = $this->db->buildConcat( array( "'$prefix-'", $titleSql ) );
}
$sql = "SELECT {$page}_id AS id,
{$page}_title AS oldtitle,
$encNamespace + {$page}_namespace AS namespace,
$titleSql AS title,
{$page}_namespace AS oldnamespace
FROM {$table}
WHERE ( {$page}_namespace=0 OR {$page}_namespace=1 )
AND {$page}_title " . $this->db->buildLike( $name . ':', $this->db->anyString() );
$result = $this->db->query( $sql, __METHOD__ );
$set = array();
foreach( $result as $row ) {
$set[] = $row;
}
return $set;
}
示例9: updateRevision
public function updateRevision($columnPrefix, DatabaseBase $dbw, $continue = null)
{
$rows = $dbw->select('flow_revision', array('rev_id', 'rev_type'), array('rev_id > ' . $dbw->addQuotes($continue), "{$columnPrefix}_id > 0", "{$columnPrefix}_ip IS NOT NULL"), __METHOD__, array('LIMIT' => $this->mBatchSize, 'ORDER BY' => 'rev_id'));
$ids = $objs = array();
foreach ($rows as $row) {
$id = UUID::create($row->rev_id);
$type = self::$types[$row->rev_type];
$om = $this->storage->getStorage($type);
$obj = $om->get($id);
if ($obj) {
$om->merge($obj);
$ids[] = $row->rev_id;
$objs[] = $obj;
} else {
$this->error(__METHOD__ . ": Failed loading {$type}: " . $id->getAlphadecimal());
}
}
if (!$ids) {
return null;
}
$dbw->update('flow_revision', array("{$columnPrefix}_ip" => null), array('rev_id' => $ids), __METHOD__);
foreach ($objs as $obj) {
$this->storage->cachePurge($obj);
}
$this->completeCount += count($ids);
return end($ids);
}
示例10: __getCategories
private static function __getCategories($aParamValues, &$parser)
{
wfProfileIn(__METHOD__);
self::$aCategoryNames = $aParamValues;
$aPages = array();
if (!empty($aParamValues)) {
# RT 26917
$aParamValues = array_map("strip_tags", array_map(array("self", "__parseCategories"), $aParamValues, array($parser)));
// set timestamp option, if set
$timestampLimit = BLOGS_TIMESTAMP;
if (!empty(self::$aOptions['timestamp'])) {
$timestampLimit = self::$aOptions['timestamp'];
}
/* set max length of group concat query */
self::$dbr->query('SET group_concat_max_len = ' . GROUP_CONCAT, __METHOD__);
/* run query */
$res = self::$dbr->select(array(self::$dbr->tableName('page'), self::$dbr->tableName('categorylinks')), array("cl_to", "GROUP_CONCAT(DISTINCT cl_from SEPARATOR ',') AS cl_page"), array("page_namespace" => NS_BLOG_ARTICLE, "page_id = cl_from", "cl_to in (" . self::$dbr->makeList($aParamValues) . ")", "page_touched >= " . self::$dbr->addQuotes($timestampLimit)), __METHOD__, array('GROUP BY' => 'cl_to'));
while ($oRow = self::$dbr->fetchObject($res)) {
// BugId:49408
// Since GROUP_CONCAT respects group_concat_max_len arbitrarily,
// sometimes we end up with a comma or a truncated item, which
// we don't want.
if (GROUP_CONCAT == strlen($oRow->cl_page)) {
$aPages[] = preg_replace('/,\\d+,?$/', '', $oRow->cl_page);
} else {
$aPages[] = $oRow->cl_page;
}
}
self::$dbr->freeResult($res);
}
wfProfileOut(__METHOD__);
return $aPages;
}
示例11: getConflicts
/**
* Find pages in mainspace that have a prefix of the new namespace
* so we know titles that will need migrating
*
* @param int $ns Namespace id (id for new namespace?)
* @param string $name Prefix that is being made a namespace
*
* @return array
*/
private function getConflicts($ns, $name)
{
$titleSql = "TRIM(LEADING {$this->db->addQuotes("{$name}:")} FROM page_title)";
if ($ns == 0) {
// An interwiki; try an alternate encoding with '-' for ':'
$titleSql = $this->db->buildConcat(array($this->db->addQuotes("{$name}-"), $titleSql));
}
return iterator_to_array($this->db->select('page', array('id' => 'page_id', 'oldtitle' => 'page_title', 'namespace' => $this->db->addQuotes($ns) . ' + page_namespace', 'title' => $titleSql, 'oldnamespace' => 'page_namespace'), array('page_namespace' => array(0, 1), 'page_title' . $this->db->buildLike("{$name}:", $this->db->anyString())), __METHOD__));
}
示例12: fromText
/**
* @param DatabaseBase $db
* @param string $table
* @param string $field
* @return null|PostgresField
*/
static function fromText($db, $table, $field)
{
$q = <<<SQL
SELECT
attnotnull, attlen, conname AS conname,
atthasdef,
adsrc,
COALESCE(condeferred, 'f') AS deferred,
COALESCE(condeferrable, 'f') AS deferrable,
CASE WHEN typname = 'int2' THEN 'smallint'
WHEN typname = 'int4' THEN 'integer'
WHEN typname = 'int8' THEN 'bigint'
WHEN typname = 'bpchar' THEN 'char'
ELSE typname END AS typname
FROM pg_class c
JOIN pg_namespace n ON (n.oid = c.relnamespace)
JOIN pg_attribute a ON (a.attrelid = c.oid)
JOIN pg_type t ON (t.oid = a.atttypid)
LEFT JOIN pg_constraint o ON (o.conrelid = c.oid AND a.attnum = ANY(o.conkey) AND o.contype = 'f')
LEFT JOIN pg_attrdef d on c.oid=d.adrelid and a.attnum=d.adnum
WHERE relkind = 'r'
AND nspname=%s
AND relname=%s
AND attname=%s;
SQL;
$table = $db->tableName($table, 'raw');
$res = $db->query(sprintf($q, $db->addQuotes($db->getCoreSchema()), $db->addQuotes($table), $db->addQuotes($field)));
$row = $db->fetchObject($res);
if (!$row) {
return null;
}
$n = new PostgresField();
$n->type = $row->typname;
$n->nullable = $row->attnotnull == 'f';
$n->name = $field;
$n->tablename = $table;
$n->max_length = $row->attlen;
$n->deferrable = $row->deferrable == 't';
$n->deferred = $row->deferred == 't';
$n->conname = $row->conname;
$n->has_default = $row->atthasdef === 't';
$n->default = $row->adsrc;
return $n;
}
示例13: doCollationUpdate
protected function doCollationUpdate()
{
global $wgCategoryCollation;
if ($this->db->selectField('categorylinks', 'COUNT(*)', 'cl_collation != ' . $this->db->addQuotes($wgCategoryCollation), __METHOD__) == 0) {
$this->output("...collations up-to-date.\n");
return;
}
$task = new UpdateCollation();
$task->execute();
}
示例14: buildUpdateCondition
protected function buildUpdateCondition(DatabaseBase $dbw)
{
$rcNew = $dbw->addQuotes(RC_NEW);
$rcSrcNew = $dbw->addQuotes(RecentChange::SRC_NEW);
$rcEdit = $dbw->addQuotes(RC_EDIT);
$rcSrcEdit = $dbw->addQuotes(RecentChange::SRC_EDIT);
$rcLog = $dbw->addQuotes(RC_LOG);
$rcSrcLog = $dbw->addQuotes(RecentChange::SRC_LOG);
$rcExternal = $dbw->addQuotes(RC_EXTERNAL);
$rcSrcExternal = $dbw->addQuotes(RecentChange::SRC_EXTERNAL);
return "rc_source = CASE\n\t\t\t\t\tWHEN rc_type = {$rcNew} THEN {$rcSrcNew}\n\t\t\t\t\tWHEN rc_type = {$rcEdit} THEN {$rcSrcEdit}\n\t\t\t\t\tWHEN rc_type = {$rcLog} THEN {$rcSrcLog}\n\t\t\t\t\tWHEN rc_type = {$rcExternal} THEN {$rcSrcExternal}\n\t\t\t\t\tELSE ''\n\t\t\t\tEND";
}
示例15: buildPostInExpr
public static function buildPostInExpr(\DatabaseBase $db, array $arr)
{
$range = '';
foreach ($arr as $post) {
if ($range) {
$range .= ',';
}
$range .= $db->addQuotes($post->id->getBin());
}
return ' IN(' . $range . ')';
}