Connection.php 2.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\sphinx;

/**
 * Class Connection
 *
13
 * @property Schema $schema The schema information for this Sphinx connection. This property is read-only.
14
 * @property \yii\sphinx\QueryBuilder $queryBuilder The query builder for this Sphinx connection. This property is
15
 * read-only.
16
 * @method Schema getSchema() The schema information for this Sphinx connection
17
 * @method \yii\sphinx\QueryBuilder getQueryBuilder() the query builder for this Sphinx connection
18
 *
19 20 21 22 23
 * @author Paul Klimov <klimov.paul@gmail.com>
 * @since 2.0
 */
class Connection extends \yii\db\Connection
{
24 25 26 27 28 29 30
	/**
	 * @inheritdoc
	 */
	public $schemaMap = [
		'mysqli' => 'yii\sphinx\Schema',   // MySQL
		'mysql' => 'yii\sphinx\Schema',    // MySQL
	];
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

	/**
	 * Obtains the schema information for the named index.
	 * @param string $name index name.
	 * @param boolean $refresh whether to reload the table schema even if it is found in the cache.
	 * @return IndexSchema index schema information. Null if the named index does not exist.
	 */
	public function getIndexSchema($name, $refresh = false)
	{
		return $this->getSchema()->getIndexSchema($name, $refresh);
	}

	/**
	 * Quotes a index name for use in a query.
	 * If the index name contains schema prefix, the prefix will also be properly quoted.
	 * If the index name is already quoted or contains special characters including '(', '[[' and '{{',
	 * then this method will do nothing.
	 * @param string $name index name
	 * @return string the properly quoted index name
	 */
	public function quoteIndexName($name)
	{
		return $this->getSchema()->quoteIndexName($name);
	}
55

56 57 58 59 60 61 62 63 64 65
	/**
	 * Alias of [[quoteIndexName()]].
	 * @param string $name table name
	 * @return string the properly quoted table name
	 */
	public function quoteTableName($name)
	{
		return $this->quoteIndexName($name);
	}

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
	/**
	 * Creates a command for execution.
	 * @param string $sql the SQL statement to be executed
	 * @param array $params the parameters to be bound to the SQL statement
	 * @return Command the Sphinx command
	 */
	public function createCommand($sql = null, $params = [])
	{
		$this->open();
		$command = new Command([
			'db' => $this,
			'sql' => $sql,
		]);
		return $command->bindValues($params);
	}
81
}