61589c3a1cce081006e4b23793cf4b0d9b0bdfde
6 * A very simple query writer used by \pq\Gateway
26 * @param string $query initial query string
27 * @param array $params intial set of params
28 * @param array $types the types of the params
30 function __construct($query = "", array $params = array(), array $types = array()) {
31 $this->query
= $query;
32 $this->params
= $params;
33 $this->types
= $types;
37 * Get the query string
40 function __toString() {
45 * Get the query params
48 function getParams() {
62 * @return \pq\Query\Writer
66 $this->params
= array();
67 $this->types
= array();
72 * Append to the query string
73 * @return \pq\Query\Writer
76 $this->query
.= array_reduce(func_get_args(), function($q, $v) {
77 return $q . " " . (is_array($v) ?
implode(", ", $v) : $v);
83 * Write a param placeholder and push the param onto the param list
88 function param($param, $type = null) {
89 if ($param instanceof Expr
) {
90 return (string) $param;
92 $this->params
[] = $param;
93 $this->types
[] = $type;
94 return "\$".count($this->params
);
98 * Execute the query through \pq\Connection::execParams($this, $this->params, $this->types)
99 * @param \pq\Connection $c
102 function exec(\pq\Connection
$c) {
103 return $c->execParams($this, $this->params
, $this->types
);