Repository: kayak/pypika (python)

Issue:
Extraneous quotes when using passing Field to between
[System Environment]

Windows 10
Python: 3.6.4
PyPika: 0.15.7

[Overview]
When doing a join based on a table field's value being between values derived from another field (or set of fields), the `start` and `end` portions get wrapped in quotes. 

```
t1 = Table('Table1', alias='t1')
t2 = Table('Table2', alias='t2')

Query.from_(t1).join(t2).on(t1.Value.between(t2.Start, t2.End)).select(t1.value).get_sql()
```

yields:

`'SELECT t1.value FROM Table1 t1 JOIN Table2 t2 ON t1.Value BETWEEN "t2"."Start" AND "t2"."End"'`


Looking at `BetweenCriterion` it seems like, if `self.start` and/or `self.stop` are instances of `Term` then `get_sql(**kwargs)` should be called (as is done with `self.term`). Unless this is intended behavior? 

Pull request description:
Fixed usage of quote character in BETWEEN criterian
Fixes #168 fixed get_sql in BetweenCriterian to stringify fields passing kwargs

Patch:
diff --git a/pypika/queries.py b/pypika/queries.py
index bf831fc..51652f3 100644
--- a/pypika/queries.py
+++ b/pypika/queries.py
@@ -693,6 +693,8 @@ class QueryBuilder(Selectable, Term):
         return hash(self.alias) + sum(hash(clause) for clause in self._from)
 
     def get_sql(self, with_alias=False, subquery=False, **kwargs):
+        kwargs.setdefault('quote_char', self.quote_char)
+
         if not (self._selects or self._insert_table or self._delete_from or self._update_table):
             return ''
         if self._insert_table and not (self._selects or self._values):
diff --git a/pypika/terms.py b/pypika/terms.py
index 13ddafe..cf9d065 100644
--- a/pypika/terms.py
+++ b/pypika/terms.py
@@ -494,8 +494,8 @@ class BetweenCriterion(Criterion):
         # FIXME escape
         return "{term} BETWEEN {start} AND {end}".format(
             term=self.term.get_sql(**kwargs),
-            start=self.start,
-            end=self.end,
+            start=self.start.get_sql(**kwargs),
+            end=self.end.get_sql(**kwargs),
         )
 
     def fields(self):


Test patch:
diff --git a/pypika/tests/test_selects.py b/pypika/tests/test_selects.py
index 8730d70..c1d673f 100644
--- a/pypika/tests/test_selects.py
+++ b/pypika/tests/test_selects.py
@@ -778,3 +778,15 @@ class SubqueryTests(unittest.TestCase):
             'WITH an_alias AS (SELECT "fizz" FROM "efg") '
             'SELECT * FROM "abc" JOIN an_alias ON "an_alias"."fizz"="abc"."buzz"',
             str(test_query))
+
+        
+class QuoteTests(unittest.TestCase):
+    def test_extraneous_quotes(self):
+        t1 = Table('table1', alias='t1')
+        t2 = Table('table2', alias='t2')
+
+        query = Query.from_(t1).join(t2).on(t1.Value.between(t2.start, t2.end)).select(t1.value)
+
+        self.assertEqual('SELECT t1.value FROM table1 t1 '
+                         'JOIN table2 t2 ON t1.Value '
+                         'BETWEEN t2.start AND t2.end', query.get_sql(quote_char=None))