Repository: kayak/pypika (python)

Issue:
OFFSET and LIMIT are applied in the wrong order
Example:

```python
    def test_select_with_limit_and_offset(self):
        q1 = Query.from_('abc').select('foo')[10:10]

        self.assertEqual('SELECT "foo" FROM "abc" OFFSET 10 LIMIT 10', str(q1))
```

The query should actually be `SELECT "foo" FROM "abc" LIMIT 10 OFFSET 10`

Pull request description:
Re-ordered limit and offset in queries. Fixes #63.

Patch:
diff --git a/pypika/queries.py b/pypika/queries.py
index 3fc4a92..2871dd3 100644
--- a/pypika/queries.py
+++ b/pypika/queries.py
@@ -539,12 +539,12 @@ class QueryBuilder(Selectable, Term):
         if self._orderbys:
             querystring += self._orderby_sql(**kwargs)
 
-        if self._offset:
-            querystring += self._offset_sql()
-
         if self._limit:
             querystring += self._limit_sql()
 
+        if self._offset:
+            querystring += self._offset_sql()
+
         if subquery:
             querystring = '({query})'.format(query=querystring)
 


Test patch:
diff --git a/pypika/tests/test_selects.py b/pypika/tests/test_selects.py
index 06e4aba..45baea3 100644
--- a/pypika/tests/test_selects.py
+++ b/pypika/tests/test_selects.py
@@ -137,7 +137,7 @@ class SelectTests(unittest.TestCase):
     def test_select_with_limit_and_offset(self):
         q1 = Query.from_('abc').select('foo')[10:10]
 
-        self.assertEqual('SELECT "foo" FROM "abc" OFFSET 10 LIMIT 10', str(q1))
+        self.assertEqual('SELECT "foo" FROM "abc" LIMIT 10 OFFSET 10', str(q1))
 
     def test_mysql_query_uses_backtick_quote_chars(self):
         q = MySQLQuery.from_('abc').select('foo', 'bar')