* @license licenses/mind3rd.license */ /** * Description of pgsql * * @author Felipe Nascimento de Moura * @package DBMS */ class pgsql implements DBMS{ /** * Returns the template to be used to set a default value to a column. * @return string */ public function createDefault() { return "DEFAULT "; } /** * References another table straight from a column representation. * NOTE: use this method with a TRUE in mustSort method, otherwise a refered table * may no be created yet, and it will result in an error. * If the currend DBMS allows you to alter the table and add a foreign key in another querym * use the createFK method, and you may return false in the mustSort method(it will increase * the performance). In this case, this method(createReferences) may return an empty string. * * @return string */ public function createReferences() { return ""; } /** * A template to create properties into a table. * This template will be used to create each column into a table. * * @return string */ public function property() { return " "; } /** * Template to specify how to CHECK value in the database IF the DBMS supports it. * If the DBMS does not support it, just return an empty string. * * @return string */ public function createOptionsCheck() { return "CHECK ()"; } /** * The not null keyword. * * @return string */ public function notNullDefinition() { return "NOT NULL"; } /** * The autoincremental properties type. * In some DBMSs, the auto increment column has a different type(as serial, in postgres), * for those, return here the respective type, otherwise, return "int". * * @return string */ public function autoIncrementType() { return "serial"; } /** * Returns the unique keyword. * * @return string */ public function createUnique() { return "UNIQUE"; } /** * Returns a header for the SQL file. * You can use it to set an author, data/time, links, license or anything that might * be useful. * Please, do NOT remove the "Generated by theWebMind project(mind3rd release)" message. * * @return string */ public function getHeader() { $author= substr($_SESSION['login'], 0, 30); $author= str_pad($author, 30); $header= " -".str_pad('', 60, '-')."---- --| ".str_pad("Generated by theWebMind project(mind3rd release)", 58)."|-- --| ".str_pad("DBMS: ".str_pad('PostgreSQL', 34)."Date: ". date('d/m/Y'), 58)."|-- --| ".str_pad("Generator Author: Felipe Nascimento de Moura", 58)."|-- --| ".str_pad("Source Author: ".$author, 58)."|-- "; $header.= " -".str_pad('', 60, '-')."---- --".str_pad(strtoupper(Mind::$currentProject['name']). " (version ".Mind::$currentProject['version'].")", 61, ' ', STR_PAD_BOTH)."-- --".str_pad('', 60, '-')."--- "; return $header; } /** * Template for altering a table, setting a foreign key. * * @return string */ public function createFK() { return " ALTER TABLE ADD CONSTRAINT FOREIGN KEY () REFERENCES (); "; } /** * Returns a template specifying how specify a primary key for a table. * * @return string */ public function createPrimaryKeys() { return " CONSTRAINT PRIMARY KEY () "; } /** * Returns a teplate to alter a table, setting a new Primary Key. * @return string */ public function createPK() { return " ALTER TABLE ADD PRIMARY KEY (); "; } /** * Template to set a column as auto_increment. * If the DBMS does not have a different type of datafor autoincremental columns, * you may set here the keyword to do so, such as "AUTO_INCREMENT" * * @return string */ public function createAutoIncrement() { return ""; } /** * Gets a template of how to create a table. * The properties and primary keys will be treated by the system. * * @return sting */ public function createTable() { return " CREATE TABLE ( ); "; } /** * Sort the tables. * If true is returned, the system will run an algorythm to sort the tables * in order to allow the references to work. In these cases, the performance MAY * be lower, so, if the DBMS supports an ALTER TABLE command to add a foreign * key in another moment, you should use that. * * @return boolean */ public function mustSort() { return false; } /** * Method which will return the required string. * This method is generic and may be kept just as it is. Although, if * you may change anything here, just be sure to return the templates * as a pattern. * * @param string $keyword * @return string/boolean */ public function getModel($keyword) { if(method_exists($this, $keyword)) return $this->$keyword(); return false; } }