mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-30 15:53:59 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		|  | @ -2,28 +2,29 @@ | |||
| /** | ||||
|  * MS SQL Server layer for DBO | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Model.Datasource.Database | ||||
|  * @since         CakePHP(tm) v 0.10.5.1790 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('DboSource', 'Model/Datasource'); | ||||
| 
 | ||||
| /** | ||||
|  * Dbo driver for SQLServer | ||||
|  * Dbo layer for Microsoft's official SQLServer driver | ||||
|  * | ||||
|  * A Dbo driver for SQLServer 2008 and higher.  Requires the `sqlsrv` | ||||
|  * and `pdo_sqlsrv` extensions to be enabled. | ||||
|  * A Dbo layer for MS SQL Server 2005 and higher. Requires the | ||||
|  * `pdo_sqlsrv` extension to be enabled. | ||||
|  * | ||||
|  * @link http://www.php.net/manual/en/ref.pdo-sqlsrv.php | ||||
|  * | ||||
|  * @package       Cake.Model.Datasource.Database | ||||
|  */ | ||||
|  | @ -51,7 +52,7 @@ class Sqlserver extends DboSource { | |||
| 	public $endQuote = "]"; | ||||
| 
 | ||||
| /** | ||||
|  * Creates a map between field aliases and numeric indexes.  Workaround for the | ||||
|  * Creates a map between field aliases and numeric indexes. Workaround for the | ||||
|  * SQL Server driver's 30-character column name limitation. | ||||
|  * | ||||
|  * @var array | ||||
|  | @ -77,6 +78,7 @@ class Sqlserver extends DboSource { | |||
| 		'password' => '', | ||||
| 		'database' => 'cake', | ||||
| 		'schema' => '', | ||||
| 		'flags' => array() | ||||
| 	); | ||||
| 
 | ||||
| /** | ||||
|  | @ -86,41 +88,50 @@ class Sqlserver extends DboSource { | |||
|  */ | ||||
| 	public $columns = array( | ||||
| 		'primary_key' => array('name' => 'IDENTITY (1, 1) NOT NULL'), | ||||
| 		'string'	=> array('name' => 'nvarchar', 'limit' => '255'), | ||||
| 		'text'		=> array('name' => 'nvarchar', 'limit' => 'MAX'), | ||||
| 		'integer'	=> array('name' => 'int', 'formatter' => 'intval'), | ||||
| 		'float'		=> array('name' => 'numeric', 'formatter' => 'floatval'), | ||||
| 		'datetime'	=> array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), | ||||
| 		'string' => array('name' => 'nvarchar', 'limit' => '255'), | ||||
| 		'text' => array('name' => 'nvarchar', 'limit' => 'MAX'), | ||||
| 		'integer' => array('name' => 'int', 'formatter' => 'intval'), | ||||
| 		'biginteger' => array('name' => 'bigint'), | ||||
| 		'numeric' => array('name' => 'decimal', 'formatter' => 'floatval'), | ||||
| 		'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), | ||||
| 		'float' => array('name' => 'float', 'formatter' => 'floatval'), | ||||
| 		'real' => array('name' => 'float', 'formatter' => 'floatval'), | ||||
| 		'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), | ||||
| 		'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), | ||||
| 		'time'		=> array('name' => 'datetime', 'format' => 'H:i:s', 'formatter' => 'date'), | ||||
| 		'date'		=> array('name' => 'datetime', 'format' => 'Y-m-d', 'formatter' => 'date'), | ||||
| 		'binary'	=> array('name' => 'varbinary'), | ||||
| 		'boolean'	=> array('name' => 'bit') | ||||
| 		'time' => array('name' => 'datetime', 'format' => 'H:i:s', 'formatter' => 'date'), | ||||
| 		'date' => array('name' => 'datetime', 'format' => 'Y-m-d', 'formatter' => 'date'), | ||||
| 		'binary' => array('name' => 'varbinary'), | ||||
| 		'boolean' => array('name' => 'bit') | ||||
| 	); | ||||
| 
 | ||||
