Browse Source

rename column schema typecast method

tags/2.0.0-rc
Carsten Brandt 10 years ago
parent
commit
8a70d9fbd1
  1. 2
      extensions/sphinx/ActiveRecord.php
  2. 2
      extensions/sphinx/CHANGELOG.md
  3. 6
      extensions/sphinx/ColumnSchema.php
  4. 4
      extensions/sphinx/QueryBuilder.php
  5. 2
      framework/CHANGELOG.md
  6. 4
      framework/db/ActiveRecord.php
  7. 6
      framework/db/ColumnSchema.php
  8. 6
      framework/db/QueryBuilder.php
  9. 2
      framework/db/cubrid/Schema.php
  10. 2
      framework/db/mssql/Schema.php
  11. 2
      framework/db/mysql/Schema.php
  12. 2
      framework/db/oci/Schema.php
  13. 4
      framework/db/pgsql/Schema.php
  14. 2
      framework/db/sqlite/QueryBuilder.php
  15. 2
      framework/db/sqlite/Schema.php

2
extensions/sphinx/ActiveRecord.php

@ -623,7 +623,7 @@ abstract class ActiveRecord extends BaseActiveRecord
$mvaValue = explode(',', $value);
$row[$name] = array_map(array($columns[$name], 'typecast'), $mvaValue);
} else {
$row[$name] = $columns[$name]->typecastToPhp($value);
$row[$name] = $columns[$name]->typecast($value);
}
}
}

2
extensions/sphinx/CHANGELOG.md

@ -8,7 +8,7 @@ Yii Framework 2 sphinx extension Change Log
- Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Chg #2287: Split `yii\sphinx\ColumnSchema::typecast()` into two methods `typecastToPhp()` and `typecastToDatabase()` to allow specifying PDO type explicitly (cebe)
- Chg #2287: Split `yii\sphinx\ColumnSchema::typecast()` into two methods `typecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe)
2.0.0-beta April 13, 2014

6
extensions/sphinx/ColumnSchema.php

@ -60,7 +60,7 @@ class ColumnSchema extends Object
* @param mixed $value input value
* @return mixed converted value
*/
public function typecastToPhp($value)
public function typecast($value)
{
if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
return $value;
@ -89,10 +89,10 @@ class ColumnSchema extends Object
* @return mixed converted value. This may also be an array containing the value as the first element
* and the PDO type as the second element.
*/
public function typecastToDatabase($value)
public function dbTypecast($value)
{
// the default implementation does the same as casting for PHP but it should be possible
// to override this with annotation of explicit PDO type.
return $this->typecastToPhp($value);
return $this->typecast($value);
}
}

4
extensions/sphinx/QueryBuilder.php

@ -973,14 +973,14 @@ class QueryBuilder extends Object
} else {
$phName = self::PARAM_PREFIX . count($params);
$lineParts[] = $phName;
$params[$phName] = (isset($columnSchema)) ? $columnSchema->typecastToDatabase($subValue) : $subValue;
$params[$phName] = (isset($columnSchema)) ? $columnSchema->dbTypecast($subValue) : $subValue;
}
}
return '(' . implode(',', $lineParts) . ')';
} else {
$phName = self::PARAM_PREFIX . count($params);
$params[$phName] = (isset($columnSchema)) ? $columnSchema->typecastToDatabase($value) : $value;
$params[$phName] = (isset($columnSchema)) ? $columnSchema->dbTypecast($value) : $value;
return $phName;
}

2
framework/CHANGELOG.md

@ -124,7 +124,7 @@ Yii Framework 2 Change Log
- Enh: Improved `yii\helpers\Inflector::slug` to support more cases for Russian, Hebrew and special characters (samdark)
- Enh #3926: `yii\widgets\Breadcrumbs::$links`. Allows individual link to have its own `template` (creocoder, umneeq)
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Chg #2287: Split `yii\db\ColumnSchema::typecast()` into two methods `typecastToPhp()` and `typecastToDatabase()` to allow specifying PDO type explicitly (cebe)
- Chg #2287: Split `yii\db\ColumnSchema::typecast()` into two methods `typecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe)
- Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark)
- Chg #2913: RBAC `DbManager` is now initialized via migration (samdark)
- Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue)

4
framework/db/ActiveRecord.php

