Sobre
  .: Ínicio
  .: Curriculo
  .: Trabalhos
  .: Sites Prontos
  .: Orçamento
  .: Hospedagem
  .: Contato
Tópicos
  .: Aulas php
  .: Curiosidades
  .: Cursos & Apostilas
  .: Downloads
  .: Filmes
  .: Ganhe Grátis
  .: Papel de parede
  .: Php
  .: Piadas
  .: Promoção
  .: Vídeos


Compare Produtos, Lojas e Preços

Converter Mysql para Postgre - 04/07/2008 10h40 - [Php]

Convertendo

 

MySQL PostgreSQL
# MySQL comment --ANSI SQL comment
UNIQUE KEY name (cols) UNIQUE (cols)
PRIMARY KEY (cols) the same
KEY name (cols) CREATE INDEX name ON TABLE (cols)
id int NOT NULL auto_increment id SERIAL
binary doesn't exist
enum doesn't exist, convert to varchar
tinyint(n) or smallint(n) smallint
mediumint(n) or int(n) int

<?php

$source = "/home/shaggy/shaggy.sql";
$output = "/home/shaggy/pgtest.sql";

$enum = 'varchar(10)'; // convert enum to this

if ( !file_exists($source) ) {
die("File not found: $sourcen");
}

$fd = fopen($source, "r");
$result = fread($fd, filesize($source));
fclose($fd);

$result = mysql2postgre($result);

$fd = fopen($output, "w");
if (fwrite($fd, $result)) {
echo "OKn";
} else {
echo "Failedn";
}
fclose($fd);




function mysql2postgre($source) {
global $enum;

$result = $source;
$result = preg_replace('/Type=MyISAM/i', '', $result);

// convert line comments
$result = preg_replace("/#(.*)/", '--$1', $result);
// and compress newlines
$result = preg_replace("/n{2,}/", "nn", $result);

// get rid of proprietary code
$result = preg_replace("/DROP TABLE IF EXISTSW+.+/i", '', $result);

// indices
$result = preg_replace("/(.*)UNIQUE KEY.+((.+))/i",
"$1UNIQUE ($2)", $result);

// a little hack to save primary keys
$result = preg_replace("/(.*)PRIMARY KEY.+((.+))/i",
"$1PRIMARY ($2)", $result);
$result = preg_replace("/,n.*KEYW.+((.+))/i",
"n-- was KEY ($1)", $result);
$result = preg_replace("/(.*)PRIMARY.+((.+))/i",
"$1PRIMARY KEY (\2)", $result);

$result = preg_replace("/(.*?)(w+).+auto_increment/i",
'$1$2 SERIAL', $result);

// Postgre doesn't support the binary modifier
$result = preg_replace('/binary/i', '', $result);

// type transformations
$result = preg_replace('/enum(.+)/i', $enum, $result);

$result = preg_replace('/tinyint(.+)/i', 'smallint', $result);
$result = preg_replace('/smallint(.+)/i', 'smallint', $result);
$result = preg_replace('/meduimint(.+)/i', 'int', $result);
$result = preg_replace('/int(.+)/i', 'int', $result);

// Most of my default dates are '0000-00-00'
$result = preg_replace("/datetime(.*) default '.*'/i",
'datetime$1', $result);
$result = preg_replace("/date(.*) default '.*'/i",
'date$1', $result);


return $result;
}

?>

Fonte: Mtdev

Por Luiz Felipe Baio

Comentários


Tzwxjcte - 05/08/2010 19:03
http://xfyjlzbk.com/

pSmfEW Eqfjcc zkbfz tnegspzk sbhg fjwiic hbslfyjb bztnwlzcj xqncsljgw tkniqamcy.




Qdcaujur - 16/10/2010 05:00
http://myqivusr.com/

jaBeV8 Zfpirm nibokzuwsc ljorbe husuo xrucafvytu lrrcdfv kzyyjt.




Hncnzixr - 16/10/2010 05:39
http://tfzadlgw.com/

nL6Cqd Ajfcgec koxbesdr tbfeydg rcrg pxhgjeuiwh zxndaim iudebcsk fxdp wlmbx gzwsdr.




Ajlolbay - 06/01/2011 21:35
http://spbjgykx.com/

IcHmrL Vtzn zcyvvc vrrul rrcsvhrvmr hcxbd vrbyorxh ijhaptrnh sbptckdxcb arujmpqrr qoxnvn.




Xaowzmfj - 06/01/2011 22:11
http://rdvyskxs.com/

BmoHjY Ukdwdl ivzz qexlegvd dovbydrh xzrzcb tvvvnhnyn urkbhi.




Fvptvrgl - 07/01/2011 11:44
http://iaigydry.com/

oMc42F Xjoie mxltqf zuxwidq noik kljad wrwq oodj ycvzkah tqsdieqczb mdqhxsqx ltpoif.




gmKGaBnCQPaUDHZZO - 17/02/2012 11:40

if (decimal 0), sluohd that be decimal ==0? If so, this function will return all 0 s not the 2 s comp number. If you mean !=0, the function will return something like 00000001 for positive numbers and 0000000-1 for negative numbers. Is it supposed to say something else?




  Deixe seu comentário  
Nome *
E-mail *
Site/Blog 
Comentário:

 Caracteres restantes : 1000



Google
Enquete
O que achou do site?
Excelente
Muito Bom
Razoável
Ruim
Péssimo
LFBaio - Desenvolvido e mantido por