Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
0e61c37c
Commit
0e61c37c
authored
Oct 31, 2010
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-41'
parents
18fb5028
738757b8
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
241 additions
and
136 deletions
+241
-136
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+73
-68
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+28
-26
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+1
-1
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+35
-35
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+3
-3
DecimalType.php
lib/Doctrine/DBAL/Types/DecimalType.php
+0
-2
FloatType.php
lib/Doctrine/DBAL/Types/FloatType.php
+54
-0
Type.php
lib/Doctrine/DBAL/Types/Type.php
+3
-1
AllTests.php
tests/Doctrine/Tests/DBAL/AllTests.php
+1
-0
TypeConversionTest.php
tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
+4
-0
FloatTest.php
tests/Doctrine/Tests/DBAL/Types/FloatTest.php
+39
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
0e61c37c
...
...
@@ -85,6 +85,74 @@ abstract class AbstractPlatform
*/
public
function
__construct
()
{}
/**
* Gets the SQL snippet that declares a boolean column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getBooleanTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares a 4 byte integer column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getIntegerTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares an 8 byte integer column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getBigIntTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares a 2 byte integer column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getSmallIntTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares common properties of an integer column.
*
* @param array $columnDef
* @return string
*/
abstract
protected
function
_getCommonIntegerTypeDeclarationSQL
(
array
$columnDef
);
/**
* Lazy load Doctrine Type Mappings
*
* @return void
*/
abstract
protected
function
initializeDoctrineTypeMappings
();
/**
* Gets the SQL snippet used to declare a VARCHAR column type.
*
* @param array $field
*/
abstract
public
function
getVarcharTypeDeclarationSQL
(
array
$field
);
/**
* Gets the SQL snippet used to declare a CLOB column type.
*
* @param array $field
*/
abstract
public
function
getClobTypeDeclarationSQL
(
array
$field
);
/**
* Gets the name of the platform.
*
* @return string
*/
abstract
public
function
getName
();
/**
* Register a doctrine type to be used in conjunction with a column type of this platform.
*
...
...
@@ -141,13 +209,6 @@ abstract class AbstractPlatform
return
isset
(
$this
->
doctrineTypeMapping
[
$dbType
]);
}
/**
* Lazy load Doctrine Type Mappings
*
* @return void
*/
abstract
protected
function
initializeDoctrineTypeMappings
();
/**
* Gets the character used for identifier quoting.
*
...
...
@@ -1090,46 +1151,6 @@ abstract class AbstractPlatform
return
'NUMERIC('
.
$columnDef
[
'precision'
]
.
', '
.
$columnDef
[
'scale'
]
.
')'
;
}
/**
* Gets the SQL snippet that declares a boolean column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getBooleanTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares a 4 byte integer column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getIntegerTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares an 8 byte integer column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getBigIntTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares a 2 byte integer column.
*
* @param array $columnDef
* @return string
*/
abstract
public
function
getSmallIntTypeDeclarationSQL
(
array
$columnDef
);
/**
* Gets the SQL snippet that declares common properties of an integer column.
*
* @param array $columnDef
* @return string
*/
abstract
protected
function
_getCommonIntegerTypeDeclarationSQL
(
array
$columnDef
);
/**
* Obtain DBMS specific SQL code portion needed to set a default value
* declaration to be used in statements like CREATE TABLE.
...
...
@@ -1703,6 +1724,11 @@ abstract class AbstractPlatform
throw
DBALException
::
notSupported
(
__METHOD__
);
}
public
function
getFloatDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'DOUBLE PRECISION'
;
}
/**
* Gets the default transaction isolation level of the platform.
*
...
...
@@ -1905,27 +1931,6 @@ abstract class AbstractPlatform
return
$query
;
}
/**
* Gets the SQL snippet used to declare a VARCHAR column type.
*
* @param array $field
*/
abstract
public
function
getVarcharTypeDeclarationSQL
(
array
$field
);
/**
* Gets the SQL snippet used to declare a CLOB column type.
*
* @param array $field
*/
abstract
public
function
getClobTypeDeclarationSQL
(
array
$field
);
/**
* Gets the name of the platform.
*
* @return string
*/
abstract
public
function
getName
();
/**
* Gets the character casing of a column in an SQL result set of this platform.
...
...
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
0e61c37c
...
...
@@ -653,32 +653,34 @@ DROP DATABASE ' . $name . ';';
protected
function
initializeDoctrineTypeMappings
()
{
$this
->
doctrineTypeMapping
=
array
(
'bigint'
=>
'bigint'
,
'numeric'
=>
'decimal'
,
'bit'
=>
'boolean'
,
'smallint'
=>
'smallint'
,
'decimal'
=>
'decimal'
,
'smallmoney'
=>
'integer'
,
'int'
=>
'integer'
,
'tinyint'
=>
'smallint'
,
'money'
=>
'integer'
,
'float'
=>
'decimal'
,
'real'
=>
'decimal'
,
'date'
=>
'date'
,
'datetimeoffset'
=>
'datetimetz'
,
'datetime2'
=>
'datetime'
,
'smalldatetime'
=>
'datetime'
,
'datetime'
=>
'datetime'
,
'time'
=>
'time'
,
'char'
=>
'string'
,
'varchar'
=>
'string'
,
'text'
=>
'text'
,
'nchar'
=>
'string'
,
'nvarchar'
=>
'string'
,
'ntext'
=>
'text'
,
'binary'
=>
'text'
,
'varbinary'
=>
'text'
,
'image'
=>
'text'
,
'bigint'
=>
'bigint'
,
'numeric'
=>
'decimal'
,
'bit'
=>
'boolean'
,
'smallint'
=>
'smallint'
,
'decimal'
=>
'decimal'
,
'smallmoney'
=>
'integer'
,
'int'
=>
'integer'
,
'tinyint'
=>
'smallint'
,
'money'
=>
'integer'
,
'float'
=>
'float'
,
'real'
=>
'float'
,
'double'
=>
'float'
,
'double precision'
=>
'float'
,
'date'
=>
'date'
,
'datetimeoffset'
=>
'datetimetz'
,
'datetime2'
=>
'datetime'
,
'smalldatetime'
=>
'datetime'
,
'datetime'
=>
'datetime'
,
'time'
=>
'time'
,
'char'
=>
'string'
,
'varchar'
=>
'string'
,
'text'
=>
'text'
,
'nchar'
=>
'string'
,
'nvarchar'
=>
'string'
,
'ntext'
=>
'text'
,
'binary'
=>
'text'
,
'varbinary'
=>
'text'
,
'image'
=>
'text'
,
);
}
...
...
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
0e61c37c
...
...
@@ -702,7 +702,7 @@ LEFT JOIN all_cons_columns r_cols
'date'
=>
'datetime'
,
'timestamp'
=>
'datetime'
,
'timestamptz'
=>
'datetimetz'
,
'float'
=>
'
decimal
'
,
'float'
=>
'
float
'
,
'long'
=>
'string'
,
'clob'
=>
'text'
,
'nclob'
=>
'text'
,
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
0e61c37c
...
...
@@ -670,41 +670,41 @@ class PostgreSqlPlatform extends AbstractPlatform
protected
function
initializeDoctrineTypeMappings
()
{
$this
->
doctrineTypeMapping
=
array
(
'smallint'
=>
'smallint'
,
'int2'
=>
'smallint'
,
'serial'
=>
'integer'
,
'serial4'
=>
'integer'
,
'int'
=>
'integer'
,
'int4'
=>
'integer'
,
'integer'
=>
'integer'
,
'bigserial'
=>
'bigint'
,
'serial8'
=>
'bigint'
,
'bigint'
=>
'bigint'
,
'int8'
=>
'bigint'
,
'bool'
=>
'boolean'
,
'boolean'
=>
'boolean'
,
'text'
=>
'text'
,
'varchar'
=>
'string'
,
'interval'
=>
'string'
,
'_varchar'
=>
'string'
,
'char'
=>
'string'
,
'bpchar'
=>
'string'
,
'date'
=>
'date'
,
'datetime'
=>
'datetime'
,
'timestamp'
=>
'datetime'
,
'timestamptz'
=>
'datetimetz'
,
'time'
=>
'time'
,
'timetz'
=>
'time'
,
'float'
=>
'decimal
'
,
'float4'
=>
'decimal
'
,
'float8'
=>
'decimal
'
,
'double'
=>
'decimal
'
,
'double precision'
=>
'
decimal
'
,
'real'
=>
'decimal
'
,
'decimal'
=>
'decimal'
,
'money'
=>
'decimal'
,
'numeric'
=>
'decimal'
,
'year'
=>
'date'
,
'smallint'
=>
'smallint'
,
'int2'
=>
'smallint'
,
'serial'
=>
'integer'
,
'serial4'
=>
'integer'
,
'int'
=>
'integer'
,
'int4'
=>
'integer'
,
'integer'
=>
'integer'
,
'bigserial'
=>
'bigint'
,
'serial8'
=>
'bigint'
,
'bigint'
=>
'bigint'
,
'int8'
=>
'bigint'
,
'bool'
=>
'boolean'
,
'boolean'
=>
'boolean'
,
'text'
=>
'text'
,
'varchar'
=>
'string'
,
'interval'
=>
'string'
,
'_varchar'
=>
'string'
,
'char'
=>
'string'
,
'bpchar'
=>
'string'
,
'date'
=>
'date'
,
'datetime'
=>
'datetime'
,
'timestamp'
=>
'datetime'
,
'timestamptz'
=>
'datetimetz'
,
'time'
=>
'time'
,
'timetz'
=>
'time'
,
'float'
=>
'float
'
,
'float4'
=>
'float
'
,
'float8'
=>
'float
'
,
'double'
=>
'float
'
,
'double precision'
=>
'
float
'
,
'real'
=>
'float
'
,
'decimal'
=>
'decimal'
,
'money'
=>
'decimal'
,
'numeric'
=>
'decimal'
,
'year'
=>
'date'
,
);
}
}
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
0e61c37c
...
...
@@ -464,9 +464,9 @@ class SqlitePlatform extends AbstractPlatform
'datetime'
=>
'datetime'
,
'timestamp'
=>
'datetime'
,
'time'
=>
'time'
,
'float'
=>
'
decimal
'
,
'double'
=>
'
decimal
'
,
'real'
=>
'
decimal
'
,
'float'
=>
'
float
'
,
'double'
=>
'
float
'
,
'real'
=>
'
float
'
,
'decimal'
=>
'decimal'
,
'numeric'
=>
'decimal'
,
);
...
...
lib/Doctrine/DBAL/Types/DecimalType.php
View file @
0e61c37c
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...
...
lib/Doctrine/DBAL/Types/FloatType.php
0 → 100644
View file @
0e61c37c
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
class
FloatType
extends
Type
{
public
function
getName
()
{
return
Type
::
FLOAT
;
}
/**
* @param array $fieldDeclaration
* @param AbstractPlatform $platform
* @return string
*/
public
function
getSQLDeclaration
(
array
$fieldDeclaration
,
AbstractPlatform
$platform
)
{
return
$platform
->
getFloatDeclarationSQL
(
$fieldDeclaration
);
}
/**
* Converts a value from its database representation to its PHP representation
* of this type.
*
* @param mixed $value The value to convert.
* @param AbstractPlatform $platform The currently used database platform.
* @return mixed The PHP representation of the value.
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
return
(
null
===
$value
)
?
null
:
(
double
)
$value
;
}
}
lib/Doctrine/DBAL/Types/Type.php
View file @
0e61c37c
...
...
@@ -47,6 +47,7 @@ abstract class Type
const
SMALLINT
=
'smallint'
;
const
STRING
=
'string'
;
const
TEXT
=
'text'
;
const
FLOAT
=
'float'
;
/** Map of already instantiated type objects. One instance per type (flyweight). */
private
static
$_typeObjects
=
array
();
...
...
@@ -65,7 +66,8 @@ abstract class Type
self
::
DATETIMETZ
=>
'Doctrine\DBAL\Types\DateTimeTzType'
,
self
::
DATE
=>
'Doctrine\DBAL\Types\DateType'
,
self
::
TIME
=>
'Doctrine\DBAL\Types\TimeType'
,
self
::
DECIMAL
=>
'Doctrine\DBAL\Types\DecimalType'
self
::
DECIMAL
=>
'Doctrine\DBAL\Types\DecimalType'
,
self
::
FLOAT
=>
'Doctrine\DBAL\Types\FloatType'
,
);
/* Prevent instantiation and force use of the factory method. */
...
...
tests/Doctrine/Tests/DBAL/AllTests.php
View file @
0e61c37c
...
...
@@ -43,6 +43,7 @@ class AllTests
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\IntegerTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\SmallIntTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\StringTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\FloatTest'
);
// Schema tests
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Schema\ColumnTest'
);
...
...
tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
View file @
0e61c37c
...
...
@@ -32,6 +32,8 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table
->
addColumn
(
'test_text'
,
'text'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_array'
,
'array'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_object'
,
'object'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_float'
,
'float'
,
array
(
'notnull'
=>
false
));
$table
->
addColumn
(
'test_decimal'
,
'decimal'
,
array
(
'notnull'
=>
false
,
'scale'
=>
2
,
'precision'
=>
10
));
$table
->
setPrimaryKey
(
array
(
'id'
));
$sm
->
createTable
(
$table
);
...
...
@@ -57,6 +59,8 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
array
(
'text'
,
str_repeat
(
'foo '
,
1000
),
'string'
),
array
(
'array'
,
array
(
'foo'
=>
'bar'
),
'array'
),
array
(
'object'
,
$obj
,
'object'
),
array
(
'float'
,
1.5
,
'float'
),
array
(
'decimal'
,
1.55
,
'float'
),
);
}
...
...
tests/Doctrine/Tests/DBAL/Types/FloatTest.php
0 → 100644
View file @
0e61c37c
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
FloatTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
$this
->
_type
=
Type
::
getType
(
'float'
);
}
public
function
testFloatConvertsToPHPValue
()
{
$this
->
assertType
(
'float'
,
$this
->
_type
->
convertToPHPValue
(
'5.5'
,
$this
->
_platform
));
}
public
function
testFloatNullConvertsToPHPValue
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToPHPValue
(
null
,
$this
->
_platform
));
}
public
function
testFloatConvertToDatabaseValue
()
{
$this
->
assertType
(
'float'
,
$this
->
_type
->
convertToDatabaseValue
(
5.5
,
$this
->
_platform
));
}
public
function
testFloatNullConvertToDatabaseValue
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToDatabaseValue
(
null
,
$this
->
_platform
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment