Commit 3c310535 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'master' of github.com:doctrine/dbal

parents b61d442d 4ce8fed1
......@@ -555,8 +555,9 @@ class Connection implements DriverConnection
public function quote($input, $type = null)
{
$this->connect();
return $this->_conn->quote($input, $type);
list($value, $bindingType) = $this->getBindingInfo($input, $type);
return $this->_conn->quote($input, $bindingType);
}
/**
......@@ -1069,15 +1070,7 @@ class Connection implements DriverConnection
$typeIndex = $bindIndex + $typeOffset;
if (isset($types[$typeIndex])) {
$type = $types[$typeIndex];
if (is_string($type)) {
$type = Type::getType($type);
}
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->_platform);
$bindingType = $type->getBindingType();
} else {
$bindingType = $type; // PDO::PARAM_* constants
}
list($value, $bindingType) = $this->getBindingInfo($value, $type);
$stmt->bindValue($bindIndex, $value, $bindingType);
} else {
$stmt->bindValue($bindIndex, $value);
......@@ -1089,15 +1082,7 @@ class Connection implements DriverConnection
foreach ($params as $name => $value) {
if (isset($types[$name])) {
$type = $types[$name];
if (is_string($type)) {
$type = Type::getType($type);
}
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->_platform);
$bindingType = $type->getBindingType();
} else {
$bindingType = $type; // PDO::PARAM_* constants
}
list($value, $bindingType) = $this->getBindingInfo($value, $type);
$stmt->bindValue($name, $value, $bindingType);
} else {
$stmt->bindValue($name, $value);
......@@ -1105,7 +1090,28 @@ class Connection implements DriverConnection
}
}
}
/**
* Gets the binding type of a given type. The given type can be a PDO or DBAL mapping type.
*
* @param mixed $value The value to bind
* @param mixed $type The type to bind (PDO or DBAL)
* @return array [0] => the (escaped) value, [1] => the binding type
*/
private function getBindingInfo($value, $type)
{
if (is_string($type)) {
$type = Type::getType($type);
}
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->_platform);
$bindingType = $type->getBindingType();
} else {
$bindingType = $type; // PDO::PARAM_* constants
}
return array($value, $bindingType);
}
/**
* Create a new instance of a SQL query builder.
*
......@@ -1115,4 +1121,4 @@ class Connection implements DriverConnection
{
return new Query\QueryBuilder($this);
}
}
\ No newline at end of file
}
......@@ -607,14 +607,12 @@ class MsSqlPlatform extends AbstractPlatform
// Remove ORDER BY clause from $query
$query = preg_replace('/\s+ORDER BY(.*)/', '', $query);
// Add ORDER BY clause as an argument for ROW_NUMBER()
$query = "SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", * FROM ($query) AS inner_tbl";
$query = preg_replace('/^SELECT\s/', '', $query);
$start = $offset + 1;
$end = $offset + $count;
$query = "WITH outer_tbl AS ($query) SELECT * FROM outer_tbl WHERE \"doctrine_rownum\" BETWEEN $start AND $end";
$query = "SELECT * FROM (SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", $query) AS doctrine_tbl WHERE \"doctrine_rownum\" BETWEEN $start AND $end";
}
}
......
......@@ -475,9 +475,16 @@ LEFT JOIN all_cons_columns r_cols
public function getListTableColumnsSQL($table, $database = null)
{
$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 . "' ORDER BY c.column_name";
"WHERE c.table_name = '" . $table . "' ".$ownerCondition." ORDER BY c.column_name";
}
/**
......
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Types\Type;
require_once __DIR__ . '/../../TestInit.php';
......@@ -207,4 +208,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
});
}
}
\ No newline at end of file
/**
* Tests that the quote function accepts DBAL and PDO types.
*/
public function testQuote()
{
$this->assertEquals($this->_conn->quote("foo", Type::STRING), $this->_conn->quote("foo", \PDO::PARAM_STR));
}
}
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