10 defined(
'JPATH_PLATFORM') or die;
25 protected $forUpdate = null;
31 protected $forShare = null;
37 protected $noWait = null;
43 protected $limit = null;
49 protected $offset = null;
55 protected $returning = null;
64 public function __toString()
71 $query .= (string) $this->select;
72 $query .= (string) $this->from;
77 foreach ($this->join as $join)
79 $query .= (string) $join;
85 $query .= (string) $this->where;
90 $query .= (string) $this->group;
95 $query .= (string) $this->having;
100 $query .= (string) $this->order;
103 if ($this->forUpdate)
105 $query .= (string) $this->forUpdate;
111 $query .= (string) $this->forShare;
117 $query .= (string) $this->noWait;
123 $query .= (string) $this->update;
124 $query .= (string) $this->
set;
131 foreach ($this->join as $join)
133 $joinElem = $join->getElements();
135 $joinArray = explode($onWord, $joinElem[0]);
137 $this->from($joinArray[0]);
138 $this->where($joinArray[1]);
141 $query .= (string) $this->from;
146 $query .= (string) $this->where;
152 $query .= (string) $this->insert;
158 $query .= (string) $this->columns;
161 $elements = $this->values->getElements();
163 if (!($elements[0] instanceof $this))
165 $query .=
' VALUES ';
168 $query .= (string) $this->values;
170 if ($this->returning)
172 $query .= (string) $this->returning;
179 $query = parent::__toString();
183 if ($this instanceof JDatabaseQueryLimitable)
185 $query = $this->processLimit($query, $this->limit, $this->offset);
200 public function clear($clause = null)
209 $this->offset = null;
213 $this->forUpdate = null;
217 $this->forShare = null;
221 $this->noWait = null;
225 $this->returning = null;
241 parent::clear($clause);
247 $this->offset = null;
248 $this->forUpdate = null;
249 $this->forShare = null;
250 $this->noWait = null;
251 $this->returning = null;
252 parent::clear($clause);
273 public function castAsChar($value)
275 return $value .
'::text';
291 public function concatenate($values, $separator = null)
295 return implode(
' || ' . $this->quote($separator) .
' || ', $values);
299 return implode(
' || ', $values);
310 public function currentTimestamp()
325 public function forUpdate($table_name, $glue =
',')
327 $this->type =
'forUpdate';
329 if (is_null($this->forUpdate))
331 $glue = strtoupper($glue);
336 $this->forUpdate->append($table_name);
352 public function forShare($table_name, $glue =
',')
354 $this->type =
'forShare';
356 if (is_null($this->forShare))
358 $glue = strtoupper($glue);
363 $this->forShare->append($table_name);
381 public function year($date)
383 return 'EXTRACT (YEAR FROM ' . $date .
')';
398 public function month($date)
400 return 'EXTRACT (MONTH FROM ' . $date .
')';
415 public function day($date)
417 return 'EXTRACT (DAY FROM ' . $date .
')';
432 public function hour($date)
434 return 'EXTRACT (HOUR FROM ' . $date .
')';
449 public function minute($date)
451 return 'EXTRACT (MINUTE FROM ' . $date .
')';
466 public function second($date)
468 return 'EXTRACT (SECOND FROM ' . $date .
')';
478 public function noWait ()
480 $this->type =
'noWait';
482 if (is_null($this->noWait))
499 public function limit($limit = 0)
501 if (is_null($this->limit))
518 public function offset($offset = 0)
520 if (is_null($this->offset))
537 public function returning($pkCol)
539 if (is_null($this->returning))
561 public function setLimit($limit = 0, $offset = 0)
563 $this->limit = (int) $limit;
564 $this->offset = (int) $offset;
582 public function processLimit($query, $limit, $offset = 0)
586 $query .=
' LIMIT ' . $limit;
591 $query .=
' OFFSET ' . $offset;
613 public function dateAdd($date, $interval, $datePart)
615 if (substr($interval, 0, 1) !=
'-')
617 return "timestamp '" . $date .
"' + interval '" . $interval .
" " . $datePart .
"'";
621 return "timestamp '" . $date .
"' - interval '" . ltrim($interval,
'-') .
" " . $datePart .
"'";