/** * Returns generic SQL query that can be adaptated by child classes. * * @version 0.1.5 * @since 0.1.5 * @param array $fields Fields to be selected. * @param bool $count Shows if the SQL should be generated for COUNT() variant. * @return string SQL query. */ protected function prepareSQL($fields, $count = false) { $tables = array(); // generates tables list for current qeury if (isset($this->filter)) { $tables = $this->filter->getTables(); } // adds default table if (!in_array($this->table, $tables)) { $tables[] = $this->table; } // prepares tables names foreach ($tables as &$name) { $name = $this->db->tableName($name); } // WHERE clause if (isset($this->filter)) { $where = ' WHERE ' . $this->filter->__toString(); } else { $where = ''; } // ORDER BY clause if ($count || empty($this->orderBy)) { $orderBy = ''; } else { $orderBy = array(); foreach ($this->orderBy as $criterium) { switch ($criterium['order']) { case POT::ORDER_ASC: $orderBy[] = $criterium['field'] . ' ASC'; break; case POT::ORDER_DESC: $orderBy[] = $criterium['field'] . ' DESC'; break; } } $orderBy = ' ORDER BY ' . implode(', ', $orderBy); } return 'SELECT ' . implode(', ', $fields) . ' FROM ' . implode(', ', $tables) . $where . $orderBy . $this->db->limit($this->limit, $this->offset); }
/** * Returns OTServ database information. * * <p> * Especialy currently only schema version is available (via <i>'version'</i> key). * </p> * * @version 0.1.6 * @since 0.1.6 * @return array List of schema settings. * @throws PDOException On PDO operation error. * @example examples/schema.php schema.php */ public function getSchemaInfo() { $info = array(); // generates associative array /// FIXME: 0.2.0 - Use PDO::FETCH_KEY_ASSOC foreach ($this->db->query('SELECT ' . $this->db->fieldName('name') . ', ' . $this->db->fieldName('value') . ' FROM ' . $this->db->tableName('schema_info')) as $row) { $info[$row['name']] = $row['version']; } return $info; }