本文整理汇总了PHP中Doctrine\DBAL\Connection::quoteIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::quoteIdentifier方法的具体用法?PHP Connection::quoteIdentifier怎么用?PHP Connection::quoteIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::quoteIdentifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getQueryBuilderForEntity
/**
* @param $data
* @param $entity
* @param $primaryId
* @return QueryBuilder
*/
public function getQueryBuilderForEntity($data, $entity, $primaryId)
{
$metaData = $this->modelManager->getClassMetadata($entity);
$table = $metaData->table['name'];
$builder = $this->getQueryBuilder();
if ($primaryId) {
$id = $builder->createNamedParameter($primaryId, \PDO::PARAM_INT);
$builder->update($table);
//update article id in case we don't have any field for update
$builder->set('id', $id);
$builder->where('id = ' . $id);
} else {
$builder->insert($table);
}
foreach ($data as $field => $value) {
if (!array_key_exists($field, $metaData->fieldMappings)) {
continue;
}
$key = $this->connection->quoteIdentifier($metaData->fieldMappings[$field]['columnName']);
$value = $this->getNamedParameter($value, $field, $metaData, $builder);
if ($primaryId) {
$builder->set($key, $value);
} else {
$builder->setValue($key, $value);
}
}
return $builder;
}
示例2: getQuotedFields
/**
* @return array
*/
private function getQuotedFields()
{
$fields = [];
foreach (self::$columnNames as $field) {
$fields[] = $this->connection->quoteIdentifier($field);
}
return $fields;
}
示例3: __construct
public function __construct(Connection $conn, StorageKeyGeneratorInterface $storageKeyGenerator)
{
$this->conn = $conn;
$this->storageKeyGenerator = $storageKeyGenerator;
$this->schemaManager = $this->conn->getSchemaManager();
$this->keyColumn = $this->conn->quoteIdentifier(self::KEY_COLUMN);
$this->valueColumn = $this->conn->quoteIdentifier(self::VALUE_COLUMN);
}
示例4: fetchAll
/**
* Fetch all
*
* @return array
*/
public function fetchAll()
{
$tableName = $this->connection->quoteIdentifier($this->tableName);
$sql = "SELECT version FROM {$tableName} ORDER BY version ASC";
$all = $this->connection->fetchAll($sql);
return array_map(function ($v) {
return $v['version'];
}, $all);
}
示例5: quoteIdentifiers
/**
* @param array $rows
* @return array
*/
protected function quoteIdentifiers(array $rows)
{
$quotedRows = array_map(function ($row) {
$quoted = [];
foreach ($row as $identifier => $value) {
$quoted[$this->connection->quoteIdentifier($identifier)] = $value;
}
return $quoted;
}, $rows);
return $quotedRows;
}
示例6: findBy
/**
* Find User instances that match the given criteria.
*
* @param array $criteria
* @param array $options An array of the following options (all optional):<pre>
* limit (int|array) The maximum number of results to return, or an array of (offset, limit).
* order_by (string|array) The name of the column to order by, or an array of column name and direction, ex. array(time_created, DESC)
* </pre>
* @return User[] An array of matching User instances, or an empty array if no matching users were found.
*/
public function findBy(array $criteria = array(), array $options = array())
{
// Check the identity map first.
if (array_key_exists('id', $criteria) && array_key_exists($criteria['id'], $this->identityMap)) {
return array($this->identityMap[$criteria['id']]);
}
list($common_sql, $params) = $this->createCommonFindSql($criteria);
$sql = 'SELECT * ' . $common_sql;
if (array_key_exists('order_by', $options)) {
list($order_by, $order_dir) = is_array($options['order_by']) ? $options['order_by'] : array($options['order_by']);
$sql .= 'ORDER BY ' . $this->conn->quoteIdentifier($order_by) . ' ' . ($order_dir == 'DESC' ? 'DESC' : 'ASC') . ' ';
}
if (array_key_exists('limit', $options)) {
list($offset, $limit) = is_array($options['limit']) ? $options['limit'] : array(0, $options['limit']);
$sql .= 'LIMIT ' . (int) $offset . ', ' . (int) $limit . ' ';
}
$data = $this->conn->fetchAll($sql, $params);
$users = array();
foreach ($data as $userData) {
if (array_key_exists($userData['id'], $this->identityMap)) {
$user = $this->identityMap[$userData['id']];
} else {
$user = $this->hydrateUser($userData);
$this->identityMap[$user->getId()] = $user;
}
$users[] = $user;
}
return $users;
}
示例7: updateJob
/**
* {@inheritdoc}
*/
public function updateJob(Enlight_Components_Cron_Job $job)
{
$data = [];
$data['action'] = $job->getAction();
$data[$this->connection->quoteIdentifier('interval')] = $job->getInterval();
$data['data'] = serialize($job->getData());
$data['active'] = $job->getActive() ? '1' : '0';
$data['next'] = $job->getNext() ? $job->getNext()->toString('YYYY-MM-dd HH:mm:ss') : null;
$data['start'] = $job->getStart() ? $job->getStart()->toString('YYYY-MM-dd HH:mm:ss') : null;
$data['end'] = $job->getEnd() ? $job->getEnd()->toString('YYYY-MM-dd HH:mm:ss') : null;
if (is_null($job->getId())) {
$this->connection->insert($this->tableName, $data);
} else {
$this->connection->update($this->tableName, $data, ['id' => $job->getId()]);
}
}
示例8: convertToCharacterSetAndCollation
/**
* Convert the tables in the current database to use given character set and collation.
*
* @param string $characterSet Character set to convert to
* @param string $collation Collation to set, must be compatible with the character set
* @param string $outputPathAndFilename
* @param boolean $verbose
* @throws ConnectionException
* @throws DBALException
*/
protected function convertToCharacterSetAndCollation($characterSet = 'utf8', $collation = 'utf8_unicode_ci', $outputPathAndFilename = null, $verbose = false)
{
$statements = ['SET foreign_key_checks = 0'];
$statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
$tableNames = $this->connection->getSchemaManager()->listTableNames();
foreach ($tableNames as $tableName) {
$statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
$statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
}
$statements[] = 'SET foreign_key_checks = 1';
if ($outputPathAndFilename === null) {
try {
$this->connection->beginTransaction();
foreach ($statements as $statement) {
if ($verbose) {
$this->outputLine($statement);
}
$this->connection->exec($statement);
}
$this->connection->commit();
} catch (\Exception $exception) {
$this->connection->rollBack();
$this->outputLine($exception->getMessage());
$this->outputLine('[ERROR] The transaction was rolled back.');
}
} else {
file_put_contents($outputPathAndFilename, implode(';' . PHP_EOL, $statements) . ';');
}
}
示例9: lockTables
/**
* Lock one or more tables
*
* @param array $arrTables An array of table names to be locked
*/
public function lockTables($arrTables)
{
$arrLocks = array();
foreach ($arrTables as $table => $mode) {
$arrLocks[] = $this->resConnection->quoteIdentifier($table) . ' ' . $mode;
}
$this->resConnection->exec('LOCK TABLES ' . implode(', ', $arrLocks) . ';');
}
示例10: quoteIdentifiers
/**
* @param array $where column => value pairs
* @return array `column` => value pairs
*/
protected function quoteIdentifiers(array $where)
{
$columns = array_map(function ($column) {
return $this->db->quoteIdentifier($column);
}, array_keys($where));
$identifier = array_combine($columns, array_values($where));
return $identifier;
}
示例11: delete
/**
* Delete a User from the database.
*
* @param User $user
*/
public function delete(User $user)
{
$this->dispatcher->dispatch(UserEvents::BEFORE_DELETE, new UserEvent($user));
$this->clearIdentityMap($user);
$this->conn->executeUpdate('DELETE FROM ' . $this->conn->quoteIdentifier($this->userTableName) . ' WHERE ' . $this->getUserColumns('id') . ' = ?', array($user->getId()));
$this->conn->executeUpdate('DELETE FROM ' . $this->conn->quoteIdentifier($this->userCustomFieldsTableName) . ' WHERE ' . $this->getUserColumns('user_id') . ' = ?', array($user->getId()));
$this->dispatcher->dispatch(UserEvents::AFTER_DELETE, new UserEvent($user));
}
示例12: quoteColumns
/**
* Quote the column names.
* @param array $data
* @return array
*/
private function quoteColumns(array $data)
{
$safeData = [];
foreach ($data as $key => $value) {
$key = $this->connection->quoteIdentifier($key);
$safeData[$key] = $value;
}
return $safeData;
}
示例13: quoteIdentifier
/**
* Tries to autodetect, if identifier has to be quoted and quotes it.
*
* @param string $expression
* @return string
*/
public function quoteIdentifier($expression)
{
$expression = trim($expression);
if ($expression[0] === $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
return $expression;
// already quoted
}
return parent::quoteIdentifier($expression);
}
示例14: write
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
if ($this->columnMap === null) {
$dataToInsert = $record;
} else {
$dataToInsert = array();
foreach ($this->columnMap as $columnName => $fieldKey) {
if (isset($record[$fieldKey])) {
$dataToInsert[$this->conn->quoteIdentifier($columnName)] = $record[$fieldKey];
}
}
}
array_walk_recursive($dataToInsert, function (&$value) {
// Convert DateTime instances to ISO-8601 Strings
if ($value instanceof \DateTime) {
$value = $value->format(\DateTime::ISO8601);
}
});
$this->conn->insert($this->table, $dataToInsert);
}
示例15: quoteIdentifier
/**
* {@inheritdoc}
*/
public function quoteIdentifier($identifier)
{
if (ConnectionDecoratorChain::isDecorate()) {
return (new ConnectionDecoratorChain($this, $this->decorators))->quoteIdentifier($identifier);
}
try {
return $this->conn->quoteIdentifier($identifier);
} catch (\Exception $e) {
throw $this->convertException($e);
}
}