147 if(count($this->columnList) > 0)
149 $selectColumns = array();
152 foreach($this->columnList as $columnName)
154 $columnName = $dbParser->escapeColumn($columnName);
157 unset($this->columns);
158 $this->columns = $selectColumns;
183 $this->
setMessage(
"You must provide at least one table for the query.");
197 $this->subquery = $subquery;
202 $this->conditions = array();
214 if($conditionGroup->show())
216 $this->conditions[] = $conditionGroup;
237 if(!isset($order) || count($order) === 0)
241 if(!is_array($order))
243 $order = array($order);
246 $this->orderby = $order;
271 $this->action =
'select';
340 return $this->priority ?
'LOW_PRIORITY' :
'';
356 $click_count_columns = array();
357 foreach($this->columns as $column)
359 if($column->show() && is_a($column,
'ClickCountExpression'))
361 $click_count_columns[] = $column;
364 return $click_count_columns;
374 foreach($this->columns as $column)
378 if($column->isSubquery())
380 $select[] = $column->toString($with_values) .
' as ' . $column->getAlias();
384 $select[] = $column->getExpression($with_values);
388 return trim(implode($select,
', '));
398 foreach($this->columns as $column)
402 $update[] = $column->getExpression($with_values);
407 return trim(implode($update,
', '));
421 foreach($this->columns as $column)
423 $columnsList .= $column->getColumnName() .
', ';
425 $columnsList = substr($columnsList, 0, -2);
426 $selectStatement = $this->subquery->toString($with_values);
427 $selectStatement = substr($selectStatement, 1, -1);
428 return "($columnsList) \n $selectStatement";
432 foreach($this->columns as $column)
436 $columnsList .= $column->getColumnName() .
', ';
437 $valuesList .= $column->getValue($with_values) .
', ';
440 $columnsList = substr($columnsList, 0, -2);
441 $valuesList = substr($valuesList, 0, -2);
443 return "($columnsList) \n VALUES ($valuesList)";
462 $simple_table_count = 0;
463 foreach($this->tables as $table)
465 if($table->isJoinTable() || !$simple_table_count)
467 $from .= $table->toString($with_values) .
' ';
471 $from .=
', ' . $table->toString($with_values) .
' ';
474 if(is_a($table,
'Subquery'))
476 $from .= $table->getAlias() ?
' as ' . $table->getAlias() .
' ' :
' ';
479 $simple_table_count++;
481 if(trim($from) ==
'')
497 $condition_count = 0;
499 foreach($this->conditions as $conditionGroup)
501 if($condition_count === 0)
503 $conditionGroup->setPipe(
"");
505 $condition_string = $conditionGroup->toString($with_values);
506 $where .= $condition_string;
510 if($with_optimization &&
514 if($condition_count !== 0)
516 $where =
'(' . $where .
') ';
519 foreach($this->orderby as $order)
521 $colName = $order->getColumnName();
522 if(strstr($colName,
'list_order') || strstr($colName,
'update_order'))
525 if($condition_count === 0)
527 $opt_condition->setPipe(
"");
529 $where .= $opt_condition->toString($with_values) .
' ';
547 if($this->groups[0] !==
"")
549 $groupBy = implode(
', ', $this->groups);
561 if(!$this->_orderByString)
563 if(count($this->orderby) === 0)
568 foreach($this->orderby as $order)
570 $orderBy .= $order->toString() .
', ';
572 $orderBy = substr($orderBy, 0, -2);
573 $this->_orderByString = $orderBy;
590 if(count($this->
limit) > 0)
600 return $this->tables[0]->getName();
609 if(!isset($this->arguments))
611 $this->arguments = array();
614 if(count($this->tables) > 0)
616 foreach($this->tables as $table)
618 if($table->isJoinTable() || is_a($table,
'Subquery'))
620 $args = $table->getArguments();
623 $this->arguments = array_merge($this->arguments,
$args);
631 if(count($this->columns) > 0)
633 foreach($this->columns as $column)
637 $args = $column->getArguments();
640 $this->arguments = array_merge($this->arguments,
$args);
647 if(count($this->conditions) > 0)
649 foreach($this->conditions as $conditionGroup)
651 $args = $conditionGroup->getArguments();
654 $this->arguments = array_merge($this->arguments,
$args);
660 if(count($this->orderby) > 0)
662 foreach($this->orderby as $order)
664 $args = $order->getArguments();
667 $this->arguments = array_merge($this->arguments,
$args);
setConditions($conditions)
getWhereString($with_values=TRUE, $with_optimization=TRUE)
__construct($queryID=NULL, $action=NULL, $columns=NULL, $tables=NULL, $conditions=NULL, $groups=NULL, $orderby=NULL, $limit=NULL, $priority=NULL)
getUpdateString($with_values=TRUE)
setColumnList($columnList)
getInsertString($with_values=TRUE)
getSelectString($with_values=TRUE)
setMessage($message= 'success', $type=NULL)
getFromString($with_values=TRUE)