mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-05 23:53:38 +02: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,23 +2,22 @@
|
|||
/**
|
||||
* SQLite 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.9.0
|
||||
* @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');
|
||||
App::uses('String', 'Utility');
|
||||
App::uses('CakeText', 'Utility');
|
||||
|
||||
/**
|
||||
* DBO implementation for the SQLite3 DBMS.
|
||||
|
@ -57,7 +56,8 @@ class Sqlite extends DboSource {
|
|||
*/
|
||||
protected $_baseConfig = array(
|
||||
'persistent' => false,
|
||||
'database' => null
|
||||
'database' => null,
|
||||
'flags' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,9 @@ class Sqlite extends DboSource {
|
|||
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||
'text' => array('name' => 'text'),
|
||||
'integer' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'),
|
||||
'biginteger' => array('name' => 'bigint', 'limit' => 20),
|
||||
'float' => array('name' => 'float', 'formatter' => 'floatval'),
|
||||
'decimal' => array('name' => 'decimal', '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' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'),
|
||||
|
@ -100,12 +102,12 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Connects to the database using config['database'] as a filename.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @throws MissingConnectionException
|
||||
*/
|
||||
public function connect() {
|
||||
$config = $this->config;
|
||||
$flags = array(
|
||||
$flags = $config['flags'] + array(
|
||||
PDO::ATTR_PERSISTENT => $config['persistent'],
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
@ -124,7 +126,7 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Check whether the SQLite extension is installed/loaded
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function enabled() {
|
||||
return in_array('sqlite', PDO::getAvailableDrivers());
|
||||
|
@ -133,12 +135,12 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $data Unused.
|
||||
* @return array Array of table names in the database
|
||||
*/
|
||||
public function listSources($data = null) {
|
||||
$cache = parent::listSources();
|
||||
if ($cache != null) {
|
||||
if ($cache) {
|
||||
return $cache;
|
||||
}
|
||||
|
||||
|
@ -146,14 +148,14 @@ class Sqlite extends DboSource {
|
|||
|
||||
if (!$result || empty($result)) {
|
||||
return array();
|
||||
} else {
|
||||
$tables = array();
|
||||
foreach ($result as $table) {
|
||||
$tables[] = $table[0]['name'];
|
||||
}
|
||||
parent::listSources($tables);
|
||||
return $tables;
|
||||
}
|
||||
|
||||
$tables = array();
|
||||
foreach ($result as $table) {
|
||||
$tables[] = $table[0]['name'];
|
||||
}
|
||||
parent::listSources($tables);
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,7 +167,7 @@ class Sqlite extends DboSource {
|
|||
public function describe($model) {
|
||||
$table = $this->fullTableName($model, false, false);
|
||||
$cache = parent::describe($table);
|
||||
if ($cache != null) {
|
||||
if ($cache) {
|
||||
return $cache;
|
||||
}
|
||||
$fields = array();
|
||||
|
@ -183,6 +185,9 @@ class Sqlite extends DboSource {
|
|||
'default' => $default,
|
||||
'length' => $this->length($column['type'])
|
||||
);
|
||||
if (in_array($fields[$column['name']]['type'], array('timestamp', 'datetime')) && strtoupper($fields[$column['name']]['default']) === 'CURRENT_TIMESTAMP') {
|
||||
$fields[$column['name']]['default'] = null;
|
||||
}
|
||||
if ($column['pk'] == 1) {
|
||||
$fields[$column['name']]['key'] = $this->index['PRI'];
|
||||
$fields[$column['name']]['null'] = false;
|
||||
|
@ -200,10 +205,10 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Generates and executes an SQL UPDATE statement for given model, fields, and values.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param array $fields
|
||||
* @param array $values
|
||||
* @param mixed $conditions
|
||||
* @param Model $model The model instance to update.
|
||||
* @param array $fields The fields to update.
|
||||
* @param array $values The values to set columns to.
|
||||
* @param mixed $conditions array of conditions to use.
|
||||
* @return array
|
||||
*/
|
||||
public function update(Model $model, $fields = array(), $values = null, $conditions = null) {
|
||||
|
@ -225,10 +230,12 @@ class Sqlite extends DboSource {
|
|||
* primary key, where applicable.
|
||||
*
|
||||
* @param string|Model $table A string or model class representing the table to be truncated
|
||||
* @return boolean SQL TRUNCATE TABLE statement, false if not applicable.
|
||||
* @return bool SQL TRUNCATE TABLE statement, false if not applicable.
|
||||
*/
|
||||
public function truncate($table) {
|
||||
$this->_execute('DELETE FROM sqlite_sequence where name=' . $this->startQuote . $this->fullTableName($table, false, false) . $this->endQuote);
|
||||
if (in_array('sqlite_sequence', $this->listSources())) {
|
||||
$this->_execute('DELETE FROM sqlite_sequence where name=' . $this->startQuote . $this->fullTableName($table, false, false) . $this->endQuote);
|
||||
}
|
||||
return $this->execute('DELETE FROM ' . $this->fullTableName($table));
|
||||
}
|
||||
|
||||
|
@ -248,14 +255,26 @@ class Sqlite extends DboSource {
|
|||
}
|
||||
|
||||
$col = strtolower(str_replace(')', '', $real));
|
||||
$limit = null;
|
||||
if (strpos($col, '(') !== false) {
|
||||
list($col, $limit) = explode('(', $col);
|
||||
list($col) = explode('(', $col);
|
||||
}
|
||||
|
||||
if (in_array($col, array('text', 'integer', 'float', 'boolean', 'timestamp', 'date', 'datetime', 'time'))) {
|
||||
$standard = array(
|
||||
'text',
|
||||
'integer',
|
||||
'float',
|
||||
'boolean',
|
||||
'timestamp',
|
||||
'date',
|
||||
'datetime',
|
||||
'time'
|
||||
);
|
||||
if (in_array($col, $standard)) {
|
||||
return $col;
|
||||
}
|
||||
if ($col === 'bigint') {
|
||||
return 'biginteger';
|
||||
}
|
||||
if (strpos($col, 'char') !== false) {
|
||||
return 'string';
|
||||
}
|
||||
|
@ -263,7 +282,7 @@ class Sqlite extends DboSource {
|
|||
return 'binary';
|
||||
}
|
||||
if (strpos($col, 'numeric') !== false || strpos($col, 'decimal') !== false) {
|
||||
return 'float';
|
||||
return 'decimal';
|
||||
}
|
||||
return 'text';
|
||||
}
|
||||
|
@ -271,7 +290,7 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Generate ResultSet
|
||||
*
|
||||
* @param mixed $results
|
||||
* @param mixed $results The results to modify.
|
||||
* @return void
|
||||
*/
|
||||
public function resultSet($results) {
|
||||
|
@ -281,14 +300,19 @@ class Sqlite extends DboSource {
|
|||
$index = 0;
|
||||
$j = 0;
|
||||
|
||||
//PDO::getColumnMeta is experimental and does not work with sqlite3,
|
||||
// so try to figure it out based on the querystring
|
||||
// PDO::getColumnMeta is experimental and does not work with sqlite3,
|
||||
// so try to figure it out based on the querystring
|
||||
$querystring = $results->queryString;
|
||||
if (stripos($querystring, 'SELECT') === 0) {
|
||||
$last = strripos($querystring, 'FROM');
|
||||
if ($last !== false) {
|
||||
$selectpart = substr($querystring, 7, $last - 8);
|
||||
$selects = String::tokenize($selectpart, ',', '(', ')');
|
||||
if (stripos($querystring, 'SELECT') === 0 && stripos($querystring, 'FROM') > 0) {
|
||||
$selectpart = substr($querystring, 7);
|
||||
$selects = array();
|
||||
foreach (CakeText::tokenize($selectpart, ',', '(', ')') as $part) {
|
||||
$fromPos = stripos($part, ' FROM ');
|
||||
if ($fromPos !== false) {
|
||||
$selects[] = trim(substr($part, 0, $fromPos));
|
||||
break;
|
||||
}
|
||||
$selects[] = $part;
|
||||
}
|
||||
} elseif (strpos($querystring, 'PRAGMA table_info') === 0) {
|
||||
$selects = array('cid', 'name', 'type', 'notnull', 'dflt_value', 'pk');
|
||||
|
@ -302,8 +326,8 @@ class Sqlite extends DboSource {
|
|||
$j++;
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/\bAS\s+(.*)/i', $selects[$j], $matches)) {
|
||||
$columnName = trim($matches[1], '"');
|
||||
if (preg_match('/\bAS(?!.*\bAS\b)\s+(.*)/i', $selects[$j], $matches)) {
|
||||
$columnName = trim($matches[1], '"');
|
||||
} else {
|
||||
$columnName = trim(str_replace('"', '', $selects[$j]));
|
||||
}
|
||||
|
@ -342,33 +366,28 @@ class Sqlite extends DboSource {
|
|||
foreach ($this->map as $col => $meta) {
|
||||
list($table, $column, $type) = $meta;
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
return $resultRow;
|
||||
} else {
|
||||
$this->_result->closeCursor();
|
||||
return false;
|
||||
}
|
||||
$this->_result->closeCursor();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if ($limit) {
|
||||
$rt = '';
|
||||
if (!strpos(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0) {
|
||||
$rt = ' LIMIT';
|
||||
}
|
||||
$rt .= ' ' . $limit;
|
||||
$rt = sprintf(' LIMIT %u', $limit);
|
||||
if ($offset) {
|
||||
$rt .= ' OFFSET ' . $offset;
|
||||
$rt .= sprintf(' OFFSET %u', $offset);
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
|
@ -384,7 +403,7 @@ class Sqlite extends DboSource {
|
|||
*/
|
||||
public function buildColumn($column) {
|
||||
$name = $type = null;
|
||||
$column = array_merge(array('null' => true), $column);
|
||||
$column += array('null' => true);
|
||||
extract($column);
|
||||
|
||||
if (empty($name) || empty($type)) {
|
||||
|
@ -397,17 +416,26 @@ class Sqlite extends DboSource {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
|
||||
$isPrimary = (isset($column['key']) && $column['key'] === 'primary');
|
||||
if ($isPrimary && $type === 'integer') {
|
||||
return $this->name($name) . ' ' . $this->columns['primary_key']['name'];
|
||||
}
|
||||
return parent::buildColumn($column);
|
||||
$out = parent::buildColumn($column);
|
||||
if ($isPrimary && $type === 'biginteger') {
|
||||
$replacement = 'PRIMARY KEY';
|
||||
if ($column['null'] === false) {
|
||||
$replacement = 'NOT NULL ' . $replacement;
|
||||
}
|
||||
return str_replace($this->columns['primary_key']['name'], $replacement, $out);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database encoding
|
||||
*
|
||||
* @param string $enc Database encoding
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function setEncoding($enc) {
|
||||
if (!in_array($enc, array("UTF-8", "UTF-16", "UTF-16le", "UTF-16be"))) {
|
||||
|
@ -428,9 +456,9 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Removes redundant primary key indexes, as they are handled in the column def of the key.
|
||||
*
|
||||
* @param array $indexes
|
||||
* @param string $table
|
||||
* @return string
|
||||
* @param array $indexes The indexes to build.
|
||||
* @param string $table The table name.
|
||||
* @return string The completed index.
|
||||
*/
|
||||
public function buildIndex($indexes, $table = null) {
|
||||
$join = array();
|
||||
|
@ -441,7 +469,7 @@ class Sqlite extends DboSource {
|
|||
|
||||
foreach ($indexes as $name => $value) {
|
||||
|
||||
if ($name == 'PRIMARY') {
|
||||
if ($name === 'PRIMARY') {
|
||||
continue;
|
||||
}
|
||||
$out = 'CREATE ';
|
||||
|
@ -450,7 +478,7 @@ class Sqlite extends DboSource {
|
|||
$out .= 'UNIQUE ';
|
||||
}
|
||||
if (is_array($value['column'])) {
|
||||
$value['column'] = join(', ', array_map(array(&$this, 'name'), $value['column']));
|
||||
$value['column'] = implode(', ', array_map(array(&$this, 'name'), $value['column']));
|
||||
} else {
|
||||
$value['column'] = $this->name($value['column']);
|
||||
}
|
||||
|
@ -489,7 +517,7 @@ class Sqlite extends DboSource {
|
|||
$key['name'] = 'PRIMARY';
|
||||
}
|
||||
$index[$key['name']]['column'] = $keyCol[0]['name'];
|
||||
$index[$key['name']]['unique'] = intval($key['unique'] == 1);
|
||||
$index[$key['name']]['unique'] = (int)$key['unique'] === 1;
|
||||
} else {
|
||||
if (!is_array($index[$key['name']]['column'])) {
|
||||
$col[] = $index[$key['name']]['column'];
|
||||
|
@ -506,8 +534,8 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Overrides DboSource::renderStatement to handle schema generation with SQLite-style indexes
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $data
|
||||
* @param string $type The type of statement being rendered.
|
||||
* @param array $data The data to convert to SQL.
|
||||
* @return string
|
||||
*/
|
||||
public function renderStatement($type, $data) {
|
||||
|
@ -515,10 +543,10 @@ class Sqlite extends DboSource {
|
|||
case 'schema':
|
||||
extract($data);
|
||||
if (is_array($columns)) {
|
||||
$columns = "\t" . join(",\n\t", array_filter($columns));
|
||||
$columns = "\t" . implode(",\n\t", array_filter($columns));
|
||||
}
|
||||
if (is_array($indexes)) {
|
||||
$indexes = "\t" . join("\n\t", array_filter($indexes));
|
||||
$indexes = "\t" . implode("\n\t", array_filter($indexes));
|
||||
}
|
||||
return "CREATE TABLE {$table} (\n{$columns});\n{$indexes}";
|
||||
default:
|
||||
|
@ -529,28 +557,20 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* PDO deals in objects, not resources, so overload accordingly.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function hasResult() {
|
||||
return is_object($this->_result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n";
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
protected function _dropTable($table) {
|
||||
return 'DROP TABLE IF EXISTS ' . $this->fullTableName($table) . ";";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -565,7 +585,7 @@ class Sqlite extends DboSource {
|
|||
/**
|
||||
* Check if the server support nested transactions
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function nestedTransactionSupported() {
|
||||
return $this->useNestedTransactions && version_compare($this->getVersion(), '3.6.8', '>=');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue