mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Fixes #15015: Added StringHelper::floatToString() to savely cast float values independent of the locale, also fixes some places in the framework that use it now
This commit is contained in:
committed by
Alexander Makarov
parent
f259eadf7a
commit
93bbf5b39d
@ -8,6 +8,7 @@
|
||||
namespace yii\db;
|
||||
|
||||
use yii\base\BaseObject;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
/**
|
||||
* ColumnSchema class describes the metadata of a column in a database table.
|
||||
@ -127,9 +128,8 @@ class ColumnSchema extends BaseObject
|
||||
}
|
||||
if (is_float($value)) {
|
||||
// ensure type cast always has . as decimal separator in all locales
|
||||
return str_replace(',', '.', (string) $value);
|
||||
return StringHelper::floatToString($value);
|
||||
}
|
||||
|
||||
return (string) $value;
|
||||
case 'integer':
|
||||
return (int) $value;
|
||||
|
||||
@ -9,6 +9,7 @@ namespace yii\db;
|
||||
|
||||
use Yii;
|
||||
use yii\base\BaseObject;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
/**
|
||||
* ColumnSchemaBuilder helps to define database schema types using a PHP interface.
|
||||
@ -345,7 +346,7 @@ class ColumnSchemaBuilder extends BaseObject
|
||||
break;
|
||||
case 'double':
|
||||
// ensure type cast always has . as decimal separator in all locales
|
||||
$string .= str_replace(',', '.', (string) $this->default);
|
||||
$string .= StringHelper::floatToString($this->default);
|
||||
break;
|
||||
case 'boolean':
|
||||
$string .= $this->default ? 'TRUE' : 'FALSE';
|
||||
|
||||
@ -10,6 +10,7 @@ namespace yii\db;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\NotSupportedException;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
/**
|
||||
* QueryBuilder builds a SELECT SQL statement based on the specification given as a [[Query]] object.
|
||||
@ -282,7 +283,7 @@ class QueryBuilder extends \yii\base\BaseObject
|
||||
$value = $schema->quoteValue($value);
|
||||
} elseif (is_float($value)) {
|
||||
// ensure type cast always has . as decimal separator in all locales
|
||||
$value = str_replace(',', '.', (string) $value);
|
||||
$value = StringHelper::floatToString($value);
|
||||
} elseif ($value === false) {
|
||||
$value = 0;
|
||||
} elseif ($value === null) {
|
||||
|
||||
@ -11,6 +11,7 @@ use yii\base\InvalidParamException;
|
||||
use yii\db\Connection;
|
||||
use yii\db\Exception;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
/**
|
||||
* QueryBuilder is the query builder for Oracle databases.
|
||||
@ -271,7 +272,7 @@ EOD;
|
||||
$value = $schema->quoteValue($value);
|
||||
} elseif (is_float($value)) {
|
||||
// ensure type cast always has . as decimal separator in all locales
|
||||
$value = str_replace(',', '.', (string) $value);
|
||||
$value = StringHelper::floatToString($value);
|
||||
} elseif ($value === false) {
|
||||
$value = 0;
|
||||
} elseif ($value === null) {
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
namespace yii\db\pgsql;
|
||||
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
/**
|
||||
* QueryBuilder is the query builder for PostgreSQL databases.
|
||||
@ -308,7 +309,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
$value = $schema->quoteValue($value);
|
||||
} elseif (is_float($value)) {
|
||||
// ensure type cast always has . as decimal separator in all locales
|
||||
$value = str_replace(',', '.', (string) $value);
|
||||
$value = StringHelper::floatToString($value);
|
||||
} elseif ($value === true) {
|
||||
$value = 'TRUE';
|
||||
} elseif ($value === false) {
|
||||
|
||||
@ -12,6 +12,7 @@ use yii\base\NotSupportedException;
|
||||
use yii\db\Connection;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
use yii\helpers\StringHelper;
|
||||
|
||||
/**
|
||||
* QueryBuilder is the query builder for SQLite databases.
|
||||
@ -104,7 +105,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
$value = $schema->quoteValue($value);
|
||||
} elseif (is_float($value)) {
|
||||
// ensure type cast always has . as decimal separator in all locales
|
||||
$value = str_replace(',', '.', (string) $value);
|
||||
$value = StringHelper::floatToString($value);
|
||||
} elseif ($value === false) {
|
||||
$value = 0;
|
||||
} elseif ($value === null) {
|
||||
|
||||
Reference in New Issue
Block a user