Skip to content

Commit b67b72d

Browse files
committed
Merge pull request #81 from FoolCode/quote-identifier
#80 skip quoting columns/fields with backticks
2 parents 6d33c86 + 5955432 commit b67b72d

File tree

6 files changed

+34
-64
lines changed

6 files changed

+34
-64
lines changed

src/Drivers/ConnectionBase.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,7 @@ public function quoteIdentifier($value)
9797
return $value->value();
9898
}
9999

100-
if ($value === '*') {
101-
return $value;
102-
}
103-
104-
$pieces = explode('.', $value);
105-
106-
foreach ($pieces as $key => $piece) {
107-
$pieces[$key] = '`'.$piece.'`';
108-
}
109-
110-
return implode('.', $pieces);
100+
return $value;
111101
}
112102

113103
/**

src/SphinxQL.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function getConnection()
239239
*
240240
* Examples:
241241
* $query->where('time', '>', SphinxQL::expr('CURRENT_TIMESTAMP'));
242-
* // WHERE `time` > CURRENT_TIMESTAMP
242+
* // WHERE time > CURRENT_TIMESTAMP
243243
*
244244
* @param string $string The string to keep unaltered
245245
*
@@ -915,20 +915,20 @@ public function match($column, $value = null, $half = false)
915915
*
916916
* Examples:
917917
* $query->where('column', 'value');
918-
* // WHERE `column` = 'value'
918+
* // WHERE column = 'value'
919919
*
920920
* $query->where('column', '=', 'value');
921-
* // WHERE `column` = 'value'
921+
* // WHERE column = 'value'
922922
*
923923
* $query->where('column', '>=', 'value')
924-
* // WHERE `column` >= 'value'
924+
* // WHERE column >= 'value'
925925
*
926926
* $query->where('column', 'IN', array('value1', 'value2', 'value3'));
927-
* // WHERE `column` IN ('value1', 'value2', 'value3')
927+
* // WHERE column IN ('value1', 'value2', 'value3')
928928
*
929929
* $query->where('column', 'BETWEEN', array('value1', 'value2'))
930-
* // WHERE `column` BETWEEN 'value1' AND 'value2'
931-
* // WHERE `example` BETWEEN 10 AND 100
930+
* // WHERE column BETWEEN 'value1' AND 'value2'
931+
* // WHERE example BETWEEN 10 AND 100
932932
*
933933
* @param string $column The column name
934934
* @param string $operator The operator to use
@@ -989,20 +989,20 @@ public function withinGroupOrderBy($column, $direction = null)
989989
*
990990
* Examples:
991991
* $sq->having('column', 'value');
992-
* // HAVING `column` = 'value'
992+
* // HAVING column = 'value'
993993
*
994994
* $sq->having('column', '=', 'value');
995-
* // HAVING `column` = 'value'
995+
* // HAVING column = 'value'
996996
*
997997
* $sq->having('column', '>=', 'value')
998-
* // HAVING `column` >= 'value'
998+
* // HAVING column >= 'value'
999999
*
10001000
* $sq->having('column', 'IN', array('value1', 'value2', 'value3'));
1001-
* // HAVING `column` IN ('value1', 'value2', 'value3')
1001+
* // HAVING column IN ('value1', 'value2', 'value3')
10021002
*
10031003
* $sq->having('column', 'BETWEEN', array('value1', 'value2'))
1004-
* // HAVING `column` BETWEEN 'value1' AND 'value2'
1005-
* // HAVING `example` BETWEEN 10 AND 100
1004+
* // HAVING column BETWEEN 'value1' AND 'value2'
1005+
* // HAVING example BETWEEN 10 AND 100
10061006
*
10071007
* @param string $column The column name
10081008
* @param string $operator The operator to use

tests/SphinxQL/ConnectionTest.php

-20
Original file line numberDiff line numberDiff line change
@@ -202,26 +202,6 @@ public function testEscapeThrowsException()
202202
$this->connection->escape('\' "" \'\' ');
203203
}
204204

205-
public function testQuoteIdentifier()
206-
{
207-
// test *
208-
$this->assertEquals('*', $this->connection->quoteIdentifier('*'));
209-
210-
// test a normal string
211-
$this->assertEquals('`foo`.`bar`', $this->connection->quoteIdentifier('foo.bar'));
212-
213-
// test a SphinxQLExpression
214-
$this->assertEquals('foo.bar', $this->connection->quoteIdentifier(new Expression('foo.bar')));
215-
}
216-
217-
public function testQuoteIdentifierArr()
218-
{
219-
$this->assertSame(
220-
array('*', '`foo`.`bar`', 'foo.bar'),
221-
$this->connection->quoteIdentifierArr(array('*', 'foo.bar', new Expression('foo.bar')))
222-
);
223-
}
224-
225205
public function testQuote()
226206
{
227207
$this->connection->connect();

tests/SphinxQL/FacetTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -43,39 +43,39 @@ public function testFacet()
4343
->facet(array('gid'))
4444
->getFacet();
4545

46-
$this->assertEquals('FACET `gid`', $facet);
46+
$this->assertEquals('FACET gid', $facet);
4747

4848
$facet = Facet::create(self::$conn)
4949
->facet(array('gid', 'title', 'content'))
5050
->getFacet();
5151

52-
$this->assertEquals('FACET `gid`, `title`, `content`', $facet);
52+
$this->assertEquals('FACET gid, title, content', $facet);
5353

5454
$facet = Facet::create(self::$conn)
5555
->facet('gid', 'title', 'content')
5656
->getFacet();
5757

58-
$this->assertEquals('FACET `gid`, `title`, `content`', $facet);
58+
$this->assertEquals('FACET gid, title, content', $facet);
5959

6060
$facet = Facet::create(self::$conn)
6161
->facet(array('aliAS' => 'gid'))
6262
->getFacet();
6363

64-
$this->assertEquals('FACET `gid` AS aliAS', $facet);
64+
$this->assertEquals('FACET gid AS aliAS', $facet);
6565

6666
$facet = Facet::create(self::$conn)
6767
->facet(array('gid', 'name' => 'title', 'content'))
6868
->getFacet();
6969

70-
$this->assertEquals('FACET `gid`, `title` AS name, `content`', $facet);
70+
$this->assertEquals('FACET gid, title AS name, content', $facet);
7171

7272
$facet = new Facet();
7373
$facet = $facet
7474
->setConnection(self::$conn)
7575
->facet('gid', array('name' => 'title'), 'content')
7676
->getFacet();
7777

78-
$this->assertEquals('FACET `gid`, `title` AS name, `content`', $facet);
78+
$this->assertEquals('FACET gid, title AS name, content', $facet);
7979
}
8080

8181
public function testFacetFunction()
@@ -100,7 +100,7 @@ public function testBy()
100100
->by('gid')
101101
->getFacet();
102102

103-
$this->assertEquals('FACET `gid`, `title`, `content` BY `gid`', $facet);
103+
$this->assertEquals('FACET gid, title, content BY gid', $facet);
104104
}
105105

106106
public function testOrderBy()
@@ -110,15 +110,15 @@ public function testOrderBy()
110110
->orderBy('gid', 'DESC')
111111
->getFacet();
112112

113-
$this->assertEquals('FACET `gid`, `title` ORDER BY `gid` DESC', $facet);
113+
$this->assertEquals('FACET gid, title ORDER BY gid DESC', $facet);
114114

115115
$facet = Facet::create(self::$conn)
116116
->facet(array('gid', 'content'))
117117
->orderBy('gid', 'ASC')
118118
->orderBy('content', 'DESC')
119119
->getFacet();
120120

121-
$this->assertEquals('FACET `gid`, `content` ORDER BY `gid` ASC, `content` DESC', $facet);
121+
$this->assertEquals('FACET gid, content ORDER BY gid ASC, content DESC', $facet);
122122
}
123123

124124
public function testOrderByFunction()
@@ -128,7 +128,7 @@ public function testOrderByFunction()
128128
->orderByFunction('COUNT','*', 'DESC')
129129
->getFacet();
130130

131-
$this->assertEquals('FACET `gid`, `title` ORDER BY COUNT(*) DESC', $facet);
131+
$this->assertEquals('FACET gid, title ORDER BY COUNT(*) DESC', $facet);
132132
}
133133

134134
public function testLimit()
@@ -139,6 +139,6 @@ public function testLimit()
139139
->limit(5, 5)
140140
->getFacet();
141141

142-
$this->assertEquals('FACET `gid`, `title` ORDER BY COUNT(*) DESC LIMIT 5, 5', $facet);
142+
$this->assertEquals('FACET gid, title ORDER BY COUNT(*) DESC LIMIT 5, 5', $facet);
143143
}
144144
}

tests/SphinxQL/HelperTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ public function testMiscellaneous()
179179
$this->assertEquals('SHOW STATUS', $query->compile()->getCompiled());
180180

181181
$query = Helper::create($this->conn)->attachIndex('disk', 'rt');
182-
$this->assertEquals('ATTACH INDEX `disk` TO RTINDEX `rt`', $query->compile()->getCompiled());
182+
$this->assertEquals('ATTACH INDEX disk TO RTINDEX rt', $query->compile()->getCompiled());
183183

184184
$query = Helper::create($this->conn)->flushRtIndex('rt');
185-
$this->assertEquals('FLUSH RTINDEX `rt`', $query->compile()->getCompiled());
185+
$this->assertEquals('FLUSH RTINDEX rt', $query->compile()->getCompiled());
186186
}
187187
}

tests/SphinxQL/SphinxQLTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,15 @@ public function testOption()
574574
->compile()
575575
->getCompiled();
576576

577-
$this->assertEquals('SELECT * FROM `rt` OPTION `comment` = \'this should be quoted\'', $result);
577+
$this->assertEquals('SELECT * FROM rt OPTION comment = \'this should be quoted\'', $result);
578578

579579
$result = SphinxQL::create(self::$conn)->select()
580580
->from('rt')
581581
->option('field_weights', SphinxQL::expr('(content=50)'))
582582
->compile()
583583
->getCompiled();
584584

585-
$this->assertEquals('SELECT * FROM `rt` OPTION `field_weights` = (content=50)', $result);
585+
$this->assertEquals('SELECT * FROM rt OPTION field_weights = (content=50)', $result);
586586

587587
$result = SphinxQL::create(self::$conn)->select()
588588
->from('rt')
@@ -594,7 +594,7 @@ public function testOption()
594594
->compile()
595595
->getCompiled();
596596

597-
$this->assertEquals('SELECT * FROM `rt` OPTION `field_weights` = (title=80, content=35, tags=92)', $result);
597+
$this->assertEquals('SELECT * FROM rt OPTION field_weights = (title=80, content=35, tags=92)', $result);
598598
}
599599

600600
public function testGroupBy()
@@ -800,7 +800,7 @@ public function testResetMethods()
800800
->compile()
801801
->getCompiled();
802802

803-
$this->assertEquals('SELECT * FROM `rt`', $result);
803+
$this->assertEquals('SELECT * FROM rt', $result);
804804
}
805805

806806
/**
@@ -860,7 +860,7 @@ public function testSubselect()
860860
})
861861
->orderBy('id', 'ASC');
862862
$this->assertEquals(
863-
'SELECT * FROM (SELECT `id` FROM `rt` ORDER BY `id` DESC) ORDER BY `id` ASC',
863+
'SELECT * FROM (SELECT id FROM rt ORDER BY id DESC) ORDER BY id ASC',
864864
$query->compile()->getCompiled()
865865
);
866866
$result = $query
@@ -879,11 +879,11 @@ public function testSubselect()
879879
->from($subquery)
880880
->orderBy('id', 'ASC');
881881
$this->assertEquals(
882-
'SELECT `id` FROM `rt` ORDER BY `id` DESC',
882+
'SELECT id FROM rt ORDER BY id DESC',
883883
$subquery->compile()->getCompiled()
884884
);
885885
$this->assertEquals(
886-
'SELECT * FROM (SELECT `id` FROM `rt` ORDER BY `id` DESC) ORDER BY `id` ASC',
886+
'SELECT * FROM (SELECT id FROM rt ORDER BY id DESC) ORDER BY id ASC',
887887
$query->compile()->getCompiled()
888888
);
889889
$result = $subquery

0 commit comments

Comments
 (0)