getSupplementalDriver() public method

public getSupplementalDriver ( ) : Nette\Database\ISupplementalDriver
return Nette\Database\ISupplementalDriver
示例#1
0
文件: Statement.php 项目: bazo/Tatami
 /**
  * Normalizes result row.
  * @param  array
  * @return array
  */
 public function normalizeRow($row)
 {
     if ($this->types === NULL) {
         $this->types = array();
         if ($this->connection->getSupplementalDriver()->supports['meta']) {
             // workaround for PHP bugs #53782, #54695
             $col = 0;
             foreach ($row as $key => $foo) {
                 $type = $this->getColumnMeta($col++);
                 if (isset($type['native_type'])) {
                     $this->types[$key] = Reflection\DatabaseReflection::detectType($type['native_type']);
                 }
             }
         }
     }
     foreach ($this->types as $key => $type) {
         $value = $row[$key];
         if ($value === NULL || $value === FALSE || $type === Reflection\DatabaseReflection::FIELD_TEXT) {
         } elseif ($type === Reflection\DatabaseReflection::FIELD_INTEGER) {
             $row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
         } elseif ($type === Reflection\DatabaseReflection::FIELD_FLOAT) {
             $row[$key] = (string) ($tmp = (double) $value) === $value ? $tmp : $value;
         } elseif ($type === Reflection\DatabaseReflection::FIELD_BOOL) {
             $row[$key] = (bool) $value && $value !== 'f' && $value !== 'F';
         }
     }
     return $this->connection->getSupplementalDriver()->normalizeRow($row, $this);
 }
示例#2
0
 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     try {
         if (substr($queryString, 0, 2) === '::') {
             $connection->getPdo()->{substr($queryString, 2)}();
         } elseif ($queryString !== NULL) {
             static $types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL];
             $this->pdoStatement = $connection->getPdo()->prepare($queryString);
             foreach ($params as $key => $value) {
                 $type = gettype($value);
                 $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR);
             }
             $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
             $this->pdoStatement->execute();
         }
     } catch (\PDOException $e) {
         $e = $this->supplementalDriver->convertException($e);
         $e->queryString = $queryString;
         throw $e;
     }
     $this->time = microtime(TRUE) - $time;
 }
示例#3
0
	public function __construct($tableName, Connection $connection, IReflection $reflection)
	{
		$this->tableName = $tableName;
		$this->databaseReflection = $reflection;
		$this->driver = $connection->getSupplementalDriver();
		$this->delimitedTable = implode('.', array_map(array($this->driver, 'delimite'), explode('.', $tableName)));
	}
示例#4
0
	/**
	 * Normalizes result row.
	 * @param  array
	 * @return array
	 */
	public function normalizeRow($row)
	{
		if ($this->types === NULL) {
			try {
				$this->types = array();
				foreach ($row as $key => $foo) {
					$type = $this->getColumnMeta(count($this->types));
					if (isset($type['native_type'])) {
						$this->types[$key] = DatabaseReflection::detectType($type['native_type']);
					}
				}
			} catch (\PDOException $e) {
			}
		}
		foreach ($this->types as $key => $type) {
			$value = $row[$key];
			if ($value === NULL || $value === FALSE || $type === DatabaseReflection::FIELD_TEXT) {

			} elseif ($type === DatabaseReflection::FIELD_INTEGER) {
				$row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;

			} elseif ($type === DatabaseReflection::FIELD_FLOAT) {
				$row[$key] = (string) ($tmp = (float) $value) === $value ? $tmp : $value;

			} elseif ($type === DatabaseReflection::FIELD_BOOL) {
				$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
			}
		}

		return $this->connection->getSupplementalDriver()->normalizeRow($row, $this);
	}
示例#5
0
 protected function tryDelimite($s)
 {
     $driver = $this->connection->getSupplementalDriver();
     return preg_replace_callback('#(?<=[\\s,<>=]|^)[a-z_][a-z0-9_.]*(?=[\\s,<>=]|$)#i', function ($m) use($driver) {
         return strtoupper($m[0]) === $m[0] ? $m[0] : implode('.', array_map(array($driver, 'delimite'), explode('.', $m[0])));
     }, $s);
 }
 protected function tryDelimite($s)
 {
     $driver = $this->connection->getSupplementalDriver();
     return preg_replace_callback('#(?<=[^\\w`"\\[]|^)[a-z_][a-z0-9_]*(?=[^\\w`"(\\]]|$)#i', function ($m) use($driver) {
         return strtoupper($m[0]) === $m[0] ? $m[0] : $driver->delimite($m[0]);
     }, $s);
 }
 public function __construct($tableName, Connection $connection, IReflection $reflection)
 {
     $this->tableName = $tableName;
     $this->databaseReflection = $reflection;
     $this->driver = $connection->getSupplementalDriver();
     $this->delimitedTable = $this->tryDelimite($tableName);
 }
 protected function reloadForeignKeys($table)
 {
     foreach ($this->connection->getSupplementalDriver()->getForeignKeys($table) as $row) {
         $this->structure['belongsTo'][strtolower($table)][$row['local']] = $row['table'];
         $this->structure['hasMany'][strtolower($row['table'])][$row['local'] . $table] = array($row['local'], $table);
     }
     if (isset($this->structure['belongsTo'][$table])) {
         uksort($this->structure['belongsTo'][$table], function ($a, $b) {
             return strlen($a) - strlen($b);
         });
     }
 }