@ -369,7 +369,7 @@ class ActiveRecord extends BaseActiveRecord
$columns = static::getTableSchema()->columns;
foreach ($row as $name => $value) {
if (isset($columns[$name])) {
$row[$name] = $columns[$name]->typecastToPhp($value);
$row[$name] = $columns[$name]->typecast($value);
}
}
parent::populateRecord($record, $row);
@ -466,7 +466,7 @@ class ActiveRecord extends BaseActiveRecord
if ($table->sequenceName !== null) {
foreach ($table->primaryKey as $name) {
if ($this->getAttribute($name) === null) {
$id = $table->columns[$name]->typecastToPhp($db->getLastInsertID($table->sequenceName));
$id = $table->columns[$name]->typecast($db->getLastInsertID($table->sequenceName));
$this->setAttribute($name, $id);
$values[$name] = $id;
break;

6
framework/db/ColumnSchema.php

@ -84,7 +84,7 @@ class ColumnSchema extends Object
* @param mixed $value input value
* @return mixed converted value
*/
public function typecastToPhp($value)
public function typecast($value)
{
if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) {
return null;
@ -113,10 +113,10 @@ class ColumnSchema extends Object
* @return mixed converted value. This may also be an array containing the value as the first element
* and the PDO type as the second element.
*/
public function typecastToDatabase($value)
public function dbTypecast($value)
{
// the default implementation does the same as casting for PHP but it should be possible
// to override this with annotation of explicit PDO type.
return $this->typecastToPhp($value);
return $this->typecast($value);
}
}

6
framework/db/QueryBuilder.php

@ -147,7 +147,7 @@ class QueryBuilder extends \yii\base\Object
} else {
$phName = self::PARAM_PREFIX . count($params);
$placeholders[] = $phName;
$params[$phName] = !is_array($value) && isset($columnSchemas[$name]) ? $columnSchemas[$name]->typecastToDatabase($value) : $value;
$params[$phName] = !is_array($value) && isset($columnSchemas[$name]) ? $columnSchemas[$name]->dbTypecast($value) : $value;
}
}
@ -188,7 +188,7 @@ class QueryBuilder extends \yii\base\Object
$vs = [];
foreach ($row as $i => $value) {
if (!is_array($value) && isset($columnSchemas[$columns[$i]])) {
$value = $columnSchemas[$columns[$i]]->typecastToDatabase($value);
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}
if (is_string($value)) {
$value = $this->db->quoteValue($value);
@ -247,7 +247,7 @@ class QueryBuilder extends \yii\base\Object
} else {
$phName = self::PARAM_PREFIX . count($params);
$lines[] = $this->db->quoteColumnName($name) . '=' . $phName;
$params[$phName] = !is_array($value) && isset($columnSchemas[$name]) ? $columnSchemas[$name]->typecastToDatabase($value) : $value;
$params[$phName] = !is_array($value) && isset($columnSchemas[$name]) ? $columnSchemas[$name]->dbTypecast($value) : $value;
}
}

2
framework/db/cubrid/Schema.php

@ -251,7 +251,7 @@ class Schema extends \yii\db\Schema
} elseif (isset($type) && $type === 'bit') {
$column->defaultValue = hexdec(trim($info['Default'],'X\''));
} else {
$column->defaultValue = $column->typecastToPhp($info['Default']);
$column->defaultValue = $column->typecast($info['Default']);
}
return $column;

2
framework/db/mssql/Schema.php

@ -222,7 +222,7 @@ class Schema extends \yii\db\Schema
$info['column_default'] = null;
}
if (!$column->isPrimaryKey && ($column->type !== 'timestamp' || $info['column_default'] !== 'CURRENT_TIMESTAMP')) {
$column->defaultValue = $column->typecastToPhp($info['column_default']);
$column->defaultValue = $column->typecast($info['column_default']);
}
return $column;

2
framework/db/mysql/Schema.php

@ -177,7 +177,7 @@ class Schema extends \yii\db\Schema
} elseif (isset($type) && $type === 'bit') {
$column->defaultValue = bindec(trim($info['Default'],'b\''));
} else {
$column->defaultValue = $column->typecastToPhp($info['Default']);
$column->defaultValue = $column->typecast($info['Default']);
}
}

2
framework/db/oci/Schema.php

@ -174,7 +174,7 @@ EOD;
if (stripos($column['DATA_DEFAULT'], 'timestamp') !== false) {
$c->defaultValue = null;
} else {
$c->defaultValue = $c->typecastToPhp($column['DATA_DEFAULT']);
$c->defaultValue = $c->typecast($column['DATA_DEFAULT']);
}
}

4
framework/db/pgsql/Schema.php

@ -416,9 +416,9 @@ SQL;
} elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches)) {
$column->defaultValue = $matches[1];
} elseif (preg_match("/^(.*?)::/", $column->defaultValue, $matches)) {
$column->defaultValue = $column->typecastToPhp($matches[1]);
$column->defaultValue = $column->typecast($matches[1]);
} else {
$column->defaultValue = $column->typecastToPhp($column->defaultValue);
$column->defaultValue = $column->typecast($column->defaultValue);
}
}
}

2
framework/db/sqlite/QueryBuilder.php

@ -80,7 +80,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$vs = [];
foreach ($row as $i => $value) {
if (!is_array($value) && isset($columnSchemas[$columns[$i]])) {
$value = $columnSchemas[$columns[$i]]->typecastToDatabase($value);
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}
if (is_string($value)) {
$value = $this->db->quoteValue($value);

2
framework/db/sqlite/Schema.php

@ -251,7 +251,7 @@ class Schema extends \yii\db\Schema
$column->defaultValue = new Expression('CURRENT_TIMESTAMP');
} else {
$value = trim($info['dflt_value'], "'\"");
$column->defaultValue = $column->typecastToPhp($value);
$column->defaultValue = $column->typecast($value);
}
}

Loading…
Cancel
Save