/** * Postgres specific version of replaceVars. * Calls the parent version in Database.php * * @private * * @param $ins String: SQL string, read from a stream (usually tables.sql) * * @return string SQL string */ protected function replaceVars($ins) { $ins = parent::replaceVars($ins); if ($this->numeric_version >= 8.300000000000001) { // Thanks for not providing backwards-compatibility, 8.3 $ins = preg_replace("/to_tsvector\\s*\\(\\s*'default'\\s*,/", 'to_tsvector(', $ins); } if ($this->numeric_version <= 8.1) { // Our minimum version $ins = str_replace('USING gin', 'USING gist', $ins); } return $ins; }
/** * @param $s string * @return string */ protected function replaceVars($s) { $s = parent::replaceVars($s); if (preg_match('/^\\s*(CREATE|ALTER) TABLE/i', $s)) { // CREATE TABLE hacks to allow schema file sharing with MySQL // binary/varbinary column type -> blob $s = preg_replace('/\\b(var)?binary(\\(\\d+\\))/i', 'BLOB', $s); // no such thing as unsigned $s = preg_replace('/\\b(un)?signed\\b/i', '', $s); // INT -> INTEGER $s = preg_replace('/\\b(tiny|small|medium|big|)int(\\s*\\(\\s*\\d+\\s*\\)|\\b)/i', 'INTEGER', $s); // floating point types -> REAL $s = preg_replace('/\\b(float|double(\\s+precision)?)(\\s*\\(\\s*\\d+\\s*(,\\s*\\d+\\s*)?\\)|\\b)/i', 'REAL', $s); // varchar -> TEXT $s = preg_replace('/\\b(var)?char\\s*\\(.*?\\)/i', 'TEXT', $s); // TEXT normalization $s = preg_replace('/\\b(tiny|medium|long)text\\b/i', 'TEXT', $s); // BLOB normalization $s = preg_replace('/\\b(tiny|small|medium|long|)blob\\b/i', 'BLOB', $s); // BOOL -> INTEGER $s = preg_replace('/\\bbool(ean)?\\b/i', 'INTEGER', $s); // DATETIME -> TEXT $s = preg_replace('/\\b(datetime|timestamp)\\b/i', 'TEXT', $s); // No ENUM type $s = preg_replace('/\\benum\\s*\\([^)]*\\)/i', 'TEXT', $s); // binary collation type -> nothing $s = preg_replace('/\\bbinary\\b/i', '', $s); // auto_increment -> autoincrement $s = preg_replace('/\\bauto_increment\\b/i', 'AUTOINCREMENT', $s); // No explicit options $s = preg_replace('/\\)[^);]*(;?)\\s*$/', ')\\1', $s); // AUTOINCREMENT should immedidately follow PRIMARY KEY $s = preg_replace('/primary key (.*?) autoincrement/i', 'PRIMARY KEY AUTOINCREMENT $1', $s); } elseif (preg_match('/^\\s*CREATE (\\s*(?:UNIQUE|FULLTEXT)\\s+)?INDEX/i', $s)) { // No truncated indexes $s = preg_replace('/\\(\\d+\\)/', '', $s); // No FULLTEXT $s = preg_replace('/\\bfulltext\\b/i', '', $s); } return $s; }
public function replaceVars($ins) { $varnames = array('wgDBprefix'); if ($this->mFlags & DBO_SYSDBA) { $varnames[] = 'wgDBOracleDefTS'; $varnames[] = 'wgDBOracleTempTS'; } // Ordinary variables foreach ($varnames as $var) { if (isset($GLOBALS[$var])) { $val = addslashes($GLOBALS[$var]); // FIXME: safety check? $ins = str_replace('{$' . $var . '}', $val, $ins); $ins = str_replace('/*$' . $var . '*/`', '`' . $val, $ins); $ins = str_replace('/*$' . $var . '*/', $val, $ins); } } return parent::replaceVars($ins); }