本文整理汇总了PHP中Zend_Db_Adapter_Abstract::quoteIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Adapter_Abstract::quoteIdentifier方法的具体用法?PHP Zend_Db_Adapter_Abstract::quoteIdentifier怎么用?PHP Zend_Db_Adapter_Abstract::quoteIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Adapter_Abstract
的用法示例。
在下文中一共展示了Zend_Db_Adapter_Abstract::quoteIdentifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTableDataDump
public function getTableDataDump($tableName, $step = 100)
{
$sql = '';
if ($this->_read) {
$quotedTableName = $this->_read->quoteIdentifier($tableName);
$colunms = $this->_read->fetchRow('SELECT * FROM ' . $quotedTableName . ' LIMIT 1');
if ($colunms) {
$arrSql = array();
$colunms = array_keys($colunms);
$quote = $this->_read->getQuoteIdentifierSymbol();
$sql = 'INSERT INTO ' . $quotedTableName . ' (' . $quote . implode($quote . ', ' . $quote, $colunms) . $quote . ')';
$sql .= ' VALUES ';
$startRow = 0;
$select = $this->_read->select();
$select->from($tableName)->limit($step, $startRow);
while ($data = $this->_read->fetchAll($select)) {
$dataSql = array();
foreach ($data as $row) {
$dataSql[] = $this->_read->quoteInto('(?)', $row);
}
$arrSql[] = $sql . implode(', ', $dataSql) . ';';
$startRow += $step;
$select->limit($step, $startRow);
}
$sql = implode("\n", $arrSql) . "\n";
}
}
return $sql;
}
示例2: generateInserts
/**
* Generates an array of SQL insert statements that
* will save the current
*
* @param array $resources
* @access public
* @return string
*/
public function generateInserts(array $resources)
{
$quotedName = $this->_db->quoteIdentifier('name');
$quotedDescription = $this->_db->quoteIdentifier('description');
$quotedFlagsTable = $this->_db->quoteIdentifier('flags');
$insertResourceTemplate = sprintf('INSERT IGNORE INTO %s (%s, %s) VALUES (?, ?);', $quotedFlagsTable, $quotedName, $quotedDescription);
$selectResourceTemplate = sprintf('SET @flag_id := (SELECT id FROM %s WHERE %s = ?);', $quotedFlagsTable, $quotedName);
$insertPrivilegeTemplate = '(@flag_id, %s, %s)';
$inserts = array();
foreach ($resources as $resource) {
// ready the insert resource query
$insertResourceSql = $this->_db->quoteInto($insertResourceTemplate, $resource['name'], NULL, 1);
$insertResourceSql = $this->_db->quoteInto($insertResourceSql, $resource['description'], NULL, 1);
// ready the select resource query
$selectResourceSql = $this->_db->quoteInto($selectResourceTemplate, $resource['name']);
// ready the insert privilege query
$insertPrivilegeSql = sprintf('INSERT IGNORE INTO %s (%s, %s, %s) VALUES ', $this->_db->quoteIdentifier('privileges'), $this->_db->quoteIdentifier('flag_id'), $quotedName, $quotedDescription);
$insertPrivilegeSqlParts = array();
foreach ($resource['methods'] as $method) {
$insertPrivilegeSqlParts[] = sprintf($insertPrivilegeTemplate, $this->_db->quote($method['name']), $this->_db->quote($method['description']));
}
$inserts[] = $insertResourceSql . PHP_EOL . $selectResourceSql . PHP_EOL . $insertPrivilegeSql . PHP_EOL . "\t" . implode(',' . PHP_EOL . "\t", $insertPrivilegeSqlParts) . ';' . PHP_EOL;
}
return $inserts;
}
示例3: getSwitch
/**
* get switch case expression with multiple cases
*
* @param string $field
* @param array $cases
*
* @return Zend_Db_Expr
*/
public function getSwitch($field, $cases)
{
$case = 'CASE ' . $this->_adapter->quoteIdentifier($field) . ' ';
foreach ($cases as $when => $then) {
$case .= $this->_adapter->quoteInto(' WHEN ' . $when . ' THEN ?', $then);
}
$case .= ' END';
return new Zend_Db_Expr($case);
}
示例4: copyTreeByShadowPath
/**
* @param $shadowPath
* @param $newPath
* @param $oldPath
* @param $newShadowPath
* @param $oldShadowPath
*/
public function copyTreeByShadowPath($shadowPath, $newPath, $oldPath, $newShadowPath, $oldShadowPath)
{
$select = $this->_db->select()->from($this->_tablePrefix . $this->_tableName, array('path' => new Zend_Db_Expr($this->_db->quoteInto($this->_db->quoteInto('REPLACE(path, ?', $oldPath) . ', ?)', $newPath)), 'shadow_path' => new Zend_Db_Expr($this->_db->quoteInto($this->_db->quoteInto('REPLACE(shadow_path, ?', $oldShadowPath) . ', ?)', $newShadowPath)), 'record_id' => 'record_id', 'creation_time' => new Zend_Db_Expr('NOW()')))->where($this->_db->quoteInto($this->_db->quoteIdentifier('shadow_path') . ' like ?', $shadowPath . '/%'));
$stmt = $this->_db->query($select);
$entries = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
foreach ($entries as $entry) {
$entry['id'] = Tinebase_Record_Abstract::generateUID();
$this->_db->insert($this->_tablePrefix . $this->_tableName, $entry);
}
}
示例5: extractAndQuoteCols
function extractAndQuoteCols($bind, &$cols, &$vals)
{
// extract and quote col names from the array keys
$cols = array();
$vals = array();
foreach ($bind as $col => $val) {
$cols[] = $this->wrappedAdapter->quoteIdentifier($col, true);
if ($val instanceof Zend_Db_Expr) {
$vals[] = $val->__toString();
unset($bind[$col]);
} else {
$vals[] = '?';
}
}
}
示例6: _authenticateCreateSelect
/**
* _authenticateCreateSelect() - This method creates a Zend_Db_Select object that
* is completely configured to be queried against the database.
*
* @return Zend_Db_Select
*/
protected function _authenticateCreateSelect()
{
// build credential expression
if (empty($this->_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) {
$this->_credentialTreatment = '?';
}
$credentialExpression = new Zend_Db_Expr(
'(CASE WHEN ' .
$this->_zendDb->quoteInto(
$this->_zendDb->quoteIdentifier($this->_credentialColumn, true)
. ' = ' . $this->_credentialTreatment, $this->_credential
)
. ' THEN 1 ELSE 0 END) AS '
. $this->_zendDb->quoteIdentifier(
$this->_zendDb->foldCase('zend_auth_credential_match')
)
);
// get select
$dbSelect = clone $this->getDbSelect();
$dbSelect->from($this->_tableName, array('*', $credentialExpression))
->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity);
return $dbSelect;
}
示例7: validate
/**
* get array of ids which got send to the client for a given class
*
* @param Syncope_Model_IDevice|string $_deviceId
* @param Syncope_Model_IFolder|string $_folderId
* @return Syncope_Model_SyncState
*/
public function validate($_deviceId, $_folderId, $_syncKey)
{
$deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
$folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
$select = $this->_db->select()->from($this->_tablePrefix . 'synckey')->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey)->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId);
$stmt = $this->_db->query($select);
$state = $stmt->fetchObject('Syncope_Model_SyncState');
$stmt = null;
# see https://bugs.php.net/bug.php?id=44081
if (!$state instanceof Syncope_Model_ISyncState) {
return false;
}
$this->_convertFields($state);
// check if this was the latest syncKey
$select = $this->_db->select()->from($this->_tablePrefix . 'synckey')->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey + 1)->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId);
$stmt = $this->_db->query($select);
$moreRecentState = $stmt->fetchObject('Syncope_Model_SyncState');
$stmt = null;
# see https://bugs.php.net/bug.php?id=44081
// found more recent synckey => the last sync repsone got not received by the client
if ($moreRecentState instanceof Syncope_Model_ISyncState) {
// undelete entries marked as deleted in syncope_content table
$this->_db->update($this->_tablePrefix . 'content', array('is_deleted' => 0), array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'creation_synckey = ?' => $state->counter, 'is_deleted = ?' => 1));
// remove entries added during latest sync in syncope_content table
$this->_db->delete($this->_tablePrefix . 'content', array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'creation_synckey > ?' => $state->counter));
} else {
// finaly delete all entries marked for removal in syncope_content table
$this->_db->delete($this->_tablePrefix . 'content', array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'is_deleted = ?' => 1));
}
// remove all other synckeys
$this->_deleteOtherStates($state);
return $state;
}
示例8: applyTo
/**
* Apply filter
* @param Zend_Db_Adapter_Abstract $db
* @param Db_Select | Zend_Db_Select $sql
* @throws Exception
*/
public function applyTo(Zend_Db_Adapter_Abstract $db, $sql)
{
if (!$sql instanceof Db_Select && !$sql instanceof Zend_Db_Select) {
throw new Exception('Db_Select_Filter::applyTo $sql must be instance of Db_Select/Zend_Db_Select');
}
$quotedField = $db->quoteIdentifier($this->field);
switch ($this->type) {
case self::LT:
case self::GT:
case self::EQ:
case self::GT_EQ:
case self::LT_EQ:
case self::LIKE:
case self::NOT:
case self::NOT_LIKE:
$sql->where($quotedField . ' ' . $this->type . ' ?', $this->value);
break;
case self::IN:
case self::NOT_IN:
$sql->where($quotedField . ' ' . $this->type . ' (?)', $this->value);
break;
case self::NOT_NULL:
case self::IS_NULL:
$sql->where($quotedField . ' ' . $this->type);
break;
case self::BETWEEN:
case self::NOT_BETWEEN:
$sql->where($quotedField . ' ' . $this->type . ' ' . $db->quote($this->value[0]) . ' AND ' . $db->quote($this->value[1]));
break;
}
}
示例9: _stripQuoted
/**
* Remove parts of a SQL string that contain quoted strings
* of values or identifiers.
*
* @param string $sql
* @return string
*/
protected function _stripQuoted($sql)
{
// get the character for value quoting
// this should be '
$q = $this->_adapter->quote('a');
$q = $q[0];
// get the value used as an escaped quote,
// e.g. \' or ''
$qe = $this->_adapter->quote($q);
$qe = substr($qe, 1, 2);
$qe = preg_quote($qe);
$escapeChar = substr($qe, 0, 1);
// remove 'foo\'bar'
if (!empty($q)) {
$escapeChar = preg_quote($escapeChar);
// this segfaults only after 65,000 characters instead of 9,000
$sql = preg_replace("/{$q}([^{$q}{$escapeChar}]*|({$qe})*)*{$q}/s", '', $sql);
}
// get a version of the SQL statement with all quoted
// values and delimited identifiers stripped out
// remove "foo\"bar"
$sql = preg_replace("/\"(\\\\\"|[^\"])*\"/Us", '', $sql);
// get the character for delimited id quotes,
// this is usually " but in MySQL is `
$d = $this->_adapter->quoteIdentifier('a');
$d = $d[0];
// get the value used as an escaped delimited id quote,
// e.g. \" or "" or \`
$de = $this->_adapter->quoteIdentifier($d);
$de = substr($de, 1, 2);
$de = preg_quote($de);
// Note: $de and $d where never used..., now they are:
$sql = preg_replace("/{$d}({$de}|\\\\{2}|[^{$d}])*{$d}/Us", '', $sql);
return $sql;
}
示例10: getTag
/**
* converts category to tag
*
* @param int $catId
* @return string tagid
*/
public function getTag($catId)
{
if (!(isset($this->_tagMapCache[$catId]) || array_key_exists($catId, $this->_tagMapCache))) {
$select = $this->_egwDb->select()->from(array('cats' => 'egw_categories'))->where($this->_egwDb->quoteInto($this->_egwDb->quoteIdentifier('cat_id') . ' = ?', $catId));
$cat = $this->_egwDb->fetchAll($select, NULL, Zend_Db::FETCH_ASSOC);
$cat = count($cat) === 1 ? $cat[0] : NULL;
if (!$cat) {
$this->_log->DEBUG(__METHOD__ . '::' . __LINE__ . " category {$catId} not found in egw, skipping tag");
return $this->_tagMapCache[$catId] = NULL;
}
$tineDb = Tinebase_Core::getDb();
$select = $tineDb->select()->from(array('tags' => $tineDb->table_prefix . 'tags'))->where($tineDb->quoteInto($tineDb->quoteIdentifier('name') . ' LIKE ?', $cat['cat_name']));
$tag = $tineDb->fetchAll($select, NULL, Zend_Db::FETCH_ASSOC);
$tag = count($tag) > 0 ? $tag[0] : NULL;
if ($tag) {
return $this->_tagMapCache[$catId] = $tag['id'];
}
// create tag
$catData = unserialize($cat['cat_data']);
$tagId = Tinebase_Record_Abstract::generateUID();
$tagType = $cat['cat_access'] == 'public' ? Tinebase_Model_Tag::TYPE_SHARED : Tinebase_Model_Tag::TYPE_PERSONAL;
$tagOwner = $tagType == Tinebase_Model_Tag::TYPE_SHARED ? 0 : $this->mapAccountIdEgw2Tine($cat['cat_owner']);
$this->_log->NOTICE(__METHOD__ . '::' . __LINE__ . " creating new {$tagType} tag '{$cat['cat_name']}'");
$tineDb->insert($tineDb->table_prefix . 'tags', array('id' => $tagId, 'type' => $tagType, 'owner' => $tagOwner, 'name' => $cat['cat_name'], 'description' => $cat['cat_description'], 'color' => $catData['color'], 'created_by' => $tagOwner ? $tagOwner : Tinebase_Core::getUser()->getId(), 'creation_time' => $cat['last_mod'] ? $this->convertDate($cat['last_mod']) : Tinebase_DateTime::now()));
$right = new Tinebase_Model_TagRight(array('tag_id' => $tagId, 'account_type' => $tagType == Tinebase_Model_Tag::TYPE_SHARED ? Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE : Tinebase_Acl_Rights::ACCOUNT_TYPE_USER, 'account_id' => $tagOwner, 'view_right' => true, 'use_right' => true));
Tinebase_Tags::getInstance()->setRights($right);
Tinebase_Tags::getInstance()->setContexts(array(0), $tagId);
$this->_tagMapCache[$catId] = $tagId;
}
return $this->_tagMapCache[$catId];
}
示例11: resolve
/**
* Resolve credentials
*
* Only the first matching username/realm combination in the file is
* returned. If the file contains credentials for Digest authentication,
* the returned string is the password hash, or h(a1) from RFC 2617. The
* returned string is the plain-text password for Basic authentication.
*
* The expected format of the file is:
* username:realm:sharedSecret
*
* That is, each line consists of the user's username, the applicable
* authentication realm, and the password or hash, each delimited by
* colons.
*
* @param string $username Username
* @param string $realm Authentication Realm
* @throws Zend_Auth_Adapter_Http_Resolver_Exception
* @return string|false User's shared secret, if the user is found in the
* realm, false otherwise.
*/
public function resolve($username, $realm)
{
$exception = null;
if ($this->_tableName == '') {
$exception = 'A table must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
} elseif ($this->_identityColumn == '') {
$exception = 'An identity column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
} elseif ($this->_credentialColumn == '') {
$exception = 'A credential column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
}
if (null !== $exception) {
throw new Zend_Auth_Adapter_Http_Resolver_Exception($exception);
}
// create result array
$authResult = array('code' => Zend_Auth_Result::FAILURE, 'identity' => $username, 'messages' => array());
// get select
$select = $this->_zendDb->select();
$select->from($this->_tableName, array('credential' => $this->_credentialColumn))->where($this->_zendDb->quoteIdentifier($this->_identityColumn) . ' = ?', $username);
// query for the identity
try {
$resultIdentities = $this->_zendDb->fetchAll($select->__toString());
} catch (Exception $e) {
/**
* @see Zend_Auth_Adapter_Exception
*/
require_once 'Zend/Auth/Adapter/Exception.php';
throw new Zend_Auth_Adapter_Exception('The supplied parameters to Zend_Auth_Adapter_DbTable failed to ' . 'produce a valid sql statement, please check table and column names ' . 'for validity.');
}
if (count($resultIdentities) != 1) {
return false;
}
$resultIdentity = $resultIdentities[0];
return $resultIdentity['credential'];
}
示例12: _truncate
/**
* Truncate a given table.
*
* @param Zend_Db_Adapter_Abstract $db
* @param string $tableName
* @return void
*/
protected function _truncate(Zend_Db_Adapter_Abstract $db, $tableName)
{
$tableName = $db->quoteIdentifier($tableName, true);
if ($db instanceof Zend_Db_Adapter_Pdo_Sqlite) {
$db->query('DELETE FROM ' . $tableName);
} else {
if ($db instanceof Zend_Db_Adapter_Db2) {
/*if(strstr(PHP_OS, "WIN")) {
$file = tempnam(sys_get_temp_dir(), "zendtestdbibm_");
file_put_contents($file, "");
$db->query('IMPORT FROM '.$file.' OF DEL REPLACE INTO '.$tableName);
unlink($file);
} else {
$db->query('IMPORT FROM /dev/null OF DEL REPLACE INTO '.$tableName);
}*/
require_once "Zend/Exception.php";
throw Zend_Exception("IBM Db2 TRUNCATE not supported.");
} else {
if ($this->_isMssqlOrOracle($db)) {
$db->query('TRUNCATE TABLE ' . $tableName);
} else {
if ($db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
$db->query('TRUNCATE ' . $tableName . ' CASCADE');
} else {
$db->query('TRUNCATE ' . $tableName);
}
}
}
}
}
示例13: _stripQuoted
/**
* Remove parts of a SQL string that contain quoted strings
* of values or identifiers.
*
* @param string $sql
* @return string
*/
protected function _stripQuoted($sql)
{
// XF CUSTOM: this function has problems. The regex isn't accurate and the
// accurate regex "{$q}([^\\\\{$q}]+|{$q}{$q}|\\\\.)*{$q}" has issues with
// extremely limited stack sizes.
return '';
// get the character for delimited id quotes,
// this is usually " but in MySQL is `
$d = $this->_adapter->quoteIdentifier('a');
$d = $d[0];
// get the character for value quoting
// this should be '
$q = $this->_adapter->quote('a');
$q = $q[0];
// get a version of the SQL statement with all quoted
// values and delimited identifiers stripped out
// remove quoted identifiers
if (!empty($d)) {
$rx = "{$d}{$d}|{$d}.*?(?<!(((?<![{$d}\\\\]){$d})|((?<!\\\\)\\\\))){$d}(?!{$d})";
$sql = preg_replace("/{$rx}/s", '', $sql);
}
// remove quoted values
if (!empty($q)) {
$rx = "{$q}{$q}|{$q}.*?(?<!(((?<![{$q}\\\\]){$q})|((?<!\\\\)\\\\))){$q}(?!{$q})";
$sql = preg_replace("/{$rx}/s", '', $sql);
}
return $sql;
}
示例14: _stripQuoted
/**
* Remove parts of a SQL string that contain quoted strings
* of values or identifiers.
*
* @param string $sql
* @return string
*/
protected function _stripQuoted($sql)
{
// get the character for delimited id quotes,
// this is usually " but in MySQL is `
$d = $this->_adapter->quoteIdentifier('a');
$d = $d[0];
// get the value used as an escaped delimited id quote,
// e.g. \" or "" or \`
$de = $this->_adapter->quoteIdentifier($d);
$de = substr($de, 1, 2);
$de = str_replace('\\', '\\\\', $de);
// get the character for value quoting
// this should be '
$q = $this->_adapter->quote('a');
$q = $q[0];
// get the value used as an escaped quote,
// e.g. \' or ''
$qe = $this->_adapter->quote($q);
$qe = substr($qe, 1, 2);
$qe = str_replace('\\', '\\\\', $qe);
// get a version of the SQL statement with all quoted
// values and delimited identifiers stripped out
// remove "foo\"bar"
$sql = preg_replace("/{$q}({$qe}|\\\\{2}|[^{$q}])*{$q}/", '', $sql);
// remove 'foo\'bar'
if (!empty($q)) {
$sql = preg_replace("/{$q}({$qe}|[^{$q}])*{$q}/", '', $sql);
}
return $sql;
}
示例15: _authenticateCreateSelect
protected function _authenticateCreateSelect()
{
// get select
$dbSelect = clone $this->getDbSelect();
$dbSelect->from($this->_tableName, array('*'))->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_apiKey);
return $dbSelect;
}