Commit 177903df authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-6'

parents 5be16133 d919b50e
# 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
This diff is collapsed.
...@@ -30,13 +30,15 @@ use \PDO; ...@@ -30,13 +30,15 @@ use \PDO;
class OCI8Statement implements \Doctrine\DBAL\Driver\Statement class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
{ {
/** Statement handle. */ /** Statement handle. */
protected $_dbh;
protected $_sth; protected $_sth;
protected $_executeMode; protected $_executeMode;
protected static $_PARAM = ':param'; protected static $_PARAM = ':param';
protected static $fetchStyleMap = array( protected static $fetchStyleMap = array(
PDO::FETCH_BOTH => OCI_BOTH, PDO::FETCH_BOTH => OCI_BOTH,
PDO::FETCH_ASSOC => OCI_ASSOC, PDO::FETCH_ASSOC => OCI_ASSOC,
PDO::FETCH_NUM => OCI_NUM PDO::FETCH_NUM => OCI_NUM,
PDO::PARAM_LOB => OCI_B_BLOB,
); );
protected $_paramMap = array(); protected $_paramMap = array();
...@@ -50,6 +52,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement ...@@ -50,6 +52,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
{ {
list($statement, $paramMap) = self::convertPositionalToNamedPlaceholders($statement); list($statement, $paramMap) = self::convertPositionalToNamedPlaceholders($statement);
$this->_sth = oci_parse($dbh, $statement); $this->_sth = oci_parse($dbh, $statement);
$this->_dbh = $dbh;
$this->_paramMap = $paramMap; $this->_paramMap = $paramMap;
$this->_executeMode = $executeMode; $this->_executeMode = $executeMode;
} }
...@@ -72,7 +75,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement ...@@ -72,7 +75,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
* @return string * @return string
*/ */
static public function convertPositionalToNamedPlaceholders($statement) static public function convertPositionalToNamedPlaceholders($statement)
{ {
$count = 1; $count = 1;
$inLiteral = false; // a valid query never starts with quotes $inLiteral = false; // a valid query never starts with quotes
$stmtLen = strlen($statement); $stmtLen = strlen($statement);
...@@ -108,8 +111,15 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement ...@@ -108,8 +111,15 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
public function bindParam($column, &$variable, $type = null) public function bindParam($column, &$variable, $type = null)
{ {
$column = isset($this->_paramMap[$column]) ? $this->_paramMap[$column] : $column; $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 ...@@ -122,7 +132,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
return oci_free_statement($this->_sth); return oci_free_statement($this->_sth);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function columnCount() public function columnCount()
...@@ -141,7 +151,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement ...@@ -141,7 +151,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
} }
return $error; return $error;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -181,7 +191,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement ...@@ -181,7 +191,7 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
if ( ! isset(self::$fetchStyleMap[$fetchStyle])) { if ( ! isset(self::$fetchStyleMap[$fetchStyle])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle); throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle);
} }
return oci_fetch_array($this->_sth, self::$fetchStyleMap[$fetchStyle] | OCI_RETURN_NULLS | OCI_RETURN_LOBS); 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 ...@@ -193,11 +203,11 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
if ( ! isset(self::$fetchStyleMap[$fetchStyle])) { if ( ! isset(self::$fetchStyleMap[$fetchStyle])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle); throw new \InvalidArgumentException("Invalid fetch style: " . $fetchStyle);
} }
$result = array(); $result = array();
oci_fetch_all($this->_sth, $result, 0, -1, oci_fetch_all($this->_sth, $result, 0, -1,
self::$fetchStyleMap[$fetchStyle] | OCI_RETURN_NULLS | OCI_FETCHSTATEMENT_BY_ROW | OCI_RETURN_LOBS); self::$fetchStyleMap[$fetchStyle] | OCI_RETURN_NULLS | OCI_FETCHSTATEMENT_BY_ROW | OCI_RETURN_LOBS);
return $result; return $result;
} }
...@@ -216,5 +226,5 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement ...@@ -216,5 +226,5 @@ class OCI8Statement implements \Doctrine\DBAL\Driver\Statement
public function rowCount() public function rowCount()
{ {
return oci_num_rows($this->_sth); return oci_num_rows($this->_sth);
} }
} }
...@@ -25,6 +25,14 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -25,6 +25,14 @@ use Doctrine\DBAL\Schema\TableDiff;
class DB2Platform extends AbstractPlatform 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() public function initializeDoctrineTypeMappings()
{ {
$this->doctrineTypeMapping = array( $this->doctrineTypeMapping = array(
...@@ -347,7 +355,7 @@ class DB2Platform extends AbstractPlatform ...@@ -347,7 +355,7 @@ class DB2Platform extends AbstractPlatform
$indexes = $options['indexes']; $indexes = $options['indexes'];
} }
$options['indexes'] = array(); $options['indexes'] = array();
$sqls = parent::_getCreateTableSQL($tableName, $columns, $options); $sqls = parent::_getCreateTableSQL($tableName, $columns, $options);
foreach ($indexes as $index => $definition) { foreach ($indexes as $index => $definition) {
...@@ -550,7 +558,7 @@ class DB2Platform extends AbstractPlatform ...@@ -550,7 +558,7 @@ class DB2Platform extends AbstractPlatform
{ {
return false; return false;
} }
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\DB2Keywords'; return 'Doctrine\DBAL\Platforms\Keywords\DB2Keywords';
......
...@@ -40,26 +40,26 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -40,26 +40,26 @@ class MsSqlPlatform extends AbstractPlatform
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
return 'DATEDIFF(day, ' . $date2 . ',' . $date1 . ')'; return 'DATEDIFF(day, ' . $date2 . ',' . $date1 . ')';
} }
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return 'DATEADD(day, ' . $days . ', ' . $date . ')'; return 'DATEADD(day, ' . $days . ', ' . $date . ')';
} }
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return 'DATEADD(day, -1 * ' . $days . ', ' . $date . ')'; return 'DATEADD(day, -1 * ' . $days . ', ' . $date . ')';
} }
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return 'DATEADD(month, ' . $months . ', ' . $date . ')'; return 'DATEADD(month, ' . $months . ', ' . $date . ')';
} }
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return 'DATEADD(month, -1 * ' . $months . ', ' . $date . ')'; return 'DATEADD(month, -1 * ' . $months . ', ' . $date . ')';
...@@ -278,7 +278,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -278,7 +278,7 @@ class MsSqlPlatform extends AbstractPlatform
{ {
$queryParts = array(); $queryParts = array();
$sql = array(); $sql = array();
if ($diff->newName !== false) { if ($diff->newName !== false) {
$queryParts[] = 'RENAME TO ' . $diff->newName; $queryParts[] = 'RENAME TO ' . $diff->newName;
} }
...@@ -822,9 +822,17 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -822,9 +822,17 @@ class MsSqlPlatform extends AbstractPlatform
{ {
return "[" . str_replace("]", "][", $str) . "]"; return "[" . str_replace("]", "][", $str) . "]";
} }
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
return 'TRUNCATE TABLE '.$tableName; return 'TRUNCATE TABLE '.$tableName;
} }
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public function getBlobTypeDeclarationSQL(array $field)
{
return 'VARBINARY(MAX)';
}
} }
...@@ -46,7 +46,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -46,7 +46,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return '`'; return '`';
} }
/** /**
* Returns the regular expression operator. * Returns the regular expression operator.
* *
...@@ -137,9 +137,9 @@ class MySqlPlatform extends AbstractPlatform ...@@ -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". * prefered, because it doesn't cause problems with SQL keywords such as "order" or "table".
* *
* @param string $table * @param string $table
* @param string $currentDatabase * @param string $currentDatabase
* @return string * @return string
...@@ -150,7 +150,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -150,7 +150,7 @@ class MySqlPlatform extends AbstractPlatform
return "SELECT TABLE_NAME AS `Table`, NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, ". 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, ". "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, " . "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 . "'"; "FROM information_schema.STATISTICS WHERE TABLE_NAME = '" . $table . "' AND TABLE_SCHEMA = '" . $currentDatabase . "'";
} else { } else {
return 'SHOW INDEX FROM ' . $table; return 'SHOW INDEX FROM ' . $table;
...@@ -228,7 +228,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -228,7 +228,7 @@ class MySqlPlatform extends AbstractPlatform
return 'DATETIME'; return 'DATETIME';
} }
} }
/** /**
* @override * @override
*/ */
...@@ -240,10 +240,10 @@ class MySqlPlatform extends AbstractPlatform ...@@ -240,10 +240,10 @@ class MySqlPlatform extends AbstractPlatform
/** /**
* @override * @override
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
return 'TIME'; return 'TIME';
} }
/** /**
* @override * @override
...@@ -265,7 +265,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -265,7 +265,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'COLLATE ' . $collation; return 'COLLATE ' . $collation;
} }
/** /**
* Whether the platform prefers identity columns for ID generation. * Whether the platform prefers identity columns for ID generation.
* MySql prefers "autoincrement" identity columns since sequences can only * MySql prefers "autoincrement" identity columns since sequences can only
...@@ -278,7 +278,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -278,7 +278,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return true; return true;
} }
/** /**
* Whether the platform supports identity columns. * Whether the platform supports identity columns.
* MySql supports this through AUTO_INCREMENT columns. * MySql supports this through AUTO_INCREMENT columns.
...@@ -300,7 +300,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -300,7 +300,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'SHOW DATABASES'; return 'SHOW DATABASES';
} }
public function getListTablesSQL() public function getListTablesSQL()
{ {
return "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"; return "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'";
...@@ -329,7 +329,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -329,7 +329,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'CREATE DATABASE ' . $name; return 'CREATE DATABASE ' . $name;
} }
/** /**
* drop an existing database * drop an existing database
* *
...@@ -341,7 +341,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -341,7 +341,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'DROP DATABASE ' . $name; return 'DROP DATABASE ' . $name;
} }
/** /**
* create a new table * create a new table
* *
...@@ -431,7 +431,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -431,7 +431,7 @@ class MySqlPlatform extends AbstractPlatform
// default to innodb // default to innodb
$optionStrings[] = 'ENGINE = InnoDB'; $optionStrings[] = 'ENGINE = InnoDB';
} }
if ( ! empty($optionStrings)) { if ( ! empty($optionStrings)) {
$query.= ' '.implode(' ', $optionStrings); $query.= ' '.implode(' ', $optionStrings);
} }
...@@ -442,10 +442,10 @@ class MySqlPlatform extends AbstractPlatform ...@@ -442,10 +442,10 @@ class MySqlPlatform extends AbstractPlatform
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName); $sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
} }
} }
return $sql; return $sql;
} }
/** /**
* Gets the SQL to alter an existing table. * Gets the SQL to alter an existing table.
* *
...@@ -496,7 +496,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -496,7 +496,7 @@ class MySqlPlatform extends AbstractPlatform
); );
return $sql; return $sql;
} }
/** /**
* Obtain DBMS specific SQL code portion needed to declare an integer type * Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
...@@ -551,7 +551,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -551,7 +551,7 @@ class MySqlPlatform extends AbstractPlatform
return $unsigned . $autoinc; return $unsigned . $autoinc;
} }
/** /**
* Return the FOREIGN KEY query section dealing with non-standard options * Return the FOREIGN KEY query section dealing with non-standard options
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ... * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
...@@ -569,7 +569,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -569,7 +569,7 @@ class MySqlPlatform extends AbstractPlatform
$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey); $query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
return $query; return $query;
} }
/** /**
* Gets the SQL to drop an index of a table. * Gets the SQL to drop an index of a table.
* *
...@@ -578,7 +578,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -578,7 +578,7 @@ class MySqlPlatform extends AbstractPlatform
* @override * @override
*/ */
public function getDropIndexSQL($index, $table=null) public function getDropIndexSQL($index, $table=null)
{ {
if($index instanceof Index) { if($index instanceof Index) {
$indexName = $index->getQuotedName($this); $indexName = $index->getQuotedName($this);
} else if(is_string($index)) { } else if(is_string($index)) {
...@@ -586,25 +586,25 @@ class MySqlPlatform extends AbstractPlatform ...@@ -586,25 +586,25 @@ class MySqlPlatform extends AbstractPlatform
} else { } else {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
} }
if($table instanceof Table) { if($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} else if(!is_string($table)) { } else if(!is_string($table)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
} }
if ($index instanceof Index && $index->isPrimary()) { 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. // so we cannot use them in statements because of them being keyword.
return $this->getDropPrimaryKeySQL($table); return $this->getDropPrimaryKeySQL($table);
} }
return 'DROP INDEX ' . $indexName . ' ON ' . $table; return 'DROP INDEX ' . $indexName . ' ON ' . $table;
} }
/** /**
* @param Index $index * @param Index $index
* @param Table $table * @param Table $table
*/ */
protected function getDropPrimaryKeySQL($table) protected function getDropPrimaryKeySQL($table)
{ {
...@@ -664,7 +664,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -664,7 +664,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 65535; return 65535;
} }
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords';
...@@ -690,4 +690,12 @@ class MySqlPlatform extends AbstractPlatform ...@@ -690,4 +690,12 @@ class MySqlPlatform extends AbstractPlatform
return 'DROP TEMPORARY TABLE ' . $table; return 'DROP TEMPORARY TABLE ' . $table;
} }
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public function getBlobTypeDeclarationSQL(array $field)
{
return 'LONGBLOB';
}
} }
...@@ -102,14 +102,14 @@ class OraclePlatform extends AbstractPlatform ...@@ -102,14 +102,14 @@ class OraclePlatform extends AbstractPlatform
/** /**
* Get the number of days difference between two dates. * Get the number of days difference between two dates.
* *
* Note: Since Oracle timestamp differences are calculated down to the microsecond we have to truncate * 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 * them to the difference in days. This is obviously a restriction of the original functionality, but we
* need to make this a portable function. * need to make this a portable function.
* *
* @param type $date1 * @param type $date1
* @param type $date2 * @param type $date2
* @return type * @return type
*/ */
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
...@@ -135,7 +135,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -135,7 +135,7 @@ class OraclePlatform extends AbstractPlatform
{ {
return "ADD_MONTHS(" . $date . ", -" . $months . ")"; return "ADD_MONTHS(" . $date . ", -" . $months . ")";
} }
/** /**
* Gets the SQL used to create a sequence that starts with a given value * Gets the SQL used to create a sequence that starts with a given value
* and increments by the given allocation size. * and increments by the given allocation size.
...@@ -151,13 +151,13 @@ class OraclePlatform extends AbstractPlatform ...@@ -151,13 +151,13 @@ class OraclePlatform extends AbstractPlatform
{ {
return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) . return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) .
' START WITH ' . $sequence->getInitialValue() . ' START WITH ' . $sequence->getInitialValue() .
' MINVALUE ' . $sequence->getInitialValue() . ' MINVALUE ' . $sequence->getInitialValue() .
' INCREMENT BY ' . $sequence->getAllocationSize(); ' INCREMENT BY ' . $sequence->getAllocationSize();
} }
public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) . return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) .
' INCREMENT BY ' . $sequence->getAllocationSize(); ' INCREMENT BY ' . $sequence->getAllocationSize();
} }
...@@ -171,7 +171,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -171,7 +171,7 @@ class OraclePlatform extends AbstractPlatform
{ {
return 'SELECT ' . $sequenceName . '.nextval FROM DUAL'; return 'SELECT ' . $sequenceName . '.nextval FROM DUAL';
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
...@@ -197,7 +197,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -197,7 +197,7 @@ class OraclePlatform extends AbstractPlatform
return parent::_getTransactionIsolationLevelSQL($level); return parent::_getTransactionIsolationLevelSQL($level);
} }
} }
/** /**
* @override * @override
*/ */
...@@ -281,7 +281,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -281,7 +281,7 @@ class OraclePlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)')
: ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)'); : ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)');
} }
/** @override */ /** @override */
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
...@@ -318,11 +318,11 @@ class OraclePlatform extends AbstractPlatform ...@@ -318,11 +318,11 @@ class OraclePlatform extends AbstractPlatform
} }
if (isset($column['autoincrement']) && $column['autoincrement'] || if (isset($column['autoincrement']) && $column['autoincrement'] ||
(isset($column['autoinc']) && $column['autoinc'])) { (isset($column['autoinc']) && $column['autoinc'])) {
$sql = array_merge($sql, $this->getCreateAutoincrementSql($name, $table)); $sql = array_merge($sql, $this->getCreateAutoincrementSql($name, $table));
} }
} }
if (isset($indexes) && ! empty($indexes)) { if (isset($indexes) && ! empty($indexes)) {
foreach ($indexes as $indexName => $index) { foreach ($indexes as $indexName => $index) {
$sql[] = $this->getCreateIndexSQL($index, $table); $sql[] = $this->getCreateIndexSQL($index, $table);
...@@ -341,7 +341,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -341,7 +341,7 @@ class OraclePlatform extends AbstractPlatform
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
$table = strtoupper($table); $table = strtoupper($table);
return "SELECT uind.index_name AS name, " . return "SELECT uind.index_name AS name, " .
" uind.index_type AS type, " . " uind.index_type AS type, " .
" decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, " . " decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, " .
...@@ -392,7 +392,7 @@ BEGIN ...@@ -392,7 +392,7 @@ BEGIN
IF constraints_Count = 0 OR constraints_Count = \'\' THEN IF constraints_Count = 0 OR constraints_Count = \'\' THEN
EXECUTE IMMEDIATE \''.$this->getCreateConstraintSQL($idx, $table).'\'; EXECUTE IMMEDIATE \''.$this->getCreateConstraintSQL($idx, $table).'\';
END IF; END IF;
END;'; END;';
$sequenceName = $table . '_SEQ'; $sequenceName = $table . '_SEQ';
$sequence = new \Doctrine\DBAL\Schema\Sequence($sequenceName, $start); $sequence = new \Doctrine\DBAL\Schema\Sequence($sequenceName, $start);
...@@ -476,12 +476,12 @@ LEFT JOIN all_cons_columns r_cols ...@@ -476,12 +476,12 @@ LEFT JOIN all_cons_columns r_cols
{ {
$table = strtoupper($table); $table = strtoupper($table);
$ownerCondition = ''; $ownerCondition = '';
if(null !== $database){ if(null !== $database){
$database = strtoupper($database); $database = strtoupper($database);
$ownerCondition = "AND c.owner = '".$database."'"; $ownerCondition = "AND c.owner = '".$database."'";
} }
return "SELECT c.*, d.comments FROM all_tab_columns c ". 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 ". "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"; "WHERE c.table_name = '" . $table . "' ".$ownerCondition." ORDER BY c.column_name";
...@@ -639,12 +639,12 @@ LEFT JOIN all_cons_columns r_cols ...@@ -639,12 +639,12 @@ LEFT JOIN all_cons_columns r_cols
} }
return $query; return $query;
} }
/** /**
* Gets the character casing of a column in an SQL result set of this platform. * 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. * 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. * @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. * @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 ...@@ -652,12 +652,12 @@ LEFT JOIN all_cons_columns r_cols
{ {
return strtoupper($column); return strtoupper($column);
} }
public function getCreateTemporaryTableSnippetSQL() public function getCreateTemporaryTableSnippetSQL()
{ {
return "CREATE GLOBAL TEMPORARY TABLE"; return "CREATE GLOBAL TEMPORARY TABLE";
} }
public function getDateTimeTzFormatString() public function getDateTimeTzFormatString()
{ {
return 'Y-m-d H:i:sP'; return 'Y-m-d H:i:sP';
...@@ -672,7 +672,7 @@ LEFT JOIN all_cons_columns r_cols ...@@ -672,7 +672,7 @@ LEFT JOIN all_cons_columns r_cols
{ {
return '1900-01-01 H:i:s'; return '1900-01-01 H:i:s';
} }
public function fixSchemaElementName($schemaElementName) public function fixSchemaElementName($schemaElementName)
{ {
if (strlen($schemaElementName) > 30) { if (strlen($schemaElementName) > 30) {
...@@ -769,9 +769,17 @@ LEFT JOIN all_cons_columns r_cols ...@@ -769,9 +769,17 @@ LEFT JOIN all_cons_columns r_cols
{ {
return ''; return '';
} }
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\OracleKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\OracleKeywords';
} }
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public function getBlobTypeDeclarationSQL(array $field)
{
return 'BLOB';
}
} }
...@@ -116,7 +116,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -116,7 +116,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return "(" . $date . "- interval '" . $months . " month')"; return "(" . $date . "- interval '" . $months . " month')";
} }
/** /**
* parses a literal boolean value and returns * parses a literal boolean value and returns
* proper sql equivalent * proper sql equivalent
...@@ -128,7 +128,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -128,7 +128,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return $value; return $value;
}*/ }*/
/** /**
* Whether the platform supports sequences. * Whether the platform supports sequences.
* Postgres has native support for sequences. * Postgres has native support for sequences.
...@@ -139,17 +139,17 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -139,17 +139,17 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return true; return true;
} }
/** /**
* Whether the platform supports database schemas. * Whether the platform supports database schemas.
* *
* @return boolean * @return boolean
*/ */
public function supportsSchemas() public function supportsSchemas()
{ {
return true; return true;
} }
/** /**
* Whether the platform supports identity columns. * Whether the platform supports identity columns.
* Postgres supports these through the SERIAL keyword. * Postgres supports these through the SERIAL keyword.
...@@ -165,7 +165,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -165,7 +165,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return true; return true;
} }
/** /**
* Whether the platform prefers sequences for ID generation. * Whether the platform prefers sequences for ID generation.
* *
...@@ -187,7 +187,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -187,7 +187,7 @@ class PostgreSqlPlatform extends AbstractPlatform
c.relname, n.nspname AS schemaname c.relname, n.nspname AS schemaname
FROM FROM
pg_class c, pg_namespace n 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')"; (n.nspname NOT LIKE 'pg_%' AND n.nspname != 'information_schema')";
} }
...@@ -304,7 +304,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -304,7 +304,7 @@ class PostgreSqlPlatform extends AbstractPlatform
AND n.oid = c.relnamespace AND n.oid = c.relnamespace
ORDER BY a.attnum"; ORDER BY a.attnum";
} }
/** /**
* create a new database * create a new database
* *
...@@ -357,7 +357,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -357,7 +357,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
return $query; return $query;
} }
/** /**
* generates the sql for altering an existing table on postgresql * generates the sql for altering an existing table on postgresql
* *
...@@ -391,7 +391,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -391,7 +391,7 @@ class PostgreSqlPlatform extends AbstractPlatform
foreach ($diff->changedColumns AS $columnDiff) { foreach ($diff->changedColumns AS $columnDiff) {
$oldColumnName = $columnDiff->oldColumnName; $oldColumnName = $columnDiff->oldColumnName;
$column = $columnDiff->column; $column = $columnDiff->column;
if ($columnDiff->hasChanged('type')) { if ($columnDiff->hasChanged('type')) {
$type = $column->getType(); $type = $column->getType();
...@@ -437,7 +437,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -437,7 +437,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL); return array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
} }
/** /**
* Gets the SQL to create a sequence on this platform. * Gets the SQL to create a sequence on this platform.
* *
...@@ -451,13 +451,13 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -451,13 +451,13 @@ class PostgreSqlPlatform extends AbstractPlatform
' MINVALUE ' . $sequence->getInitialValue() . ' MINVALUE ' . $sequence->getInitialValue() .
' START ' . $sequence->getInitialValue(); ' START ' . $sequence->getInitialValue();
} }
public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) . return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) .
' INCREMENT BY ' . $sequence->getAllocationSize(); ' INCREMENT BY ' . $sequence->getAllocationSize();
} }
/** /**
* Drop existing sequence * Drop existing sequence
* @param \Doctrine\DBAL\Schema\Sequence $sequence * @param \Doctrine\DBAL\Schema\Sequence $sequence
...@@ -480,7 +480,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -480,7 +480,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return $this->getDropConstraintSQL($foreignKey, $table); return $this->getDropConstraintSQL($foreignKey, $table);
} }
/** /**
* Gets the SQL used to create a table. * Gets the SQL used to create a table.
* *
...@@ -516,7 +516,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -516,7 +516,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return $sql; return $sql;
} }
/** /**
* Postgres wants boolean values converted to the strings 'true'/'false'. * Postgres wants boolean values converted to the strings 'true'/'false'.
* *
...@@ -549,7 +549,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -549,7 +549,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
. $this->_getTransactionIsolationLevelSQL($level); . $this->_getTransactionIsolationLevelSQL($level);
} }
/** /**
* @override * @override
*/ */
...@@ -566,7 +566,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -566,7 +566,7 @@ class PostgreSqlPlatform extends AbstractPlatform
if ( ! empty($field['autoincrement'])) { if ( ! empty($field['autoincrement'])) {
return 'SERIAL'; return 'SERIAL';
} }
return 'INT'; return 'INT';
} }
...@@ -604,7 +604,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -604,7 +604,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return 'TIMESTAMP(0) WITH TIME ZONE'; return 'TIMESTAMP(0) WITH TIME ZONE';
} }
/** /**
* @override * @override
*/ */
...@@ -640,7 +640,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -640,7 +640,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
} }
/** @override */ /** @override */
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
...@@ -656,12 +656,12 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -656,12 +656,12 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return 'postgresql'; return 'postgresql';
} }
/** /**
* Gets the character casing of a column in an SQL result set. * Gets the character casing of a column in an SQL result set.
* *
* PostgreSQL returns all column names in SQL result sets in lowercase. * 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. * @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. * @return string The column name in the character casing used in SQL result sets.
*/ */
...@@ -669,7 +669,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -669,7 +669,7 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return strtolower($column); return strtolower($column);
} }
public function getDateTimeTzFormatString() public function getDateTimeTzFormatString()
{ {
return 'Y-m-d H:i:sO'; return 'Y-m-d H:i:sO';
...@@ -678,8 +678,8 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -678,8 +678,8 @@ class PostgreSqlPlatform extends AbstractPlatform
/** /**
* Get the insert sql for an empty insert statement * Get the insert sql for an empty insert statement
* *
* @param string $tableName * @param string $tableName
* @param string $identifierColumnName * @param string $identifierColumnName
* @return string $sql * @return string $sql
*/ */
public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName) public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName)
...@@ -745,9 +745,17 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -745,9 +745,17 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return 65535; return 65535;
} }
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords';
} }
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public function getBlobTypeDeclarationSQL(array $field)
{
return 'BYTEA';
}
} }
...@@ -169,70 +169,70 @@ class SqlitePlatform extends AbstractPlatform ...@@ -169,70 +169,70 @@ class SqlitePlatform extends AbstractPlatform
return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSQL($level); return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSQL($level);
} }
/** /**
* @override * @override
*/ */
public function prefersIdentityColumns() public function prefersIdentityColumns()
{ {
return true; return true;
} }
/** /**
* @override * @override
*/ */
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field)
{ {
return 'BOOLEAN'; return 'BOOLEAN';
} }
/** /**
* @override * @override
*/ */
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field)
{ {
return $this->_getCommonIntegerTypeDeclarationSQL($field); return $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** /**
* @override * @override
*/ */
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field)
{ {
return $this->_getCommonIntegerTypeDeclarationSQL($field); return $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** /**
* @override * @override
*/ */
public function getTinyIntTypeDeclarationSql(array $field) public function getTinyIntTypeDeclarationSql(array $field)
{ {
return $this->_getCommonIntegerTypeDeclarationSQL($field); return $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** /**
* @override * @override
*/ */
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field)
{ {
return $this->_getCommonIntegerTypeDeclarationSQL($field); return $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** /**
* @override * @override
*/ */
public function getMediumIntTypeDeclarationSql(array $field) public function getMediumIntTypeDeclarationSql(array $field)
{ {
return $this->_getCommonIntegerTypeDeclarationSQL($field); return $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** /**
* @override * @override
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
return 'DATETIME'; return 'DATETIME';
} }
/** /**
* @override * @override
*/ */
...@@ -249,8 +249,8 @@ class SqlitePlatform extends AbstractPlatform ...@@ -249,8 +249,8 @@ class SqlitePlatform extends AbstractPlatform
return 'TIME'; return 'TIME';
} }
/** /**
* @override * @override
*/ */
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
...@@ -330,7 +330,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -330,7 +330,7 @@ class SqlitePlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
} }
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
return 'CLOB'; return 'CLOB';
...@@ -487,9 +487,17 @@ class SqlitePlatform extends AbstractPlatform ...@@ -487,9 +487,17 @@ class SqlitePlatform extends AbstractPlatform
'numeric' => 'decimal', 'numeric' => 'decimal',
); );
} }
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords';
} }
/**
* Gets the SQL Snippet used to declare a BLOB column type.
*/
public function getBlobTypeDeclarationSQL(array $field)
{
return 'BLOB';
}
} }
<?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
...@@ -46,6 +46,7 @@ abstract class Type ...@@ -46,6 +46,7 @@ abstract class Type
const SMALLINT = 'smallint'; const SMALLINT = 'smallint';
const STRING = 'string'; const STRING = 'string';
const TEXT = 'text'; const TEXT = 'text';
const BLOB = 'blob';
const FLOAT = 'float'; const FLOAT = 'float';
/** Map of already instantiated type objects. One instance per type (flyweight). */ /** Map of already instantiated type objects. One instance per type (flyweight). */
...@@ -67,6 +68,7 @@ abstract class Type ...@@ -67,6 +68,7 @@ abstract class Type
self::TIME => 'Doctrine\DBAL\Types\TimeType', self::TIME => 'Doctrine\DBAL\Types\TimeType',
self::DECIMAL => 'Doctrine\DBAL\Types\DecimalType', self::DECIMAL => 'Doctrine\DBAL\Types\DecimalType',
self::FLOAT => 'Doctrine\DBAL\Types\FloatType', self::FLOAT => 'Doctrine\DBAL\Types\FloatType',
self::BLOB => 'Doctrine\DBAL\Types\BlobType',
); );
/* Prevent instantiation and force use of the factory method. */ /* Prevent instantiation and force use of the factory method. */
...@@ -194,15 +196,15 @@ abstract class Type ...@@ -194,15 +196,15 @@ abstract class Type
/** /**
* Gets the (preferred) binding type for values of this type that * Gets the (preferred) binding type for values of this type that
* can be used when binding parameters to prepared statements. * can be used when binding parameters to prepared statements.
* *
* This method should return one of the PDO::PARAM_* constants, that is, one of: * This method should return one of the PDO::PARAM_* constants, that is, one of:
* *
* PDO::PARAM_BOOL * PDO::PARAM_BOOL
* PDO::PARAM_NULL * PDO::PARAM_NULL
* PDO::PARAM_INT * PDO::PARAM_INT
* PDO::PARAM_STR * PDO::PARAM_STR
* PDO::PARAM_LOB * PDO::PARAM_LOB
* *
* @return integer * @return integer
*/ */
public function getBindingType() public function getBindingType()
...@@ -244,7 +246,7 @@ abstract class Type ...@@ -244,7 +246,7 @@ abstract class Type
/** /**
* Modifies the SQL expression (identifier, parameter) to convert to a database value. * Modifies the SQL expression (identifier, parameter) to convert to a database value.
* *
* @param string $sqlExpr * @param string $sqlExpr
* @param AbstractPlatform $platform * @param AbstractPlatform $platform
* @return string * @return string
......
<?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
...@@ -6,6 +6,14 @@ use Doctrine\DBAL\Platforms; ...@@ -6,6 +6,14 @@ use Doctrine\DBAL\Platforms;
class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform 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 getBooleanTypeDeclarationSQL(array $columnDef) {}
public function getIntegerTypeDeclarationSQL(array $columnDef) {} public function getIntegerTypeDeclarationSQL(array $columnDef) {}
public function getBigIntTypeDeclarationSQL(array $columnDef) {} public function getBigIntTypeDeclarationSQL(array $columnDef) {}
...@@ -16,7 +24,7 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -16,7 +24,7 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform
{ {
return "DUMMYVARCHAR()"; return "DUMMYVARCHAR()";
} }
/** @override */ /** @override */
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
......
...@@ -8,7 +8,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection ...@@ -8,7 +8,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
private $_platformMock; private $_platformMock;
private $_lastInsertId = 0; private $_lastInsertId = 0;
private $_inserts = array(); private $_inserts = array();
public function __construct(array $params, $driver, $config = null, $eventManager = null) public function __construct(array $params, $driver, $config = null, $eventManager = null)
{ {
$this->_platformMock = new DatabasePlatformMock(); $this->_platformMock = new DatabasePlatformMock();
...@@ -18,7 +18,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection ...@@ -18,7 +18,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
// Override possible assignment of platform to database platform mock // Override possible assignment of platform to database platform mock
$this->_platform = $this->_platformMock; $this->_platform = $this->_platformMock;
} }
/** /**
* @override * @override
*/ */
...@@ -26,15 +26,15 @@ class ConnectionMock extends \Doctrine\DBAL\Connection ...@@ -26,15 +26,15 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
{ {
return $this->_platformMock; return $this->_platformMock;
} }
/** /**
* @override * @override
*/ */
public function insert($tableName, array $data) public function insert($tableName, array $data, array $types = array())
{ {
$this->_inserts[$tableName][] = $data; $this->_inserts[$tableName][] = $data;
} }
/** /**
* @override * @override
*/ */
...@@ -50,7 +50,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection ...@@ -50,7 +50,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
{ {
return $this->_fetchOneResult; return $this->_fetchOneResult;
} }
/** /**
* @override * @override
*/ */
...@@ -61,29 +61,29 @@ class ConnectionMock extends \Doctrine\DBAL\Connection ...@@ -61,29 +61,29 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
} }
return $input; return $input;
} }
/* Mock API */ /* Mock API */
public function setFetchOneResult($fetchOneResult) public function setFetchOneResult($fetchOneResult)
{ {
$this->_fetchOneResult = $fetchOneResult; $this->_fetchOneResult = $fetchOneResult;
} }
public function setDatabasePlatform($platform) public function setDatabasePlatform($platform)
{ {
$this->_platformMock = $platform; $this->_platformMock = $platform;
} }
public function setLastInsertId($id) public function setLastInsertId($id)
{ {
$this->_lastInsertId = $id; $this->_lastInsertId = $id;
} }
public function getInserts() public function getInserts()
{ {
return $this->_inserts; return $this->_inserts;
} }
public function reset() public function reset()
{ {
$this->_inserts = array(); $this->_inserts = array();
......
...@@ -57,7 +57,7 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -57,7 +57,7 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
/** @override */ /** @override */
public function getVarcharTypeDeclarationSQL(array $field) {} public function getVarcharTypeDeclarationSQL(array $field) {}
/** @override */ /** @override */
public function getClobTypeDeclarationSQL(array $field) {} public function getClobTypeDeclarationSQL(array $field) {}
...@@ -86,6 +86,13 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -86,6 +86,13 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
} }
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment