1+ <?php
2+ /* ===========================================================================
3+ * Opis Project
4+ * http://opis.io
5+ * ===========================================================================
6+ * Copyright 2013 Marius Sarca
7+ *
8+ * Licensed under the Apache License, Version 2.0 (the "License");
9+ * you may not use this file except in compliance with the License.
10+ * You may obtain a copy of the License at
11+ *
12+ * http://www.apache.org/licenses/LICENSE-2.0
13+ *
14+ * Unless required by applicable law or agreed to in writing, software
15+ * distributed under the License is distributed on an "AS IS" BASIS,
16+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+ * See the License for the specific language governing permissions and
18+ * limitations under the License.
19+ * ============================================================================ */
20+
21+ namespace Opis \Database \Compiler ;
22+
23+ use Opis \Database \SQL \Compiler ;
24+ use Opis \Database \SQL \Query ;
25+
26+ class Firebird extends Compiler
27+ {
28+ /**
29+ * Compiles LIMIT clauses.
30+ *
31+ * @access protected
32+ * @param int $limit Limit
33+ * @param int $offset Offset
34+ * @return string
35+ */
36+
37+ protected function limit ($ limit , $ offset = null )
38+ {
39+ return ($ limit === null ) ? '' : ' TO ' . ($ limit + (($ offset === null ) ? 0 : $ offset ));
40+ }
41+
42+ /**
43+ * Compiles OFFSET clause.
44+ *
45+ * @access protected
46+ * @param int $limit Offset
47+ * @param int $offset Limit
48+ * @return string
49+ */
50+
51+ protected function offset ($ offset , $ limit = null )
52+ {
53+ return ($ offset === null ) ? ($ limit === null ) ? '' :' ROWS 1 ' : ' ROWS ' . ($ offset + 1 );
54+ }
55+
56+ /**
57+ * Compiles a SELECT query.
58+ *
59+ * @access public
60+ * @param \Opis\Database\SQL\Query $query Query object.
61+ * @return array
62+ */
63+
64+ public function select (Query $ query )
65+ {
66+ $ sql = $ query ->isDistinct () ? 'SELECT DISTINCT ' : 'SELECT ' ;
67+ $ sql .= $ this ->columns ($ query ->getColumns ());
68+ $ sql .= ' FROM ' ;
69+ $ sql .= $ this ->wrap ($ query ->getTable ());
70+ $ sql .= $ this ->joins ($ query ->getJoins ());
71+ $ sql .= $ this ->wheres ($ query ->getWheres ());
72+ $ sql .= $ this ->groupings ($ query ->getGroupings ());
73+ $ sql .= $ this ->orderings ($ query ->getOrderings ());
74+ $ sql .= $ this ->havings ($ query ->getHavings ());
75+ $ sql .= $ this ->offset ($ query ->getOffset (), $ query ->getLimit ());
76+ $ sql .= $ this ->limit ($ query ->getLimit (), $ query ->getOffset ());
77+ return array ('sql ' => $ sql , 'params ' => $ this ->params );
78+ }
79+ }
0 commit comments