| /** | ||||
|  * Magic column name used to provide pagination support for SQLServer 2008 | ||||
|  * which lacks proper limit/offset support. | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	const ROW_COUNTER = '_cake_page_rownum_'; | ||||
| 
 | ||||
| /** | ||||
|  * Connects to the database using options in the given configuration array. | ||||
|  * | ||||
|  * @return boolean True if the database could be connected, else false | ||||
|  * @return bool True if the database could be connected, else false | ||||
|  * @throws MissingConnectionException | ||||
|  */ | ||||
| 	public function connect() { | ||||
| 		$config = $this->config; | ||||
| 		$this->connected = false; | ||||
| 
 | ||||
| 		$flags = $config['flags'] + array( | ||||
| 			PDO::ATTR_PERSISTENT => $config['persistent'], | ||||
| 			PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION | ||||
| 		); | ||||
| 
 | ||||
| 		if (!empty($config['encoding'])) { | ||||
| 			$flags[PDO::SQLSRV_ATTR_ENCODING] = $config['encoding']; | ||||
| 		} | ||||
| 
 | ||||
| 		try { | ||||
| 			$flags = array( | ||||
| 				PDO::ATTR_PERSISTENT => $config['persistent'], | ||||
| 				PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION | ||||
| 			); | ||||
| 			if (!empty($config['encoding'])) { | ||||
| 				$flags[PDO::SQLSRV_ATTR_ENCODING] = $config['encoding']; | ||||
| 			} | ||||
| 			$this->_connection = new PDO( | ||||
| 				"sqlsrv:server={$config['host']};Database={$config['database']}", | ||||
| 				$config['login'], | ||||
|  | @ -128,6 +139,11 @@ class Sqlserver extends DboSource { | |||
| 				$flags | ||||
| 			); | ||||
| 			$this->connected = true; | ||||
| 			if (!empty($config['settings'])) { | ||||
| 				foreach ($config['settings'] as $key => $value) { | ||||
| 					$this->_execute("SET $key $value"); | ||||
| 				} | ||||
| 			} | ||||
| 		} catch (PDOException $e) { | ||||
| 			throw new MissingConnectionException(array( | ||||
| 				'class' => get_class($this), | ||||
|  | @ -141,7 +157,7 @@ class Sqlserver extends DboSource { | |||
| /** | ||||
|  * Check that PDO SQL Server is installed/loaded | ||||
|  * | ||||
|  * @return boolean | ||||
|  * @return bool | ||||
|  */ | ||||
| 	public function enabled() { | ||||
| 		return in_array('sqlsrv', PDO::getAvailableDrivers()); | ||||
|  | @ -150,7 +166,7 @@ class Sqlserver extends DboSource { | |||
| /** | ||||
|  * Returns an array of sources (tables) in the database. | ||||
|  * | ||||
|  * @param mixed $data | ||||
|  * @param mixed $data The names | ||||
|  * @return array Array of table names in the database | ||||
|  */ | ||||
| 	public function listSources($data = null) { | ||||
|  | @ -163,17 +179,16 @@ class Sqlserver extends DboSource { | |||
| 		if (!$result) { | ||||
| 			$result->closeCursor(); | ||||
| 			return array(); | ||||
| 		} else { | ||||
| 			$tables = array(); | ||||
| 
 | ||||
| 			while ($line = $result->fetch(PDO::FETCH_NUM)) { | ||||
| 				$tables[] = $line[0]; | ||||
| 			} | ||||
| 
 | ||||
| 			$result->closeCursor(); | ||||
| 			parent::listSources($tables); | ||||
| 			return $tables; | ||||
| 		} | ||||
| 		$tables = array(); | ||||
| 
 | ||||
| 		while ($line = $result->fetch(PDO::FETCH_NUM)) { | ||||
| 			$tables[] = $line[0]; | ||||
| 		} | ||||
| 
 | ||||
| 		$result->closeCursor(); | ||||
| 		parent::listSources($tables); | ||||
| 		return $tables; | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -184,25 +199,30 @@ class Sqlserver extends DboSource { | |||
|  * @throws CakeException | ||||
|  */ | ||||
| 	public function describe($model) { | ||||
| 		$table = $this->fullTableName($model, false); | ||||
| 		$cache = parent::describe($table); | ||||
| 		if ($cache != null) { | ||||
| 		$table = $this->fullTableName($model, false, false); | ||||
| 		$fulltable = $this->fullTableName($model, false, true); | ||||
| 
 | ||||
| 		$cache = parent::describe($fulltable); | ||||
| 		if ($cache) { | ||||
| 			return $cache; | ||||
| 		} | ||||
| 
 | ||||
| 		$fields = array(); | ||||
| 		$table = $this->fullTableName($model, false); | ||||
| 		$schema = is_object($model) ? $model->schemaName : false; | ||||
| 
 | ||||
| 		$cols = $this->_execute( | ||||
| 			"SELECT
 | ||||
| 				COLUMN_NAME as Field, | ||||
| 				DATA_TYPE as Type, | ||||
| 				COL_LENGTH('" . $table . "', COLUMN_NAME) as Length, | ||||
| 				COL_LENGTH('" . ($schema ? $fulltable : $table) . "', COLUMN_NAME) as Length, | ||||
| 				IS_NULLABLE As [Null], | ||||
| 				COLUMN_DEFAULT as [Default], | ||||
| 				COLUMNPROPERTY(OBJECT_ID('" . $table . "'), COLUMN_NAME, 'IsIdentity') as [Key], | ||||
| 				COLUMNPROPERTY(OBJECT_ID('" . ($schema ? $fulltable : $table) . "'), COLUMN_NAME, 'IsIdentity') as [Key], | ||||
| 				NUMERIC_SCALE as Size | ||||
| 			FROM INFORMATION_SCHEMA.COLUMNS | ||||
| 			WHERE TABLE_NAME = '" . $table . "'" | ||||
| 			WHERE TABLE_NAME = '" . $table . "'" . ($schema ? " AND TABLE_SCHEMA = '" . $schema . "'" : '')
 | ||||
| 		); | ||||
| 
 | ||||
| 		if (!$cols) { | ||||
| 			throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $table)); | ||||
| 		} | ||||
|  | @ -212,18 +232,24 @@ class Sqlserver extends DboSource { | |||
| 			$fields[$field] = array( | ||||
| 				'type' => $this->column($column), | ||||
| 				'null' => ($column->Null === 'YES' ? true : false), | ||||
| 				'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column->Default), | ||||
| 				'default' => $column->Default, | ||||
| 				'length' => $this->length($column), | ||||
| 				'key' => ($column->Key == '1') ? 'primary' : false | ||||
| 			); | ||||
| 
 | ||||
| 			if ($fields[$field]['default'] === 'null') { | ||||
| 				$fields[$field]['default'] = null; | ||||
| 			} else { | ||||
| 			} | ||||
| 			if ($fields[$field]['default'] !== null) { | ||||
| 				$fields[$field]['default'] = preg_replace( | ||||
| 					"/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", | ||||
| 					"$1", | ||||
| 					$fields[$field]['default'] | ||||
| 				); | ||||
| 				$this->value($fields[$field]['default'], $fields[$field]['type']); | ||||
| 			} | ||||
| 
 | ||||
| 			if ($fields[$field]['key'] !== false && $fields[$field]['type'] == 'integer') { | ||||
| 			if ($fields[$field]['key'] !== false && $fields[$field]['type'] === 'integer') { | ||||
| 				$fields[$field]['length'] = 11; | ||||
| 			} elseif ($fields[$field]['key'] === false) { | ||||
| 				unset($fields[$field]['key']); | ||||
|  | @ -231,7 +257,7 @@ class Sqlserver extends DboSource { | |||
| 			if (in_array($fields[$field]['type'], array('date', 'time', 'datetime', 'timestamp'))) { | ||||
| 				$fields[$field]['length'] = null; | ||||
| 			} | ||||
| 			if ($fields[$field]['type'] == 'float' && !empty($column->Size)) { | ||||
| 			if ($fields[$field]['type'] === 'float' && !empty($column->Size)) { | ||||
| 				$fields[$field]['length'] = $fields[$field]['length'] . ',' . $column->Size; | ||||
| 			} | ||||
| 		} | ||||
|  | @ -243,10 +269,10 @@ class Sqlserver extends DboSource { | |||
| /** | ||||
|  * Generates the fields list of an SQL query. | ||||
|  * | ||||
|  * @param Model $model | ||||
|  * @param Model $model The model to get fields for. | ||||
|  * @param string $alias Alias table name | ||||
|  * @param array $fields | ||||
|  * @param boolean $quote | ||||
|  * @param array $fields The fields so far. | ||||
|  * @param bool $quote Whether or not to quote identfiers. | ||||
|  * @return array | ||||
|  */ | ||||
| 	public function fields(Model $model, $alias = null, $fields = array(), $quote = true) { | ||||
|  | @ -261,13 +287,13 @@ class Sqlserver extends DboSource { | |||
| 			for ($i = 0; $i < $count; $i++) { | ||||
| 				$prepend = ''; | ||||
| 
 | ||||
| 				if (strpos($fields[$i], 'DISTINCT') !== false) { | ||||
| 				if (strpos($fields[$i], 'DISTINCT') !== false && strpos($fields[$i], 'COUNT') === false) { | ||||
| 					$prepend = 'DISTINCT '; | ||||
| 					$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i])); | ||||
| 				} | ||||
| 
 | ||||
| 				if (!preg_match('/\s+AS\s+/i', $fields[$i])) { | ||||
| 					if (substr($fields[$i], -1) == '*') { | ||||
| 					if (substr($fields[$i], -1) === '*') { | ||||
| 						if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') { | ||||
| 							$build = explode('.', $fields[$i]); | ||||
| 							$AssociatedModel = $model->{$build[0]}; | ||||
|  | @ -282,7 +308,7 @@ class Sqlserver extends DboSource { | |||
| 
 | ||||
| 					if (strpos($fields[$i], '.') === false) { | ||||
| 						$this->_fieldMappings[$alias . '__' . $fields[$i]] = $alias . '.' . $fields[$i]; | ||||
| 						$fieldName  = $this->name($alias . '.' . $fields[$i]); | ||||
| 						$fieldName = $this->name($alias . '.' . $fields[$i]); | ||||
| 						$fieldAlias = $this->name($alias . '__' . $fields[$i]); | ||||
| 					} else { | ||||
| 						$build = explode('.', $fields[$i]); | ||||
|  | @ -295,7 +321,7 @@ class Sqlserver extends DboSource { | |||
| 						$fieldName = $this->name($name); | ||||
| 						$fieldAlias = $this->name($alias); | ||||
| 					} | ||||
| 					if ($model->getColumnType($fields[$i]) == 'datetime') { | ||||
| 					if ($model->getColumnType($fields[$i]) === 'datetime') { | ||||
| 						$fieldName = "CONVERT(VARCHAR(20), {$fieldName}, 20)"; | ||||
| 					} | ||||
| 					$fields[$i] = "{$fieldName} AS {$fieldAlias}"; | ||||
|  | @ -303,9 +329,8 @@ class Sqlserver extends DboSource { | |||
| 				$result[] = $prepend . $fields[$i]; | ||||
| 			} | ||||
| 			return $result; | ||||
| 		} else { | ||||
| 			return $fields; | ||||
| 		} | ||||
| 		return $fields; | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -313,9 +338,9 @@ class Sqlserver extends DboSource { | |||
|  * Removes Identity (primary key) column from update data before returning to parent, if | ||||
|  * value is empty. | ||||
|  * | ||||
|  * @param Model $model | ||||
|  * @param array $fields | ||||
|  * @param array $values | ||||
|  * @param Model $model The model to insert into. | ||||
|  * @param array $fields The fields to set. | ||||
|  * @param array $values The values to set. | ||||
|  * @return array | ||||
|  */ | ||||
| 	public function create(Model $model, $fields = null, $values = null) { | ||||
|  | @ -342,10 +367,10 @@ class Sqlserver extends DboSource { | |||
|  * Generates and executes an SQL UPDATE statement for given model, fields, and values. | ||||
|  * Removes Identity (primary key) column from update data before returning to parent. | ||||
|  * | ||||
|  * @param Model $model | ||||
|  * @param array $fields | ||||
|  * @param array $values | ||||
|  * @param mixed $conditions | ||||
|  * @param Model $model The model to update. | ||||
|  * @param array $fields The fields to set. | ||||
|  * @param array $values The values to set. | ||||
|  * @param mixed $conditions The conditions to use. | ||||
|  * @return array | ||||
|  */ | ||||
| 	public function update(Model $model, $fields = array(), $values = null, $conditions = null) { | ||||
|  | @ -364,8 +389,8 @@ class Sqlserver extends DboSource { | |||
| /** | ||||
|  * Returns a limit statement in the correct format for the particular database. | ||||
|  * | ||||
|  * @param integer $limit Limit of results returned | ||||
|  * @param integer $offset Offset from which to start results | ||||
|  * @param int $limit Limit of results returned | ||||
|  * @param int $offset Offset from which to start results | ||||
|  * @return string SQL limit/offset statement | ||||
|  */ | ||||
| 	public function limit($limit, $offset = null) { | ||||
|  | @ -374,9 +399,9 @@ class Sqlserver extends DboSource { | |||
| 			if (!strpos(strtolower($limit), 'top') || strpos(strtolower($limit), 'top') === 0) { | ||||
| 				$rt = ' TOP'; | ||||
| 			} | ||||
| 			$rt .= ' ' . $limit; | ||||
| 			$rt .= sprintf(' %u', $limit); | ||||
| 			if (is_int($offset) && $offset > 0) { | ||||
| 				$rt = ' OFFSET ' . intval($offset) . ' ROWS FETCH FIRST ' . intval($limit) . ' ROWS ONLY'; | ||||
| 				$rt = sprintf(' OFFSET %u ROWS FETCH FIRST %u ROWS ONLY', $offset, $limit); | ||||
| 			} | ||||
| 			return $rt; | ||||
| 		} | ||||
|  | @ -398,15 +423,18 @@ class Sqlserver extends DboSource { | |||
| 			$col = $real->Type; | ||||
| 		} | ||||
| 
 | ||||
| 		if ($col == 'datetime2') { | ||||
| 		if ($col === 'datetime2') { | ||||
| 			return 'datetime'; | ||||
| 		} | ||||
| 		if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) { | ||||
| 			return $col; | ||||
| 		} | ||||
| 		if ($col == 'bit') { | ||||
| 		if ($col === 'bit') { | ||||
| 			return 'boolean'; | ||||
| 		} | ||||
| 		if (strpos($col, 'bigint') !== false) { | ||||
| 			return 'biginteger'; | ||||
| 		} | ||||
| 		if (strpos($col, 'int') !== false) { | ||||
| 			return 'integer'; | ||||
| 		} | ||||
|  | @ -419,12 +447,15 @@ class Sqlserver extends DboSource { | |||
| 		if (strpos($col, 'text') !== false) { | ||||
| 			return 'text'; | ||||
| 		} | ||||
| 		if (strpos($col, 'binary') !== false || $col == 'image') { | ||||
| 		if (strpos($col, 'binary') !== false || $col === 'image') { | ||||
| 			return 'binary'; | ||||
| 		} | ||||
| 		if (in_array($col, array('float', 'real', 'decimal', 'numeric'))) { | ||||
| 		if (in_array($col, array('float', 'real'))) { | ||||
| 			return 'float'; | ||||
| 		} | ||||
| 		if (in_array($col, array('decimal', 'numeric'))) { | ||||
| 			return 'decimal'; | ||||
| 		} | ||||
| 		return 'text'; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -443,6 +474,9 @@ class Sqlserver extends DboSource { | |||
| 			if (in_array($length->Type, array('nchar', 'nvarchar'))) { | ||||
| 				return floor($length->Length / 2); | ||||
| 			} | ||||
| 			if ($length->Type === 'text') { | ||||
| 				return null; | ||||
| 			} | ||||
| 			return $length->Length; | ||||
| 		} | ||||
| 		return parent::length($length); | ||||
|  | @ -451,7 +485,7 @@ class Sqlserver extends DboSource { | |||
| /** | ||||
|  * Builds a map of the columns contained in a result | ||||
|  * | ||||
|  * @param PDOStatement $results | ||||
|  * @param PDOStatement $results The result to modify. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function resultSet($results) { | ||||
|  | @ -474,7 +508,7 @@ class Sqlserver extends DboSource { | |||
| 			} else { | ||||
| 				$map = array(0, $name); | ||||
| 			} | ||||
| 			$map[] = ($column['sqlsrv:decl_type'] == 'bit') ? 'boolean' : $column['native_type']; | ||||
| 			$map[] = ($column['sqlsrv:decl_type'] === 'bit') ? 'boolean' : $column['native_type']; | ||||
| 			$this->map[$index++] = $map; | ||||
| 		} | ||||
| 	} | ||||
|  | @ -506,25 +540,24 @@ class Sqlserver extends DboSource { | |||
| 				if (version_compare($this->getVersion(), '11', '<') && preg_match('/FETCH\sFIRST\s+([0-9]+)/i', $limit, $offset)) { | ||||
| 					preg_match('/OFFSET\s*(\d+)\s*.*?(\d+)\s*ROWS/', $limit, $limitOffset); | ||||
| 
 | ||||
| 					$limit = 'TOP ' . intval($limitOffset[2]); | ||||
| 					$page = intval($limitOffset[1] / $limitOffset[2]); | ||||
| 					$offset = intval($limitOffset[2] * $page); | ||||
| 					$limit = 'TOP ' . (int)$limitOffset[2]; | ||||
| 					$page = (int)($limitOffset[1] / $limitOffset[2]); | ||||
| 					$offset = (int)($limitOffset[2] * $page); | ||||
| 
 | ||||
| 					$rowCounter = self::ROW_COUNTER; | ||||
| 					return " | ||||
| 						SELECT {$limit} * FROM ( | ||||
| 					$rowCounter = static::ROW_COUNTER; | ||||
| 					$sql = "SELECT {$limit} * FROM (
 | ||||
| 							SELECT {$fields}, ROW_NUMBER() OVER ({$order}) AS {$rowCounter} | ||||
| 							FROM {$table} {$alias} {$joins} {$conditions} {$group} | ||||
| 						) AS _cake_paging_ | ||||
| 						WHERE _cake_paging_.{$rowCounter} > {$offset} | ||||
| 						ORDER BY _cake_paging_.{$rowCounter} | ||||
| 					";
 | ||||
| 				} elseif (strpos($limit, 'FETCH') !== false) { | ||||
| 					return "SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}"; | ||||
| 				} else { | ||||
| 					return "SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}"; | ||||
| 					return trim($sql); | ||||
| 				} | ||||
| 			break; | ||||
| 				if (strpos($limit, 'FETCH') !== false) { | ||||
| 					return trim("SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}"); | ||||
| 				} | ||||
| 				return trim("SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}"); | ||||
| 			case "schema": | ||||
| 				extract($data); | ||||
| 
 | ||||
|  | @ -540,7 +573,7 @@ class Sqlserver extends DboSource { | |||
| 						${$var} = "\t" . implode(",\n\t", array_filter(${$var})); | ||||
| 					} | ||||
| 				} | ||||
| 				return "CREATE TABLE {$table} (\n{$columns});\n{$indexes}"; | ||||
| 				return trim("CREATE TABLE {$table} (\n{$columns});\n{$indexes}"); | ||||
| 			default: | ||||
| 				return parent::renderStatement($type, $data); | ||||
| 		} | ||||
|  | @ -551,12 +584,14 @@ class Sqlserver extends DboSource { | |||
|  * | ||||
|  * @param string $data String to be prepared for use in an SQL statement | ||||
|  * @param string $column The column into which this data will be inserted | ||||
|  * @param bool $null Column allows NULL values | ||||
|  * @return string Quoted and escaped data | ||||
|  */ | ||||
| 	public function value($data, $column = null) { | ||||
| 		if (is_array($data) || is_object($data)) { | ||||
| 			return parent::value($data, $column); | ||||
| 		} elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { | ||||
| 	public function value($data, $column = null, $null = true) { | ||||
| 		if ($data === null || is_array($data) || is_object($data)) { | ||||
| 			return parent::value($data, $column, $null); | ||||
| 		} | ||||
| 		if (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { | ||||
| 			return $data; | ||||
| 		} | ||||
| 
 | ||||
|  | @ -569,7 +604,7 @@ class Sqlserver extends DboSource { | |||
| 			case 'text': | ||||
| 				return 'N' . $this->_connection->quote($data, PDO::PARAM_STR); | ||||
| 			default: | ||||
| 				return parent::value($data, $column); | ||||
| 				return parent::value($data, $column, $null); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  | @ -577,10 +612,10 @@ class Sqlserver extends DboSource { | |||
|  * Returns an array of all result rows for a given SQL query. | ||||
|  * Returns false if no rows matched. | ||||
|  * | ||||
|  * @param Model $model | ||||
|  * @param array $queryData | ||||
|  * @param integer $recursive | ||||
|  * @return array Array of resultset rows, or false if no rows matched | ||||
|  * @param Model $model The model to read from | ||||
|  * @param array $queryData The query data | ||||
|  * @param int $recursive How many layers to go. | ||||
|  * @return array|false Array of resultset rows, or false if no rows matched | ||||
|  */ | ||||
| 	public function read(Model $model, $queryData = array(), $recursive = null) { | ||||
| 		$results = parent::read($model, $queryData, $recursive); | ||||
|  | @ -599,11 +634,11 @@ class Sqlserver extends DboSource { | |||
| 			$resultRow = array(); | ||||
| 			foreach ($this->map as $col => $meta) { | ||||
| 				list($table, $column, $type) = $meta; | ||||
| 				if ($table === 0 && $column === self::ROW_COUNTER) { | ||||
| 				if ($table === 0 && $column === static::ROW_COUNTER) { | ||||
| 					continue; | ||||
| 				} | ||||
| 				$resultRow[$table][$column] = $row[$col]; | ||||
| 				if ($type === 'boolean' && !is_null($row[$col])) { | ||||
| 				if ($type === 'boolean' && $row[$col] !== null) { | ||||
| 					$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]); | ||||
| 				} | ||||
| 			} | ||||
|  | @ -616,14 +651,14 @@ class Sqlserver extends DboSource { | |||
| /** | ||||
|  * Inserts multiple values into a table | ||||
|  * | ||||
|  * @param string $table | ||||
|  * @param string $fields | ||||
|  * @param array $values | ||||
|  * @param string $table The table to insert into. | ||||
|  * @param string $fields The fields to set. | ||||
|  * @param array $values The values to set. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function insertMulti($table, $fields, $values) { | ||||
| 		$primaryKey = $this->_getPrimaryKey($table); | ||||
| 		$hasPrimaryKey = $primaryKey != null && ( | ||||
| 		$hasPrimaryKey = $primaryKey && ( | ||||
| 			(is_array($fields) && in_array($primaryKey, $fields) | ||||
| 			|| (is_string($fields) && strpos($fields, $this->startQuote . $primaryKey . $this->endQuote) !== false)) | ||||
| 		); | ||||
|  | @ -649,7 +684,7 @@ class Sqlserver extends DboSource { | |||
|  */ | ||||
| 	public function buildColumn($column) { | ||||
| 		$result = parent::buildColumn($column); | ||||
| 		$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', $result); | ||||
| 		$result = preg_replace('/(bigint|int|integer)\([0-9]+\)/i', '$1', $result); | ||||
| 		$result = preg_replace('/(bit)\([0-9]+\)/i', '$1', $result); | ||||
| 		if (strpos($result, 'DEFAULT NULL') !== false) { | ||||
| 			if (isset($column['default']) && $column['default'] === '') { | ||||
|  | @ -657,7 +692,7 @@ class Sqlserver extends DboSource { | |||
| 			} else { | ||||
| 				$result = str_replace('DEFAULT NULL', 'NULL', $result); | ||||
| 			} | ||||
| 		} elseif (array_keys($column) == array('type', 'name')) { | ||||
| 		} elseif (array_keys($column) === array('type', 'name')) { | ||||
| 			$result .= ' NULL'; | ||||
| 		} elseif (strpos($result, "DEFAULT N'")) { | ||||
| 			$result = str_replace("DEFAULT N'", "DEFAULT '", $result); | ||||
|  | @ -668,15 +703,15 @@ class Sqlserver extends DboSource { | |||
| /** | ||||
|  * Format indexes for create table | ||||
|  * | ||||
|  * @param array $indexes | ||||
|  * @param string $table | ||||
|  * @param array $indexes The indexes to build | ||||
|  * @param string $table The table to make indexes for. | ||||
|  * @return string | ||||
|  */ | ||||
| 	public function buildIndex($indexes, $table = null) { | ||||
| 		$join = array(); | ||||
| 
 | ||||
| 		foreach ($indexes as $name => $value) { | ||||
| 			if ($name == 'PRIMARY') { | ||||
| 			if ($name === 'PRIMARY') { | ||||
| 				$join[] = 'PRIMARY KEY (' . $this->name($value['column']) . ')'; | ||||
| 			} elseif (isset($value['unique']) && $value['unique']) { | ||||
| 				$out = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE"; | ||||
|  | @ -702,7 +737,7 @@ class Sqlserver extends DboSource { | |||
| 	protected function _getPrimaryKey($model) { | ||||
| 		$schema = $this->describe($model); | ||||
| 		foreach ($schema as $field => $props) { | ||||
| 			if (isset($props['key']) && $props['key'] == 'primary') { | ||||
| 			if (isset($props['key']) && $props['key'] === 'primary') { | ||||
| 				return $field; | ||||
| 			} | ||||
| 		} | ||||
|  | @ -713,8 +748,8 @@ class Sqlserver extends DboSource { | |||
|  * Returns number of affected rows in previous database operation. If no previous operation exists, | ||||
|  * this returns false. | ||||
|  * | ||||
|  * @param mixed $source | ||||
|  * @return integer Number of affected rows | ||||
|  * @param mixed $source Unused | ||||
|  * @return int Number of affected rows | ||||
|  */ | ||||
| 	public function lastAffected($source = null) { | ||||
| 		$affected = parent::lastAffected(); | ||||
|  | @ -736,7 +771,8 @@ class Sqlserver extends DboSource { | |||
|  */ | ||||
| 	protected function _execute($sql, $params = array(), $prepareOptions = array()) { | ||||
| 		$this->_lastAffected = false; | ||||
| 		if (strncasecmp($sql, 'SELECT', 6) == 0 || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) { | ||||
| 		$sql = trim($sql); | ||||
| 		if (strncasecmp($sql, 'SELECT', 6) === 0 || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) { | ||||
| 			$prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL); | ||||
| 			return parent::_execute($sql, $params, $prepareOptions); | ||||
| 		} | ||||
|  | @ -760,21 +796,13 @@ class Sqlserver extends DboSource { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Generate a "drop table" statement for the given Schema object | ||||
|  * Generate a "drop table" statement for the given table | ||||
|  * | ||||
|  * @param CakeSchema $schema An instance of a subclass of CakeSchema | ||||
|  * @param string $table Optional.  If specified only the table name given will be generated. | ||||
|  *   Otherwise, all tables defined in the schema are generated. | ||||
|  * @return string | ||||
|  * @param type $table Name of the table to drop | ||||
|  * @return string Drop table SQL statement | ||||
|  */ | ||||
| 	public function dropSchema(CakeSchema $schema, $table = null) { | ||||
| 		$out = ''; | ||||
| 		foreach ($schema->tables as $curTable => $columns) { | ||||
| 			if (!$table || $table == $curTable) { | ||||
| 				$out .= "IF OBJECT_ID('" . $this->fullTableName($curTable, false) . "', 'U') IS NOT NULL DROP TABLE " . $this->fullTableName($curTable) . ";\n"; | ||||
| 			} | ||||
| 		} | ||||
| 		return $out; | ||||
| 	protected function _dropTable($table) { | ||||
| 		return "IF OBJECT_ID('" . $this->fullTableName($table, false) . "', 'U') IS NOT NULL DROP TABLE " . $this->fullTableName($table) . ";"; | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko