Skip to content

Commit abb6e5c

Browse files
committed
Conflicts:
lib/Doctrine/Connection/Mssql.php
1 parent 34b1c74 commit abb6e5c

File tree

2 files changed

+85
-10
lines changed

2 files changed

+85
-10
lines changed

lib/Doctrine/Connection/Mssql.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,20 +346,16 @@ public function exec($query, array $params = array())
346346
*/
347347
protected function replaceBoundParamsWithInlineValuesInQuery($query, array $params) {
348348

349-
foreach($params as $key => $value) {
350-
if(is_null($value)) {
351-
$value = 'NULL';
352-
}
353-
else {
354-
$value = $this->quote($value);
355-
}
349+
foreach ($params as $key => $value) {
350+
$value = is_null($value) ? 'NULL' : $this->quote($value);
356351

357-
$re = '/([=><,\(][^\\\']*)(\?)/iU';
352+
// Supported:
353+
// * all variations of =, <, >
354+
// * LIKE
355+
$re = '/(?<=WHERE)(\s+.+?\s+([=<>]+|LIKE)\s+)(\?)/';
358356

359357
$query = preg_replace($re, "\\1 {$value}", $query, 1);
360-
361358
}
362-
363359
return $query;
364360

365361
}

tests/Ticket/DC841TestCase.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/*
3+
* $Id$
4+
*
5+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16+
*
17+
* This software consists of voluntary contributions made by many individuals
18+
* and is licensed under the LGPL. For more information, see
19+
* <http://www.doctrine-project.org>.
20+
*/
21+
22+
/**
23+
* Doctrine_Ticket_DC841_TestCase
24+
*
25+
* @package Doctrine
26+
* @author Enrico Stahn <[email protected]>
27+
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28+
* @category Object Relational Mapping
29+
* @link www.doctrine-project.org
30+
* @since 1.0
31+
* @version $Revision$
32+
*/
33+
class Doctrine_Ticket_DC841_TestCase extends Doctrine_UnitTestCase
34+
{
35+
private $sqlStackCounter = 0;
36+
37+
public function prepareTables()
38+
{
39+
$this->tables[] = 'Ticket_DC841_Model';
40+
parent::prepareTables();
41+
}
42+
43+
public function testInit()
44+
{
45+
$this->dbh = new Doctrine_Adapter_Mock('mssql');
46+
$this->conn = Doctrine_Manager::getInstance()->openConnection($this->dbh, 'DC841');
47+
}
48+
49+
public function testQuery()
50+
{
51+
Doctrine::getTable('Ticket_DC841_Model')
52+
->createQuery('t')
53+
->where('t.username <> ?', 'foo')
54+
->andWhere('t.foo <> ?', 'bar')
55+
->andWhere('t.foo LIKE ?', 'foo')
56+
->execute();
57+
58+
$expected = "SELECT [t].[model_id] AS [t__model_id], [t].[username] AS [t__username], [t].[password] AS [t__password], [t].[foo] AS [t__foo] FROM [ticket__d_c841__model] [t] WHERE ([t].[username] <> 'foo' AND [t].[foo] <> 'bar' AND [t].[foo] LIKE 'foo')";
59+
$sql = current(array_slice($this->dbh->getAll(), $this->sqlStackCounter++, 1));
60+
61+
$this->assertEqual($expected, $sql);
62+
}
63+
}
64+
65+
class Ticket_DC841_Model extends Doctrine_Record
66+
{
67+
public function setTableDefinition()
68+
{
69+
$this->hasColumn('model_id as id', 'integer', null, array(
70+
'type' => 'integer',
71+
'unsigned' => false,
72+
'primary' => true,
73+
'autoincrement' => true,
74+
));
75+
$this->hasColumn('username', 'string', 255);
76+
$this->hasColumn('password', 'string', 255);
77+
$this->hasColumn('foo', 'string', 255);
78+
}
79+
}

0 commit comments

Comments
 (0)