示例#9
0
 protected function analyzeForeignKeys(&$structure, $table)
 {
     $lowerTable = strtolower($table);
     foreach ($this->connection->getSupplementalDriver()->getForeignKeys($table) as $row) {
         $structure['belongsTo'][$lowerTable][$row['local']] = $row['table'];
         $structure['hasMany'][strtolower($row['table'])][$table][] = $row['local'];
     }
     if (isset($structure['belongsTo'][$lowerTable])) {
         uksort($structure['belongsTo'][$lowerTable], function ($a, $b) {
             return strlen($a) - strlen($b);
         });
     }
 }
示例#10
0
	public function __construct(Connection $connection)
	{
		$this->connection = $connection;
		$this->driver = $connection->getSupplementalDriver();
		$this->arrayModes = array(
			'INSERT' => $this->driver->isSupported(ISupplementalDriver::SUPPORT_MULTI_INSERT_AS_SELECT) ? 'select' : 'values',
			'REPLACE' => 'values',
			'UPDATE' => 'assoc',
			'WHERE' => 'and',
			'HAVING' => 'and',
			'ORDER BY' => 'order',
			'GROUP BY' => 'order',
		);
	}
示例#11
0
 /**
  * Returns SQL query.
  *
  * @return string
  */
 public function buildSelectQuery()
 {
     $join = $this->buildJoins(implode(',', $this->conditions), true);
     $join += $this->buildJoins(implode(',', $this->select) . ",{$this->group},{$this->having}," . implode(',', $this->order));
     $prefix = $join ? "{$this->delimitedTable}." : '';
     if ($this->select) {
         $cols = $this->tryDelimite($this->removeExtraTables(implode(', ', $this->select)));
     } elseif ($prevAccessed = $this->selection->getPreviousAccessed()) {
         $cols = array_map(array($this->connection->getSupplementalDriver(), 'delimite'), array_keys(array_filter($prevAccessed)));
         $cols = $prefix . implode(', ' . $prefix, $cols);
     } else {
         $cols = $prefix . '*';
     }
     return "SELECT{$this->buildTopClause()} {$cols} FROM {$this->delimitedTable}" . implode($join) . $this->buildConditions();
 }
示例#12
0
 /**
  * @return string
  */
 public function getPrimarySequence()
 {
     if ($this->primarySequence === FALSE) {
         $this->primarySequence = NULL;
         $driver = $this->connection->getSupplementalDriver();
         if ($driver->isSupported(ISupplementalDriver::SUPPORT_SEQUENCE) && $this->primary !== NULL) {
             foreach ($driver->getColumns($this->name) as $column) {
                 if ($column['name'] === $this->primary) {
                     $this->primarySequence = $column['vendor']['sequence'];
                     break;
                 }
             }
         }
     }
     return $this->primarySequence;
 }
示例#13
0
 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     if (substr($queryString, 0, 2) === '::') {
         $connection->getPdo()->{substr($queryString, 2)}();
     } elseif ($queryString !== NULL) {
         $this->pdoStatement = $connection->getPdo()->prepare($queryString);
         $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
         $this->pdoStatement->execute($params);
     }
     $this->time = microtime(TRUE) - $time;
 }
 private function detectColumnTypes()
 {
     if ($this->types === null) {
         $this->types = array();
         if ($this->connection->getSupplementalDriver()->isSupported(ISupplementalDriver::META)) {
             // workaround for PHP bugs #53782, #54695
             $col = 0;
             while ($meta = $this->getColumnMeta($col++)) {
                 if (isset($meta['native_type'])) {
                     $this->types[$meta['name']] = Helpers::detectType($meta['native_type']);
                 }
             }
         }
     }
     return $this->types;
 }
示例#15
0
 private function detectColumnTypes()
 {
     if ($this->types === NULL) {
         $this->types = array();
         if ($this->connection->getSupplementalDriver()->isSupported(ISupplementalDriver::SUPPORT_COLUMNS_META)) {
             // workaround for PHP bugs #53782, #54695
             $count = $this->columnCount();
             for ($col = 0; $col < $count; $col++) {
                 $meta = $this->getColumnMeta($col);
                 if (isset($meta['native_type'])) {
                     $this->types[$meta['name']] = Helpers::detectType($meta['native_type']);
                 }
             }
         }
     }
     return $this->types;
 }
示例#16
0
 public function escapeIdentifier($value)
 {
     return $this->conn->getSupplementalDriver()->delimite($value);
 }
示例#17
0
 public function __construct(Connection $connection)
 {
     $this->connection = $connection;
     $this->driver = $connection->getSupplementalDriver();
 }
示例#18
0
 /** @internal */
 private function __testbench_ndb_connectToDatabase(Connection $db, $databaseName = NULL)
 {
     //connect to an existing database other than $this->_databaseName
     $container = $this->__testbench_ndb_getContainer();
     if ($databaseName === NULL) {
         $config = $container->parameters['testbench'];
         if (isset($config['dbname'])) {
             $databaseName = $config['dbname'];
         } elseif ($db->getSupplementalDriver() instanceof PgSqlDriver) {
             $databaseName = 'postgres';
         } else {
             throw new \LogicException('You should setup existing database name using testbench:dbname option.');
         }
     }
     $dsn = preg_replace('~dbname=[a-z0-9_-]+~i', "dbname={$databaseName}", $db->getDsn());
     $dbr = $db->getReflection();
     //:-(
     $params = $dbr->getProperty('params');
     $params->setAccessible(TRUE);
     $params = $params->getValue($db);
     $options = $dbr->getProperty('options');
     $options->setAccessible(TRUE);
     $options = $options->getValue($db);
     $db->disconnect();
     $db->__construct($dsn, $params[1], $params[2], $options);
     $db->connect();
 }
示例#19
0
	/**
	 * Normalizes result row.
	 * @param  array
	 * @return array
	 */
	public function normalizeRow($row)
	{
		return $this->connection->getSupplementalDriver()->normalizeRow($row, $this);
	}
示例#20
0
 function __construct($tableName, Connection $connection, IReflection $reflection)
 {
     $this->tableName = $tableName;
     $this->databaseReflection = $reflection;
     $this->driver = $connection->getSupplementalDriver();
     $this->driverName = $connection->getAttribute(\PDO::ATTR_DRIVER_NAME);
     $this->delimitedTable = $this->tryDelimite($tableName);
 }
示例#21
0
 /**
  * @param string $dns
  * @param string $username
  * @param string $password
  */
 function __construct($dns, $username, $password = NULL)
 {
     $this->connection = new Connection($dns, $username, $password);
     $this->driver = $this->connection->getSupplementalDriver();
 }
示例#22
0
 protected function tryDelimite($s)
 {
     return preg_match('#^[a-z_][a-z0-9_.]*$#i', $s) ? implode('.', array_map(array($this->connection->getSupplementalDriver(), 'delimite'), explode('.', $s))) : $s;
 }
示例#23
0
Nette\Object{private$connection;private$driver;private$params;private$remaining;private$counter;private$arrayMode;function
__construct(Connection$connection){$this->connection=$connection;$this->driver=$connection->getSupplementalDriver();}function
示例#24
0
implements\Iterator,\ArrayAccess,\Countable{protected$connection;protected$name;protected$primary;protected$rows;protected$data;protected$select=array();protected$where=array();protected$conditions=array();protected$parameters=array();protected$order=array();protected$limit=NULL;protected$offset=NULL;protected$group='';protected$having='';protected$checkReferenceNewKeys=FALSE;protected$referenced=array();protected$referencing=array();protected$accessed;protected$prevAccessed;protected$keys=array();protected$delimitedName;protected$delimitedPrimary;function
__construct($table,Nette\Database\Connection$connection){$this->name=$table;$this->connection=$connection;$this->primary=$connection->getDatabaseReflection()->getPrimary($table);$this->delimitedName=$this->tryDelimite($this->name);$this->delimitedPrimary=$connection->getSupplementalDriver()->delimite($this->primary);}function
示例#25
0
 function __construct($table, Nette\Database\Connection $connection)
 {
     $this->name = $table;
     $this->connection = $connection;
     $this->primary = $connection->getDatabaseReflection()->getPrimary($table);
     $this->delimitedName = $this->tryDelimite($this->name);
     $this->delimitedPrimary = $connection->getSupplementalDriver()->delimite($this->primary);
 }