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
177903df
Commit
177903df
authored
Oct 30, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-6'
parents
5be16133
d919b50e
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
484 additions
and
244 deletions
+484
-244
UPGRADE
UPGRADE
+6
-0
Connection.php
lib/Doctrine/DBAL/Connection.php
+51
-49
OCI8Statement.php
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
+20
-10
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+66
-61
DB2Platform.php
lib/Doctrine/DBAL/Platforms/DB2Platform.php
+10
-2
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+15
-7
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+33
-25
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+31
-23
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+35
-27
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+30
-22
BlobType.php
lib/Doctrine/DBAL/Types/BlobType.php
+69
-0
Type.php
lib/Doctrine/DBAL/Types/Type.php
+6
-4
BlobTest.php
tests/Doctrine/Tests/DBAL/Functional/BlobTest.php
+83
-0
MockPlatform.php
tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php
+9
-1
ConnectionMock.php
tests/Doctrine/Tests/Mocks/ConnectionMock.php
+11
-11
DatabasePlatformMock.php
tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
+9
-2
No files found.
UPGRADE
0 → 100644
View file @
177903df
# Upgrade to 2.2
## Doctrine\DBAL\Connection#insert and Doctrine\DBAL\Connnection#update
Both methods now accept an optional last parameter $types with binding types of the values passed.
This can potentially break child classes that have overwritten one of these methods.
\ No newline at end of file
lib/Doctrine/DBAL/Connection.php
View file @
177903df
This diff is collapsed.
Click to expand it.
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
View file @
177903df
...
...
@@ -30,13 +30,15 @@ use \PDO;
class
OCI8Statement
implements
\Doctrine\DBAL\Driver\Statement
{
/** Statement handle. */
protected
$_dbh
;
protected
$_sth
;
protected
$_executeMode
;
protected
static
$_PARAM
=
':param'
;
protected
static
$fetchStyleMap
=
array
(
PDO
::
FETCH_BOTH
=>
OCI_BOTH
,
PDO
::
FETCH_ASSOC
=>
OCI_ASSOC
,
PDO
::
FETCH_NUM
=>
OCI_NUM
PDO
::
FETCH_NUM
=>
OCI_NUM
,
PDO
::
PARAM_LOB
=>
OCI_B_BLOB
,
);
protected
$_paramMap
=
array
();
...
...
@@ -50,6 +52,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
{
list
(
$statement
,
$paramMap
)
=
self
::
convertPositionalToNamedPlaceholders
(
$statement
);
$this
->
_sth
=
oci_parse
(
$dbh
,
$statement
);
$this
->
_dbh
=
$dbh
;
$this
->
_paramMap
=
$paramMap
;
$this
->
_executeMode
=
$executeMode
;
}
...
...
@@ -72,7 +75,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
* @return string
*/
static
public
function
convertPositionalToNamedPlaceholders
(
$statement
)
{
{
$count
=
1
;
$inLiteral
=
false
;
// a valid query never starts with quotes
$stmtLen
=
strlen
(
$statement
);
...
...
@@ -108,8 +111,15 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
public
function
bindParam
(
$column
,
&
$variable
,
$type
=
null
)
{
$column
=
isset
(
$this
->
_paramMap
[
$column
])
?
$this
->
_paramMap
[
$column
]
:
$column
;
return
oci_bind_by_name
(
$this
->
_sth
,
$column
,
$variable
);
if
(
$type
==
\PDO
::
PARAM_LOB
)
{
$lob
=
oci_new_descriptor
(
$this
->
_dbh
,
OCI_D_LOB
);
$lob
->
writeTemporary
(
$variable
,
OCI_TEMP_BLOB
);
return
oci_bind_by_name
(
$this
->
_sth
,
$column
,
$lob
,
-
1
,
OCI_B_BLOB
);
}
else
{
return
oci_bind_by_name
(
$this
->
_sth
,
$column
,
$variable
);
}
}
/**
...
...
@@ -122,7 +132,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
return
oci_free_statement
(
$this
->
_sth
);
}
/**
/**
* {@inheritdoc}
*/
public
function
columnCount
()
...
...
@@ -141,7 +151,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
}
return
$error
;
}
/**
* {@inheritdoc}
*/
...
...
@@ -181,7 +191,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
if
(
!
isset
(
self
::
$fetchStyleMap
[
$fetchStyle
]))
{
throw
new
\InvalidArgumentException
(
"Invalid fetch style: "
.
$fetchStyle
);
}
return
oci_fetch_array
(
$this
->
_sth
,
self
::
$fetchStyleMap
[
$fetchStyle
]
|
OCI_RETURN_NULLS
|
OCI_RETURN_LOBS
);
}
...
...
@@ -193,11 +203,11 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
if
(
!
isset
(
self
::
$fetchStyleMap
[
$fetchStyle
]))
{
throw
new
\InvalidArgumentException
(
"Invalid fetch style: "
.
$fetchStyle
);
}
$result
=
array
();
oci_fetch_all
(
$this
->
_sth
,
$result
,
0
,
-
1
,
self
::
$fetchStyleMap
[
$fetchStyle
]
|
OCI_RETURN_NULLS
|
OCI_FETCHSTATEMENT_BY_ROW
|
OCI_RETURN_LOBS
);
return
$result
;
}
...
...
@@ -216,5 +226,5 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
public
function
rowCount
()
{
return
oci_num_rows
(
$this
->
_sth
);
}
}
}
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
177903df
This diff is collapsed.
Click to expand it.
lib/Doctrine/DBAL/Platforms/DB2Platform.php
View file @
177903df
...
...
@@ -25,6 +25,14 @@ use Doctrine\DBAL\Schema\TableDiff;
class
DB2Platform
extends
AbstractPlatform
{
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
public
function
initializeDoctrineTypeMappings
()
{
$this
->
doctrineTypeMapping
=
array
(
...
...
@@ -347,7 +355,7 @@ class DB2Platform extends AbstractPlatform
$indexes
=
$options
[
'indexes'
];
}
$options
[
'indexes'
]
=
array
();
$sqls
=
parent
::
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
foreach
(
$indexes
as
$index
=>
$definition
)
{
...
...
@@ -550,7 +558,7 @@ class DB2Platform extends AbstractPlatform
{
return
false
;
}
protected
function
getReservedKeywordsClass
()
{
return
'Doctrine\DBAL\Platforms\Keywords\DB2Keywords'
;
...
...
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
177903df
...
...
@@ -40,26 +40,26 @@ class MsSqlPlatform extends AbstractPlatform
/**
* {@inheritDoc}
*/
public
function
getDateDiffExpression
(
$date1
,
$date2
)
public
function
getDateDiffExpression
(
$date1
,
$date2
)
{
return
'DATEDIFF(day, '
.
$date2
.
','
.
$date1
.
')'
;
}
public
function
getDateAddDaysExpression
(
$date
,
$days
)
{
return
'DATEADD(day, '
.
$days
.
', '
.
$date
.
')'
;
}
public
function
getDateSubDaysExpression
(
$date
,
$days
)
{
return
'DATEADD(day, -1 * '
.
$days
.
', '
.
$date
.
')'
;
}
public
function
getDateAddMonthExpression
(
$date
,
$months
)
{
return
'DATEADD(month, '
.
$months
.
', '
.
$date
.
')'
;
}
public
function
getDateSubMonthExpression
(
$date
,
$months
)
{
return
'DATEADD(month, -1 * '
.
$months
.
', '
.
$date
.
')'
;
...
...
@@ -278,7 +278,7 @@ class MsSqlPlatform extends AbstractPlatform
{
$queryParts
=
array
();
$sql
=
array
();
if
(
$diff
->
newName
!==
false
)
{
$queryParts
[]
=
'RENAME TO '
.
$diff
->
newName
;
}
...
...
@@ -822,9 +822,17 @@ class MsSqlPlatform extends AbstractPlatform
{
return
"["
.
str_replace
(
"]"
,
"]["
,
$str
)
.
"]"
;
}
public
function
getTruncateTableSQL
(
$tableName
,
$cascade
=
false
)
{
return
'TRUNCATE TABLE '
.
$tableName
;
}
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
return
'VARBINARY(MAX)'
;
}
}
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
177903df
...
...
@@ -46,7 +46,7 @@ class MySqlPlatform extends AbstractPlatform
{
return
'`'
;
}
/**
* Returns the regular expression operator.
*
...
...
@@ -137,9 +137,9 @@ class MySqlPlatform extends AbstractPlatform
}
/**
* Two approaches to listing the table indexes. The information_schema is
* Two approaches to listing the table indexes. The information_schema is
* prefered, because it doesn't cause problems with SQL keywords such as "order" or "table".
*
*
* @param string $table
* @param string $currentDatabase
* @return string
...
...
@@ -150,7 +150,7 @@ class MySqlPlatform extends AbstractPlatform
return
"SELECT TABLE_NAME AS `Table`, NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, "
.
"SEQ_IN_INDEX AS Seq_in_index, COLUMN_NAME AS Column_Name, COLLATION AS Collation, "
.
"CARDINALITY AS Cardinality, SUB_PART AS Sub_Part, PACKED AS Packed, "
.
"NULLABLE AS `Null`, INDEX_TYPE AS Index_Type, COMMENT AS Comment "
.
"NULLABLE AS `Null`, INDEX_TYPE AS Index_Type, COMMENT AS Comment "
.
"FROM information_schema.STATISTICS WHERE TABLE_NAME = '"
.
$table
.
"' AND TABLE_SCHEMA = '"
.
$currentDatabase
.
"'"
;
}
else
{
return
'SHOW INDEX FROM '
.
$table
;
...
...
@@ -228,7 +228,7 @@ class MySqlPlatform extends AbstractPlatform
return
'DATETIME'
;
}
}
/**
* @override
*/
...
...
@@ -240,10 +240,10 @@ class MySqlPlatform extends AbstractPlatform
/**
* @override
*/
public
function
getTimeTypeDeclarationSQL
(
array
$fieldDeclaration
)
public
function
getTimeTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'TIME'
;
}
}
/**
* @override
...
...
@@ -265,7 +265,7 @@ class MySqlPlatform extends AbstractPlatform
{
return
'COLLATE '
.
$collation
;
}
/**
* Whether the platform prefers identity columns for ID generation.
* MySql prefers "autoincrement" identity columns since sequences can only
...
...
@@ -278,7 +278,7 @@ class MySqlPlatform extends AbstractPlatform
{
return
true
;
}
/**
* Whether the platform supports identity columns.
* MySql supports this through AUTO_INCREMENT columns.
...
...
@@ -300,7 +300,7 @@ class MySqlPlatform extends AbstractPlatform
{
return
'SHOW DATABASES'
;
}
public
function
getListTablesSQL
()
{
return
"SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
;
...
...
@@ -329,7 +329,7 @@ class MySqlPlatform extends AbstractPlatform
{
return
'CREATE DATABASE '
.
$name
;
}
/**
* drop an existing database
*
...
...
@@ -341,7 +341,7 @@ class MySqlPlatform extends AbstractPlatform
{
return
'DROP DATABASE '
.
$name
;
}
/**
* create a new table
*
...
...
@@ -431,7 +431,7 @@ class MySqlPlatform extends AbstractPlatform
// default to innodb
$optionStrings
[]
=
'ENGINE = InnoDB'
;
}
if
(
!
empty
(
$optionStrings
))
{
$query
.=
' '
.
implode
(
' '
,
$optionStrings
);
}
...
...
@@ -442,10 +442,10 @@ class MySqlPlatform extends AbstractPlatform
$sql
[]
=
$this
->
getCreateForeignKeySQL
(
$definition
,
$tableName
);
}
}
return
$sql
;
}
/**
* Gets the SQL to alter an existing table.
*
...
...
@@ -496,7 +496,7 @@ class MySqlPlatform extends AbstractPlatform
);
return
$sql
;
}
/**
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
...
...
@@ -551,7 +551,7 @@ class MySqlPlatform extends AbstractPlatform
return
$unsigned
.
$autoinc
;
}
/**
* Return the FOREIGN KEY query section dealing with non-standard options
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
...
...
@@ -569,7 +569,7 @@ class MySqlPlatform extends AbstractPlatform
$query
.=
parent
::
getAdvancedForeignKeyOptionsSQL
(
$foreignKey
);
return
$query
;
}
/**
* Gets the SQL to drop an index of a table.
*
...
...
@@ -578,7 +578,7 @@ class MySqlPlatform extends AbstractPlatform
* @override
*/
public
function
getDropIndexSQL
(
$index
,
$table
=
null
)
{
{
if
(
$index
instanceof
Index
)
{
$indexName
=
$index
->
getQuotedName
(
$this
);
}
else
if
(
is_string
(
$index
))
{
...
...
@@ -586,25 +586,25 @@ class MySqlPlatform extends AbstractPlatform
}
else
{
throw
new
\InvalidArgumentException
(
'MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'
);
}
if
(
$table
instanceof
Table
)
{
$table
=
$table
->
getQuotedName
(
$this
);
}
else
if
(
!
is_string
(
$table
))
{
throw
new
\InvalidArgumentException
(
'MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'
);
}
if
(
$index
instanceof
Index
&&
$index
->
isPrimary
())
{
// mysql primary keys are always named "PRIMARY",
// mysql primary keys are always named "PRIMARY",
// so we cannot use them in statements because of them being keyword.
return
$this
->
getDropPrimaryKeySQL
(
$table
);
}
return
'DROP INDEX '
.
$indexName
.
' ON '
.
$table
;
}
/**
* @param Index $index
* @param Table $table
* @param Table $table
*/
protected
function
getDropPrimaryKeySQL
(
$table
)
{
...
...
@@ -664,7 +664,7 @@ class MySqlPlatform extends AbstractPlatform
{
return
65535
;
}
protected
function
getReservedKeywordsClass
()
{
return
'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords'
;
...
...
@@ -690,4 +690,12 @@ class MySqlPlatform extends AbstractPlatform
return
'DROP TEMPORARY TABLE '
.
$table
;
}
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
return
'LONGBLOB'
;
}
}
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
177903df
...
...
@@ -102,14 +102,14 @@ class OraclePlatform extends AbstractPlatform
/**
* Get the number of days difference between two dates.
*
*
* Note: Since Oracle timestamp differences are calculated down to the microsecond we have to truncate
* them to the difference in days. This is obviously a restriction of the original functionality, but we
* need to make this a portable function.
*
*
* @param type $date1
* @param type $date2
* @return type
* @return type
*/
public
function
getDateDiffExpression
(
$date1
,
$date2
)
{
...
...
@@ -135,7 +135,7 @@ class OraclePlatform extends AbstractPlatform
{
return
"ADD_MONTHS("
.
$date
.
", -"
.
$months
.
")"
;
}
/**
* Gets the SQL used to create a sequence that starts with a given value
* and increments by the given allocation size.
...
...
@@ -151,13 +151,13 @@ class OraclePlatform extends AbstractPlatform
{
return
'CREATE SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
' START WITH '
.
$sequence
->
getInitialValue
()
.
' MINVALUE '
.
$sequence
->
getInitialValue
()
.
' MINVALUE '
.
$sequence
->
getInitialValue
()
.
' INCREMENT BY '
.
$sequence
->
getAllocationSize
();
}
public
function
getAlterSequenceSQL
(
\Doctrine\DBAL\Schema\Sequence
$sequence
)
{
return
'ALTER SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
return
'ALTER SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
' INCREMENT BY '
.
$sequence
->
getAllocationSize
();
}
...
...
@@ -171,7 +171,7 @@ class OraclePlatform extends AbstractPlatform
{
return
'SELECT '
.
$sequenceName
.
'.nextval FROM DUAL'
;
}
/**
* {@inheritdoc}
*
...
...
@@ -197,7 +197,7 @@ class OraclePlatform extends AbstractPlatform
return
parent
::
_getTransactionIsolationLevelSQL
(
$level
);
}
}
/**
* @override
*/
...
...
@@ -281,7 +281,7 @@ class OraclePlatform extends AbstractPlatform
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR(2000)'
)
:
(
$length
?
'VARCHAR2('
.
$length
.
')'
:
'VARCHAR2(4000)'
);
}
/** @override */
public
function
getClobTypeDeclarationSQL
(
array
$field
)
{
...
...
@@ -318,11 +318,11 @@ class OraclePlatform extends AbstractPlatform
}
if
(
isset
(
$column
[
'autoincrement'
])
&&
$column
[
'autoincrement'
]
||
(
isset
(
$column
[
'autoinc'
])
&&
$column
[
'autoinc'
]))
{
(
isset
(
$column
[
'autoinc'
])
&&
$column
[
'autoinc'
]))
{
$sql
=
array_merge
(
$sql
,
$this
->
getCreateAutoincrementSql
(
$name
,
$table
));
}
}
if
(
isset
(
$indexes
)
&&
!
empty
(
$indexes
))
{
foreach
(
$indexes
as
$indexName
=>
$index
)
{
$sql
[]
=
$this
->
getCreateIndexSQL
(
$index
,
$table
);
...
...
@@ -341,7 +341,7 @@ class OraclePlatform extends AbstractPlatform
public
function
getListTableIndexesSQL
(
$table
,
$currentDatabase
=
null
)
{
$table
=
strtoupper
(
$table
);
return
"SELECT uind.index_name AS name, "
.
" uind.index_type AS type, "
.
" decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, "
.
...
...
@@ -392,7 +392,7 @@ BEGIN
IF constraints_Count = 0 OR constraints_Count = \'\' THEN
EXECUTE IMMEDIATE \''
.
$this
->
getCreateConstraintSQL
(
$idx
,
$table
)
.
'\';
END IF;
END;'
;
END;'
;
$sequenceName
=
$table
.
'_SEQ'
;
$sequence
=
new
\Doctrine\DBAL\Schema\Sequence
(
$sequenceName
,
$start
);
...
...
@@ -476,12 +476,12 @@ LEFT JOIN all_cons_columns r_cols
{
$table
=
strtoupper
(
$table
);
$ownerCondition
=
''
;
if
(
null
!==
$database
){
$database
=
strtoupper
(
$database
);
$ownerCondition
=
"AND c.owner = '"
.
$database
.
"'"
;
}
return
"SELECT c.*, d.comments FROM all_tab_columns c "
.
"INNER JOIN all_col_comments d ON d.OWNER = c.OWNER AND d.TABLE_NAME = c.TABLE_NAME AND d.COLUMN_NAME = c.COLUMN_NAME "
.
"WHERE c.table_name = '"
.
$table
.
"' "
.
$ownerCondition
.
" ORDER BY c.column_name"
;
...
...
@@ -639,12 +639,12 @@ LEFT JOIN all_cons_columns r_cols
}
return
$query
;
}
/**
* Gets the character casing of a column in an SQL result set of this platform.
*
*
* Oracle returns all column names in SQL result sets in uppercase.
*
*
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/
...
...
@@ -652,12 +652,12 @@ LEFT JOIN all_cons_columns r_cols
{
return
strtoupper
(
$column
);
}
public
function
getCreateTemporaryTableSnippetSQL
()
{
return
"CREATE GLOBAL TEMPORARY TABLE"
;
}
public
function
getDateTimeTzFormatString
()
{
return
'Y-m-d H:i:sP'
;
...
...
@@ -672,7 +672,7 @@ LEFT JOIN all_cons_columns r_cols
{
return
'1900-01-01 H:i:s'
;
}
public
function
fixSchemaElementName
(
$schemaElementName
)
{
if
(
strlen
(
$schemaElementName
)
>
30
)
{
...
...
@@ -769,9 +769,17 @@ LEFT JOIN all_cons_columns r_cols
{
return
''
;
}
protected
function
getReservedKeywordsClass
()
{
return
'Doctrine\DBAL\Platforms\Keywords\OracleKeywords'
;
}
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
return
'BLOB'
;
}
}
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
177903df
...
...
@@ -116,7 +116,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
"("
.
$date
.
"- interval '"
.
$months
.
" month')"
;
}
/**
* parses a literal boolean value and returns
* proper sql equivalent
...
...
@@ -128,7 +128,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return $value;
}*/
/**
* Whether the platform supports sequences.
* Postgres has native support for sequences.
...
...
@@ -139,17 +139,17 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
true
;
}
/**
* Whether the platform supports database schemas.
*
*
* @return boolean
*/
public
function
supportsSchemas
()
{
return
true
;
}
/**
* Whether the platform supports identity columns.
* Postgres supports these through the SERIAL keyword.
...
...
@@ -165,7 +165,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
true
;
}
/**
* Whether the platform prefers sequences for ID generation.
*
...
...
@@ -187,7 +187,7 @@ class PostgreSqlPlatform extends AbstractPlatform
c.relname, n.nspname AS schemaname
FROM
pg_class c, pg_namespace n
WHERE relkind = 'S' AND n.oid = c.relnamespace AND
WHERE relkind = 'S' AND n.oid = c.relnamespace AND
(n.nspname NOT LIKE 'pg_%' AND n.nspname != 'information_schema')"
;
}
...
...
@@ -304,7 +304,7 @@ class PostgreSqlPlatform extends AbstractPlatform
AND n.oid = c.relnamespace
ORDER BY a.attnum"
;
}
/**
* create a new database
*
...
...
@@ -357,7 +357,7 @@ class PostgreSqlPlatform extends AbstractPlatform
}
return
$query
;
}
/**
* generates the sql for altering an existing table on postgresql
*
...
...
@@ -391,7 +391,7 @@ class PostgreSqlPlatform extends AbstractPlatform
foreach
(
$diff
->
changedColumns
AS
$columnDiff
)
{
$oldColumnName
=
$columnDiff
->
oldColumnName
;
$column
=
$columnDiff
->
column
;
if
(
$columnDiff
->
hasChanged
(
'type'
))
{
$type
=
$column
->
getType
();
...
...
@@ -437,7 +437,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return
array_merge
(
$sql
,
$this
->
_getAlterTableIndexForeignKeySQL
(
$diff
),
$commentsSQL
);
}
/**
* Gets the SQL to create a sequence on this platform.
*
...
...
@@ -451,13 +451,13 @@ class PostgreSqlPlatform extends AbstractPlatform
' MINVALUE '
.
$sequence
->
getInitialValue
()
.
' START '
.
$sequence
->
getInitialValue
();
}
public
function
getAlterSequenceSQL
(
\Doctrine\DBAL\Schema\Sequence
$sequence
)
{
return
'ALTER SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
return
'ALTER SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
' INCREMENT BY '
.
$sequence
->
getAllocationSize
();
}
/**
* Drop existing sequence
* @param \Doctrine\DBAL\Schema\Sequence $sequence
...
...
@@ -480,7 +480,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
$this
->
getDropConstraintSQL
(
$foreignKey
,
$table
);
}
/**
* Gets the SQL used to create a table.
*
...
...
@@ -516,7 +516,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return
$sql
;
}
/**
* Postgres wants boolean values converted to the strings 'true'/'false'.
*
...
...
@@ -549,7 +549,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
.
$this
->
_getTransactionIsolationLevelSQL
(
$level
);
}
/**
* @override
*/
...
...
@@ -566,7 +566,7 @@ class PostgreSqlPlatform extends AbstractPlatform
if
(
!
empty
(
$field
[
'autoincrement'
]))
{
return
'SERIAL'
;
}
return
'INT'
;
}
...
...
@@ -604,7 +604,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
'TIMESTAMP(0) WITH TIME ZONE'
;
}
/**
* @override
*/
...
...
@@ -640,7 +640,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR(255)'
)
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'VARCHAR(255)'
);
}
/** @override */
public
function
getClobTypeDeclarationSQL
(
array
$field
)
{
...
...
@@ -656,12 +656,12 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
'postgresql'
;
}
/**
* Gets the character casing of a column in an SQL result set.
*
*
* PostgreSQL returns all column names in SQL result sets in lowercase.
*
*
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/
...
...
@@ -669,7 +669,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
strtolower
(
$column
);
}
public
function
getDateTimeTzFormatString
()
{
return
'Y-m-d H:i:sO'
;
...
...
@@ -678,8 +678,8 @@ class PostgreSqlPlatform extends AbstractPlatform
/**
* Get the insert sql for an empty insert statement
*
* @param string $tableName
* @param string $identifierColumnName
* @param string $tableName
* @param string $identifierColumnName
* @return string $sql
*/
public
function
getEmptyIdentityInsertSQL
(
$quotedTableName
,
$quotedIdentifierColumnName
)
...
...
@@ -745,9 +745,17 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
65535
;
}
protected
function
getReservedKeywordsClass
()
{
return
'Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords'
;
}
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
return
'BYTEA'
;
}
}
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
177903df
...
...
@@ -169,70 +169,70 @@ class SqlitePlatform extends AbstractPlatform
return
'PRAGMA read_uncommitted = '
.
$this
->
_getTransactionIsolationLevelSQL
(
$level
);
}
/**
* @override
/**
* @override
*/
public
function
prefersIdentityColumns
()
{
return
true
;
}
/**
* @override
/**
* @override
*/
public
function
getBooleanTypeDeclarationSQL
(
array
$field
)
{
return
'BOOLEAN'
;
}
/**
* @override
/**
* @override
*/
public
function
getIntegerTypeDeclarationSQL
(
array
$field
)
{
return
$this
->
_getCommonIntegerTypeDeclarationSQL
(
$field
);
}
/**
* @override
/**
* @override
*/
public
function
getBigIntTypeDeclarationSQL
(
array
$field
)
{
return
$this
->
_getCommonIntegerTypeDeclarationSQL
(
$field
);
}
/**
* @override
/**
* @override
*/
public
function
getTinyIntTypeDeclarationSql
(
array
$field
)
{
return
$this
->
_getCommonIntegerTypeDeclarationSQL
(
$field
);
}
/**
* @override
/**
* @override
*/
public
function
getSmallIntTypeDeclarationSQL
(
array
$field
)
{
return
$this
->
_getCommonIntegerTypeDeclarationSQL
(
$field
);
}
/**
* @override
/**
* @override
*/
public
function
getMediumIntTypeDeclarationSql
(
array
$field
)
{
return
$this
->
_getCommonIntegerTypeDeclarationSQL
(
$field
);
}
/**
* @override
/**
* @override
*/
public
function
getDateTimeTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'DATETIME'
;
}
/**
* @override
*/
...
...
@@ -249,8 +249,8 @@ class SqlitePlatform extends AbstractPlatform
return
'TIME'
;
}
/**
* @override
/**
* @override
*/
protected
function
_getCommonIntegerTypeDeclarationSQL
(
array
$columnDef
)
{
...
...
@@ -330,7 +330,7 @@ class SqlitePlatform extends AbstractPlatform
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR(255)'
)
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'TEXT'
);
}
public
function
getClobTypeDeclarationSQL
(
array
$field
)
{
return
'CLOB'
;
...
...
@@ -487,9 +487,17 @@ class SqlitePlatform extends AbstractPlatform
'numeric'
=>
'decimal'
,
);
}
protected
function
getReservedKeywordsClass
()
{
return
'Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords'
;
}
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
return
'BLOB'
;
}
}
lib/Doctrine/DBAL/Types/BlobType.php
0 → 100644
View file @
177903df
<?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
;
/**
* Type that maps an SQL BLOB to a PHP resource stream
*
* @since 2.2
*/
class
BlobType
extends
Type
{
/** @override */
public
function
getSQLDeclaration
(
array
$fieldDeclaration
,
AbstractPlatform
$platform
)
{
return
$platform
->
getBlobTypeDeclarationSQL
(
$fieldDeclaration
);
}
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
$hex
=
''
;
for
(
$i
=
0
;
$i
<
strlen
(
$value
);
$i
++
)
{
$hex
.=
dechex
(
ord
(
$value
[
$i
]));
}
return
$value
;
}
/**
* 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
)
{
if
(
is_string
(
$value
))
{
$value
=
fopen
(
'data://text/plain;base64,'
.
base64_encode
(
$value
),
'r'
);
}
else
if
(
!
is_resource
(
$value
))
{
throw
ConversionException
::
conversionFailed
(
$value
,
self
::
BLOB
);
}
return
$value
;
}
public
function
getName
()
{
return
Type
::
BLOB
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Types/Type.php
View file @
177903df
...
...
@@ -46,6 +46,7 @@ abstract class Type
const
SMALLINT
=
'smallint'
;
const
STRING
=
'string'
;
const
TEXT
=
'text'
;
const
BLOB
=
'blob'
;
const
FLOAT
=
'float'
;
/** Map of already instantiated type objects. One instance per type (flyweight). */
...
...
@@ -67,6 +68,7 @@ abstract class Type
self
::
TIME
=>
'Doctrine\DBAL\Types\TimeType'
,
self
::
DECIMAL
=>
'Doctrine\DBAL\Types\DecimalType'
,
self
::
FLOAT
=>
'Doctrine\DBAL\Types\FloatType'
,
self
::
BLOB
=>
'Doctrine\DBAL\Types\BlobType'
,
);
/* Prevent instantiation and force use of the factory method. */
...
...
@@ -194,15 +196,15 @@ abstract class Type
/**
* Gets the (preferred) binding type for values of this type that
* can be used when binding parameters to prepared statements.
*
*
* This method should return one of the PDO::PARAM_* constants, that is, one of:
*
*
* PDO::PARAM_BOOL
* PDO::PARAM_NULL
* PDO::PARAM_INT
* PDO::PARAM_STR
* PDO::PARAM_LOB
*
*
* @return integer
*/
public
function
getBindingType
()
...
...
@@ -244,7 +246,7 @@ abstract class Type
/**
* Modifies the SQL expression (identifier, parameter) to convert to a database value.
*
*
* @param string $sqlExpr
* @param AbstractPlatform $platform
* @return string
...
...
tests/Doctrine/Tests/DBAL/Functional/BlobTest.php
0 → 100644
View file @
177903df
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\DBAL\Connection
;
use
PDO
;
require_once
__DIR__
.
'/../../TestInit.php'
;
/**
* @group DBAL-6
*/
class
BlobTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
try
{
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$table
=
new
\Doctrine\DBAL\Schema\Table
(
"blob_table"
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'clobfield'
,
'text'
);
$table
->
addColumn
(
'blobfield'
,
'blob'
);
$table
->
setPrimaryKey
(
array
(
'id'
));
$sm
=
$this
->
_conn
->
getSchemaManager
();
$sm
->
createTable
(
$table
);
}
catch
(
\Exception
$e
)
{
}
$this
->
_conn
->
exec
(
$this
->
_conn
->
getDatabasePlatform
()
->
getTruncateTableSQL
(
'blob_table'
));
}
public
function
testInsert
()
{
$ret
=
$this
->
_conn
->
insert
(
'blob_table'
,
array
(
'id'
=>
1
,
'clobfield'
=>
'test'
,
'blobfield'
=>
'test'
),
array
(
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_STR
,
\PDO
::
PARAM_LOB
)
);
$this
->
assertEquals
(
1
,
$ret
);
}
public
function
testSelect
()
{
$ret
=
$this
->
_conn
->
insert
(
'blob_table'
,
array
(
'id'
=>
1
,
'clobfield'
=>
'test'
,
'blobfield'
=>
'test'
),
array
(
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_STR
,
\PDO
::
PARAM_LOB
)
);
$this
->
assertBlobContains
(
'test'
);
}
public
function
testUpdate
()
{
$ret
=
$this
->
_conn
->
insert
(
'blob_table'
,
array
(
'id'
=>
1
,
'clobfield'
=>
'test'
,
'blobfield'
=>
'test'
),
array
(
\PDO
::
PARAM_INT
,
\PDO
::
PARAM_STR
,
\PDO
::
PARAM_LOB
)
);
$this
->
_conn
->
update
(
'blob_table'
,
array
(
'blobfield'
=>
'test2'
),
array
(
'id'
=>
1
),
array
(
\PDO
::
PARAM_LOB
,
\PDO
::
PARAM_INT
)
);
$this
->
assertBlobContains
(
'test2'
);
}
private
function
assertBlobContains
(
$text
)
{
$rows
=
$this
->
_conn
->
fetchAll
(
'SELECT * FROM blob_table'
);
$this
->
assertEquals
(
1
,
count
(
$rows
));
$row
=
array_change_key_case
(
$rows
[
0
],
CASE_LOWER
);
$blobValue
=
Type
::
getType
(
'blob'
)
->
convertToPHPValue
(
$row
[
'blobfield'
],
$this
->
_conn
->
getDatabasePlatform
());
$this
->
assertInternalType
(
'resource'
,
$blobValue
);
$this
->
assertEquals
(
$text
,
stream_get_contents
(
$blobValue
));
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php
View file @
177903df
...
...
@@ -6,6 +6,14 @@ use Doctrine\DBAL\Platforms;
class
MockPlatform
extends
\Doctrine\DBAL\Platforms\AbstractPlatform
{
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
public
function
getBooleanTypeDeclarationSQL
(
array
$columnDef
)
{}
public
function
getIntegerTypeDeclarationSQL
(
array
$columnDef
)
{}
public
function
getBigIntTypeDeclarationSQL
(
array
$columnDef
)
{}
...
...
@@ -16,7 +24,7 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform
{
return
"DUMMYVARCHAR()"
;
}
/** @override */
public
function
getClobTypeDeclarationSQL
(
array
$field
)
{
...
...
tests/Doctrine/Tests/Mocks/ConnectionMock.php
View file @
177903df
...
...
@@ -8,7 +8,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
private
$_platformMock
;
private
$_lastInsertId
=
0
;
private
$_inserts
=
array
();
public
function
__construct
(
array
$params
,
$driver
,
$config
=
null
,
$eventManager
=
null
)
{
$this
->
_platformMock
=
new
DatabasePlatformMock
();
...
...
@@ -18,7 +18,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
// Override possible assignment of platform to database platform mock
$this
->
_platform
=
$this
->
_platformMock
;
}
/**
* @override
*/
...
...
@@ -26,15 +26,15 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
{
return
$this
->
_platformMock
;
}
/**
* @override
*/
public
function
insert
(
$tableName
,
array
$data
)
public
function
insert
(
$tableName
,
array
$data
,
array
$types
=
array
()
)
{
$this
->
_inserts
[
$tableName
][]
=
$data
;
}
/**
* @override
*/
...
...
@@ -50,7 +50,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
{
return
$this
->
_fetchOneResult
;
}
/**
* @override
*/
...
...
@@ -61,29 +61,29 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
}
return
$input
;
}
/* Mock API */
public
function
setFetchOneResult
(
$fetchOneResult
)
{
$this
->
_fetchOneResult
=
$fetchOneResult
;
}
public
function
setDatabasePlatform
(
$platform
)
{
$this
->
_platformMock
=
$platform
;
}
public
function
setLastInsertId
(
$id
)
{
$this
->
_lastInsertId
=
$id
;
}
public
function
getInserts
()
{
return
$this
->
_inserts
;
}
public
function
reset
()
{
$this
->
_inserts
=
array
();
...
...
tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
View file @
177903df
...
...
@@ -57,7 +57,7 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
/** @override */
public
function
getVarcharTypeDeclarationSQL
(
array
$field
)
{}
/** @override */
public
function
getClobTypeDeclarationSQL
(
array
$field
)
{}
...
...
@@ -86,6 +86,13 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
}
protected
function
getVarcharTypeDeclarationSQLSnippet
(
$length
,
$fixed
)
{
}
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
}
\ 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